2010-08-18 14 views
3

在linux内核中执行自旋锁,例如 http://lxr.linux.no/#linux+v2.6.18/include/asm-i386/semaphore.h#L97为什么在Linux内核中的自旋锁在“.subsection 1”(或“.text.lock.smth”)中?

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部分推杆。

是什么原因?

回答

1

我不是100%确定,但我认为这与SMP alternatives for i386有关,其中内核可以在启动时甚至在运行时在SMP和UP之间切换。

+0

.subsection 1也用于用户空间http://www.google.com/codesearch/p?hl=zh-CN#5ge3gHPB4K4/gnu/glibc/glibc-2.3.1.tar.gz%7CQzvfrd4m2kQ/glibc中的原子-2.3.1/sysdeps/alpha/atomicity.h&q = glibc%20subsection%20package:%22ftp://sources.redhat.com/pub/glibc/releases/glibc-2.3.1.tar.bz2%22 什么? – osgx 2010-08-19 09:45:06

相关问题