corba 发表于 2005-7-16 12:18

请教linux内核高手

何为system context ? 何为interrupt context?他们的意义是什么呢?spinlocks是何解?它和semaphoore的区别又在何处?

希望大家不闵回答,说出一个也好,在此先谢过。

asdfgh 发表于 2005-7-19 15:44

原帖由 corba 于 2005-7-16 13:18 发表
何为system context ? 何为interrupt context?他们的意义是什么呢?spinlocks是何解?它和semaphoore的区别又在何处?

希望大家不闵回答,说出一个也好,在此先谢过。

http://www.cis.temple.edu/~ingargio/cis307/readings/spinsem.html

Spinlocks are abstract data types, or classes, that support a Busy-Wait solution for the Mutual Exclusion Problem。

People use the term "Semaphore" to refer to a variety of synchronization mechanisms. Here by "Semaphore" we mean the "non-busy-waiting" analog of SpinLocks.

*Spinlocks implement a "busy wait condition" for a resource. If a processor attempts to obtain a spinlock being held by another processor, it will wait until the lock is released.

      Spinlocks can be acquired on an interrupt stack. A deadlock can arise, however, if a processor takes an interrupt while holding a spinlock and the interrupt code tries to acquire the same spinlock. To prevent this from occurring, HP-UX requires the spl level to be raised whenever a spinlock is acquired. When the spinlock is released, the prior spl level is reverted to. Once a spinlock is acquired, the spl level should not be lowered within the spinlocked critical section.

      Spinlocks are used to synchronize access to data between multiple processors, and as such, have little value in a uniprocessor system. Within the kernel the MP_SPINLOCK() macro checks the uniprocessor flag and returns if not an MP system.



* Kernel semaphores control access through blocking strategies. With blocking semaphores, a processor attempting to acquire a semaphore already held by another processor will put its current thread to sleep and context switch to another task.

      Semaphores are used to provide mutual exclusion or to synchronize access between multiple processes or threads, regardless of how many processors there are.

[ 本帖最后由 asdfgh 于 2005-7-19 16:46 编辑 ]

corba 发表于 2005-7-19 17:46

唉,多谢asdfgh兄弟了,可惜内核考试今天已经考完了。关于这个,偶也从网上找了些资料,可是没有你的英文介绍那么全。

说说偶的理解,spin lock 和 semaphore都是kern用来synchronisation的operation,主要区别是应用的区域,spin lock 用在短期,semaphore用在长期,另外spin lock 是原子操作,semaphore不能用于中断处理。

上面的两个则是kern用来存储临时信息的区域,一个对进程,一个对中断,具体意义就是在任务切换的时候,能够保留当前运行信息,然后回头还能继续完成。
页: [1]
查看完整版本: 请教linux内核高手