LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-17-2008, 11:53 AM   #1
balinju
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Rep: Reputation: 0
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
 
Old 01-18-2008, 10:52 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,154

Rep: Reputation: 333Reputation: 333Reputation: 333Reputation: 333
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.
 
Old 01-19-2008, 07:18 AM   #3
balinju
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Original Poster
Rep: Reputation: 0
I also considered going that route, but I couldn't include signal.h in the kernel module
 
Old 01-22-2008, 02:28 AM   #4
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
in the module: #include <linux/signal.h>
in the app: #include <signal.h>
 
Old 01-24-2008, 01:59 PM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by PTrenholme View Post
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?
 
Old 01-25-2008, 01:21 PM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
notify user space application from the kernel space lordofring Linux - Software 2 06-22-2009 01:32 PM
Kernel and user space address ? ashok449 Linux - Kernel 1 12-29-2007 01:17 PM
kernel user space communication mbm Linux - Kernel 1 10-17-2007 09:21 PM
How to share data b/w user space and kernel space nandac Linux - Kernel 1 11-28-2006 11:15 PM
User Space - Kernel Space basu_arani Programming 3 05-25-2004 12:46 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration