LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 02-01-2012, 07:20 PM   #1
bayoulinux
LQ Newbie
 
Registered: Oct 2011
Posts: 27

Rep: Reputation: Disabled
How to signal user space kernel event has occurred


Hello:

I'm trying to understand how the kernel can signal user space with regards to a completion of the kernels event processing based up timer events (timer schedules task on work queue, work queue finishes final processing and needs to alert user space).

Here's the example:

1. User space sends ioctl to kernel. The ioctl is going to activate a timer in the kernel to process something 10 times

2. The kernel processes the ioctl which results in a timer handler to schedule a task on a work queue. This timer fires 10 times say every 30 seconds. So the work queue handler is going to be scheduled to run every 30 seconds (approximately, for the sake of example) over 10 iteration.

3. Upon the 10th timer firing, the schedules yet again the task handing upon the work queue. This final work queue handler completes. It is at this time I want to signal to user space this 10th processing is done. How should I do this?

Another way to ask the question, or a parallel question, is perhaps for an more asynchronous event perspective. Say the kernel has a tone detection algorithm in place and it scans incoming data samples for a certain tone. If the kernel's algorithm detects the tone, it needs to alert some event handler within user space. There is no way to determine if a tone will be detected 5 seconds from now, or 50 days from now. What user space/kernel space scheme should be in place to allow the kernel to notify user space of such an event.

Thanks folks!
 
Old 02-02-2012, 06:40 AM   #2
smallpond
Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 456

Rep: Reputation: 85
Set up a signal handler in the user space process. When all is set up start the kernel code and give it the process ID. When the event happens the kernel sends a signal to the process. The signal handler reads the data from the kernel.
 
Old 02-02-2012, 08:21 AM   #3
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,681

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
Do you think that the kernel really should be the one doing this, and not just a nice user-land process?

One technique that might be handy is to use the notion of a /proc file ... the userland process simply reads from the file with a blocking read as though it were a pipe. The kernel writes to the file (with some reasonable size-limit in case the userland process is "stuck"), doing so only when it knows that someone's got it open for reading.
 
Old 02-03-2012, 10:34 AM   #4
bayoulinux
LQ Newbie
 
Registered: Oct 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Thanks for the input thus far...

>>> Do you think that the kernel really should be the one doing this, and not just a nice user-land process?

I would say 'yes'... what I really have an user space API that sends an ioctl down to the kernel to write to a GPIO device. The GPIO device is connect to LEDs:

User space ---> ioctl ---> Kernel ---> GPIO ----> LED

So that is used to change LED state ('On green', 'On red', 'Off')... one ioctl per LED state change.

Now I want to blink the LED 'On Green'/'Off' 5,000 times. I do not want to make 5,000 ioctl calls into the kernel. Therefore, I send one ioctl to the kernel with my new 'BLINK_CMD' opcode. This in turn activates a kernel timer. When the timer fires, it schedules a task upon a workqueue that will change LED state. The kernel SMBUS API is used, which needs to sleep, and therefore I use this "process context" workqueue technique.

Continuing this example, after the 5,000th kernel timer firing/LED state change, I want to indicate to user space my blink pattern of 5,000 LED changes has completed. I desire some sort of indication from the kernel that the blinking is done. From user space, consider a particular LED "locked" until the current blink processing is done - no other process or application can use that LED. In order to "unlock" the LED, I need the kernel to indicate "I'm done blinking LED #5, so go let someone else else have access to it".

Thoughts?

>>>> One technique that might be handy is to use the notion of a /proc file ... the userland process simply reads from the file with a blocking read as though it were a pipe.

This sounds interesting... could you point me to perhaps a piece of example code?

Thanks again to all!
 
Old 02-05-2012, 09:50 AM   #5
bayoulinux
LQ Newbie
 
Registered: Oct 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
>>> Set up a signal handler in the user space process. When all is set up start the kernel code and give it the process ID. >>> When the event happens the kernel sends a signal to the process. The signal handler reads the data from the kernel.

Everything I'm discribing needs to be done via a kernel loadable module. I don't (without getting into the "why") have permission to rebuild the entire kernel and add signalling. Can signalling be added via loadable module without rebuilding the entire kernel?
 
Old 02-05-2012, 12:04 PM   #6
smallpond
Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 456

Rep: Reputation: 85
Quote:
Originally Posted by bayoulinux View Post
>>> Set up a signal handler in the user space process. When all is set up start the kernel code and give it the process ID. >>> When the event happens the kernel sends a signal to the process. The signal handler reads the data from the kernel.

Everything I'm discribing needs to be done via a kernel loadable module. I don't (without getting into the "why") have permission to rebuild the entire kernel and add signalling. Can signalling be added via loadable module without rebuilding the entire kernel?
Signals have been built into the kernel since the early sixties for this exact purpose. Its how async I/O works. The call is send_sig.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal from kernel space to user space sunil.d Programming 4 07-22-2011 08:17 AM
How to receive the signal multiple times in user space without terminating it? pobitro Linux - Embedded 0 06-20-2011 10:44 PM
Free user space pages of different user processes from inside kernel space trueskyte Linux - Kernel 1 10-22-2010 04:37 PM
Division of Logical Memory Space in to User Space and Kernel Space shreshtha Linux - Newbie 2 01-14-2010 09:59 AM


All times are GMT -5. The time now is 12:32 PM.

Main Menu
 
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
Open Source Consulting | Domain Registration