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.8.2~16 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3046b99ebe14547404cb0578c1007aa5eda42472;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 97ddf977..c3728867 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);