Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Interrupt Threading?

(NB: This is not about interrupting Java/.NET threads, this is about kernel-mode interrupts.)

Hi,

Wikipedia has this to say about Interrupt Threads in the Interrupt handler article:

Interrupt threads

Several operating systems - Solaris, NetBSD, Mac OS X, WinCE and FreeBSD, for example - use different scheme known as interrupt threads. An interrupt handler provided by the device driver is just a high-priority thread which runs with interrupts enabled and, more importantly, may block on mutex. This greatly simplifies locking in the kernel. Also, interrupt thread may be preempted by higher-priority interrupt thread.

What is this technique of Interrupt Threads that FreeBSD (among others) apparently uses? And where can I read more about it?

Thanks in advance. :)

like image 220
Bjarke Freund-Hansen Avatar asked Oct 13 '22 19:10

Bjarke Freund-Hansen


2 Answers

Hardware informs the operating systems of some event with interruptions. They can be raised when an error occurs or when some peripheral has new data available (user pressed a key, a packet arrived on the network, a timer expired, ...). Those interruptions need to be handled quickly by the system (so that it appears responsive).

They are handled by the kernel. Generally, when one such interruption arrives, the currently running code is stopped, and a function of the kernel is called. The interruptions must be acted upon quickly to have a responsive system, so they must not block the kernel waiting for some resource, or do something like that. The classic solution is to have a dumb interruption function that just note the number of the interruption and return, and then in the main loop of the kernel, to check if any interruption occurred and to call the real handler.

As those interruption can be masked (except for non maskable interruption - NMI), the kernel can spawn some threads in kernel mode, and only have them unmasks the interruption and handle them. As those thread are independent of the main kernel thread, they can block, provided there are enough threads to handle the interruptions that may arrive while the thread is blocked.

like image 171
Sylvain Defresne Avatar answered Oct 18 '22 03:10

Sylvain Defresne


There's some more technical information in FreeBSD's ithread(9).

like image 23
BCran Avatar answered Oct 18 '22 01:10

BCran