Skip to contentSkip to conversation

Is it useful to support user level drivers

DISCUSSION Balbir Singh 10 participants 28 messages Jun 21, 2001 – Jun 29, 2001

lore
Share & tools
lore
#0 lore raw

I realize that the Linux kernel supports user level drivers (via ioperm, etc). However interrupts at user level are not supported, does anyone think it would be a good idea to add user level interrupt support ? I have a framework for it, but it still needs
a lot of work.

Depending on the response I get, I can send out more email. Please cc me to the replies as I am no longer a part of the Linux kernel mailing list - due to the humble size of my mail box.

Balbir

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

#1 lore raw
Quoted 5 lines · Balbir Singh

I realize that the Linux kernel supports user level drivers (via ioperm, etc). However interrupts at user level are not supported, does anyone think it would be a good idea to add user level interrupt support ? I have a framework for it, but it still needs a lot of work.

Well, for parallel port devices, take a look at libieee1284 and /dev/parport0.

Tim.
*/

#2 lore raw
In reply to Balbir Singh
Quoted 6 lines

level drivers (via ioperm, etc). However interrupts at user level are not supported, does anyone think it would be a good idea to add user level interrupt support ? I have a framework for it, but it still needs
a lot of work.

The problem is that the IRQ has to be cleared in kernel space, because otherwise you may deadlock.

#3 lore raw
Quoted 4 lines · --- Alan Cox

The problem is that the IRQ has to be cleared in
kernel space, because otherwise
you may deadlock.

I agree, the idea is to clear the IRQ in kernel space and then deliver to user level programs interested using a signal (Real time SIGINT or something similar) If somebody is interested I could in sometime come up with what I have in mind and send it to this list, accept comments and criticism.

Balbir

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

#4 lore raw
Quoted 6 lines

I agree, the idea is to clear the IRQ in kernel space and then deliver to user level programs interested using a signal (Real time SIGINT or something similar) If somebody is interested I could in sometime come up with what I have in mind and send it to this list, accept comments and criticism.

I think you should yes. The XFree86 people for one are trying to find a way to handle vertical blank interrupts nicely

#5 lore raw
In reply to Alan Cox
Quoted 5 lines · Alan Cox
Quoted 2 lines

it would be a good idea to add user level interrupt support ? I have a framework for it, but it still

The problem is that the IRQ has to be cleared in kernel space, because otherwise you may deadlock.

It depends on device type. Good designed ones does not raises a new interrupt until an explicit acknowledge by I/O from [user space] driver will be received.

Access to device's ports and IRQs from user space is subject of system admistration policy so direct access to a dangerous devices should not be allowed.

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

#6 lore raw
Quoted 7 lines
Quoted 2 lines

The problem is that the IRQ has to be cleared in kernel space, because otherwise you may deadlock.

It depends on device type. Good designed ones does not raises a new interrupt until an explicit acknowledge by I/O from [user space] driver will be received.

Quoted 6 lines

Access to device's ports and IRQs from user space is subject of system admistration policy so direct access to a dangerous devices should not be allowed.

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

Unless you need that interrupt to be enabled to deliver the signal or let userspace reenable the interrupt.

In addition, how do you handle shared interrupts ?

Regards
Oliver

#7 lore raw
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

Unless you need that interrupt to be enabled to deliver the signal or let

Need not. Signal and other event delivery mechanisms has nothing common with disable/enable_irq().

Quoted 1 line

userspace reenable the interrupt.

"user acknowledge" is mean that.

Quoted 1 line

In addition, how do you handle shared interrupts ?

It is impossible, see my another message.

#8 lore raw
Quoted 8 lines · Dmitry A. Fedorov
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

Unless you need that interrupt to be enabled to deliver the signal or let

Need not. Signal and other event delivery mechanisms has nothing common with disable/enable_irq().

And how do you ensure that no interrupt is lost ?
In fact you now are likely to have a race condition reading device status or the like.

Quoted 7 lines
Quoted 1 line

userspace reenable the interrupt.

"user acknowledge" is mean that.

Quoted 1 line

In addition, how do you handle shared interrupts ?

It is impossible, see my another message.

