Skip to content

Commit

Permalink
tools/power turbostat: Survive sparse die_id
Browse files Browse the repository at this point in the history
Turbostat assumed that every package had a die_id = 0.
When this assumption was violated, it exited
when looking for the package uncore frequency:

turbostat: /sys/.../intel_uncore_frequency/package_01_die_00/current_freq_khz: open failed: No such file or directory

Signed-off-by: Len Brown <[email protected]>
  • Loading branch information
lenb committed Apr 21, 2024
1 parent cda2033 commit c8b246e
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions tools/power/x86/turbostat/turbostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2992,14 +2992,29 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp)
return 0;
}

unsigned long long get_uncore_mhz(int package, int die)
unsigned long long get_legacy_uncore_mhz(int package)
{
char path[128];
int die;
static int warn_once;

sprintf(path, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/current_freq_khz", package,
die);
/*
* for this package, use the first die_id that exists
*/
for (die = 0; die <= topo.max_die_id; ++die) {

sprintf(path, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/current_freq_khz",
package, die);

return (snapshot_sysfs_counter(path) / 1000);
if (access(path, R_OK) == 0)
return (snapshot_sysfs_counter(path) / 1000);
}
if (!warn_once) {
warnx("BUG: %s: No %s", __func__, path);
warn_once = 1;
}

return 0;
}

int get_epb(int cpu)
Expand Down Expand Up @@ -3631,9 +3646,8 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
p->pkg_temp_c = tj_max - ((msr >> 16) & 0x7F);
}

/* n.b. assume die0 uncore frequency applies to whole package */
if (DO_BIC(BIC_UNCORE_MHZ))
p->uncore_mhz = get_uncore_mhz(p->package_id, 0);
p->uncore_mhz = get_legacy_uncore_mhz(p->package_id);

if (DO_BIC(BIC_GFX_rc6))
p->gfx_rc6_ms = gfx_info[GFX_rc6].val_ull;
Expand Down Expand Up @@ -5300,22 +5314,22 @@ static void probe_intel_uncore_frequency_legacy(void)
int i, j;
char path[256];

if (access("/sys/devices/system/cpu/intel_uncore_frequency/package_00_die_00/current_freq_khz", R_OK))
return;

BIC_PRESENT(BIC_UNCORE_MHZ);

if (quiet)
return;

for (i = 0; i < topo.num_packages; ++i) {
for (j = 0; j < topo.num_die; ++j) {
for (j = 0; j <= topo.max_die_id; ++j) {
int k, l;
char path_base[128];

sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d", i,
j);

if (access(path_base, R_OK))
continue;

BIC_PRESENT(BIC_UNCORE_MHZ);

if (quiet)
return;

sprintf(path, "%s/min_freq_khz", path_base);
k = read_sysfs_int(path);
sprintf(path, "%s/max_freq_khz", path_base);
Expand Down Expand Up @@ -5480,7 +5494,6 @@ static void probe_graphics(void)
else if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK))
gfx_info[GFX_MHz].path = "/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz";


if (!access("/sys/class/drm/card0/gt_act_freq_mhz", R_OK))
gfx_info[GFX_ACTMHz].path = "/sys/class/drm/card0/gt_act_freq_mhz";
else if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz", R_OK))
Expand Down

0 comments on commit c8b246e

Please sign in to comment.