Communication between kernel threads in a linux kernel module Communication between kernel threads in a linux kernel module multithreading multithreading

Communication between kernel threads in a linux kernel module


You are facing two distinct problems:

  1. The actual communication between the slaves and the master. You can use the FIFO implementation in the kernel (kernel/kfifo.c).
  2. You need demultiplexing for the master without busy-waiting/polling. You can do it just like in userspace, via poll/epoll on an "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 a [kfifo, event file] pair for each slave thread. The master thread blocks in a do_poll() call and, when woken up, is able to use the right FIFO based on the fd that was "signaled". Take a look at fs/select.c to have an idea about how you should call do_poll().

You might want to use mutexes to guard the FIFO.