tools/power turbostat: Survive sparse die_id
authorLen Brown <len.brown@intel.com>
Sun, 21 Apr 2024 16:02:24 +0000 (12:02 -0400)
committerLen Brown <len.brown@intel.com>
Sun, 21 Apr 2024 21:05:55 +0000 (17:05 -0400)
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 <len.brown@intel.com>
tools/power/x86/turbostat/turbostat.c

index e6d643a58cd895293ba32de077082fd92e514ff3..4b95fd90e16c3cd97ff8684abe7adf8770764e04 100644 (file)
@@ -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)
@@ -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;
@@ -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);
@@ -5480,7 +5494,6 @@ next:
        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))