]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/power turbostat: Fix PMT mmaped file size rounding
authorPatryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
Fri, 20 Dec 2024 12:38:34 +0000 (13:38 +0100)
committerLen Brown <len.brown@intel.com>
Tue, 14 Jan 2025 19:50:53 +0000 (13:50 -0600)
This (the old code) is just not how you round up to a page size.
Noticed on a recent Intel platform. Previous ones must have been
reporting sizes already aligned to a page and so the bug was missed when
testing.

Fixes: f0e4ed752fda ("tools/power turbostat: Add early support for PMT counters")
Signed-off-by: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
tools/power/x86/turbostat/turbostat.c

index 1d99aaf9681b081434faa84d5969b1bfebaea349..a2ca1c6c3638a770ea7be3c2d08e1142e42b90b0 100644 (file)
@@ -95,6 +95,8 @@
 #define INTEL_ECORE_TYPE       0x20
 #define INTEL_PCORE_TYPE       0x40
 
+#define ROUND_UP_TO_PAGE_SIZE(n) (((n) + 0x1000UL-1UL) & ~(0x1000UL-1UL))
+
 enum counter_scope { SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE };
 enum counter_type { COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC, COUNTER_K2M };
 enum counter_format { FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT, FORMAT_AVERAGE };
@@ -8996,7 +8998,7 @@ struct pmt_mmio *pmt_mmio_open(unsigned int target_guid)
                if (fd_pmt == -1)
                        goto loop_cleanup_and_break;
 
-               mmap_size = (size + 0x1000UL) & (~0x1000UL);
+               mmap_size = ROUND_UP_TO_PAGE_SIZE(size);
                mmio = mmap(0, mmap_size, PROT_READ, MAP_SHARED, fd_pmt, 0);
                if (mmio != MAP_FAILED) {