summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2020-01-09 01:42:35 +0100
committerSlávek Banko <slavek.banko@axis.cz>2020-01-09 01:42:52 +0100
commitddf0666f4c03a6e63138b7ca2db790fdc976fedd (patch)
treeaf89a29db1474cf86e66bed639e8cfd06b04a7ba
parentd51d6d349d94947b061bec765fa89a3af1aa1524 (diff)
downloadtdelibs-ddf0666f4c03a6e63138b7ca2db790fdc976fedd.tar.gz
tdelibs-ddf0666f4c03a6e63138b7ca2db790fdc976fedd.zip
tdehwlib: Fix parsing of CPU cores frequency information
+ The current frequency is parsed from the scaling_cur_freq file If the current frequency is not found in /proc/cpuinfo, the attempt to read value from cpuinfo_cur_freq failed because only root can read this file. + The have_frequency flag is not set when parsing current frequency from sysfs Setting the have_frequency flag after parsing current frequency for the first core caused the current frequency not to be parsed for other cores. + Frequency characteristics are parsed for all cores The assumption that the frequency characteristics for all cores will be the same as the first core is no longer reliable. There are heterogeneous architectures - for example ARM big.LITTLE. Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit ba82cdf5be78b46889dc0d1e3906e353489925ad)
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp148
1 files changed, 71 insertions, 77 deletions
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 019b9ddda..d116325b1 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -669,8 +669,6 @@ void TDEHardwareDevices::processModifiedCPUs() {
time1 = time2;
#endif
- TDECPUDevice* firstCPU = NULL;
-
// Read in other information from cpufreq, if available
for (processorNumber=0; processorNumber<processorCount; processorNumber++) {
cdevice = dynamic_cast<TDECPUDevice*>(findCPUBySystemPath(TQString("/sys/devices/system/cpu/cpu%1").arg(processorNumber)));
@@ -685,79 +683,62 @@ void TDEHardwareDevices::processModifiedCPUs() {
TQStringList governorlist;
if (cpufreq_dir.exists()) {
TQString nodename;
- if ((processorNumber == 0) || (!firstCPU)) {
- // Remember the first CPU options so that we can reuse it later.
- firstCPU = cdevice;
-
- nodename = cpufreq_dir.path();
- nodename.append("/scaling_governor");
- TQFile scalinggovernorfile(nodename);
- if (scalinggovernorfile.open(IO_ReadOnly)) {
- TQTextStream stream( &scalinggovernorfile );
- scalinggovernor = stream.readLine();
- scalinggovernorfile.close();
- }
- nodename = cpufreq_dir.path();
- nodename.append("/scaling_driver");
- TQFile scalingdriverfile(nodename);
- if (scalingdriverfile.open(IO_ReadOnly)) {
- TQTextStream stream( &scalingdriverfile );
- scalingdriver = stream.readLine();
- scalingdriverfile.close();
- }
- nodename = cpufreq_dir.path();
- nodename.append("/cpuinfo_min_freq");
- TQFile minfrequencyfile(nodename);
- if (minfrequencyfile.open(IO_ReadOnly)) {
- TQTextStream stream( &minfrequencyfile );
- minfrequency = stream.readLine().toDouble()/1000.0;
- minfrequencyfile.close();
- }
- nodename = cpufreq_dir.path();
- nodename.append("/cpuinfo_max_freq");
- TQFile maxfrequencyfile(nodename);
- if (maxfrequencyfile.open(IO_ReadOnly)) {
- TQTextStream stream( &maxfrequencyfile );
- maxfrequency = stream.readLine().toDouble()/1000.0;
- maxfrequencyfile.close();
- }
- nodename = cpufreq_dir.path();
- nodename.append("/cpuinfo_transition_latency");
- TQFile trlatencyfile(nodename);
- if (trlatencyfile.open(IO_ReadOnly)) {
- TQTextStream stream( &trlatencyfile );
- trlatency = stream.readLine().toDouble()/1000.0;
- trlatencyfile.close();
- }
- nodename = cpufreq_dir.path();
- nodename.append("/scaling_available_frequencies");
- TQFile availfreqsfile(nodename);
- if (availfreqsfile.open(IO_ReadOnly)) {
- TQTextStream stream( &availfreqsfile );
- frequencylist = TQStringList::split(" ", stream.readLine());
- availfreqsfile.close();
- }
- nodename = cpufreq_dir.path();
- nodename.append("/scaling_available_governors");
- TQFile availgvrnsfile(nodename);
- if (availgvrnsfile.open(IO_ReadOnly)) {
- TQTextStream stream( &availgvrnsfile );
- governorlist = TQStringList::split(" ", stream.readLine());
- availgvrnsfile.close();
- }
+ nodename = cpufreq_dir.path();
+ nodename.append("/scaling_governor");
+ TQFile scalinggovernorfile(nodename);
+ if (scalinggovernorfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &scalinggovernorfile );
+ scalinggovernor = stream.readLine();
+ scalinggovernorfile.close();
}
- // Other CPU should have the same values as the first one. Simply copy them.
- else {
- scalinggovernor = firstCPU->governor();
- scalingdriver = firstCPU->scalingDriver();
- minfrequency = firstCPU->minFrequency();
- maxfrequency = firstCPU->maxFrequency();
- trlatency = firstCPU->transitionLatency();
- frequencylist = firstCPU->availableFrequencies();
- governorlist = firstCPU->availableGovernors();
+ nodename = cpufreq_dir.path();
+ nodename.append("/scaling_driver");
+ TQFile scalingdriverfile(nodename);
+ if (scalingdriverfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &scalingdriverfile );
+ scalingdriver = stream.readLine();
+ scalingdriverfile.close();
+ }
+ nodename = cpufreq_dir.path();
+ nodename.append("/cpuinfo_min_freq");
+ TQFile minfrequencyfile(nodename);
+ if (minfrequencyfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &minfrequencyfile );
+ minfrequency = stream.readLine().toDouble()/1000.0;
+ minfrequencyfile.close();
+ }
+ nodename = cpufreq_dir.path();
+ nodename.append("/cpuinfo_max_freq");
+ TQFile maxfrequencyfile(nodename);
+ if (maxfrequencyfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &maxfrequencyfile );
+ maxfrequency = stream.readLine().toDouble()/1000.0;
+ maxfrequencyfile.close();
+ }
+ nodename = cpufreq_dir.path();
+ nodename.append("/cpuinfo_transition_latency");
+ TQFile trlatencyfile(nodename);
+ if (trlatencyfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &trlatencyfile );
+ trlatency = stream.readLine().toDouble()/1000.0;
+ trlatencyfile.close();
+ }
+ nodename = cpufreq_dir.path();
+ nodename.append("/scaling_available_frequencies");
+ TQFile availfreqsfile(nodename);
+ if (availfreqsfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &availfreqsfile );
+ frequencylist = TQStringList::split(" ", stream.readLine());
+ availfreqsfile.close();
+ }
+ nodename = cpufreq_dir.path();
+ nodename.append("/scaling_available_governors");
+ TQFile availgvrnsfile(nodename);
+ if (availgvrnsfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &availgvrnsfile );
+ governorlist = TQStringList::split(" ", stream.readLine());
+ availgvrnsfile.close();
}
-
- // The following data are different on each CPU
nodename = cpufreq_dir.path();
nodename.append("/affected_cpus");
TQFile tiedcpusfile(nodename);
@@ -769,16 +750,29 @@ void TDEHardwareDevices::processModifiedCPUs() {
// We may already have the CPU Mhz information in '/proc/cpuinfo'
if (!have_frequency) {
+ bool cpufreq_have_frequency = false;
nodename = cpufreq_dir.path();
- nodename.append("/cpuinfo_cur_freq");
+ nodename.append("/scaling_cur_freq");
TQFile cpufreqfile(nodename);
if (cpufreqfile.open(IO_ReadOnly)) {
+ cpufreq_have_frequency = true;
+ }
+ else {
+ nodename = cpufreq_dir.path();
+ nodename.append("/cpuinfo_cur_freq");
+ cpufreqfile.setName(nodename);
+ if (cpufreqfile.open(IO_ReadOnly)) {
+ cpufreq_have_frequency = true;
+ }
+ }
+ if (cpufreq_have_frequency) {
TQTextStream stream( &cpufreqfile );
- if (cdevice) {
- cdevice->internalSetFrequency(stream.readLine().toDouble()/1000.0);
+ double cpuinfo_cur_freq = stream.readLine().toDouble()/1000.0;
+ if (cdevice && cdevice->frequency() != cpuinfo_cur_freq) {
+ modified = true;
+ cdevice->internalSetFrequency(cpuinfo_cur_freq);
}
cpufreqfile.close();
- have_frequency = true;
}
}