kdbus: add walk-through user space example
authorDaniel Mack <daniel@zonque.org>
Thu, 26 Feb 2015 20:06:38 +0000 (21:06 +0100)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Thu, 2 Apr 2015 15:24:19 +0000 (17:24 +0200)
commit9d52feac44dccc20209d24c3d1f411c27b7cb92c
treef4531ca6c9415243ea4e60daea5e79a883cd8362
parent4c81a23b1f43cd1a662da67a8e437b0ea156241a
kdbus: add walk-through user space example

Provide a walk-through example that explains how to use the low-level
ioctl API that kdbus offers. This example is meant to be useful for
developers who want to gain a in-depth understanding of how the kdbus
API works by reading a well-documented real-world example.

This program computes prime-numbers based on the sieve of Eratosthenes.
The master sets up a shared memory region and spawns workers which clear
out the non-primes. The master reacts to keyboard input and to
client-requests to control what each worker does. Note that this is in
no way meant as efficient way to compute primes. It should only serve as
example how a master/worker concept can be implemented with kdbus used
as control messages.

The main process is called the 'master'. It creates a new, private bus
which will be used between the master and its workers to communicate.
The master then spawns a fixed number of workers. Whenever a worker dies
(detected via SIGCHLD), the master spawns a new worker. When done, the
master waits for all workers to exit, prints a status report and exits
itself.

The master process does *not* keep track of its workers. Instead, this
example implements a PULL model. That is, the master acquires a
well-known name on the bus which each worker uses to request tasks from
the master. If there are no more tasks, the master will return an empty
task-list, which casues a worker to exit immediately.

As tasks can be computationally expensive, we support cancellation.
Whenever the master process is interrupted, it will drop its well-known
name on the bus. This causes kdbus to broadcast a name-change
notification. The workers check for broadcast messages regularly and
will exit if they receive one.

Signed-off-by: Daniel Mack <daniel@zonque.org>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
samples/Makefile
samples/kdbus/.gitignore [new file with mode: 0644]
samples/kdbus/Makefile [new file with mode: 0644]
samples/kdbus/kdbus-api.h [new file with mode: 0644]
samples/kdbus/kdbus-workers.c [new file with mode: 0644]