irq

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

irq package provides low-level functions to read interrupts from /proc/interrupts and to read and write CPU affinities of interrupts through /proc/irq/NUMBER/smp_affinity_list.

Interrupt data read from procfs is cached, which assumes that interrupts are neither added nor removed at runtime and that no entity outside this package alters interrupt affinities. Affinities set between BlockWrites and UnblockWrites are buffered, and only the affinity set last for an interrupt reaches procfs.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrDeniedInterrupt is the error returned for attempts to reference or control
	// globally disallowed interrupts.
	ErrDeniedInterrupt = errors.New("denied interrupt")
)

Functions

func BlockWrites

func BlockWrites()

BlockWrites starts buffering interrupt affinities instead of writing them to procfs. Every call must be paired with an UnblockWrites call, and the calls may be nested.

func DropCache

func DropCache()

DropCache drops all cached interrupt data: the interrupts read from the interrupts file, the affinities read from or written to procfs, and the affinities which are buffered but not written yet.

func ForEachInterrupt

func ForEachInterrupt(fn func(*Irq) error) error

ForEachInterrupt collects all numbered interrupts listed in /proc/interrupts, calling the given function on each. If the function returns an error, iteration is stopped early and the received error is returned. It uses the currently set allowed patterns to determine if an interrupt is allowed to be controller by this package.

func IsAllowedInterrupt

func IsAllowedInterrupt(description string) bool

IsAllowedInterrupt returns true if the IRQ corresponding to the given description is allowed to be controlled via this package, as defined by the currently set allowed patterns.

func SetAllowedInterrupts

func SetAllowedInterrupts(patterns []string) ([]string, error)

SetAllowedInterrupts configures which interrupts can be controller using this package. With allow patterns unset any interrupt can be controlled. With patterns set, only interrupts with a matching description in /proc/interrupts can be controlled. If any pattern fails validity checking an error is returned. On success, the old patterns previously in effect are returned.

func SetProcRoot

func SetProcRoot(root string)

SetProcRoot sets the procfs root directory and proc mountpoint. All data cached from the previous mountpoint is dropped, including buffered interrupt affinities.

func UnblockWrites

func UnblockWrites()

UnblockWrites removes one write block set by BlockWrites. Removing the last block writes all buffered interrupt affinities to procfs, logging write errors instead of returning them.

func ValidateAllowedPatterns

func ValidateAllowedPatterns(patterns []string) error

ValidateAllowedPatterns validates zero or more globbing patterns for interrupt description matching.

Types

type Irq

type Irq struct {
	// contains filtered or unexported fields
}

Irq represents a single numbered hardware interrupt.

func Interrupts

func Interrupts() ([]*Irq, error)

Interrupts collects and returns the numbered interrupts listed in /proc/interrupts which can be controlled by this package according to the currently set allowed patterns.

func ValidateAllowedReferencedInterrupts

func ValidateAllowedReferencedInterrupts(references []string, allow []string) ([]*Irq, error)

ValidateAllowedReferencedInterrupts takes a set of user interrupt glob patterns and validates them against the denied set of HW IRQs, as defined by the given allow patterns. Returns denied IRQs referenced by any pattern, with denied reference details in errors.

func ValidateReferencedInterrupts

func ValidateReferencedInterrupts(references []string) ([]*Irq, error)

ValidateReferencedInterrupts takes a set of user interrupt glob patterns and validates them against the denied set of HW IRQs, as defined by the currently set allowed patterns. Returns denied IRQs referenced by any pattern, with denied reference details in errors.

func (*Irq) AffinityCpus

func (irq *Irq) AffinityCpus() (cpuset.CPUSet, error)

AffinityCpus returns the CPUs in the affinity of the interrupt. The returned CPUs are the ones set last through this package, even if they have not reached procfs yet.

func (*Irq) Description

func (irq *Irq) Description() string

Description returns the chip and device description of the interrupt.

func (*Irq) Match

func (irq *Irq) Match(pattern string) bool

Match returns whether the interrupt matches the pattern string, that is either the exact interrupt number or a shell-like wildcard pattern match of its description.

func (*Irq) Num

func (irq *Irq) Num() int

Num returns the number of the interrupt.

func (*Irq) SetAffinityCpus

func (irq *Irq) SetAffinityCpus(cpus cpuset.CPUSet) error

SetAffinityCpus sets the CPUs in the affinity of the interrupt. While writes are blocked, the affinity is only buffered and write errors are logged instead of being returned.

func (*Irq) String

func (irq *Irq) String() string

String returns the interrupt as a human readable string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL