Skip to content

Commit 0136f11

Browse files
Patryk Wlazlynmehmetb0
authored andcommitted
tools/power turbostat: Fix PMT mmaped file size rounding
BugLink: https://bugs.launchpad.net/bugs/2103829 [ Upstream commit 2f60f03934a50bc1fb69bb4f47a25cddd6807b0b ] 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: f0e4ed7 ("tools/power turbostat: Add early support for PMT counters") Signed-off-by: Patryk Wlazlyn <[email protected]> Signed-off-by: Len Brown <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Noah Wager <[email protected]> Signed-off-by: Mehmet Basaran <[email protected]>
1 parent 44c5f9c commit 0136f11

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
#define INTEL_ECORE_TYPE 0x20
9696
#define INTEL_PCORE_TYPE 0x40
9797

98+
#define ROUND_UP_TO_PAGE_SIZE(n) (((n) + 0x1000UL-1UL) & ~(0x1000UL-1UL))
99+
98100
enum counter_scope { SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE };
99101
enum counter_type { COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC, COUNTER_K2M };
100102
enum counter_format { FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT, FORMAT_AVERAGE };
@@ -8853,7 +8855,7 @@ struct pmt_mmio *pmt_mmio_open(unsigned int target_guid)
88538855
if (fd_pmt == -1)
88548856
goto loop_cleanup_and_break;
88558857

8856-
mmap_size = (size + 0x1000UL) & (~0x1000UL);
8858+
mmap_size = ROUND_UP_TO_PAGE_SIZE(size);
88578859
mmio = mmap(0, mmap_size, PROT_READ, MAP_SHARED, fd_pmt, 0);
88588860
if (mmio != MAP_FAILED) {
88598861

0 commit comments

Comments
 (0)