Score:-1

How can I get my CPU to run at maximum speed by circumventing CPU scaling?

sa flag

I am running CentOS 7 (7.9.2009) (kernel 3.10.0-1160.49.1.el7.x86_64) on a rather old laptop (Lenove T61) with a dual core CPU (Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz). The driver for CPU scaling is acpi-cpufreq, and when on the performance governor, I can get the CPU to run at the max CPU speed as listed in /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq, and observe this by doing:

$ grep -i mhz /proc/cpuinfo 
cpu MHz     : 2001.000
cpu MHz     : 2001.000

and it is rock-steady at this speed. I can verify this by doing:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
2001000
$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq 
2001000

I am trying to run at a constant frequency for a real-time program that counts CPU clock cycles for timing. I compiled a custom kernel (5.10.83-rt58) to support a piece of hardware that isn't supported in the default CentOS kernel (3.10.0). CPU scaling usually causes the clock frequency to jump around, but I found that I can get a steady frequency by setting all the values in /sys/devices/system/cpu/cpu*/cpuidle/state*/disable to 1. When I check the frequency:

$ grep -i mhz /proc/cpuinfo 
cpu MHz     : 1995.106
cpu MHz     : 1995.106

it is not quite at the 2001MHz as seen with the 3.10.0 kernel. The following command verifies this:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
1995106

But the output of:

$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
2001000

is different. My question is does anyone know why my CPU isn't running at the maximum frequency (2001MHz) but at ~6MHz less? Did something drastic change in cpu scaling between kernel 3.10 and 5.10?

Paul Gear avatar
cn flag
This question is better asked on [Super User](https://superuser.com/).
Score:1
cn flag

I am trying to run at a constant frequency for a real-time program that counts CPU clock cycles for timing.

This approach is problematic, as modern performance scaling CPUs are not going to run at one frequency. Their exact cycle count depends on thermal conditions. Maybe your socket is ever so slightly defective. And your custom kernel could have arbitrary differences from Red Hat's so yes it is possible it (or the microcode) pokes the CPU in different ways.

Use the timer APIs provided. Linux realtime outlines a basic cyclic application. Note the use of clock_nanosleep() with CLOCK_MONOTONIC.

ESR's time programming reference is a decent history of why there are several dozen time functions.


To tweak CPU governors and other tuning for latency and power reasons, have a look at tuned. For example, the latency-performance profile.

Mitch avatar
sa flag
Thanks for the answer, very insightful, but "modern performance scaling CPUs are not going to run at one frequency" isn't true, I can get my CPU to run at a constant 2001MHz using kernel 3.10. I have other machines running CentOS7 (Intel Core I5 CPU) and I can get kernel 3.10 to run the CPU at a constant frequency. I feel like there might be a kernel flag or something for this that I don't know about since I'm not a kernel expert.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.