Locking and Synchronization in Solaris kernel

1. Parallel System Architecture
        SMP - Symmetric multiprocessor with a shared memory model; single kernel image
        MPP - Message-based model; multiple kernel images
        NUMA/ccNUMA - Shared memory model; single kernel images

2. Hardware Considerations for Locks and Syncronization
        Consideration:
        (1) need For an automatic test-and-set instruction for locking primitives
        (2) Data global visibility issue because of the use of hardware load and store buffers and instruction reordering
        Solution:
        (1) Use of native machine instructions (cmpxchgl on x86)
        (2) Use of memory barrier instructions

3. Synchronization Objects in Solaris
        (1) mutex lock (exclusive read and write access to data)
        (2) read/write lock (multiple readers are allowable but only one writer is allowed)
        (3) semaphores (access to a finite number of resources)
        (4) dispatcher lock (??)
        (5) condition variables (not a type of lock, used for thread syncrhronization and an integral part of the kernel sleep/wakeup facility)

4. Mutex lock
   The kernel implements two types of mutex locks: spin locks and adaptive locks. Spin locks spin in a tight loop if a desired lock is being held when a thread attempts to acquire the lock. Adaptive locks are the most common type of lock used and are designed to dynamically either spin or block when a lock is being held, depending on the state of the holder. If the lock holder is running on a processor, the thread attempting to get the lock will spin, otherwise, block (sleep and yield the processor to other threads).
   High level interrupts (interrupt levels 11-15) are not allowed to block, so only spin locks can be used in high-level interrupt handlers. Also, spin locks can raise the interrupt level of the processor when the lock is acquired. In a word, spin locks are not allowed to used in any places when sleep and context switch is not allowed.
   Mutex lock interface:

        mutex_init()    initialize a lock, the type of the lock is specified (spin or adaptive)
        mutex_enter()   accquire the lock
        mutex_exit()    release the lock

  mutex(9F) for more information.

5. Read write lock
   The interface for read write lock is:

        rw_init()       initialize a rw lock
        rw_enter()      accquire the lock
        rw_exit()       release the lock

  rwlock(9F) for more information

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值