Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758223AbaKUJbw (ORCPT ); Fri, 21 Nov 2014 04:31:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43164 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758145AbaKUJbr (ORCPT ); Fri, 21 Nov 2014 04:31:47 -0500 From: Jiri Olsa To: linux-kernel@vger.kernel.org Cc: Jiri Olsa , Andi Kleen , Arnaldo Carvalho de Melo , Corey Ashford , David Ahern , Frederic Weisbecker , Ingo Molnar , Matt Fleming , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Stephane Eranian Subject: [PATCH 02/11] perf tools: Introduce perf_counts_values__scale function Date: Fri, 21 Nov 2014 10:31:06 +0100 Message-Id: <1416562275-12404-3-git-send-email-jolsa@kernel.org> In-Reply-To: <1416562275-12404-1-git-send-email-jolsa@kernel.org> References: <1416562275-12404-1-git-send-email-jolsa@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factoring out scale login into perf_counts_values__scale function. Cc: Andi Kleen Cc: Arnaldo Carvalho de Melo Cc: Corey Ashford Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Matt Fleming Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Signed-off-by: Jiri Olsa --- tools/perf/util/evsel.c | 47 ++++++++++++++++++++++------------------------- tools/perf/util/evsel.h | 3 +++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 1c73bc4d57d3..6dc7a67e6d35 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -897,6 +897,26 @@ void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, count->run = count->run - tmp.run; } +void perf_counts_values__scale(struct perf_counts_values *count, + bool scale, s8 *pscaled) +{ + s8 scaled = 0; + + if (scale) { + if (count->run == 0) { + scaled = -1; + count->val = 0; + } else if (count->run < count->ena) { + scaled = 1; + count->val = (u64)((double) count->val * count->ena / count->run + 0.5); + } + } else + count->ena = count->run = 0; + + if (pscaled) + *pscaled = scaled; +} + int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, int cpu, int thread, bool scale) { @@ -913,15 +933,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, return -errno; perf_evsel__compute_deltas(evsel, cpu, &count); - - if (scale) { - if (count.run == 0) - count.val = 0; - else if (count.run < count.ena) - count.val = (u64)((double)count.val * count.ena / count.run + 0.5); - } else - count.ena = count.run = 0; - + perf_counts_values__scale(&count, scale, NULL); evsel->counts->cpu[cpu] = count; return 0; } @@ -956,22 +968,7 @@ int __perf_evsel__read(struct perf_evsel *evsel, } perf_evsel__compute_deltas(evsel, -1, aggr); - - evsel->counts->scaled = 0; - if (scale) { - if (aggr->run == 0) { - evsel->counts->scaled = -1; - aggr->val = 0; - return 0; - } - - if (aggr->run < aggr->ena) { - evsel->counts->scaled = 1; - aggr->val = (u64)((double)aggr->val * aggr->ena / aggr->run + 0.5); - } - } else - aggr->ena = aggr->run = 0; - + perf_counts_values__scale(aggr, scale, &evsel->counts->scaled); return 0; } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 746b7ea84589..7af0377ceb18 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -110,6 +110,9 @@ struct thread_map; struct perf_evlist; struct record_opts; +void perf_counts_values__scale(struct perf_counts_values *count, + bool scale, s8 *pscaled); + void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, struct perf_counts_values *count); -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/