Skip to contentSkip to conversation

sleep

DISCUSSION Tobin C. Harding 4 participants 6 messages Oct 26, 2017 – Nov 16, 2017

lore
Share & tools
lore
#0 lore raw

Is there any 'non-process' context apart from interrupt context? I had a re-read of sleep sections in ldd3 and in Robert Love's book but am still not totally clear on this.

The reason for the question is understanding when we cannot sleep.

thanks in advance,
Tobin.

#1 lore raw

Sleeping while holding the spin lock is forbidden. Sleeping in Tasklets is forbidden.

Best regards,
Bogdan

Quoted 14 lines · Tobin C. Harding

Is there any 'non-process' context apart from interrupt context? I had a re-read of sleep sections in ldd3 and in Robert Love's book but am still not totally clear on this.

The reason for the question is understanding when we cannot sleep.

thanks in advance,
Tobin.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

#2 lore raw
In reply to Tobin C. Harding
Quoted 5 lines · Tobin C. Harding

Is there any 'non-process' context apart from interrupt context? I had a re-read of sleep sections in ldd3 and in Robert Love's book but am still not totally clear on this.

The reason for the question is understanding when we cannot sleep.

Well, AFAIK you can simplify things to interrupt vs process context, but you might be aware that inside interrupt context there are others (NMI, HWIRQ, SOFTIRQ, ..), infos that you can find in Robert's book. What confused me for sometime was the 'atomic' vs 'interrupt' naming, but after reading Robert's book it cames to the fact that they're the same.

The general rule is that in any interrupt context you can't sleep, and why is that? Because interrupts aren't processes, there isn't an actual process that the scheduler can put to sleep and wake it up later. It's basically a design decision. Kernel-RT patches provide the feature of sleepable interrupts, since the goal there is the latency and not performance. That said, in short, the idea in Linux Kernel (I'm not an expert, far from that actually, so anyone can correct me) is to make interrupts atomic in behalf of simplicity and performance.

But hey, be careful, there are that talk about top vs bottom halves mechanisms (to defer work) right? Top are always in interrupt context, but bottom ones can run in process context. The most basic ones are Softirqs, Tasklets and Workqueues, the former is the most low-level available and I won't talk about it, but basicaly softirqs and tasklets run in interrupt context, thus can't sleep, while workqueues is handled in process context, thus can sleep normally (it can be rescheduled).

But as I said, I'm far from expert in the subject. What I've said here is just what I know about :)

Hope it helps you.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20171114/d5bd8b2e/attachment-0001.bin

#3 lore raw
Quoted 30 lines · Bruno E. O. Meneguele
Quoted 5 lines · Tobin C. Harding

Is there any 'non-process' context apart from interrupt context? I had a re-read of sleep sections in ldd3 and in Robert Love's book but am still not totally clear on this.

The reason for the question is understanding when we cannot sleep.

Well, AFAIK you can simplify things to interrupt vs process context, but you might be aware that inside interrupt context there are others (NMI, HWIRQ, SOFTIRQ, ..), infos that you can find in Robert's book. What confused me for sometime was the 'atomic' vs 'interrupt' naming, but after reading Robert's book it cames to the fact that they're the same.

The general rule is that in any interrupt context you can't sleep, and why is that? Because interrupts aren't processes, there isn't an actual process that the scheduler can put to sleep and wake it up later. It's basically a design decision. Kernel-RT patches provide the feature of sleepable interrupts, since the goal there is the latency and not performance. That said, in short, the idea in Linux Kernel (I'm not an expert, far from that actually, so anyone can correct me) is to make interrupts atomic in behalf of simplicity and performance.

But hey, be careful, there are that talk about top vs bottom halves mechanisms (to defer work) right? Top are always in interrupt context, but bottom ones can run in process context. The most basic ones are Softirqs, Tasklets and Workqueues, the former is the most low-level available and I won't talk about it, but basicaly softirqs and tasklets run in interrupt context, thus can't sleep, while workqueues is handled in process context, thus can sleep normally (it can be rescheduled).

Quoted 4 lines

But as I said, I'm far from expert in the subject. What I've said here is just what I know about :)

Hope it helps you.

thanks for your response,
Tobin.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20171115/94d3e61b/attachment.bin

#4 lore raw
In reply to Bruno E. O. Meneguele
Quoted 3 lines · Bruno E. O. Meneguele

What
confused me for sometime was the 'atomic' vs 'interrupt' naming, but after reading Robert's book it cames to the fact that they're the same.

Not exactly the same. Atomic means you're protected from some sort of
interruption: e.g. you raise preemption counter and you're protected from scheduling, but you still may be interrupted, or you disable interrupts and you're protected from scheduling and interrupts, but there still may be an NMI.

Signature · 2 lines
Thanks.
-- Max
#5 lore raw
Quoted 6 lines · Max Filippov
Quoted 3 lines · Bruno E. O. Meneguele

What
confused me for sometime was the 'atomic' vs 'interrupt' naming, but after reading Robert's book it cames to the fact that they're the same.

Quoted 6 lines

Not exactly the same. Atomic means you're protected from some sort of
interruption: e.g. you raise preemption counter and you're protected from scheduling, but you still may be interrupted, or you disable interrupts and you're protected from scheduling and interrupts, but there still may be an NMI.

Ahh, well pointed. Got it. Thank you for the info :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20171116/ab20746b/attachment.bin