start_kernel---lockdep_init<三>
1 /*
2 * Need to run as early as possible, to initialize the
3 * lockdep hash:
4 */
5 lockdep_init();
位于kernel/lockdep.c
1 void lockdep_init(void)
2 {
3 int i;
4
5 /*
6 * Some architectures have their own start_kernel()
7 * code which calls lockdep_init(), while we also
8 * call lockdep_init() from the start_kernel() itself,
9 * and we want to initialize the hashes only once:
10 */
11 if (lockdep_initialized)
12 return;
13
14 for (i = 0; i < CLASSHASH_SIZE; i++)
15 INIT_LIST_HEAD(classhash_table + i);
16
17 for (i = 0; i < CHAINHASH_SIZE; i++)
18 INIT_LIST_HEAD(chainhash_table + i);
19
20 lockdep_initialized = 1;
21 }
只初始化该哈希表一次,
1 /*
2 * The lockdep classes are in a hash-table as well, for fast lookup:
3 */
4 #define CLASSHASH_BITS (MAX_LOCKDEP_KEYS_BITS - 1)
5 #define CLASSHASH_SIZE (1UL << CLASSHASH_BITS)
6 #define __classhashfn(key) hash_long((unsigned long)key, CLASSHASH_BITS)
7 #define classhashentry(key) (classhash_table + __classhashfn((key)))
8
9 static struct list_head classhash_table[CLASSHASH_SIZE];
in include/linux/lockdep.h中
#define MAX_LOCKDEP_KEYS_BITS 13
1 *
2 * We put the lock dependency chains into a hash-table as well, to cache
3 * their existence:
4 */
5 #define CHAINHASH_BITS (MAX_LOCKDEP_CHAINS_BITS-1)
6 #define CHAINHASH_SIZE (1UL << CHAINHASH_BITS)
7 #define __chainhashfn(chain) hash_long(chain, CHAINHASH_BITS)
8 #define chainhashentry(chain) (chainhash_table + __chainhashfn((chain)))
9
10 static struct list_head chainhash_table[CHAINHASH_SIZE];
11
12 #define MAX_LOCKDEP_ENTRIES 16384UL
13
14 #define MAX_LOCKDEP_CHAINS_BITS 15
15 #define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS)
16
17 #define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)