Skip to content

Commit 547e9e2

Browse files
committed
tools/power turbostat: Fix incorrect sorting of PMT telemetry
JIRA: https://issues.redhat.com/browse/RHEL-127415 commit cafb47b Author: Kaushlendra Kumar <kaushlendra.kumar@intel.com> Date: Sat Aug 9 10:35:15 2025 +0530 tools/power turbostat: Fix incorrect sorting of PMT telemetry 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> (cherry picked from commit cafb47b) Assisted-by: Patchpal Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 2c141fa commit 547e9e2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ int pmt_telemdir_sort(const struct dirent **a, const struct dirent **b)
18901890
sscanf((*a)->d_name, "telem%u", &aidx);
18911891
sscanf((*b)->d_name, "telem%u", &bidx);
18921892

1893-
return aidx >= bidx;
1893+
return (aidx > bidx) ? 1 : (aidx < bidx) ? -1 : 0;
18941894
}
18951895

18961896
const struct dirent *pmt_diriter_next(struct pmt_diriter_t *iter)

0 commit comments

Comments
 (0)