Which IMHO makes the concept pretty much useless.
Interrupt sharing is pretty much the norm today. And there is no evidence for this to change in the near future. Rather the opposite seems to happen in fact.

Which devices were you thinking of, that need a hardware IRQ and no kernel driver ?

Regards
Oliver

#9 lore raw
Quoted 11 lines · Oliver Neukum
Quoted 3 lines
Quoted 1 line

In addition, how do you handle shared interrupts ?

It is impossible, see my another message.

Which IMHO makes the concept pretty much useless.
Interrupt sharing is pretty much the norm today. And there is no evidence for this to change in the near future. Rather the opposite seems to happen in fact.

Which devices were you thinking of, that need a hardware IRQ and no kernel driver ?

An ISA cards, mostly for data acquisition - edge triggered interrupts, no ack required immediately from interrupt handler. Rest of hardware handling can be deferred to user space.
IRQ sharing is possible there in spite of some hardware hacking.

Yes, it is very limited range of hardware today but it exists and /dev/irq kernel module provide one of generic mechanisms for user space driver implementation.

#10 lore raw

Thanks folks, I got some great comments, pointers a list of problems which I need to take care of. I promise that when I try and implement user level interrupts - it won't be a hack, all problems will be taken care of based on good programming practices.

I will look into the steps provided by people. Yes! we need to worry about shared interrupts, I will draw out a more detailed plan of problems and solutions.

Later ...

Thanks,
Balbir

--- "Dmitry A. Fedorov" <[email protected]>

Quoted 26 lines · wrote:
Quoted 1 line · Oliver Neukum
Quoted 1 line
Quoted 1 line

In addition, how do you handle shared

interrupts ?

Quoted 5 lines
Quoted 2 lines

It is impossible, see my another message.

Which IMHO makes the concept pretty much useless.
Interrupt sharing is pretty much the norm today.

And there is no evidence for

Quoted 1 line

this to change in the near future. Rather the

opposite seems to happen in

Quoted 3 lines

fact.

Which devices were you thinking of, that need a

hardware IRQ and no kernel

Quoted 1 line

driver ?

An ISA cards, mostly for data acquisition - edge triggered interrupts,
no ack required immediately from interrupt handler. Rest of hardware
handling can be deferred to user space.
IRQ sharing is possible there in spite of some hardware hacking.

Quoted 6 lines

Yes, it is very limited range of hardware today but it exists
and /dev/irq kernel module provide one of generic mechanisms for user
space driver implementation.

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

#11 lore raw
In reply to Dmitry A. Fedorov
Quoted 11 lines · Dmitry A. Fedorov
Quoted 4 lines · Oliver Neukum
Quoted 2 lines

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

Unless you need that interrupt to be enabled to deliver the signal or let

Need not. Signal and other event delivery mechanisms has nothing common with disable/enable_irq().

Quoted 7 lines
Quoted 1 line

userspace reenable the interrupt.

"user acknowledge" is mean that.

Quoted 1 line

In addition, how do you handle shared interrupts ?

It is impossible, see my another message.

I don't see why you think it's impossible, the only thing you need is that your kernel module know how to discriminate the interrupt source.

You can do this also with a irq.o module and other tiny modules that register their irq source detection code.

Then you have /dev/irqX with the following API:

- ioctl(fd, IRQ_SUBSCRIBE, source_id);
- ioctl(fd, IRQ_ACK, source_id);
- poll
- async notification

Interrupts received between notification and acknowledge are queued (i.e. counted). An alternative to queuing (user selectable) is to block interrupt generation at hardware level in kernel space immediately before notification.

I'm missing something?

Signature · 8 lines
Abramo Bagnara                       mailto:[email protected]

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy

ALSA project               http://www.alsa-project.org
It sounds good!
#12 lore raw
Quoted 5 lines

(i.e. counted). An alternative to queuing (user selectable) is to block interrupt generation at hardware level in kernel space immediately before notification.

I'm missing something?

IRQ 9 shared between user space app and disk. IRQ arrives is disabled and reported, app wakes up, app wants to page in code, IRQ is disabled, box dies

You have to handle that in kernel space, at least enough to handle the irq event, ack it and queue the data

