GET_CYCLECOUNT(9)

πŸ’– GET_CYCLECOUNT πŸ’–

okay bestie, welcome to section 9 of the Kernel Developer's Manual β€” that's the <rainbow>kernel dev</rainbow> zone, no userspace nonsense allowed ✨. This little page is all about get_cyclecount, and honestly? She's giving "tiny function, huge personality". Let's get into it 🫢


✨ NAME ✨

get_cyclecount β€” grab the CPU's fast counter register contents, like, right now πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

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

uint64_t
get_cyclecount(void);

three includes, one function, zero arguments. she's low maintenance, she's iconic 🌸


πŸ¦‹ DESCRIPTION πŸ¦‹

so. get_cyclecount() uses a register that most modern CPUs just… have πŸ’β€β™€οΈ and it returns a value that's monotonically increasing inside each CPU. meaning: on any given CPU, that number only ever goes up. never down. she does not do backtracking, periodt ⭐

on SMP systems β€” that's symmetric multiprocessing, multiple CPUs doing their thing β€” there are going to be a whole bunch of separate monotonic sequences, one for each CPU that's running πŸ‘‘. so when you call it, the value you get is selected from one of those sequences, depending on which CPU got scheduled to service your request. so it's like, whichever CPU picked up the phone πŸ“ž

the speed and the maximum value of each counter is CPU-dependent β€” no universal vibes here, every chip does its own thing πŸ™ˆ

and now the sad part 😭: some CPUs (looking at you, Intel 80486) simply do not have such a register. rude. so on those platforms, get_cyclecount() returns a monotonic combination of numbers represented by the structure returned by binuptime(9) instead. it's not the same register magic, but it's still monotonic, so the vibe holds 🧚

and for the cool kids: AMD64 and Intel 64 processors use the TSC register πŸ”₯ (TSC = timestamp counter, iykyk)


🌈 SEE ALSO 🌈

  • binuptime(9) β€” go read her next, she's the fallback bestie πŸ’œ

⭐ HISTORY ⭐

get_cyclecount() first appeared in FreeBSD 5.0. she's been around, she's got lore πŸ‘‘


πŸ“ AUTHORS πŸ“

This manual page was written by Mark Murray <markm@FreeBSD.org>. thank you for your service, king πŸ«‘πŸ’–


ok that's the whole page, nothing skipped, nothing summarised β€” every flagless, argument-less, uint64_t-returning detail is right here πŸŽ€

and that's a wrap on this one, bestie!! this page ships with the Debian manual set, dated March 15, 2011 β€” yeah she's a little vintage, but vintage is a lifestyle πŸ’…βœ¨ bye babes!! πŸŒΈπŸ¦‹πŸ’–

πŸ“¦ where this page comes from