The relationship between kernel threads in the Linux kernel module

I'm just starting to learn the tricks for creating a kernel module on Linux 2.6. What I want to do is 3 kernel threads, called subordinates, that must send data to the fourth kernel thread, called master, and receive their responses. Slaves can request at any time, which means that I will need some kind of queue structure and a way to redirect responses to the correct stream.

At first I looked at the implementation of my own queue structure for the incoming request queue, but how can I signal this to the host? I do not want the wizard to continue polling (as is the case with direct cells / semaphores). I have a feeling that there is a better way to communicate between threads.

Due to the lack of documentation (and, admittedly, killer search skills), I don’t understand how to implement this. Can you point me in the right direction?

+4
source share
1 answer

You are faced with two different problems:

  • The actual relationship between subordinates and leaders. You can use the FIFO implementation in the kernel ( kernel/kfifo.c ).
  • You need demultiplexing for the master without animation / polling. You can do this in the same way as in user space, through poll / epoll in the "event file descriptor" (eventfd). Take a look at the kernel level API in include/linux/eventfd.h (the implementation is in fs/eventfd.h ).

You should probably use the [kfifo, event file] pair for each sub stream. The main thread blocks the do_poll() call and, when it wakes up, can use the right FIFO based on fd, which was "signalized". Take a look at fs/select.c for an idea of ​​what you should call do_poll() .

You might want to use mutexes to protect FIFOs.

+3
source

All Articles