KPREEMPT(9)
π KPREEMPT(9) β control kernel preemption
okay so bestie, this is a page from the Kernel Developer's Manual (that's the manual name, consider it folded in nicely π) and it's all about kpreempt β like, the whole vibe is controlling kernel preemption. yes it's as serious as it sounds. no cap.
β¨ SYNOPSIS β¨
first you gotta bring the header in, like:
#include <sys/systm.h>
then the actual functions, all three of them, exactly like this:
void
kpreempt_disable(void);
void
kpreempt_enable(void);
bool
kpreempt_disabled(void);
π¦ DESCRIPTION π¦
okay so here's the tea: these functions control kernel preemption of the calling LWP. that's the whole gig. π«Ά
and like β on architectures where kernel preemption is not supported natively, you can still use these functions. they don't ghost you. π
β οΈ lowkey important: kernel preemption is also disabled when you're holding the interrupt priority level aboveIPL_NONE, e.g. usingspl(9)or spinningmutex(9)calls, or holdingkernel_lock(which is basically the code screaming "i am not MT safe"). so like, keep that in mind before you go blaming these functions, iykyk.
now the main characters one by one:
kpreempt_disable()β disables kernel preemption of the calling LWP. iconic. but bestie, fair warning: disabling kernel preemption can prevent LWPs with higher priorities from running. so likeβ¦ use it with intent, not just for the aesthetic. πkpreempt_enable()β enables kernel preemption of the calling LWP, the exact preemption that was previously disabled bykpreempt_disable(). it's giving "put it back the way you found it". β¨kpreempt_disabled()β returnstrueif preemption of the calling LWP is disabled. and like, quick vibe check: it is only for diagnostic purpose. don't be out here building your whole logic on it, fr fr. π
also!! kpreempt_disable() and kpreempt_enable() can be nested π β yes queen, stack them. disable, disable, disable, then enable your way back out. slay.
πΈ SEE ALSO πΈ
go read those, they're literally the supporting cast π
ok that's the whole page, mwah π β this gem is from the Debian edition, dated February 16, 2010 (yes, a classic, vintage even π), and it says KPREEMPT(9) at the bottom like a little signature. bye bestie, preempt responsibly π¦β¨
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c)2008 YAMAMOTO Takashi
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms