INTRMAP_CREATE(9)
β¨ INTRMAP_CREATE β the interrupt-to-CPU mapping API π
okay so bestie, this is the INTRMAP_CREATE(9) page from the Kernel Developer's Manual, and it's genuinely such a serve. it's all about how hardware drivers get to use multiple CPUs at once, and honestly? iconic. let's get into it π«Ά
πΈ NAME πΈ
intrmap_create, intrmap_destroy, intrmap_count, intrmap_cpu β the interrupt to CPU mapping API, aka the whole little friend group of functions that lets your driver spread its interrupts across CPUs π
π SYNOPSIS π
#include <sys/intrmap.h>
struct intrmap *
intrmap_create(const struct device *dv, unsigned int nintr,
unsigned int maxintr, unsigned int flags);
void
intrmap_destroy(struct intrmap *im);
unsigned int
intrmap_count(struct intrmap *im);
struct cpu_info *
intrmap_cpu(struct intrmap *im, unsigned int index);
like yes, that's the whole squad right there β
π¦ DESCRIPTION π¦
so the interrupt to CPU mapping API is literally there to support hardware drivers using multiple CPUs. drivers that can use multiple interrupts hit up this API to request a set of CPUs that they can establish those interrupts on. the API lowkey keeps the requested number of interrupts within what's actually available on the system, and it tries to distribute the requested interrupts over those CPUs. on some platforms the API will filter the set of available CPUs too β vibe check on the CPUs, basically π
intrmap_create() allocates an interrupt map data structure for the driver identified by dv. the number of interrupts the hardware supports goes in the nintr argument. the driver supplies the maximum number of interrupts it can support via maxintr, which β along with the number of available CPUs at the time the function is called β is used as a constraint on the number of requested interrupts. nintr may be zero to use the driver limit as the number of requested interrupts. π
the flags argument may have the following defines OR'ed together:
INTRMAP_POWEROF2β the hardware only supports a power of 2 number of interrupts, so constrain the number of supplied interrupts after the system and driver limits are applied. no cap, math first, power-of-2 second β¨
intrmap_destroy() frees the memory associated with the interrupt map data structure passed via im. bye bestie, releasing your memory π«Ά
intrmap_count() returns the number of interrupts that the driver can establish according to the im interrupt map. it's giving "how many do you actually get" energy π₯
intrmap_cpu() returns which CPU the interrupt specified in index should be established on, according to the im interrupt map. interrupts are identified as a number from 0 to the value returned by intrmap_count(). so like, index 0 through intrmap_count() minus one, iykyk π
π CONTEXT π
intrmap_create(), intrmap_destroy(), intrmap_count(), and intrmap_cpu() can all be called during autoconf, or from process context. either era, they're ready π
π RETURN VALUES π
intrmap_create()β returns a pointer to an interrupt mapping structure on success, orNULLon failure. so like, check forNULL, bestie, that's the whole point πintrmap_count()β returns the number of interrupts that were allocated for the driver to use.intrmap_cpu()β returns a pointer to thecpu_infostructure for the CPU that the interrupt should be established on.
π HISTORY π
the interrupt mapping API is based on the if_ringmap API in DragonFly. it was ported to OpenBSD 6.8 by David Gwynne <dlg@openbsd.org>. shoutout, periodt π
ngl bestie, if you're writing a driver that wants multiple interrupts across multiple CPUs, this is the API. go slay π§
and that's the whole page, fr fr! this gem is from the Debian build of the Kernel Developer's Manual, dated July 31, 2022 β so cute, so iconic, and now you know all of it πβ¨π
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2020 David Gwynne <dlg@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms