diff options
author | Arnavion <arnavion@gmail.com> | 2019-08-10 22:19:32 -0700 |
---|---|---|
committer | Arnavion <arnavion@gmail.com> | 2019-08-10 22:19:32 -0700 |
commit | 81b64691a7ee55e5c665ac78290495b0aea946d7 (patch) | |
tree | dc534595cc17c25bbf6cad0e978eda1a9ea419c8 /CPUMeter.c | |
parent | 909bb86f05c20f0ec6f5d55994065a293932ce21 (diff) |
Move sysfs-reading code to LinuxProcessList.c and add average frequency.
This way the frequency is read from sysfs only once per update cycle
instead of every time the UI is redrawn.
This also changes the code to read from /proc/cpuinfo instead. This is because
reading from scaling_cur_freq stalls for 10ms if the previous read for the file
was more than one second ago. [1] Since htop's update cycle is
longer than that, it would cause the read of each CPU's scaling_cur_freq file
to block the UI for 20ms. This easily led to a noticeable half-second lag on
a 20+ CPU machine.
/proc/cpuinfo also has a 10ms delay, but this applies for the whole file
so the delay does not scale with the number of CPUs. [2]
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4815d3c56d1e10449a44089a47544d9ba84fad0d
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7d5905dc14a87805a59f3c5bf70173aac2bb18f8
Diffstat (limited to 'CPUMeter.c')
-rw-r--r-- | CPUMeter.c | 10 |
1 files changed, 3 insertions, 7 deletions
@@ -64,20 +64,16 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { } memset(this->values, 0, sizeof(double) * CPU_METER_ITEMCOUNT); double percent = Platform_setCPUValues(this, cpu); - if (cpu != 0 && this->pl->settings->showCPUFrequency) { - /* Initial frequency is in KHz. Divide it by 1000 till it's less than 1000, and emit unit accordingly */ + if (this->pl->settings->showCPUFrequency) { + /* Initial frequency is in MHz. Emit it as GHz if it's larger than 1000MHz */ double cpuFrequency = this->values[CPU_METER_FREQUENCY]; - char unit = 'K'; + char unit = 'M'; char cpuFrequencyBuffer[16]; if (cpuFrequency < 0) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { if (cpuFrequency > 1000) { cpuFrequency /= 1000; - unit = 'M'; - } - if (cpuFrequency > 1000) { - cpuFrequency /= 1000; unit = 'G'; } xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.3f%cHz", cpuFrequency, unit); |