As the package states, this contains some utilities which provide command-line access to the Linux kernel CPUFreq subsystem. It also contains a shared library for accessing this information from your own applications.
You can read about the subsystem here: https://www.kernel.org/doc/html/latest/cpu-freq/core.html
The Slackware package installs three utilities:
/usr/bin/cpufreq-aperf /usr/bin/cpufreq-info /usr/bin/cpufreq-set
And a shared library, header, and README:
/usr/doc/cpufrequtils-008/README usr/include/cpufreq.h usr/lib64/libcpufreq.so.0.0.0
There are man pages for info and set, but not for aperf:
$ man cpufreq-info $ man cpufreq-set
The README helpfully explains info and set, but not aperf:
"cpufreq-info" determines current cpufreq settings, and provides useful debug information to users and bug-hunters. "cpufreq-set" allows to set a specific frequency and/or new cpufreq policies without having to type "/sys/devices/system/cpu/cpu0/cpufreq" all the time.
cpufreq-info
Let’s start with the most obvious:
$ cpufreq-info cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 Report errors and bugs to cpufreq@vger.kernel.org, please. analyzing CPU 0: driver: acpi-cpufreq CPUs which run at the same hardware frequency: 0 CPUs which need to have their frequency coordinated by software: 0 maximum transition latency: 4294.55 ms. hardware limits: 2.20 GHz - 3.60 GHz available frequency steps: 3.60 GHz, 2.80 GHz, 2.20 GHz available cpufreq governors: conservative, userspace, powersave, ondemand, performance, schedutil current policy: frequency should be within 2.20 GHz and 3.60 GHz. The governor "ondemand" may decide which speed to use within this range. current CPU frequency is 2.20 GHz. cpufreq stats: 3.60 GHz:0.37%, 2.80 GHz:0.18%, 2.20 GHz:99.44% (1280) ... analyzing CPU 15: driver: acpi-cpufreq CPUs which run at the same hardware frequency: 15 CPUs which need to have their frequency coordinated by software: 15 maximum transition latency: 4294.55 ms. hardware limits: 2.20 GHz - 3.60 GHz available frequency steps: 3.60 GHz, 2.80 GHz, 2.20 GHz available cpufreq governors: conservative, userspace, powersave, ondemand, performance, schedutil current policy: frequency should be within 2.20 GHz and 3.60 GHz. The governor "ondemand" may decide which speed to use within this range. current CPU frequency is 2.55 GHz. cpufreq stats: 3.60 GHz:1.03%, 2.80 GHz:0.34%, 2.20 GHz:98.63% (894)
(I won’t waste precious Web space on all 16 cores, but the first and last entries give plenty of taste for it.)
If we just want the frequency of one core, we can ask for that with a command like the following (-f
requests just the frequency, -m
is for human-readable output, and -c
lets us request one specific core):
$ cpufreq-info -f -m -c 0 2.20 GHz
So I can see that core 0 is running at the minimum frequency.
Ah, but that’s only if we trust the Linux kernel. We can do better than that by reading the value from hardware (with superuser privileges):
$ while true do k=$(cpufreq-info -f -m -c 0) h=$(sudo cpufreq-info -w -m -c 0) echo "kernel lies: $k, hardware truth: $h"; sleep 1 done kernel lies: 2.20 GHz, hardware truth: 2.20 GHz kernel lies: 2.18 GHz, hardware truth: 3.60 GHz kernel lies: 2.18 GHz, hardware truth: 2.20 GHz kernel lies: 2.20 GHz, hardware truth: 2.20 GHz kernel lies: 2.18 GHz, hardware truth: 2.20 GHz kernel lies: 2.18 GHz, hardware truth: 2.20 GHz kernel lies: 2.20 GHz, hardware truth: 2.20 GHz kernel lies: 2.19 GHz, hardware truth: 2.20 GHz kernel lies: 2.17 GHz, hardware truth: 2.20 GHz kernel lies: 2.20 GHz, hardware truth: 2.20 GHz kernel lies: 2.18 GHz, hardware truth: 2.20 GHz kernel lies: 2.18 GHz, hardware truth: 2.20 GHz ...
Ha ha! Caught ya!
Of course, the above is a joke.
But I would like to profess my love for Bash’s C-x C-e
shortcut for editing the command line in $EDITOR
.
It’s one of the few Emacs-style Bash/readline keybinds I seem to have been able to memorize so far and it’s awesome for one-off scripts.
cpufreq-set
Moving on, it looks like the set command is quite simple. There are only a few parameters we can set, like min and max frequencies for a CPU.
I’m not a huge hardware settings tinkerer, generally, so I’ve little interest in trying this out.
Note
|
I used to love this stuff, but as the years go by, I’ve found my hardware victories to be ultimately emphemeral and rarely worth the effort - ironically, software tends to last longer. Of course, that depends on the hardware and the software. But I also contain a dichotomy: on one hand, I have learned to treat most of my home computers like cattle (as in pets vs cattle). On the other hand, I also have a strong retro-computing streak in me which loves old hardware, and I wish our computers (especially things like cell phones) weren’t so disposable. Part of me wishes the relentless pace of hardware would slow for a bit so that I could live with some of these machines long term and really learn them inside and out. Also, I’d love for us to concentrate on making better use of our hardware rather than just throwing more computing power at every problem - and this is coming from a software guy! |
cpufreq-aperf
No man page and no mention in the README. I’m just gonna see what this does:
$ cpufreq-aperf You must be root $ sudo cpufreq-aperf CPU Average freq(KHz) Time in C0 Time in Cx C0 percentage 000 2160000 00 sec 000 ms 00 sec 999 ms 00 001 2160000 00 sec 000 ms 00 sec 999 ms 00 002 2196000 00 sec 000 ms 00 sec 999 ms 00 003 2160000 00 sec 002 ms 00 sec 997 ms 00 004 2160000 00 sec 000 ms 00 sec 999 ms 00 005 2160000 00 sec 000 ms 00 sec 999 ms 00 006 2160000 00 sec 000 ms 00 sec 999 ms 00 007 2196000 00 sec 000 ms 00 sec 999 ms 00 008 2196000 00 sec 000 ms 00 sec 999 ms 00 009 2196000 00 sec 000 ms 00 sec 999 ms 00 010 2196000 00 sec 000 ms 00 sec 999 ms 00 011 2196000 00 sec 000 ms 00 sec 999 ms 00 012 2124000 00 sec 000 ms 00 sec 999 ms 00 013 2160000 00 sec 000 ms 00 sec 999 ms 00 014 2160000 00 sec 000 ms 00 sec 999 ms 00 015 2196000 00 sec 000 ms 00 sec 999 ms 00 ... <loop on repeat with slightly different numbers> ...
Okay, clearly I’m seeing output for each core. But I don’t pretend to understand what the "Time in C0/Cx" stuff means.
At first glance, the freq and times all seem to be the same, but careful examination shows that they do actually differ between cores and change over time.
I finally managed to find the "upstream" source for this utility here:
The comment at the top explains what it does:
* What does this program do: * * On latest processors exist two MSR registers refered to as: * - MPERF increasing with maxium (P0) frequency in C0 * - APERF increasing with current/actual frequency in C0 * * From this information the average frequency over a time period can be * calculated and this is what this tool does. * * A nice falloff feature beside the average frequency is the time * a processor core remained in C0 (working state) or any CX (sleep state) * processor sleep state during the measured time period. This information * can be determined from the fact that MPERF only increases in C0 state.
(There’s also an outstanding Todo item to create a man page. The tool was written in 2009 and the last commit was in 2010.)
So, not really understanding the explanation in the source, ended up reading up on a few things and I think I understand this now.
The first thing to know is that CPUs run in "C-states" or "processor states". These states indicate that the CPU is running, halted, sleeping, etc.
C0
is the operating state for a CPU.
C1
and higher are various halt or sleep states.
In addition, CPUs also have multiple "p-states" or "performance states". These states specifically scale the frequency and voltage of the CPU.
P0
always refers to "full speed ahead" maximum performance.
P1
and higher are various forms of power saving or sleep states.
All of this is defined in the ACPI standard.
(I first became aware of these when Linux would crash when my AMD Ryzen CPUs would enter state C6. Which reminds me, I need to write that up in an article with the fix for that for future reference, though new Linux kernels have now rendered this information obsolete?)
MPERF
and APERF
are x86 model-specific registers (MSRs).
Web search results for these registers were more painful than they should have been (or the results were big Intel PDFs).
Here’s an explanation for humans circa 2015 from Anil Maurya’s blog:
"Clock frequency" is something that you measure over some period of time, basically an average on how fast a clock signal went up/down.It’s something you can measure, but it’s backwards looking. Intel CPUs expose two counters (aperf and mperf) via MSR registers, and if you look at these two registers at two separate times (far enough apart to avoid rounding effects), the ratio of the delta in these two registers gives you a very nice "average frequency" over your measurement interval. (The official SDM documentation has the exact formula for this)
Clearly that’s what the comment at the top of cpufreq-aperf’s aperf.c
is talking about.
So I’m pretty sure that what I’m seeing is that my cores are spending the vast majority of their time in non-C0 states (in other words, they’re idling almost all of the time) until I start typing really hard in Vim and then they get used for a bit. Ha, actually, that’s probably just Firefox doing something in the background.)
Neat. I’ve learned a bit more today.
Until next time, happy hacking!