#13 lore raw
Quoted 5 lines · Alan Cox
Quoted 5 lines

(i.e. counted). An alternative to queuing (user selectable) is to block interrupt generation at hardware level in kernel space immediately before notification.

Quoted 7 lines
Quoted 1 line

I'm missing something?

IRQ 9 shared between user space app and disk. IRQ arrives is disabled and reported, app wakes up, app wants to page in code, IRQ is disabled, box dies

You have to handle that in kernel space, at least enough to handle the irq event, ack it and queue the data

I try to be more clear:

Kernel space:
- irq 9 arrives from our device
- interrupts are disabled
- our kernel space micro handler is invoked
- interrupt source is checked
- if no notification is pending a signal is notificated for user space (or a process is marked runnable)
- optionally our device interrupt generation is disabled
- handler returns
- interrupts are enabled

User space:
- signal arrive (or process is restarted)
- action is done
- notification is acknowledged (using an ioctl)

Kernel space:
- if we have other notifications to do, do one
- optionally our device interrupt generation is reenabled

Signature · 8 lines
Abramo Bagnara                       mailto:[email protected]

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy

ALSA project               http://www.alsa-project.org
It sounds good!
#14 lore raw
Quoted 16 lines · Abramo Bagnara
Quoted 5 lines · Alan Cox
Quoted 5 lines

(i.e. counted). An alternative to queuing (user selectable) is to block interrupt generation at hardware level in kernel space immediately before notification.

Quoted 7 lines
Quoted 1 line

I'm missing something?

IRQ 9 shared between user space app and disk. IRQ arrives is disabled and reported, app wakes up, app wants to page in code, IRQ is disabled, box dies

You have to handle that in kernel space, at least enough to handle the irq event, ack it and queue the data

I try to be more clear:

Quoted 10 lines

Kernel space:
- irq 9 arrives from our device
- interrupts are disabled
- our kernel space micro handler is invoked
- interrupt source is checked
- if no notification is pending a signal is notificated for user space (or a process is marked runnable)
- optionally our device interrupt generation is disabled
- handler returns
- interrupts are enabled

It just broke. The handler returned before the cause of the interrupt was handled. Think LEVEL interrupts. The same interrupt will again be entered, looping over and over again, until the tiny bit if CPU resource available for the few instants the handler was not in the ISR, was enough for the user-mode signal-handler to shut the damn thing off, pull the plug, and figure this will never work.

Quoted 6 lines

User space:
- signal arrive (or process is restarted)
- action is done
- notification is acknowledged (using an ioctl)

Way too late see above.

Quoted 5 lines

Kernel space:
- if we have other notifications to do, do one
- optionally our device interrupt generation is reenabled

Over and over again, I find more and more persons who haven't a clue about what an interrupt is and how it relates to the rest of the system. The start of this debacle occurred when CPUs became fast enough so sloppy 'C'-coders were able to make so-called interrupt handlers that kind of worked. Then others, looking at the code, said; "Oh! This is just ordinary 'C' code. Good, I can do this stuff too....". Ultimately we will have so-called Software Engineers reading and writing files in interrupt service routines.

There is no such thing as a "user mode" interrupt service routine. There never was one, and there will never be one on any machine that fetches instructions from memory for execution. Remember the Dr. Dobbs articles about "Interrupt THUNKS", you could use in real-mode interrupt service routines? No need to answer. They never worked, and they could never work. Remember "Call-backs" from interrupt service routines? They never worked either. These are all creations of coders, not Engineers, not even Technicians, coders who learned how to use a tool (a compiler), who came up with these "brilliant" ideas! Just because somebody published an article, doesn't mean that anything written therein was correct.

FYI. The purpose of an interrupt service routine is to handle the immediate needs of the hardware. That's all! There is nothing "immediate" in user-mode.

In a virtual memory system, the user's handler probably isn't even in memory at the time an interrupt arrives. And, it can't be paged into memory because the interrupt was for Disk I/O.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of course you get it all back when you reboot..."; Actual explanation obtained from the Micro$oft help desk.

#15 lore raw
Quoted 7 lines · Richard B. Johnson

