Commit cbaaf5f4 authored by Fabian Vogt's avatar Fabian Vogt

Try to read CPU clock from cpufreq/scaling_cur_freq instead of /proc/cpuinfo

Summary:
From kernel 4.13 on, /proc/cpuinfo always reports the static normative
CPU clock and not the current one. So try to read the frequency from
cpufreq and only fall back to cpuinfo it that fails.

BUG: 382561

Test Plan:
Started ksysguard, frequency now changes. If the file is not
readable, the frequency is read from cpuinfo as expected.

Reviewers: #plasma, sebas

Reviewed By: #plasma, sebas

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8153
parent 103ed0e9
......@@ -56,6 +56,10 @@ static void processCpuInfo( void )
* by the parse thus far */
int coreUniqueId = 0;
/* Indicates whether the "cpu MHz" value of the processor in /proc/cpuinfo should be used.
* This is not done if parsing the frequency from cpufreq worked. */
int useCpuInfoFreq = 1;
/* Reset global variables */
numCores = 0;
numProcessors = 0;
......@@ -94,8 +98,24 @@ static void processCpuInfo( void )
registerMonitor( cmdName, "float", printCPUxClock, printCPUxClockInfo,
CpuInfoSM );
}
useCpuInfoFreq = 1;
const char freqTemplate[] = "/sys/bus/cpu/devices/cpu%d/cpufreq/scaling_cur_freq";
char freqName[sizeof(freqTemplate) + 3];
snprintf(freqName, sizeof(freqName) - 1, freqTemplate, coreUniqueId);
FILE *freqFd = fopen(freqName, "r");
if (freqFd) {
unsigned long khz;
if(fscanf(freqFd, "%lu\n", &khz) == 1) {
Clocks[coreUniqueId] = khz / 1000.0f;
useCpuInfoFreq = 0;
}
fclose(freqFd);
}
}
} else if ( strcmp( tag, "cpu MHz" ) == 0 ) {
} else if ( useCpuInfoFreq && strcmp( tag, "cpu MHz" ) == 0 ) {
if (HighNumCores > coreUniqueId) {
/* The if statement above *should* always be true, but there's no harm in being safe. */
sscanf( value, "%f", &Clocks[ coreUniqueId ] );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment