SYSMON_TASKQ(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… SYSMON_TASKQ πŸ’…

okay so bestie, welcome to sysmon_taskq β€” it's a page from the Kernel Developer's Manual (section 9, the kernel-functions zone, iykyk), and it's literally the general purpose system monitoring task queue. yes the name is a mouthful. no we're not changing it. let's go πŸŽ€


✨ SYNOPSIS ✨

#include <dev/sysmon/sysmon_taskq.h>

void
sysmon_task_queue_preinit(void);

void
sysmon_task_queue_init(void);

void
sysmon_task_queue_fini(void);

int
sysmon_task_queue_sched(u_int pri, void (*func)(void *), void *arg);

void
sysmon_task_queue_barrier(u_int pri);

🌸 DESCRIPTION 🌸

so the sysmon_taskq is machine-independent, which is the cute way of saying it doesn't care what hardware you're on, and it gives you a simple general purpose task queue. that's the whole vibe. it's here to run callbacks that need thread context but honestly do not warrant pulling out some more fine-grained solution. like, don't over-engineer it, bestie. πŸ’…

the intended usage is all about system monitoring and power management context, but ngl, other comparable functions are also totally suitable for sysmon_taskq. it's not gatekeeping. 🫢


πŸ¦‹ FUNCTIONS πŸ¦‹

πŸŽ€ the setup trio

the necessary internal data structures get initialized during system startup by sysmon_task_queue_preinit(). that's the pregame. ✨

before you can actually use it, a machine-dependent procedure should finish the initialization by calling sysmon_task_queue_init(). this is the one that creates a kernel thread, and that thread can later be halted by sysmon_task_queue_fini(). and here's the important part β€” all scheduled tasks are executed before the queue is halted. no yeeting pending work into the void. queen behavior honestly. πŸ‘‘

πŸ“ the actual scheduling

  • sysmon_task_queue_sched() β€” enqueues func to be executed at the priority pri. if pri is 0, the scheduled function gets placed as the last element in the queue (aka back of the line, no cutting). the single argument passed to func is specified by arg. one arg, that's it, that's the contract. πŸ™ˆ
  • sysmon_task_queue_barrier() β€” waits for the completion of all tasks at pri or lower currently queued at the time of the call. read that again: at the time of the call. it's a vibe check for the queue, not a forever-wait. ⭐

πŸ”₯ RETURN VALUES πŸ”₯

upon successful completion, sysmon_task_queue_sched() returns 0. slay. otherwise, you get one of these little error icons:

  • [EINVAL] β€” an invalid parameter was specified. bestie, check your args. πŸ’€
  • [ENOMEM] β€” there was not enough memory. 😭

🌈 SEE ALSO 🌈

queue(3), kthread(9), workqueue(9)

go read those too, fr fr. iykyk. πŸ“š


πŸ‘‘ AUTHORS πŸ‘‘

Jason R. Thorpe <thorpej@NetBSD.org> β€” the main character who wrote this. respect the icon. πŸ’œ


🧚 tiny reminder: this page is from the kernel dev manual, so everything here is kernel-land. no cap. don't go calling these from your little userland program, it's giving undefined behavior. 🫢

and that's the page, bestie! this rendered all the way from the Debian edition, dated January 24, 2010 β€” yes she's vintage, and she still ate. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from