It just broke. The handler returned before the cause of the interrupt was handled. Think LEVEL interrupts. The same interrupt will again be entered, looping over and over again, until the tiny bit if CPU resource available for the few instants the handler was not in the ISR, was enough for the user-mode signal-handler to shut the damn thing off, pull the plug, and figure this will never work.

Sorry, I've missed an action writing the previous message (now marked with a +)

Kernel space:
- irq 9 arrives from our device
- interrupts are disabled
- our kernel space micro handler is invoked
- interrupt source is checked
+ interrupt is acknowledged to our device
- if no notification is pending a signal is notificated for user space (or a process is marked runnable)
- optionally our device interrupt generation is disabled
- handler returns
- interrupts are enabled

Quoted 8 lines
Quoted 6 lines

User space:
- signal arrive (or process is restarted)
- action is done
- notification is acknowledged (using an ioctl)

Way too late see above.

Don't equivocate me: this not the IRQ acknowledge, it's the acknowledge of the user space notification.

Also note that this mechanism is not an attempt to demonstrate that to move interrupt handlers to user space is a good thing. I wanted only to show a way to permit to have *pseudo* interrupt handlers in user space also having shared IRQ.

Signature · 8 lines
Abramo Bagnara                       mailto:[email protected]

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy

ALSA project               http://www.alsa-project.org
It sounds good!
#16 lore raw
In reply to Alan Cox
Quoted 11 lines

Kernel space:
- irq 9 arrives from our device
- interrupts are disabled
- our kernel space micro handler is invoked
- interrupt source is checked
- if no notification is pending a signal is notificated for user space (or a process is marked runnable)
- optionally our device interrupt generation is disabled
- handler returns
- interrupts are enabled

Then why bother ? Write a minimum conventional kernel driver implementing poll()

Regards
Oliver

#17 lore raw
In reply to Abramo Bagnara

Hi!

Quoted 9 lines
Quoted 5 lines

(i.e. counted). An alternative to queuing (user selectable) is to block interrupt generation at hardware level in kernel space immediately before notification.

I'm missing something?

IRQ 9 shared between user space app and disk. IRQ arrives is disabled and reported, app wakes up, app wants to page in code, IRQ is disabled, box dies

Actually, what about specifying that your usermode app has to be pagelocked?

Alternatively.... You *can* do disk I/O without interrupts. Just poll your IDE controller. [I'm doing that on my velo.] Hopefully your timer IRQ is not shared with usermode app, then :-( [but that's almost impossible on PCs, right?].
Pavel

Signature · 2 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at [email protected]
#18 lore raw
In reply to Dmitry A. Fedorov
Quoted 2 lines

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

No. The IRQ might be shared, and you get a slight problem if you just disabled an IRQ needed to make progress for user space to handle the IRQ

#19 lore raw
Quoted 2 lines · Alan Cox

No. The IRQ might be shared, and you get a slight problem if you just disabled an IRQ needed to make progress for user space to handle the IRQ

Two choices:

- Disallow shared interrupts for usermode drivers.

- Make the 'generic interrupt handler device driver' configurable and/or module-extensible. You only need three entry points ("Interrupt set?"/"Enable interrupts"/"Disable interrupts"), which is reasonably simple to get right.

Signature · 1 line
Matthias Urlichs
#20 lore raw
In reply to Alan Cox
Quoted 5 lines · Alan Cox
Quoted 2 lines

Lastly an IRQ kernel module can disable_irq() from interrupt handler and enable it again only on explicit acknowledge from user.

No. The IRQ might be shared, and you get a slight problem if you just disabled an IRQ needed to make progress for user space to handle the IRQ

Disabling the IRQ till user acknowledge is an option for particular device handling.
Yes, IRQ sharing is impossible with it and IRQ module must reject setup requests with this option and SA_SHIRQ flag together. However, it is important for rare cases only with "bad" devices (their interrupt behaviour is really bad!) and IRQ sharing requirement.

#21 lore raw
In reply to Alan Cox

Hi!

Quoted 6 lines
Quoted 2 lines

No. The IRQ might be shared, and you get a slight problem if you just disabled an IRQ needed to make progress for user space to handle the IRQ

