From e83cec0b52e0c2c1939d8b9c8aa11be3c7a672fd Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 6 Jul 2016 14:47:00 -0400 Subject: [PATCH] Fix: perf counters: sign-extend pmc register Signed-off-by: Mathieu Desnoyers --- liblttng-ust/lttng-context-perf-counters.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/liblttng-ust/lttng-context-perf-counters.c b/liblttng-ust/lttng-context-perf-counters.c index 83b371c5..61149d06 100644 --- a/liblttng-ust/lttng-context-perf-counters.c +++ b/liblttng-ust/lttng-context-perf-counters.c @@ -110,11 +110,17 @@ uint64_t read_perf_counter(struct perf_event_mmap_page *pc) cmm_barrier(); idx = pc->index; - if (idx) - count = pc->offset + rdpmc(idx - 1); - else + if (idx) { + int64_t pmcval; + + pmcval = rdpmc(idx - 1); + /* Sign-extend the pmc register result. */ + pmcval <<= 64 - pc->pmc_width; + pmcval >>= 64 - pc->pmc_width; + count = pc->offset + pmcval; + } else { count = 0; - + } cmm_barrier(); } while (CMM_LOAD_SHARED(pc->lock) != seq); -- 2.34.1