26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Message passing and client/server<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

The key to accomplishing this is message passing. Instead of having the OS modules<br />

bound directly into the kernel, and having some kind of “special” arrangement <strong>with</strong><br />

the kernel, under <strong>Neutrino</strong> the modules communicate via message passing among<br />

themselves. The kernel is basically responsible only for thread-level services (e.g.,<br />

scheduling). In fact, message passing isn’t used just for this installation and<br />

deinstallation trick — it’s the fundamental building block for almost all other services<br />

(for example, memory allocation is performed by a message to the process manager).<br />

Of course, some services are provided by direct kernel calls.<br />

Consider opening a file and writing a block of data to it. This is accomplished by a<br />

number of messages sent from the application to an installable component of <strong>Neutrino</strong><br />

called the filesystem. The message tells the filesystem to open a file, and then another<br />

message tells it to write some data (and contains that data). Don’t worry though — the<br />

<strong>Neutrino</strong> operating system performs message passing very quickly.<br />

Message passing and client/server<br />

Imagine an application reading data from the filesystem. In <strong>QNX</strong> lingo, the<br />

application is a client requesting the data from a server.<br />

This client/server model introduces several process states associated <strong>with</strong> message<br />

passing (we talked about these in the Processes and Threads chapter). Initially, the<br />

server is waiting for a message to arrive from somewhere. At this point, the server is<br />

said to be receive-blocked (also known as the RECV state). Here’s some sample pidin<br />

output:<br />

pid tid name prio STATE Blocked<br />

4 1 devc-pty 10r RECEIVE 1<br />

In the above sample, the pseudo-tty server (called devc-pty) is process ID 4, has one<br />

thread (thread ID 1), is running at priority 10 Round-Robin, and is receive-blocked,<br />

waiting for a message from channel ID 1 (we’ll see all about “channels” shortly).<br />

READY<br />

RECEIVE<br />

State transitions of server.<br />

When a message is received, the server goes into the READY state, and is capable of<br />

running. If it happens to be the highest-priority READY process, it gets the CPU and<br />

can perform some processing. Since it’s a server, it looks at the message it just got and<br />

decides what to do about it. At some point, the server will complete whatever job the<br />

message told it to do, and then will “reply” to the client.<br />

Let’s switch over to the client. Initially the client was running along, consuming CPU,<br />

until it decided to send a message. The client changed from READY to either<br />

send-blocked or reply-blocked, depending on the state of the server that it sent a<br />

message to.<br />

82 Chapter 2 • Message Passing April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!