开发者

Communication between kernel threads in a linux kernel module

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开发者_如何学Python 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:

  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