Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 5: Locking and Interprocess Communication


Longer messages must be spread over several pages with the help of thenextpointer. This points to
an instance ofmsg_msgseqthat is also situated at the beginning of a page, as shown in Figure 5-5. It is
defined as follows:


ipc/msgutils.c
struct msg_msgseg {
struct msg_msgseg* next;
/* the next part of the message follows immediately */
};

Again, the message text immediately follows the data structure instance.nextis used to enable the
message to be spread over any number of pages.


Both sender and receiver processes can go to sleep when communicating via message queues —
senders while they are attempting to write a message on a queue whose maximum capacity has
already been reached; receivers when they want to retrieve a message from a queue although none
has arrived.


Sleeping senders are placed on theq_senderslist ofmsg_queueusing the following data structure:


ipc/msg.c
struct msg_sender {
struct list_head list;
struct task_struct* tsk;
};

listis a list element, andtskis a pointer to the corresponding task structure. No additional information
is required because the sender process goes to sleep during thesys_msgsndsystem call — which can also
be activated viasys_ipc— used to send the message and automatically repeats the send operation when
it is woken.


The data structure to hold the receiver process in theq_receiverslist is a little longer.


ipc/msg.c
struct msg_receiver {
struct list_head r_list;
struct task_struct *r_tsk;

int r_mode;
long r_msgtype;
long r_maxsize;

struct msg_msg *volatile r_msg;
};

It holds not only a pointer to the corresponding task structure but also the descriptors of the expected
message (above all, the message typer_msgtype) and a pointer to amsg_msginstance into which the data
are copied if available.


Figure 5-6 illustrates the interplay of the message queue data structures (for the sake of clarity, the list of
sleeping senders is not shown).

Free download pdf