GET_CYCLECOUNT(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… GET_CYCLECOUNT(9) β€” bestie, let's read the CPU's lil stopwatch ✨

okay so this one's from the Kernel Developer's Manual, section 9, and it's about a function that's lowkey iconic for anyone doing kernel timing stuff 🫢


🌸 NAME 🌸

get_cyclecount β€” grab the contents of the CPU's fast counter register, fr fr


✨ SYNOPSIS ✨

bestie, include these first:

#include <sys/param.h>
#include <sys/systm.h>
#include <machine/cpu.h>

and here's the signature, character for character:

uint64_t
get_cyclecount(void);

πŸ’– DESCRIPTION πŸ’–

So the get_cyclecount() function uses a register that most modern CPUs have, and it returns a value that's monotonically increasing inside each CPU. Monotonic means it only ever goes up β€” it's giving main character energy that never backtracks πŸ’…

On SMP systems there will be a number of separate monotonic sequences, one for each CPU running. And in the SMP case, the value you get is selected from one of those sequences, depending on which CPU was scheduled to service the request. iykyk β€” different CPU, different sequence 🌈

The speed and the maximum value of each counter is CPU-dependent, so don't @ it for being inconsistent across machines.

Some CPUs β€” like the Intel 80486 β€” literally don't have such a register 😭 so on those platforms get_cyclecount() returns a (monotonic) combination of numbers represented by the structure returned by binuptime(9). No counter? No problem, it fakes it cutely.

And the AMD64 and Intel 64 processors use the TSC register β€” that's the one, periodt πŸ”₯


πŸ¦‹ SEE ALSO πŸ¦‹


πŸŽ€ HISTORY πŸŽ€

The get_cyclecount() function first appeared in FreeBSD 5.0, so it's been slaying since before some of us could read 🫢


πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Mark Murray <markm@FreeBSD.org> β€” shoutout to the icon who typed it up πŸ’œ


ngl, that's the whole page β€” every flag, every caveat, every lil detail, all present and accounted for ✨

okay bestie that's a wrap! 🌸 this beauty comes from the Debian fam, dated March 15, 2011 β€” a true vintage classic, and honestly? it ate πŸ’– see u in the next manpage, mwah πŸŽ€πŸ§š

πŸ“¦ where this page comes from