tools/power turbostat: Fix incorrect sorting of PMT telemetry
authorKaushlendra Kumar <kaushlendra.kumar@intel.com>
Sat, 9 Aug 2025 05:05:15 +0000 (10:35 +0530)
committerLen Brown <len.brown@intel.com>
Fri, 26 Sep 2025 03:12:00 +0000 (23:12 -0400)
The pmt_telemdir_sort() comparison function was returning a boolean
value (0 or 1) instead of the required negative, zero, or positive
value for proper sorting. This caused unpredictable and incorrect
ordering of telemetry directories named telem0, telem1, ..., telemN.
Update the comparison logic to return -1, 0, or 1 based on the
numerical value extracted from the directory name, ensuring correct
numerical ordering when using scandir.

This change improves stability and correctness when iterating PMT
telemetry directories.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
tools/power/x86/turbostat/turbostat.c

index 5230e07..b391196 100644 (file)
@@ -1649,7 +1649,7 @@ int pmt_telemdir_sort(const struct dirent **a, const struct dirent **b)
        sscanf((*a)->d_name, "telem%u", &aidx);
        sscanf((*b)->d_name, "telem%u", &bidx);
 
-       return aidx >= bidx;
+       return (aidx > bidx) ? 1 : (aidx < bidx) ? -1 : 0;
 }
 
 const struct dirent *pmt_diriter_next(struct pmt_diriter_t *iter)