2014년 3월 19일 수요일

[Linux Kernel] 46주차(2014.03.15) 후기

10차 ARM 리눅스 커널 스터디 46주차(2014.03.15) 후기입니다. 

# 일시 : 2014.03.15 (46주차)
# 모임명 : NAVER개발자커뮤니티지원_IAMROOT.ORG_10차ARM-C
# 장소 : 토즈 타워점
# 장소지원 : NAVER 개발자 커뮤니티 지원 프로그램
# 참여인원 : 5명
# 스터디 진도 : start_kernel()-> page_alloc_init();

# 45주차에서 GFP보충설명
memory관련 부분에서 계속 분석할 내용이라서 간단히 복습함

1. Zones 
 커널의 페이지테이블은 물리메모리의 PAGE_OFFSET부터 매핑해서 사용합니다.
물리 메모리를 zone 할당자가 관리합니다. 커널이 사용할 용도에 따라서 물리 페이지를 
zone으로 나누어 사용할 메모리 공간을 예약해 놓습니다. 
 ARM에서 zone 할당자는 3가지를 사용합니다. ZONE_NORMAL, ZONE_HIGHMEM, ZONE_MOVABLE 입니다.
GFP는 Get Free Page의 약어이며, gfp_mask를 설정하는 플래그를 사용해서 memory의 할당과 속성을 설정합니다. 
메모리를 관리하는 버디 시스템를 분석 할 때 자세하게 공부하기로 하였습니다. 
  
# 스터디 내용 : page_alloc_init(); 분석진행 중
2. hotcpu_notifier(page_alloc_cpu_notify,0);
컴파일러 옵션인 CONFIG_HOTPLUG_CPU (CPU 핫 스왑)이 활성화되어 있어, cpu_notifier(fn, pri) 매크로를 실행합니다. 
- cpu_notifier(fn.pri)에서 fn: page_alloc_cpu_notify_nb, pri : 0가 되어 page_alloc_cpu_notify_nb를 호출합니다.      
<code>
 #define cpu_notifier(fn, pri) {                                 \            
      static struct notifier_block fn##_nb =                  \                                                                    
                { .notifier_call = fn, .priority = pri };       \            
        register_cpu_notifier(&fn##_nb);               
}                                                          
</code>
2.1 register_cpu_notifier(struct notifier_block *nb)

2.1.1 cpu_maps_update_begin();
- mutex_lock(&cpu_add_remove_lock); 
  - lock-count를 매개변수로 해서 atomic_xchg()실행한 결과로 fastpath 인지 아닌지 체크한다. 
  - fastpath가 아니면 __mutex_lock_slowpath를 진행한다. 
  - lock-ower : current로 설정
  - __mutex_lock_slowpath 은 __mutex_lock_common을 호출

2.1.2 ret = raw_notifier_chain_register(&cpu_chain, nb);

2.1.3 cpu_maps_update_done();

# __mutex_lock_common 
 - preempt_disable();
   - 현재 task의 preempt count값을 증가시킨다.
 - mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);
   - mutex_acquire_nest : NULL 함수로 컴파일 do{} while 0로 의미가 사라지게 되어 lock->dep_map의 맴버가 선언되지 않아도 안됨. 
 - spin_lock_mutex(&lock->wait_lock, flags);
   - mutex->wait_lock.rlock.raw_lock 를 스핀락했고 CPSR을 flag에 저장
 - debug_mutex_lock_common(lock, &waiter);
   - waiter를 magic으로 설정하고, INIT_LIST로 자료구조를 만듬
 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
   - 현재 thread가 spin lock이 걸렸다는 것을 blocked_on으로 표현함
   - blocked_on은 dead_lock을 detection할때 사용한다. 
 - list_add_tail(&waiter.list, &lock->wait_list); 
   - __list_add(&waiter.list, &lock->wait_list->prev, &lock->wait_list->head)
 - if (MUTEX_SHOW_NO_WAITER(lock) && (atomic_xchg(&lock->count, -1)== 1))
   - 조건문에 따라서 done을 진행한다. 
 - done이 아닌 부분은 다음에 mutex를 호출했을때 추가 분석

- lock_acquired(&lock->dep_map, ip);
  - // NULL function
- mutex_remove_waiter(lock, &waiter, current_thread_info()); 
  - // &waiter->list를 초기화함
- mutex_set_owner(lock);   
  - // lock->owner : init_task 가 됨


# mutex 주의점
자료위치 Documents/mutex-design.txt

- only one task can hold the mutex at a time
- only the owner can unlock the mutex
- multiple unlocks are not permitted
- recursive locking is not permitted
- a mutex object must be initialized via the API
- a mutex object must not be initialized via memset or copying
- task may not exit with mutex held
- memory areas where held locks reside must not be freed
- held mutexes must not be reinitialized
- mutexes may not be used in hardware or software interrupt 
- contexts such as tasklets and timers


# 토론 내용
 -  task, thread 에 대하여.
 - mutex와 semaphore
 - barrier, 
 - 컴파일러 (LLVM)와 최적화

# git log
modified:   arch/arm/include/asm/atomic.h
modified:   arch/arm/include/asm/cmpxchg.h
modified:   arch/arm/include/asm/spinlock.h
modified:   arch/arm/include/asm/spinlock_types.h
modified:   arch/arm/include/asm/thread_info.h
modified:   arch/arm/kernel/head-common.S
modified:   include/linux/compiler-gcc.h
modified:   include/linux/compiler.h
modified:   include/linux/cpu.h
modified:   include/linux/debug_locks.h
modified:   include/linux/hardirq.h
modified:   include/linux/init_task.h
modified:   include/linux/irqflags.h
modified:   include/linux/kernel.h
modified:   include/linux/list.h
modified:   include/linux/lockdep.h
modified:   include/linux/mutex.h
modified:   include/linux/preempt.h
modified:   include/linux/sched.h
modified:   include/linux/spinlock.h
modified:   init/init_task.c
modified:   init/main.c
modified:   kernel/cpu.c
modified:   kernel/mutex-debug.c
modified:   kernel/mutex-debug.h
modified:   kernel/mutex.c
modified:   mm/page_alloc.c

댓글 없음:

댓글 쓰기