在linux内核中自旋锁的实现,例如 http://lxr.linux.no/#linux+v2.6.18/include/asm-i386/semaphore.h#L97
97static inline void down(struct semaphore * sem)
98{
99 might_sleep();
100 __asm__ __volatile__(
101 "# atomic down operation\n\t"
102 LOCK_PREFIX "decl %0\n\t" /* --sem->count */
103 "js 2f\n"
104 "1:\n"
105 LOCK_SECTION_START("")
106 "2:\tlea %0,%%eax\n\t"
107 "call __down_failed\n\t"
108 "jmp 1b\n"
109 LOCK_SECTION_END
110 :"+m" (sem->count)
111 :
112 :"memory","ax");
113}
使用 LOCK_SECTION_START 和 LOCK_SECTION_END。它们在http://lxr.linux.no/#linux+v2.6.18/include/linux/spinlock.h#L63中定义为
61#define LOCK_SECTION_NAME ".text.lock."KBUILD_BASENAME
62
63#define LOCK_SECTION_START(extra) \
64 ".subsection 1\n\t" \
65 extra \
66 ".ifndef " LOCK_SECTION_NAME "\n\t" \
67 LOCK_SECTION_NAME ":\n\t" \
68 ".endif\n"
69
70#define LOCK_SECTION_END \
71 ".previous\n\t"
所以所有锁定的操作都部分放入subsection 1
或部分.text.lock.SMTH_STRING。
这是什么原因?