Two choices:

- Disallow shared interrupts for usermode drivers.

That's hard... If you your notebook comes with soundcard and ltmodem sharing the irq, and ltmodem only has userspace driver, you are screwed.
Pavel

Signature · 2 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at [email protected]
#22 lore raw
In reply to Alan Cox

Hi!

Quoted 7 lines
Quoted 4 lines

The problem is that the IRQ has to be cleared in
kernel space, because otherwise
you may deadlock.

I agree, the idea is to clear the IRQ in kernel space and then deliver to user level programs interested

...*IF* you know how to clear it. THat differs device-to-device.
Pavel

Signature · 2 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at [email protected]
#23 lore raw
In reply to Balbir Singh
Quoted 7 lines · Balbir Singh

I realize that the Linux kernel supports user level drivers (via ioperm, etc). However interrupts at user level are not supported, does anyone think it would be a good idea to add user level interrupt support ? I have a framework for it, but it still needs
a lot of work.

http://www.ibiblio.org/pub/Linux/kernel/irq-1.68.2.tar.gz
ftp://ftp.inp.nsk.su/export/fedorov/soft/irq-1.68.2.tar.gz

(2.0.x - 2.2.x kernels)

kernel module to delivery hardware interrupts to user space programs. Hardware interrupts (IRQ) are accessible by character devices /dev/irq[0-15]. Interrupts delivered by signals and select(2)/poll(2)

#24 lore raw
Quoted 4 lines · Dmitry A. Fedorov

kernel module to delivery hardware interrupts to user space programs. Hardware interrupts (IRQ) are accessible by character devices /dev/irq[0-15]. Interrupts delivered by signals and select(2)/poll(2)

i believe libgpio uses the existing usb/iee1394/serial/parallel interfaces to provide a limited userspace driver capability. gphoto2 uses this to support a LOT of digital cameras entirely in userspace...

obviously this concept isn't covering everything but it sure covers a lot of bases. also depends on what you understand a "driver" to be... from a "common user"'s perspective it just means "it makes my WinWidget work!"

it's similar to what you describe above in that there's a kernel interface, but it's more specific than /dev/irq5. this is good in that you don't want a different usb driver for every userspace usb device driver...

http://sourceforge.net/projects/gphoto/ (i think)

j.

Signature · 1 line
"Bobby, jiggle Grandpa's rat so it looks alive, please" -- gary larson
#25 lore raw
Quoted 2 lines · john slee

i believe libgpio uses the existing usb/iee1394/serial/parallel interfaces to provide a limited userspace driver capability.

That only means, however, that the specific kernel drivers explicitly support mid-level usermode access.

They still handle the actual hardware state changes without usermode support.

Signature · 1 line
Matthias Urlichs
#26 lore raw
Quoted 8 lines · Matthias Urlichs
Quoted 2 lines · john slee

i believe libgpio uses the existing usb/iee1394/serial/parallel interfaces to provide a limited userspace driver capability.

That only means, however, that the specific kernel drivers explicitly support mid-level usermode access.

They still handle the actual hardware state changes without usermode support.

yes, that was the point. while it might be a stretch of the "mechanism, not policy" argument, i like having drivers organized this way. it makes a lot of sense for hotpluggable things like usb.

j.

Signature · 1 line
"Bobby, jiggle Grandpa's rat so it looks alive, please" -- gary larson
#27 lore raw
In reply to Balbir Singh

Hi!

Quoted 8 lines

I realize that the Linux kernel supports user level drivers (via ioperm, etc). However interrupts at user level are not supported, does anyone think it would be a good idea to add user level interrupt support ? I have a framework for it, but it still needs
a lot of work.

Quoted 4 lines

Depending on the response I get, I can send out more email. Please cc me to the replies as I am no longer a part of the Linux kernel mailing list - due to the humble size of my mail box.

I'd like to see that done for userspace ltmodem
driver... Unfortunately it can not be easily done for shared PCI interrupts.
Pavel
PS: Next needed thing is to make it possible for usermode driver to "mimic" kernel one, including ioctls.

Signature · 2 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at [email protected]