GET_CYCLECOUNT(9)
π 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
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2000 Mark R V Murray
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms