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.9.0-rc1~43 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4f58f54fdc949a00a05743ecf6d95144192c2ce2;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 0b8f9fa2..a7e1b63f 100644 --- a/liblttng-ust/lttng-context-perf-counters.c +++ b/liblttng-ust/lttng-context-perf-counters.c @@ -113,11 +113,17 @@ uint64_t read_perf_counter( 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);