Presentation is loading. Please wait.

Presentation is loading. Please wait.

14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization.

Similar presentations


Presentation on theme: "14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization."— Presentation transcript:

1 14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization

2 14 2 Embedded Software Lab. Race Condition  Prevention : Synchronization –Some code (Critical Region)could be interleaved  Not serialized. Kernel Synchronization

3 14 3 Embedded Software Lab. Spin Lock –When access a shared data or enter a critical region –If locked, spin around repeatedly executing loop – busy wait –Kernel preemption is disabled in every critical region protected by spin locks spinlock_t –slock 1 : unlocked state 0 이하 : locked state –break_lock Flag signaling that process is busy waiting for the lock

4 14 4 Embedded Software Lab. Spin Lock spin_lock() macro –Disable kernel preemption – preempt_disable() –Check slock –If slock=1, exit  Success to acquire spin lock. –If slock=0, preempt_enable() –Set break_lock=1 –Wait cycle while(spin_is_locked(slp) && slp->break_lock) cpu_relax();

5 14 5 Embedded Software Lab. Semaphore Allow waiters to sleep struct semaphore –count >0 : free =0 : busy, no waiting process <0 : busy, waiting process –wait Address of wait queue list –sleepers Flag whether processes are sleeping

6 14 6 Embedded Software Lab. Semaphore Releasing semaphores – up() –count++ and check if count>0 –count<=0 : wake up one sleeping process Getting semaphores – down() –count-- and check if count<0 –count>=0 : acquire resource –count=1, sleepers=0 : semaphore open –count=0, sleepers=0 : semaphore close, no sleeping process –count=-1, sleepers=1 : semaphore close, sleeping process

7 14 7 Embedded Software Lab. spinlock 을 사용하는 kernel 코드를 찾아 조사 –initialization 부분 –lock 부분 –unlock 부분 –critical section 에 대해 경쟁하는 부분 example(inode->i_lock) –initialization 부분 inode_init_always() –lock & unlock 부분, critical section iget_locked() –spin_lock(&inode->i_lock); –inode->i_state = I_NEW; –hlist_add_head(&inode->i_hash, head); –spin_unlock(&inode->i_lock); 실습


Download ppt "14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization."

Similar presentations


Ads by Google