lockdep_init()

lockdep_init()

  • lockdep
    • lock dependency의 약자로 커널이 lock을 모니터링하고 디버깅하기 위한 것으로 dead-lock 검출도 한다.
void lockdep_init(void)
{
        int i;

        /*   
         * Some architectures have their own start_kernel()
         * code which calls lockdep_init(), while we also
         * call lockdep_init() from the start_kernel() itself,
         * and we want to initialize the hashes only once:
         */

        if (lockdep_initialized)
                return;

        for (i = 0; i < CLASSHASH_SIZE; i++) 
                INIT_LIST_HEAD(classhash_table + i);

        for (i = 0; i < CHAINHASH_SIZE; i++) 
                INIT_LIST_HEAD(chainhash_table + i);

        lockdep_initialized = 1;
}
  • if (lockdep_initialized)
    • lockdep_initialized는 lockdep_init() 함수가 이미 초기화되었음을 의미한다. 따라서 lockdep_initialized가 true(1)일 경우에는 초기화 코드를 수행하지 않는다.
  •  INIT_LIST_HEAD(classhash_table + i);
    • lockdep에 사용될 class마다 hash table을 만든다.
    • lockdep에 사용되는 class는 4096개(CLASSHASH_SIZE)이다.
    • classhash_table을 CLASSHASH_SIZE(4096)개 만큼 초기화한다.
  • INIT_LIST_HEAD(chainhash_table + i);
    • chainhash_table을 CHAINHASH_SIZE(32768)개 만큼 초기화한다.

 

classhash_table & chainhash_table

/*
 * The lockdep classes are in a hash-table as well, for fast lookup:
 */
static struct list_head classhash_table[CLASSHASH_SIZE];

/*
 * We put the lock dependency chains into a hash-table as well, to cache
 * their existence:
 */
static struct list_head chainhash_table[CHAINHASH_SIZE];

 

list_head의 구조

struct list_head {
    struct list_head *next, *prev;
};

 

INIT_LIST_HEAD()

static inline void INIT_LIST_HEAD(struct list_head *list)
{
        list->next = list;
        list->prev = list;
}

 

참고

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다