CPU: Only use active CPU count for generic CPU progress.

Some systems disable CPU cores. In the CPU tab this is fine,
but for an accurate representation of CPU load we need to check
for the number of active CPUs. E.g. OpenBSD disables HT on amd64
thus a 2-core system will only use 1 core.
This commit is contained in:
Alastair Poole 2019-11-16 15:58:16 +00:00
parent a5355e5357
commit f472733f06
3 changed files with 24 additions and 1 deletions

View File

@ -206,6 +206,26 @@ cpu_count(void)
return cores;
}
int
system_cpu_online_count_get(void)
{
#if defined(__linux__)
return cpu_count();
#endif
static int cores = 0;
if (cores != 0) return cores;
size_t len;
int mib[2] = { CTL_HW, HW_NCPUONLINE };
len = sizeof(cores);
if (sysctl(mib, 2, &cores, &len, NULL, 0) < 0)
return cpu_count();
return cores;
}
static void
_cpu_state_get(cpu_core_t **cores, int ncpu)
{

View File

@ -74,4 +74,7 @@ int
void
system_power_state_get(power_t *power);
int
system_cpu_online_count_get();
#endif

View File

@ -434,7 +434,7 @@ _system_stats_feedback_cb(void *data, Ecore_Thread *thread, void *msg)
free(results->cores[i]);
}
cpu_usage = cpu_usage / results->cpu_count;
cpu_usage = cpu_usage / system_cpu_online_count_get();
_progressbar_value_force_set(ui->progress_cpu, (double)cpu_usage / 100);