CPUCTL(4)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 14.5, freebsd 15.1

πŸ’… CPUCTL(4) β€” the cpuctl pseudo device, explained by your favorite Unix bestie

okay so this is from the Kernel Interfaces Manual, and it's about cpuctl β€” yes the little pseudo device that lets you poke at your CPU's guts. buckle up πŸŽ€


✨ NAME ✨

cpuctl β€” the cpuctl pseudo device. that's it, that's the name. iconic. πŸ’…


🌸 SYNOPSIS 🌸

so if you wanna compile this driver into the kernel, you drop these lines in your kernel configuration file:

device cpuctl

or, bestie alternative ✨ β€” load it as a module at boot time by putting this in loader.conf(5):

cpuctl_load="YES"

either way, you're getting cpuctl. no cap. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

The special device /dev/cpuctl is basically a little interface to your system CPU. it gives you the power to grab CPUID info, read and write machine specific registers (MSR), and do CPU firmware updates. main character energy fr fr πŸ‘‘

for every CPU present in the system, a special device /dev/cpuctl%d gets created with the appropriate index. and for multicore CPUs? yes queen, one of these special devices gets created for each core. πŸ’–

currently, only i386 and amd64 processors are supported. periodt.


πŸ”₯ IOCTL INTERFACE πŸ”₯

all the supported operations get invoked using the ioctl(2) system call. currently, the following ioctls are defined:

  • CPUCTL_RDMSR cpuctl_msr_args_t *args
  • CPUCTL_WRMSR cpuctl_msr_args_t *args

read/write CPU machine specific register. the cpuctl_msr_args_t structure is defined in <sys/cpuctl.h> as:

typedef struct {
        int             msr;    /* MSR to read */
        uint64_t        data;
} cpuctl_msr_args_t;
  • CPUCTL_MSRSBIT cpuctl_msr_args_t *args
  • CPUCTL_MSRCBIT cpuctl_msr_args_t *args

set/clear MSR bits according to the mask given in the data field. slay πŸ’…

  • CPUCTL_CPUID cpuctl_cpuid_args_t *args

retrieve CPUID information. arguments are supplied in the following structure:

typedef struct {
        int             level;          /* CPUID level */
        uint32_t        data[4];
} cpuctl_cpuid_args_t;

it's equivalent to the CPUCTL_CPUID_COUNT request with level_type set to 0. iykyk ✨

  • CPUCTL_CPUID_COUNT cpuctl_cpuid_count_args_t *args

retrieve CPUID information. arguments are supplied in the following structure:

typedef struct {
        int             level;          /* CPUID level */
        int             level_type;     /* CPUID level type */
        uint32_t        data[4];
} cpuctl_cpuid_count_args_t;

the level field indicates the CPUID level to retrieve, and it gets loaded into the %eax register before the CPUID instruction is executed. the level_type field indicates the CPUID level type to retrieve, and it gets loaded into the %ecx register.

the data field is used to store the received CPUID data. that is, data[0] contains the value of the %eax register after the CPUID instruction is executed, data[1] is for %ebx, data[2] for %ecx, and data[3] for %edx. literally all four, accounted for πŸ’€

  • CPUCTL_UPDATE cpuctl_update_args_t *args

update CPU firmware (microcode). the structure is defined in <sys/cpuctl.h> as:

typedef struct {
        void    *data;
        size_t  size;
} cpuctl_update_args_t;

the data field should point to the firmware image of size size. 🧚

for additional information refer to cpuctl.h. go off, header file. πŸ‘‘


🌈 FILES 🌈

/dev/cpuctl


πŸ’œ ERRORS πŸ’œ

  • [ENXIO] β€” the operation requested is not supported by the device (e.g., unsupported architecture or the CPU is disabled). sad but valid 😭
  • [EINVAL] β€” incorrect request was supplied, or microcode image is not correct.
  • [ENOMEM] β€” no physical memory was available to complete the request.
  • [EFAULT] β€” the firmware image address points outside the process address space. rude. πŸ™ˆ

⭐ SEE ALSO ⭐

hwpmc(4), cpucontrol(8)


πŸŽ€ HISTORY πŸŽ€

The cpuctl driver first appeared in FreeBSD 7.2. a legend was born ✨


πŸ‘‘ AUTHORS πŸ‘‘

The cpuctl module and this manual page were written by Stanislav Sedov <stas@FreeBSD.org>. we stan. 🫢


πŸ’€ BUGS πŸ’€

yes, probably, report if any. that's the whole section. i'm obsessed with the honesty ngl 😭


lowkey a whole vibe check: only i386 and amd64, so don't come for this driver with anything else bestie πŸ“

and that's the tea 🍡 β€” this page is from the Debian build, dated June 20, 2014, bestie. oldie but a goodie. mwah πŸ’‹ 🌸

πŸ“¦ where this page comes from