Motherboard Forums


Reply
Thread Tools Display Modes

Synchronizing user space threads with kernel space in linux

 
 
Mad@Spammers
Guest
Posts: n/a
 
      04-29-2004, 11:54 AM
I want to synchronize a user space thread to an external event that
generates an interrupt. I thought of using the following approach: the
ISR that treats the interrupt does a quick processing (such as data
capture and buffering) and then sends data to the user space thread
through a message queue or signals to the thread waiting on a
semaphore and it gets the buffered data from shared memory or some
similar mechanism. So far I haven't succeded in finding a way to do
it. I've tryed to write a module which uses semaphores (<linux/sem.h>)
but aparently there is no way to use SysV IPC primitives in kernel
modules.

I would appreciate having hints on how to do it or pointers to
documentation and example code if available.

Thank you very much in advance for your help.

Elder.
 
Reply With Quote
 
 
 
 
Michael N. Moran
Guest
Posts: n/a
 
      04-29-2004, 12:41 PM
Mad@Spammers wrote:
> I want to synchronize a user space thread to an external event that
> generates an interrupt. I thought of using the following approach: the
> ISR that treats the interrupt does a quick processing (such as data
> capture and buffering) and then sends data to the user space thread
> through a message queue or signals to the thread waiting on a
> semaphore and it gets the buffered data from shared memory or some
> similar mechanism. So far I haven't succeded in finding a way to do
> it. I've tryed to write a module which uses semaphores (<linux/sem.h>)
> but aparently there is no way to use SysV IPC primitives in kernel
> modules.
>
> I would appreciate having hints on how to do it or pointers to
> documentation and example code if available.
>
> Thank you very much in advance for your help.
>
> Elder.


A user-space signal is the equivalent of an interrupt.
When user-space drivers are involved, I like to use
"send_sig_info()" to send a signal to the user-space
task to indicate changes in the state of the driver.

I like to model the user/kernel space interface to
look like a hardware device in terms of interrupt/signal
handling, with ioctl's to acknowledge/enable/disable
signals/interrupts from the driver. However, I'm an
embedded type that is used to that kind of thing ;-)

Getting the data to/from kernel space is another
issue, typically done by the read/write driver
interface, or by using mmap().

--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org

"... abstractions save us time working, but they don't
save us time learning."
Joel Spolsky, The Law of Leaky Abstractions

The Beatles were wrong: 1 & 1 & 1 is 1

 
Reply With Quote
 
 
 
 
Herman Bruyninckx
Guest
Posts: n/a
 
      04-29-2004, 01:45 PM
On 29 Apr 2004, Mad@Spammers wrote:

> I want to synchronize a user space thread to an external event that
> generates an interrupt.


Maybe the ongoing work about D-Bus can give you inspiration:
<http://freedesktop.org/Software/dbus>
One of its motivations was/is exactly to be able to do more driver stuff in
user space, and I got the impression that that was what you are looking
for...

Herman
--
K.U.Leuven, Mechanical Eng., Mechatronics & Robotics Research Group
<http://people.mech.kuleuven.ac.be/~bruyninc> Tel: +32 16 322480

 
Reply With Quote
 
Dan Kegel
Guest
Posts: n/a
 
      04-29-2004, 04:11 PM
Michael N. Moran wrote:
>> I want to synchronize a user space thread to an external event that
>> generates an interrupt. I thought of using the following approach: the
>> ISR that treats the interrupt does a quick processing (such as data
>> capture and buffering) and then sends data to the user space thread
>> through a message queue or signals to the thread waiting on a
>> semaphore and it gets the buffered data from shared memory or some
>> similar mechanism. So far I haven't succeded in finding a way to do
>> it. I've tryed to write a module which uses semaphores (<linux/sem.h>)
>> but aparently there is no way to use SysV IPC primitives in kernel
>> modules.

>
> A user-space signal is the equivalent of an interrupt.
> When user-space drivers are involved, I like to use
> "send_sig_info()" to send a signal to the user-space
> task to indicate changes in the state of the driver. ...
>
> Getting the data to/from kernel space is another
> issue, typically done by the read/write driver
> interface, or by using mmap().


What kind of time resolution do you need?

