Communication between kernel threads in a linux kernel module
You are facing two distinct problems:
- The actual communication between the slaves and the master. You can use the FIFO implementation in the kernel (
kernel/kfifo.c
). - 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 infs/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.