diff options
author | Andi Kleen <andi@firstfloor.org> | 2010-01-13 17:02:44 +0100 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2010-02-02 14:33:55 +0100 |
commit | e66f25d7d1be19e177cf55126a40799757efae89 (patch) | |
tree | c60ae380f0ee00ab56dc821dcff56037980a38fd /scripts/kconfig/expr.h | |
parent | 62718979780720e526a411dc66e810288aaa7bf6 (diff) |
Improve kconfig symbol hashing
While looking for something else I noticed that the symbol
hash function used by kconfig is quite poor. It doesn't
use any of the standard hash techniques but simply
adds up the string and then uses power of two masking,
which is both known to perform poorly.
The current x86 kconfig has over 7000 symbols.
When I instrumented it showed that the minimum hash chain
length was 16 and a significant number of them was over
30.
It didn't help that the hash table size was only 256 buckets.
This patch increases the hash table size to a larger prime
and switches to a FNV32 hash. I played around with a couple of hash
functions, but that one seemed to perform best with reasonable
hash table sizes.
Increasing the hash table size even further didn't
seem like a good idea, because there are a couple of global
walks which walk the complete hash table.
I also moved the unnamed bucket to 0. It's still the longest
of all the buckets (44 entries), but hopefully it's not
often hit except for the global walk which doesn't care.
The result is a much nicer distribution:
(first column bucket length, second number of buckets with that length)
1: 3505
2: 1236
3: 294
4: 52
5: 3
47: 1 <--- this is the unnamed symbols bucket
There are still some 5+ buckets, but increasing the hash table
even more would be likely not worth it.
This also cleans up the code slightly by removing hard coded
magic numbers.
I didn't notice a big performance difference either way
on my Nehalem system, but I presume it'll help somewhat
on slower systems.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig/expr.h')
-rw-r--r-- | scripts/kconfig/expr.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 6408fefae083..891cd9ce9ba2 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -86,7 +86,7 @@ struct symbol { struct expr_value rev_dep; }; -#define for_all_symbols(i, sym) for (i = 0; i < 257; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER) +#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER) #define SYMBOL_CONST 0x0001 /* symbol is const */ #define SYMBOL_CHECK 0x0008 /* used during dependency checking */ @@ -108,8 +108,7 @@ struct symbol { #define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */ #define SYMBOL_MAXLENGTH 256 -#define SYMBOL_HASHSIZE 257 -#define SYMBOL_HASHMASK 0xff +#define SYMBOL_HASHSIZE 9973 /* A property represent the config options that can be associated * with a config "symbol". |