One other option is to use netlink sockets. They're
pretty easy. One drawback is netlink socket addresses
are somewhat precious, a little like signal numbers.

- Dan
 
Reply With Quote
 
Gary Kato
Guest
Posts: n/a
 
      04-29-2004, 04:37 PM
You could use wait queues. Have your user process sleep on a queue and have
your ISR wake processes on that queue.

 
Reply With Quote
 
Wolfgang =?ISO-8859-15?Q?M=FCes?=
Guest
Posts: n/a
 
      04-29-2004, 05:32 PM
Hello Elder,

> I want to synchronize a user space thread to an external event that
> generates an interrupt. I thought of using the following approach: the
> ISR that treats the interrupt does a quick processing (such as data
> capture and buffering) and then sends data to the user space thread


- Let your driver register a character interface
- from your user space thread, do a synchronous read.
- in your interrupt routine, copy the data and wakeup the
waiting thread.

Very common situation. Works without any problem for me.

best regards

Wolfgang MŁes





 
Reply With Quote
 
Roger Larsson
Guest
Posts: n/a
 
      04-30-2004, 12:22 AM
Wolfgang MŁes wrote:

> Hello Elder,
>
>> I want to synchronize a user space thread to an external event that
>> generates an interrupt. I thought of using the following approach: the
>> ISR that treats the interrupt does a quick processing (such as data
>> capture and buffering) and then sends data to the user space thread

>
> - Let your driver register a character interface
> - from your user space thread, do a synchronous read.
> - in your interrupt routine, copy the data and wakeup the
> waiting thread.
>
> Very common situation. Works without any problem for me.
>
> best regards
>
> Wolfgang MŁes


Look twice at this approach! This is the UNIX way - everything is a file.

Read about the (now) old OSS audio drivers for block devices - same
data size on every read or write.
Or serial ports for character devices.

/RogerL

--
Roger Larsson
SkellefteŚ
Sweden
 
Reply With Quote
 
Mad@Spammers
Guest
Posts: n/a
 
      04-30-2004, 11:48 AM
Roger Larsson <(E-Mail Removed)> wrote in message

> Look twice at this approach! This is the UNIX way - everything is a file.


Is it a good or a bad thing?

Cheers.

Elder.
 
Reply With Quote
 
Mad@Spammers
Guest
Posts: n/a
 
      04-30-2004, 12:22 PM
Dan Kegel <(E-Mail Removed)> wrote in message

> What kind of time resolution do you need?
>

I presume this question was asked to me.

I am just evaluating how well would Linux (either 2.4 with preemption
and low latency patches or 2.6 with preemption enabled) perform for my
application. Worst case interrupt latency of 400us and thread
activation latency of 4ms are more than acceptable in my application.

Regards.

Elder.
 
Reply With Quote
 
Mad@Spammers
Guest
Posts: n/a
 
      04-30-2004, 12:27 PM
Herman Bruyninckx <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> On 29 Apr 2004, Mad@Spammers wrote:
>
> > I want to synchronize a user space thread to an external event that
> > generates an interrupt.

>
> Maybe the ongoing work about D-Bus can give you inspiration:
> <http://freedesktop.org/Software/dbus>
> One of its motivations was/is exactly to be able to do more driver stuff in
> user space, and I got the impression that that was what you are looking
> for...
>
> Herman


I had a quick look at it. My requirements are much more modest and I'd
rather use native linux resources instead. Still I will look at its
code for some tips.

Elder.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want a 1ms tick from Linux without modifying Linux Kernel Like2Learn Embedded 6 12-09-2010 04:24 PM
Xbox360 IBM PowerPC CPU: 3.2 GHz. 3 processing cores. 6 threads. 165m transistors Intel 2 05-14-2005 12:58 AM
ECOS max number of threads Steve Embedded 7 10-01-2004 04:26 AM
Linux and priorities within kernel space Martin Embedded 1 07-21-2004 09:42 PM
Prioritizing Threads in XP w/ Abit KT7A-RAID Damaeus Abit 3 07-25-2003 05:03 AM


All times are GMT. The time now is 11:55 PM.


Welcome!
Welcome to Motherboard Point
 

Advertisment