Skip to content

Commit ae3326a

Browse files
committed
tools/power turbostat: Harden probe_intel_uncore_frequency()
If sysfs directory "intel_uncore_frequency/cluster00/" exists, then use uncore cluster code (now its own routine). The previous check for "intel_uncore_frequency/package_00_die_00/current_freq_khz", could be unreliable in the face of sparse die id's. Signed-off-by: Len Brown <[email protected]>
1 parent 231ce08 commit ae3326a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5294,16 +5294,13 @@ static void dump_sysfs_file(char *path)
52945294
fprintf(outf, "%s: %s", strrchr(path, '/') + 1, cpuidle_buf);
52955295
}
52965296

5297-
static void probe_intel_uncore_frequency(void)
5297+
static void probe_intel_uncore_frequency_legacy(void)
52985298
{
52995299
int i, j;
53005300
char path[256];
53015301

5302-
if (!genuine_intel)
5303-
return;
5304-
53055302
if (access("/sys/devices/system/cpu/intel_uncore_frequency/package_00_die_00/current_freq_khz", R_OK))
5306-
goto probe_cluster;
5303+
return;
53075304

53085305
BIC_PRESENT(BIC_UNCORE_MHZ);
53095306

@@ -5335,9 +5332,13 @@ static void probe_intel_uncore_frequency(void)
53355332
fprintf(outf, " %d MHz\n", k / 1000);
53365333
}
53375334
}
5338-
return;
5335+
}
5336+
5337+
static void probe_intel_uncore_frequency_cluster(void)
5338+
{
5339+
int i;
5340+
char path[256];
53395341

5340-
probe_cluster:
53415342
if (access("/sys/devices/system/cpu/intel_uncore_frequency/uncore00/current_freq_khz", R_OK))
53425343
return;
53435344

@@ -5351,6 +5352,7 @@ static void probe_intel_uncore_frequency(void)
53515352

53525353
sprintf(path_base, "/sys/devices/system/cpu/intel_uncore_frequency/uncore%02d", i);
53535354

5355+
/* uncore## start at 00 and skip no numbers, so stop upon first missing */
53545356
if (access(path_base, R_OK))
53555357
break;
53565358

@@ -5382,6 +5384,17 @@ static void probe_intel_uncore_frequency(void)
53825384
}
53835385
}
53845386

5387+
static void probe_intel_uncore_frequency(void)
5388+
{
5389+
if (!genuine_intel)
5390+
return;
5391+
5392+
if (access("/sys/devices/system/cpu/intel_uncore_frequency/uncore00", R_OK) == 0)
5393+
probe_intel_uncore_frequency_cluster();
5394+
else
5395+
probe_intel_uncore_frequency_legacy();
5396+
}
5397+
53855398
static void probe_graphics(void)
53865399
{
53875400
/* Xe graphics sysfs knobs */

0 commit comments

Comments
 (0)