Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753423AbbHGNOS (ORCPT ); Fri, 7 Aug 2015 09:14:18 -0400 Received: from mail.kernel.org ([198.145.29.136]:55607 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752958AbbHGNOR (ORCPT ); Fri, 7 Aug 2015 09:14:17 -0400 Date: Fri, 7 Aug 2015 10:14:12 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: kan.liang@intel.com, jolsa@kernel.org, namhyung@kernel.org, ak@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf tools: Move perf_counts struct and functions into separate object Message-ID: <20150807131412.GC3325@kernel.org> References: <1438890294-33409-1-git-send-email-kan.liang@intel.com> <20150807105103.GB8624@krava.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150807105103.GB8624@krava.brq.redhat.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8529 Lines: 308 Em Fri, Aug 07, 2015 at 12:51:03PM +0200, Jiri Olsa escreveu: > On Thu, Aug 06, 2015 at 03:44:52PM -0400, kan.liang@intel.com wrote: > > From: Kan Liang > > > > Move callchain option parse related code to util.c > > little nore about the reason would be nice ;-) > > looks ok, but the python test is still failing, > the reason is the perf_counts struct objects and functions > bindings to util/stat.c object > > Arnaldo, > I separated the 'struct perf_counts' into util/counts.c, > because I recall you did not want them in evsel.c, > please check attached patch.. it makes the python test > pass again (on top of Kan's change). Ok, will apply, try Kan's patch, add the extra comments about why the move from callchain to util.c is needed, test the whole shebang, ship to Ingo... - Arnaldo > thanks, > jirka > > > --- > Moving perf_counts struct and functions into separate object, > so we could remove stat.c object dependency from python build. > > It makes the python code to be built properly, because now it > fails to load due to missing stat-shadow.c object dependency. > > Signed-off-by: Jiri Olsa > --- > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index a054ddc0b2a0..7aa039bd379a 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -58,6 +58,7 @@ > #include "util/cpumap.h" > #include "util/thread.h" > #include "util/thread_map.h" > +#include "util/counts.h" > > #include > #include > diff --git a/tools/perf/util/Build b/tools/perf/util/Build > index a1e5168dc1fb..4ca481cd38e6 100644 > --- a/tools/perf/util/Build > +++ b/tools/perf/util/Build > @@ -67,6 +67,7 @@ libperf-y += target.o > libperf-y += rblist.o > libperf-y += intlist.o > libperf-y += vdso.o > +libperf-y += counts.o > libperf-y += stat.o > libperf-y += stat-shadow.o > libperf-y += record.o > diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c > new file mode 100644 > index 000000000000..e3fde313deb2 > --- /dev/null > +++ b/tools/perf/util/counts.c > @@ -0,0 +1,52 @@ > +#include > +#include "evsel.h" > +#include "counts.h" > + > +struct perf_counts *perf_counts__new(int ncpus, int nthreads) > +{ > + struct perf_counts *counts = zalloc(sizeof(*counts)); > + > + if (counts) { > + struct xyarray *values; > + > + values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values)); > + if (!values) { > + free(counts); > + return NULL; > + } > + > + counts->values = values; > + } > + > + return counts; > +} > + > +void perf_counts__delete(struct perf_counts *counts) > +{ > + if (counts) { > + xyarray__delete(counts->values); > + free(counts); > + } > +} > + > +static void perf_counts__reset(struct perf_counts *counts) > +{ > + xyarray__reset(counts->values); > +} > + > +void perf_evsel__reset_counts(struct perf_evsel *evsel) > +{ > + perf_counts__reset(evsel->counts); > +} > + > +int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads) > +{ > + evsel->counts = perf_counts__new(ncpus, nthreads); > + return evsel->counts != NULL ? 0 : -ENOMEM; > +} > + > +void perf_evsel__free_counts(struct perf_evsel *evsel) > +{ > + perf_counts__delete(evsel->counts); > + evsel->counts = NULL; > +} > diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h > new file mode 100644 > index 000000000000..34d8baaf558a > --- /dev/null > +++ b/tools/perf/util/counts.h > @@ -0,0 +1,37 @@ > +#ifndef __PERF_COUNTS_H > +#define __PERF_COUNTS_H > + > +#include "xyarray.h" > + > +struct perf_counts_values { > + union { > + struct { > + u64 val; > + u64 ena; > + u64 run; > + }; > + u64 values[3]; > + }; > +}; > + > +struct perf_counts { > + s8 scaled; > + struct perf_counts_values aggr; > + struct xyarray *values; > +}; > + > + > +static inline struct perf_counts_values* > +perf_counts(struct perf_counts *counts, int cpu, int thread) > +{ > + return xyarray__entry(counts->values, cpu, thread); > +} > + > +struct perf_counts *perf_counts__new(int ncpus, int nthreads); > +void perf_counts__delete(struct perf_counts *counts); > + > +void perf_evsel__reset_counts(struct perf_evsel *evsel); > +int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads); > +void perf_evsel__free_counts(struct perf_evsel *evsel); > + > +#endif /* __PERF_COUNTS_H */ > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h > index 09a3022fa2c6..0ca0002db99a 100644 > --- a/tools/perf/util/evsel.h > +++ b/tools/perf/util/evsel.h > @@ -9,7 +9,7 @@ > #include "xyarray.h" > #include "symbol.h" > #include "cpumap.h" > -#include "stat.h" > +#include "counts.h" > > struct perf_evsel; > > diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources > index 0766d98c5da5..51be28b1bca2 100644 > --- a/tools/perf/util/python-ext-sources > +++ b/tools/perf/util/python-ext-sources > @@ -16,7 +16,7 @@ util/util.c > util/xyarray.c > util/cgroup.c > util/rblist.c > -util/stat.c > +util/counts.c > util/strlist.c > util/trace-event.c > ../lib/rbtree.c > diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c > index c5c709cdc3ce..415c359de465 100644 > --- a/tools/perf/util/stat.c > +++ b/tools/perf/util/stat.c > @@ -97,55 +97,6 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel) > } > } > > -struct perf_counts *perf_counts__new(int ncpus, int nthreads) > -{ > - struct perf_counts *counts = zalloc(sizeof(*counts)); > - > - if (counts) { > - struct xyarray *values; > - > - values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values)); > - if (!values) { > - free(counts); > - return NULL; > - } > - > - counts->values = values; > - } > - > - return counts; > -} > - > -void perf_counts__delete(struct perf_counts *counts) > -{ > - if (counts) { > - xyarray__delete(counts->values); > - free(counts); > - } > -} > - > -static void perf_counts__reset(struct perf_counts *counts) > -{ > - xyarray__reset(counts->values); > -} > - > -void perf_evsel__reset_counts(struct perf_evsel *evsel) > -{ > - perf_counts__reset(evsel->counts); > -} > - > -int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads) > -{ > - evsel->counts = perf_counts__new(ncpus, nthreads); > - return evsel->counts != NULL ? 0 : -ENOMEM; > -} > - > -void perf_evsel__free_counts(struct perf_evsel *evsel) > -{ > - perf_counts__delete(evsel->counts); > - evsel->counts = NULL; > -} > - > void perf_evsel__reset_stat_priv(struct perf_evsel *evsel) > { > int i; > diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h > index 0b897b083682..62448c8175d3 100644 > --- a/tools/perf/util/stat.h > +++ b/tools/perf/util/stat.h > @@ -33,23 +33,6 @@ enum aggr_mode { > AGGR_THREAD, > }; > > -struct perf_counts_values { > - union { > - struct { > - u64 val; > - u64 ena; > - u64 run; > - }; > - u64 values[3]; > - }; > -}; > - > -struct perf_counts { > - s8 scaled; > - struct perf_counts_values aggr; > - struct xyarray *values; > -}; > - > struct perf_stat_config { > enum aggr_mode aggr_mode; > bool scale; > @@ -57,12 +40,6 @@ struct perf_stat_config { > unsigned int interval; > }; > > -static inline struct perf_counts_values* > -perf_counts(struct perf_counts *counts, int cpu, int thread) > -{ > - return xyarray__entry(counts->values, cpu, thread); > -} > - > void update_stats(struct stats *stats, u64 val); > double avg_stats(struct stats *stats); > double stddev_stats(struct stats *stats); > @@ -96,13 +73,6 @@ void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, > void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, > double avg, int cpu, enum aggr_mode aggr); > > -struct perf_counts *perf_counts__new(int ncpus, int nthreads); > -void perf_counts__delete(struct perf_counts *counts); > - > -void perf_evsel__reset_counts(struct perf_evsel *evsel); > -int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads); > -void perf_evsel__free_counts(struct perf_evsel *evsel); > - > void perf_evsel__reset_stat_priv(struct perf_evsel *evsel); > int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel); > void perf_evsel__free_stat_priv(struct perf_evsel *evsel); -- 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/