From 4f58f54fdc949a00a05743ecf6d95144192c2ce2 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 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); -- 2.34.1