From: Mathieu Desnoyers Date: Wed, 6 Jul 2016 18:47:00 +0000 (-0400) Subject: Fix: perf counters: sign-extend pmc register X-Git-Tag: v2.7.5~15 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e83cec0b52e0c2c1939d8b9c8aa11be3c7a672fd;p=lttng-ust.git Fix: perf counters: sign-extend pmc register Signed-off-by: Mathieu Desnoyers --- 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);