Skip to content

Commit

Permalink
linux/cpukinds/freq: use acpi_cppc/nominal_freq when available
Browse files Browse the repository at this point in the history
cpufreq/base_frequency is only available on Intel so far, and works well.

acpi_cppc/nominal_freq is already available on AMD (and ARM or soon),
so it's likely good for the future.
However it reports incorrect values on Intel SPR and MTL at least.

Hence try cpufreq/base_frequency first,
then fallback to acpi_cppc/nominal_freq.

Refs #690

Signed-off-by: Brice Goglin <[email protected]>
(cherry picked from commit 2292110)
  • Loading branch information
bgoglin committed Sep 26, 2024
1 parent 64a3f86 commit a9a82a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ bug fixes (and other actions) for each version of hwloc since version
Version 2.11.2
--------------
* Add missing CPU info attrs on aarch64 on Linux.
* Use ACPI CPPC on Linux to get better information about cpukinds,
at least on AMD CPUs.
* Fix crash when manipulating cpukinds after topology
duplication, thanks to Hadrien Grasland for the report.
* Fix missing input target checks in memattr functions,
Expand Down
5 changes: 3 additions & 2 deletions doc/hwloc.doxy
Original file line number Diff line number Diff line change
Expand Up @@ -2457,8 +2457,9 @@ These CPU kinds may be annotated with the following native attributes:
as reported by <tt>cpufreq</tt> drivers on Linux.
</dd>
<dt>FrequencyBaseMHz (Linux)</dt>
<dd>The base operating frequency of the core,
as reported by some <tt>cpufreq</tt> drivers on Linux (e.g. <tt>intel_pstate</tt>).
<dd>The base/nominal operating frequency of the core,
as reported by some <tt>cpufreq</tt> or ACPI drivers on Linux
(e.g. <tt>cpufreq_cppc</tt> or <tt>intel_pstate</tt>).
</dd>
<dt>CoreType (x86)</dt>
<dd>A string describing the kind of core,
Expand Down
25 changes: 21 additions & 4 deletions hwloc/topology-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -4474,8 +4474,8 @@ look_sysfsnode(struct hwloc_topology *topology,

struct hwloc_linux_cpukinds_by_pu {
unsigned pu;
unsigned long max_freq;
unsigned long base_freq;
unsigned long max_freq; /* kHz */
unsigned long base_freq; /* kHz */
unsigned long capacity;
int done; /* temporary bit to identify PU that were processed by the current algorithm
* (only hwloc_linux_cpukinds_adjust_maxfreqs() for now)
Expand Down Expand Up @@ -4714,6 +4714,7 @@ look_sysfscpukinds(struct hwloc_topology *topology,
char *env;
hwloc_bitmap_t atom_pmu_set, core_pmu_set;
int maxfreq_enabled = -1; /* -1 means adjust (default), 0 means ignore, 1 means enforce */
int use_cppc_nominal_freq = -1; /* -1 means try, 0 no, 1 yes */
unsigned adjust_max = 10;
int force_homogeneous;
const char *info;
Expand Down Expand Up @@ -4753,10 +4754,26 @@ look_sysfscpukinds(struct hwloc_topology *topology,
sprintf(str, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i);
if (hwloc_read_path_as_uint(str, &maxfreq, data->root_fd) >= 0)
by_pu[i].max_freq = maxfreq;
/* base_frequency is intel_pstate specific */
/* base_frequency is in intel_pstate and works fine */
sprintf(str, "/sys/devices/system/cpu/cpu%d/cpufreq/base_frequency", i);
if (hwloc_read_path_as_uint(str, &basefreq, data->root_fd) >= 0)
if (hwloc_read_path_as_uint(str, &basefreq, data->root_fd) >= 0) {
by_pu[i].base_freq = basefreq;
use_cppc_nominal_freq = 0;
}
/* try acpi_cppc/nominal_freq only if cpufreq/base_frequency failed
* acpi_cppc/nominal_freq is widely available, but it returns 0 on some Intel SPR,
* same freq for all cores on RPL,
* maxfreq for E-cores and LP-E-cores but basefreq for P-cores on MTL.
*/
if (use_cppc_nominal_freq != 0) {
sprintf(str, "/sys/devices/system/cpu/cpu%d/acpi_cppc/nominal_freq", i);
if (hwloc_read_path_as_uint(str, &basefreq, data->root_fd) >= 0 && basefreq > 0) {
by_pu[i].base_freq = basefreq * 1000; /* nominal_freq is already in MHz */
use_cppc_nominal_freq = 1;
} else {
use_cppc_nominal_freq = 0;
}
}
if (maxfreq && !basefreq)
max_without_basefreq = 1;
/* capacity */
Expand Down

0 comments on commit a9a82a7

Please sign in to comment.