Fix: perf counters: sign-extend pmc register
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 6 Jul 2016 18:47:00 +0000 (14:47 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 6 Jul 2016 18:47:43 +0000 (14:47 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-context-perf-counters.c

index 97ddf977d1ba17706ae337bb66d3c1241da13038..c3728867af8f018d202ea38e8f126b51bd8015ac 100644 (file)
@@ -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);
 
This page took 0.02578 seconds and 4 git commands to generate.