|
|
HP-UX MultiProcessing: White Paper > Chapter 1 MultiProcessingBeta Semaphores |
|
In some instances the rules governing alpha semaphores are too strict to meet the needs of the kernel. Another class of semaphores exist, known as beta semaphores.
Beta semaphores are created in the kernel by a call to b_initsema(). Beta semaphores have services similar to alpha semaphore services. The following table describes the principal kernel interface routines for beta semaphore operations. Table 1-14 Interface routines used for beta semaphore operations
Beta semaphores use a hash table to access the associated spinlock and wait list information (linked list of kthreads). A kthread at the head of a semaphore's wait queue is allowed to be awakened and yet miss the semaphore a maximum of BETA_MISS_LIMIT times. Other executing code is allowed to acquire the semaphore between the time the semaphore is unlocked by the V operation and the time the awakened kthread can execute and lock it. If the miss limit is reached, the semaphore is passed to the waiting kthread. The number of misses the kthread at the head of the semaphore's wait queue has taken is maintained in the kthread's proc structure. Each V operation on the semaphore will awaken the kthread at the head of the wait queue and unlock the semaphore if the miss limit has not been reached. If the miss limit is reached, the V operation will awaken the kthread at the end of the wait queue but will not unlock the semaphore, preventing other code from acquiring the semaphore. The awaken kthread notices that the semaphore ownership has been passed to it. This is indicated by the miss count being equal to BETA_MISS_MAX. The beta semaphore itself contains only the lock and owner information. Both beta semaphore and its hash table are defined in sem_beta.h. The beta semaphore is defined as typedef b_sema_t (also defined as vm_sema_t) and consists of the three fields. Table 1-15 elements in struct b_sema
Note, the b_lock field is not a spinlock. The spinlock guarding the beta semaphore is in the hash table. The address of the beta semaphore is indexed into the beta semaphore hash table (bh_sema_t) to obtain the spinlock and waiter information. Table 1-16 elements in struct bh_sema_t
|
|