LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sharing semaphore between kernel and user space (https://www.linuxquestions.org/questions/programming-9/sharing-semaphore-between-kernel-and-user-space-614296/)

balinju 01-17-2008 10:53 AM

Sharing semaphore between kernel and user space
 
Hi all,
I am trying to write a simple kernel module and I have run into an issue which I cannot figure out. So let me give some background on the application.

I have this kernel module which will interact with a nic card. Basically the nic card will have its irq line switched off and software polling will be used. However, when no data is available, my application will enable the IRQ line for the nic card which will in turn call my interrupt handler written in this kernel module.

What I am trying to achieve is the following. Once no data is available, apart from switching on the irq line, the application will wait on a semaphore. On the other hand, when an interrupt is received, the application will be woken up by incrementing the semaphore counter and the irq will never be enable until the data stops coming through.

My problem basically is that I cannot share a semaphore between kernel space and user space. In my kernel module, when I try to create a semaphore with sys_semget(), the module compiles although it gives some warnings, such as *** Warning: "sys_semget" [/home/balinju/repository/workspace/Link/link.ko] undefined!

and insmod fails with Unknown symbol sys_semget.

I would appreciate any help. I am not stuck to using semaphores so if you have any other opinion, please shoot out.

thanks a lot for your help

PTrenholme 01-18-2008 09:52 PM

Why not just let your kernel module look for the pid(s) of any user processes running the user-space application, and, when it finds any of them, send the process an interrupt to signal the state change of the kernel process.

balinju 01-19-2008 06:18 AM

I also considered going that route, but I couldn't include signal.h in the kernel module

archieval 01-22-2008 01:28 AM

in the module: #include <linux/signal.h>
in the app: #include <signal.h>

jiml8 01-24-2008 12:59 PM

Quote:

Originally Posted by PTrenholme (Post 3027719)
Why not just let your kernel module look for the pid(s) of any user processes running the user-space application, and, when it finds any of them, send the process an interrupt to signal the state change of the kernel process.

I am facing the exact same issue as the OP right now and have the exact same problem, though I am working with a DSP rather than a NIC.

Seems to me that taking this route requires the kernel module to implement a policy decision (name of the user process) rather than merely providing a capability (defining an appropriate semaphore). It seems clumsy to me.

Also, I need to process this kdm<->userspace process communication in an interrupt handler, and searching the process table to match names seems rather heavyweight to me in such an environment.

Is this how it is commonly done in Linux when this problem comes up?

jiml8 01-25-2008 12:21 PM

Actually, the way to handle my objection about policy and the time penalty of stepping through the process list is pretty straightforward once you think about it.

If the userspace program announces its own pid to the driver when it starts, then the driver doesn't have to search the process list. Multiple userspace programs that want to be notified are easily handled by the driver if it uses a linked list to keep that information.


All times are GMT -5. The time now is 03:01 AM.