Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 5: Locking and Interprocess Communication


This definition brings to mind the sample code shown in Section 5.3.2. It is exactly the same data struc-
ture used by the program to describe an operation on a semaphore. It holds not only the number of the
semaphore in the semaphore set (sem_num) but also the desired operation (sem_op)andanumberof
operation flags (sem_flg).

ImplementingSystemCalls


All operations on semaphores are performed using a single system call namedipc.Thiscallisusednot
only for semaphores but also to manipulate message queues and shared memory. Its first parameter
delegates the actual multiplex work to other functions. These functions are as follows for semaphores:

❑ SEMCTLperforms a semaphore operation and is implemented insys_semctl.
❑ SEMGETreads the semaphore identifier;sys_semgetis the associated implementation.
❑ SEMOPandSEMTIMEDOPare responsible for incrementing anddecrementing the semaphore value;
the latter enables a time-out to be specified.

The use of a single system call to delegate work to multiple other functions is a relic of early days.^10
Some architectures to which the kernel was later ported (e.g., IA-64 and AMD64) dispense with the
implementation of theipcmultiplexer and use the above ‘‘subfunctions‘‘ directly as system calls. Older
architectures like IA-32 still provide the multiplexer, but individual system calls for the variants have
been added during the development of kernel 2.5. Since the implementation is generic, all architectures
benefit from this.sys_semtimedopoffers the functionality ofsys_ipcforSEMOPandSEMTIMEDOP,and
sys_semctlandsys_semgetare direct implementations ofSEMCTLandSEMGET, respectively.

Notice that the operations that get an IPC object are, however, quickly reunited, as Figure 5-3 illustrates.
This is possible because the data structures to manage IPC objects are generic and not dependent on a
particular IPC type as described above.

ipcget

Other operations

select
ipd_ids
instance

select
ipd_ids
instance

select
ipd_ids
instance

Yes

sys_ipc

sys_shmget sys_msgget sys_semget

IPC_PRIVATE?

ipc_get_public

ipcget_new

Figure 5-3: The system calls to obtain IPC objects can be unified by a common helper
function.

(^10) The kernel comment ‘‘This is really horribly ugly‘‘ forsys_ipcdoeshave a cause.

Free download pdf