I'm just beginning to learn the tricks of making a kernel module on linux kernel 2.6. What I'm looking to do is have 3 kernel threads, called the slaves, that need to send data to a 4th kernel thread, called master, and receive their respective responses. The slaves can request at any time, which means I will need some sort of a queue structure and a way to redirect responses to the correct thread.
First I looked at implementing my own queue structure to queue incoming requests - but how do I signal the master of this? I don't want the master to keep polling (as in the case of spinlocks/semaphores). I have a feeling there is a better way to communicate between threads.
Due to lack of documentation (and admittedly inferior searching skills), I'm at a loss on how to implement this. Can you point me in the right direction?
You are facing two distinct problems:
kernel/kfifo.c
).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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With