2014-11-21 09:31:45

by Jiri Olsa

[permalink] [raw]
Subject: [RFC 00/11] perf tools: Factor stat reading and CQM changes

hi,
this patchset factors Matt's userspace part of CQM patches:
http://marc.info/?l=linux-kernel&m=141156746730336&w=2

I needed to put counters reading into single place, which in
the end turned out to be simplification of the stat command
reading side.

any comments are welcome,
jirka


Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
Jiri Olsa (10):
perf tools: Introduce perf_evsel__compute_deltas function
perf tools: Introduce perf_counts_values__scale function
perf tools: Introduce perf_evsel__read_cb function
perf stat: Use perf_evsel__read_cb in read_counter
perf stat: Make read_counter work over the thread dimension
perf stat: Use read_counter in read_counter_aggr
perf tools: Remove perf_evsel__read interface
perf tools: Add snapshot format file parsing
perf stat: Add support for per-pkg counters
perf stat: Add support for snapshot counters

Matt Fleming (1):
perf tools: Add per-pkg format file parsing

tools/perf/builtin-stat.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
tools/perf/util/evsel.c | 100 +++++++++++++++++++++++++++------------------------------------------
tools/perf/util/evsel.h | 45 +++++++++++--------------------
tools/perf/util/parse-events.c | 2 ++
tools/perf/util/pmu.c | 74 +++++++++++++++++++++++++++++++++++++++++++--------
tools/perf/util/pmu.h | 4 +++
6 files changed, 220 insertions(+), 110 deletions(-)


2014-11-21 09:31:52

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 02/11] perf tools: Introduce perf_counts_values__scale function

Factoring out scale login into perf_counts_values__scale
function.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
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

2014-11-21 09:32:01

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 03/11] perf tools: Introduce perf_evsel__read_cb function

Adding perf_evsel__read_cb read function that retuns count
values via callback. It will be used later in stat command
as single way to retrieve counter values.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evsel.c | 16 ++++++++++++++++
tools/perf/util/evsel.h | 7 +++++++
2 files changed, 23 insertions(+)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6dc7a67e6d35..2d26b7ad6fe0 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -917,6 +917,22 @@ void perf_counts_values__scale(struct perf_counts_values *count,
*pscaled = scaled;
}

+int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
+ perf_evsel__read_cb_t cb)
+{
+ struct perf_counts_values count;
+
+ memset(&count, 0, sizeof(count));
+
+ if (FD(evsel, cpu, thread) < 0)
+ return -EINVAL;
+
+ if (readn(FD(evsel, cpu, thread), &count, sizeof(count)) < 0)
+ return -errno;
+
+ return cb(evsel, cpu, thread, &count);
+}
+
int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
int cpu, int thread, bool scale)
{
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 7af0377ceb18..5c93bed8e8d9 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -233,6 +233,13 @@ static inline bool perf_evsel__match2(struct perf_evsel *e1,
(a)->attr.type == (b)->attr.type && \
(a)->attr.config == (b)->attr.config)

+typedef int (perf_evsel__read_cb_t)(struct perf_evsel *evsel,
+ int cpu, int thread,
+ struct perf_counts_values *count);
+
+int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
+ perf_evsel__read_cb_t cb);
+
int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
int cpu, int thread, bool scale);

--
1.9.3

2014-11-21 09:32:12

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 05/11] perf stat: Make read_counter work over the thread dimension

The read function will be used laster for both aggr and cpu
counters, so we need to make it work over threads as well.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-stat.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9cc0db1d7f06..2511d3aae708 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -444,11 +444,18 @@ static int read_counter_aggr(struct perf_evsel *counter)
*/
static int read_counter(struct perf_evsel *counter)
{
- int cpu;
+ int nthreads = thread_map__nr(evsel_list->threads);
+ int ncpus = perf_evsel__nr_cpus(counter);
+ int cpu, thread;

- for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
- if (perf_evsel__read_cb(counter, cpu, 0, read_cb))
- return -1;
+ if (counter->system_wide)
+ nthreads = 1;
+
+ for (thread = 0; thread < nthreads; thread++) {
+ for (cpu = 0; cpu < ncpus; cpu++) {
+ if (perf_evsel__read_cb(counter, cpu, thread, read_cb))
+ return -1;
+ }
}

return 0;
--
1.9.3

2014-11-21 09:32:23

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 07/11] perf tools: Remove perf_evsel__read interface

Removing the perf_evsel__read interfaces because we replaced
the only user in the stat command code.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evsel.c | 34 ----------------------------------
tools/perf/util/evsel.h | 29 -----------------------------
2 files changed, 63 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 2d26b7ad6fe0..1e90c8557ede 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -954,40 +954,6 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
return 0;
}

-int __perf_evsel__read(struct perf_evsel *evsel,
- int ncpus, int nthreads, bool scale)
-{
- size_t nv = scale ? 3 : 1;
- int cpu, thread;
- struct perf_counts_values *aggr = &evsel->counts->aggr, count;
-
- if (evsel->system_wide)
- nthreads = 1;
-
- aggr->val = aggr->ena = aggr->run = 0;
-
- for (cpu = 0; cpu < ncpus; cpu++) {
- for (thread = 0; thread < nthreads; thread++) {
- if (FD(evsel, cpu, thread) < 0)
- continue;
-
- if (readn(FD(evsel, cpu, thread),
- &count, nv * sizeof(u64)) < 0)
- return -errno;
-
- aggr->val += count.val;
- if (scale) {
- aggr->ena += count.ena;
- aggr->run += count.run;
- }
- }
- }
-
- perf_evsel__compute_deltas(evsel, -1, aggr);
- perf_counts_values__scale(aggr, scale, &evsel->counts->scaled);
- return 0;
-}
-
static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
{
struct perf_evsel *leader = evsel->leader;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 5c93bed8e8d9..17da44de7339 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -269,35 +269,6 @@ static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
}

-int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
- bool scale);
-
-/**
- * perf_evsel__read - Read the aggregate results on all CPUs
- *
- * @evsel - event selector to read value
- * @ncpus - Number of cpus affected, from zero
- * @nthreads - Number of threads affected, from zero
- */
-static inline int perf_evsel__read(struct perf_evsel *evsel,
- int ncpus, int nthreads)
-{
- return __perf_evsel__read(evsel, ncpus, nthreads, false);
-}
-
-/**
- * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
- *
- * @evsel - event selector to read value
- * @ncpus - Number of cpus affected, from zero
- * @nthreads - Number of threads affected, from zero
- */
-static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
- int ncpus, int nthreads)
-{
- return __perf_evsel__read(evsel, ncpus, nthreads, true);
-}
-
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *sample);

--
1.9.3

2014-11-21 09:32:30

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 08/11] perf tools: Add per-pkg format file parsing

From: Matt Fleming <[email protected]>

The .per-pkg file indicates that all but one value per socket
should be discarded. Adding support to check up this file and
set event flag accordingly.

This patch is part of Matt's original patch:
http://marc.info/?l=linux-kernel&m=141527675002139&w=2
only the file parsing part, the rest is solved
differently.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Matt Fleming <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evsel.h | 1 +
tools/perf/util/parse-events.c | 1 +
tools/perf/util/pmu.c | 27 +++++++++++++++++++++++++++
tools/perf/util/pmu.h | 2 ++
4 files changed, 31 insertions(+)

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 17da44de7339..be295f185c32 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -91,6 +91,7 @@ struct perf_evsel {
bool immediate;
bool system_wide;
bool tracking;
+ bool per_pkg;
/* parse modifier helper */
int exclude_GH;
int nr_members;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index c659a3ca1283..5a373483f0e4 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -681,6 +681,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
if (evsel) {
evsel->unit = info.unit;
evsel->scale = info.scale;
+ evsel->per_pkg = info.per_pkg;
}

return evsel ? 0 : -ENOMEM;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 881b75490533..f003b5a9e059 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -163,6 +163,24 @@ error:
return -1;
}

+static int
+perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
+{
+ char path[PATH_MAX];
+ int fd;
+
+ snprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ close(fd);
+
+ alias->per_pkg = true;
+ return 0;
+}
+
static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
{
struct perf_pmu_alias *alias;
@@ -181,6 +199,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
INIT_LIST_HEAD(&alias->terms);
alias->scale = 1.0;
alias->unit[0] = '\0';
+ alias->per_pkg = false;

ret = parse_events_terms(&alias->terms, buf);
if (ret) {
@@ -194,6 +213,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
*/
perf_pmu__parse_unit(alias, dir, name);
perf_pmu__parse_scale(alias, dir, name);
+ perf_pmu__parse_per_pkg(alias, dir, name);

list_add_tail(&alias->list, list);

@@ -209,6 +229,8 @@ static inline bool pmu_alias_info_file(char *name)
return true;
if (len > 6 && !strcmp(name + len - 6, ".scale"))
return true;
+ if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
+ return true;

return false;
}
@@ -649,6 +671,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
struct perf_pmu_alias *alias;
int ret;

+ info->per_pkg = false;
+
/*
* Mark unit and scale as not set
* (different from default values, see below)
@@ -668,6 +692,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
if (ret)
return ret;

+ if (alias->per_pkg)
+ info->per_pkg = true;
+
list_del(&term->list);
free(term);
}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 8092de78e818..c3a74e0e17a2 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -29,6 +29,7 @@ struct perf_pmu {
struct perf_pmu_info {
const char *unit;
double scale;
+ bool per_pkg;
};

#define UNIT_MAX_LEN 31 /* max length for event unit name */
@@ -39,6 +40,7 @@ struct perf_pmu_alias {
struct list_head list; /* ELEM */
char unit[UNIT_MAX_LEN+1];
double scale;
+ bool per_pkg;
};

struct perf_pmu *perf_pmu__find(const char *name);
--
1.9.3

2014-11-21 09:32:40

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 10/11] perf stat: Add support for per-pkg counters

The .per-pkg file indicates that all but one value per socket
should be discarded. Adding the logic of skipping the rest of
the socket once first value was read.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-stat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/evsel.h | 1 +
2 files changed, 50 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b24a7a08bd1d..860e8ad06616 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -388,10 +388,56 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
update_stats(&runtime_itlb_cache_stats[0], count[0]);
}

+static void zero_per_pkg(struct perf_evsel *counter)
+{
+ if (counter->per_pkg_mask)
+ memset(counter->per_pkg_mask, 0, MAX_NR_CPUS);
+}
+
+static int check_per_pkg(struct perf_evsel *counter, int cpu, bool *skip)
+{
+ unsigned long *mask = counter->per_pkg_mask;
+ struct cpu_map *cpus = perf_evsel__cpus(counter);
+ int s;
+
+ *skip = false;
+
+ if (!counter->per_pkg)
+ return 0;
+
+ if (cpu_map__empty(cpus))
+ return 0;
+
+ if (!mask) {
+ mask = zalloc(MAX_NR_CPUS);
+ if (!mask)
+ return -ENOMEM;
+
+ counter->per_pkg_mask = mask;
+ }
+
+ s = cpu_map__get_socket(cpus, cpu);
+ if (s < 0)
+ return -1;
+
+ *skip = test_and_set_bit(s, mask) == 1;
+ return 0;
+}
+
static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
struct perf_counts_values *count)
{
struct perf_counts_values *aggr = &evsel->counts->aggr;
+ static struct perf_counts_values zero;
+ bool skip = false;
+
+ if (check_per_pkg(evsel, cpu, &skip)) {
+ pr_err("failed to read per-pkg counter\n");
+ return -1;
+ }
+
+ if (skip)
+ count = &zero;

switch (aggr_mode) {
case AGGR_CORE:
@@ -465,6 +511,9 @@ static int read_counter(struct perf_evsel *counter)
if (counter->system_wide)
nthreads = 1;

+ if (counter->per_pkg)
+ zero_per_pkg(counter);
+
for (thread = 0; thread < nthreads; thread++) {
for (cpu = 0; cpu < ncpus; cpu++) {
if (perf_evsel__read_cb(counter, cpu, thread, read_cb))
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 3207f4861038..38622747d130 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -93,6 +93,7 @@ struct perf_evsel {
bool system_wide;
bool tracking;
bool per_pkg;
+ unsigned long *per_pkg_mask;
/* parse modifier helper */
int exclude_GH;
int nr_members;
--
1.9.3

2014-11-21 09:32:47

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 11/11] perf stat: Add support for snapshot counters

The .snapshot file indicates that the provided event value is a
snapshot value. Bypassing the delta computation logic for such
event.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-stat.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 860e8ad06616..891086376381 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -443,7 +443,8 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
case AGGR_CORE:
case AGGR_SOCKET:
case AGGR_NONE:
- perf_evsel__compute_deltas(evsel, cpu, count);
+ if (!evsel->snapshot)
+ perf_evsel__compute_deltas(evsel, cpu, count);
perf_counts_values__scale(count, scale, NULL);
evsel->counts->cpu[cpu] = *count;
update_shadow_stats(evsel, count->values);
@@ -479,7 +480,8 @@ static int read_counter_aggr(struct perf_evsel *counter)
if (read_counter(counter))
return -1;

- perf_evsel__compute_deltas(counter, -1, aggr);
+ if (!counter->snapshot)
+ perf_evsel__compute_deltas(counter, -1, aggr);
perf_counts_values__scale(aggr, scale, &counter->counts->scaled);

for (i = 0; i < 3; i++)
--
1.9.3

2014-11-21 09:34:03

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 09/11] perf tools: Add snapshot format file parsing

The .snapshot file indicates that the provided event value is a
snapshot value and we have to bypass the delta computation logic.

Adding support to check up this file and set event flag accordingly.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evsel.h | 1 +
tools/perf/util/parse-events.c | 1 +
tools/perf/util/pmu.c | 47 ++++++++++++++++++++++++++++++++----------
tools/perf/util/pmu.h | 2 ++
4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index be295f185c32..3207f4861038 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -73,6 +73,7 @@ struct perf_evsel {
char *name;
double scale;
const char *unit;
+ bool snapshot;
struct event_format *tp_format;
union {
void *priv;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5a373483f0e4..77b43fe43d55 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -682,6 +682,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
evsel->unit = info.unit;
evsel->scale = info.scale;
evsel->per_pkg = info.per_pkg;
+ evsel->snapshot = info.snapshot;
}

return evsel ? 0 : -ENOMEM;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index f003b5a9e059..5c9c4947cfb4 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -181,6 +181,23 @@ perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
return 0;
}

+static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
+ char *dir, char *name)
+{
+ char path[PATH_MAX];
+ int fd;
+
+ snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ alias->snapshot = true;
+ close(fd);
+ return 0;
+}
+
static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
{
struct perf_pmu_alias *alias;
@@ -214,6 +231,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
perf_pmu__parse_unit(alias, dir, name);
perf_pmu__parse_scale(alias, dir, name);
perf_pmu__parse_per_pkg(alias, dir, name);
+ perf_pmu__parse_snapshot(alias, dir, name);

list_add_tail(&alias->list, list);

@@ -231,6 +249,8 @@ static inline bool pmu_alias_info_file(char *name)
return true;
if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
return true;
+ if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
+ return true;

return false;
}
@@ -639,23 +659,27 @@ static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
}


-static int check_unit_scale(struct perf_pmu_alias *alias,
- const char **unit, double *scale)
+static int check_info_data(struct perf_pmu_alias *alias,
+ struct perf_pmu_info *info)
{
/*
* Only one term in event definition can
- * define unit and scale, fail if there's
- * more than one.
+ * define unit, scale and snapshot, fail
+ * if there's more than one.
*/
- if ((*unit && alias->unit) ||
- (*scale && alias->scale))
+ if ((info->unit && alias->unit) ||
+ (info->scale && alias->scale) ||
+ (info->snapshot && alias->snapshot))
return -EINVAL;

if (alias->unit)
- *unit = alias->unit;
+ info->unit = alias->unit;

if (alias->scale)
- *scale = alias->scale;
+ info->scale = alias->scale;
+
+ if (alias->snapshot)
+ info->snapshot = alias->snapshot;

return 0;
}
@@ -677,8 +701,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
* Mark unit and scale as not set
* (different from default values, see below)
*/
- info->unit = NULL;
- info->scale = 0.0;
+ info->unit = NULL;
+ info->scale = 0.0;
+ info->snapshot = false;

list_for_each_entry_safe(term, h, head_terms, list) {
alias = pmu_find_alias(pmu, term);
@@ -688,7 +713,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
if (ret)
return ret;

- ret = check_unit_scale(alias, &info->unit, &info->scale);
+ ret = check_info_data(alias, info);
if (ret)
return ret;

diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index c3a74e0e17a2..6b1249fbdb5f 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -30,6 +30,7 @@ struct perf_pmu_info {
const char *unit;
double scale;
bool per_pkg;
+ bool snapshot;
};

#define UNIT_MAX_LEN 31 /* max length for event unit name */
@@ -41,6 +42,7 @@ struct perf_pmu_alias {
char unit[UNIT_MAX_LEN+1];
double scale;
bool per_pkg;
+ bool snapshot;
};

struct perf_pmu *perf_pmu__find(const char *name);
--
1.9.3

2014-11-21 09:34:45

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 06/11] perf stat: Use read_counter in read_counter_aggr

Use the read_counter function as the values retrieval
function for aggr counter values thus eliminating
the use of __perf_evsel__read function.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-stat.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 2511d3aae708..b24a7a08bd1d 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -391,6 +391,8 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
struct perf_counts_values *count)
{
+ struct perf_counts_values *aggr = &evsel->counts->aggr;
+
switch (aggr_mode) {
case AGGR_CORE:
case AGGR_SOCKET:
@@ -401,6 +403,11 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
update_shadow_stats(evsel, count->values);
break;
case AGGR_GLOBAL:
+ aggr->val += count->val;
+ if (scale) {
+ aggr->ena += count->ena;
+ aggr->run += count->run;
+ }
default:
break;
}
@@ -408,20 +415,27 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
return 0;
}

+static int read_counter(struct perf_evsel *counter);
+
/*
* Read out the results of a single counter:
* aggregate counts across CPUs in system-wide mode
*/
static int read_counter_aggr(struct perf_evsel *counter)
{
+ struct perf_counts_values *aggr = &counter->counts->aggr;
struct perf_stat *ps = counter->priv;
u64 *count = counter->counts->aggr.values;
int i;

- if (__perf_evsel__read(counter, perf_evsel__nr_cpus(counter),
- thread_map__nr(evsel_list->threads), scale) < 0)
+ aggr->val = aggr->ena = aggr->run = 0;
+
+ if (read_counter(counter))
return -1;

+ perf_evsel__compute_deltas(counter, -1, aggr);
+ perf_counts_values__scale(aggr, scale, &counter->counts->scaled);
+
for (i = 0; i < 3; i++)
update_stats(&ps->res_stats[i], count[i]);

--
1.9.3

2014-11-21 09:35:37

by Jiri Olsa

[permalink] [raw]
Subject: Re: [RFC 00/11] perf tools: Factor stat reading and CQM changes

On Fri, Nov 21, 2014 at 10:31:04AM +0100, Jiri Olsa wrote:
> hi,
> this patchset factors Matt's userspace part of CQM patches:
> http://marc.info/?l=linux-kernel&m=141156746730336&w=2
>
> I needed to put counters reading into single place, which in
> the end turned out to be simplification of the stat command
> reading side.
>
> any comments are welcome,
> jirka

available in:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_stat_cqm

jirka

>
>
> Cc: Andi Kleen <[email protected]>
> Cc: Arnaldo Carvalho de Melo <[email protected]>
> Cc: Corey Ashford <[email protected]>
> Cc: David Ahern <[email protected]>
> Cc: Frederic Weisbecker <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: Namhyung Kim <[email protected]>
> Cc: Paul Mackerras <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Stephane Eranian <[email protected]>
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> Jiri Olsa (10):
> perf tools: Introduce perf_evsel__compute_deltas function
> perf tools: Introduce perf_counts_values__scale function
> perf tools: Introduce perf_evsel__read_cb function
> perf stat: Use perf_evsel__read_cb in read_counter
> perf stat: Make read_counter work over the thread dimension
> perf stat: Use read_counter in read_counter_aggr
> perf tools: Remove perf_evsel__read interface
> perf tools: Add snapshot format file parsing
> perf stat: Add support for per-pkg counters
> perf stat: Add support for snapshot counters
>
> Matt Fleming (1):
> perf tools: Add per-pkg format file parsing
>
> tools/perf/builtin-stat.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
> tools/perf/util/evsel.c | 100 +++++++++++++++++++++++++++------------------------------------------
> tools/perf/util/evsel.h | 45 +++++++++++--------------------
> tools/perf/util/parse-events.c | 2 ++
> tools/perf/util/pmu.c | 74 +++++++++++++++++++++++++++++++++++++++++++--------
> tools/perf/util/pmu.h | 4 +++
> 6 files changed, 220 insertions(+), 110 deletions(-)

2014-11-21 09:37:38

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 04/11] perf stat: Use perf_evsel__read_cb in read_counter

Replacing __perf_evsel__read_on_cpu function with perf_evsel__read_cb
function. The read_cb callback will be used later for global aggregation
counter values as well.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-stat.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 055ce9232c9e..9cc0db1d7f06 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -388,6 +388,26 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
update_stats(&runtime_itlb_cache_stats[0], count[0]);
}

+static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
+ struct perf_counts_values *count)
+{
+ switch (aggr_mode) {
+ case AGGR_CORE:
+ case AGGR_SOCKET:
+ case AGGR_NONE:
+ perf_evsel__compute_deltas(evsel, cpu, count);
+ perf_counts_values__scale(count, scale, NULL);
+ evsel->counts->cpu[cpu] = *count;
+ update_shadow_stats(evsel, count->values);
+ break;
+ case AGGR_GLOBAL:
+ default:
+ break;
+ }
+
+ return 0;
+}
+
/*
* Read out the results of a single counter:
* aggregate counts across CPUs in system-wide mode
@@ -424,16 +444,11 @@ static int read_counter_aggr(struct perf_evsel *counter)
*/
static int read_counter(struct perf_evsel *counter)
{
- u64 *count;
int cpu;

for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
- if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
+ if (perf_evsel__read_cb(counter, cpu, 0, read_cb))
return -1;
-
- count = counter->counts->cpu[cpu].values;
-
- update_shadow_stats(counter, count);
}

return 0;
--
1.9.3

2014-11-21 09:31:51

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 01/11] perf tools: Introduce perf_evsel__compute_deltas function

Making compute_deltas functions global and renaming it
to perf_evsel__compute_deltas. It will be used in stat
command in later patch.

Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evsel.c | 9 ++++-----
tools/perf/util/evsel.h | 3 +++
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index f2dc91fb87fa..1c73bc4d57d3 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -876,9 +876,8 @@ void perf_evsel__delete(struct perf_evsel *evsel)
free(evsel);
}

-static inline void compute_deltas(struct perf_evsel *evsel,
- int cpu,
- struct perf_counts_values *count)
+void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
+ struct perf_counts_values *count)
{
struct perf_counts_values tmp;

@@ -913,7 +912,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
return -errno;

- compute_deltas(evsel, cpu, &count);
+ perf_evsel__compute_deltas(evsel, cpu, &count);

if (scale) {
if (count.run == 0)
@@ -956,7 +955,7 @@ int __perf_evsel__read(struct perf_evsel *evsel,
}
}

- compute_deltas(evsel, -1, aggr);
+ perf_evsel__compute_deltas(evsel, -1, aggr);

evsel->counts->scaled = 0;
if (scale) {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 979790951bfb..746b7ea84589 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_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
+ struct perf_counts_values *count);
+
int perf_evsel__object_config(size_t object_size,
int (*init)(struct perf_evsel *evsel),
void (*fini)(struct perf_evsel *evsel));
--
1.9.3

2014-11-24 20:35:55

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 04/11] perf stat: Use perf_evsel__read_cb in read_counter

Em Fri, Nov 21, 2014 at 10:31:08AM +0100, Jiri Olsa escreveu:
> Replacing __perf_evsel__read_on_cpu function with perf_evsel__read_cb
> function. The read_cb callback will be used later for global aggregation
> counter values as well.

But the changeset makes it look like there are no changes made... Can
you elaborate here?

> Cc: Andi Kleen <[email protected]>
> Cc: Arnaldo Carvalho de Melo <[email protected]>
> Cc: Corey Ashford <[email protected]>
> Cc: David Ahern <[email protected]>
> Cc: Frederic Weisbecker <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: Matt Fleming <[email protected]>
> Cc: Namhyung Kim <[email protected]>
> Cc: Paul Mackerras <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Stephane Eranian <[email protected]>
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/perf/builtin-stat.c | 27 +++++++++++++++++++++------
> 1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 055ce9232c9e..9cc0db1d7f06 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -388,6 +388,26 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
> update_stats(&runtime_itlb_cache_stats[0], count[0]);
> }
>
> +static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
> + struct perf_counts_values *count)
> +{
> + switch (aggr_mode) {
> + case AGGR_CORE:
> + case AGGR_SOCKET:
> + case AGGR_NONE:
> + perf_evsel__compute_deltas(evsel, cpu, count);
> + perf_counts_values__scale(count, scale, NULL);
> + evsel->counts->cpu[cpu] = *count;
> + update_shadow_stats(evsel, count->values);
> + break;
> + case AGGR_GLOBAL:
> + default:
> + break;
> + }
> +
> + return 0;
> +}
> +
> /*
> * Read out the results of a single counter:
> * aggregate counts across CPUs in system-wide mode
> @@ -424,16 +444,11 @@ static int read_counter_aggr(struct perf_evsel *counter)
> */
> static int read_counter(struct perf_evsel *counter)
> {
> - u64 *count;
> int cpu;
>
> for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
> - if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
> + if (perf_evsel__read_cb(counter, cpu, 0, read_cb))
> return -1;
> -
> - count = counter->counts->cpu[cpu].values;
> -
> - update_shadow_stats(counter, count);
> }
>
> return 0;
> --
> 1.9.3

2014-11-25 09:36:56

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH 04/11] perf stat: Use perf_evsel__read_cb in read_counter

On Mon, Nov 24, 2014 at 06:35:33PM -0200, Arnaldo Carvalho de Melo wrote:
> Em Fri, Nov 21, 2014 at 10:31:08AM +0100, Jiri Olsa escreveu:
> > Replacing __perf_evsel__read_on_cpu function with perf_evsel__read_cb
> > function. The read_cb callback will be used later for global aggregation
> > counter values as well.
>
> But the changeset makes it look like there are no changes made... Can
> you elaborate here?

well the patch change the 'read_counter' function to use the
perf_evsel__read_cb instead of __perf_evsel__read_on_cpu

SNIP

> > +
> > /*
> > * Read out the results of a single counter:
> > * aggregate counts across CPUs in system-wide mode
> > @@ -424,16 +444,11 @@ static int read_counter_aggr(struct perf_evsel *counter)
> > */
> > static int read_counter(struct perf_evsel *counter)
> > {
> > - u64 *count;
> > int cpu;
> >
> > for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
> > - if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
> > + if (perf_evsel__read_cb(counter, cpu, 0, read_cb))

right here ^^^

> > return -1;
> > -
> > - count = counter->counts->cpu[cpu].values;
> > -
> > - update_shadow_stats(counter, count);
> > }
> >
> > return 0;
> > --
> > 1.9.3

2014-11-25 19:38:42

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 04/11] perf stat: Use perf_evsel__read_cb in read_counter

Em Tue, Nov 25, 2014 at 10:36:33AM +0100, Jiri Olsa escreveu:
> On Mon, Nov 24, 2014 at 06:35:33PM -0200, Arnaldo Carvalho de Melo wrote:
> > Em Fri, Nov 21, 2014 at 10:31:08AM +0100, Jiri Olsa escreveu:
> > > Replacing __perf_evsel__read_on_cpu function with perf_evsel__read_cb
> > > function. The read_cb callback will be used later for global aggregation
> > > counter values as well.
> >
> > But the changeset makes it look like there are no changes made... Can
> > you elaborate here?
>
> well the patch change the 'read_counter' function to use the
> perf_evsel__read_cb instead of __perf_evsel__read_on_cpu

That part is ok with me, matches what the subject states it does. The
part I thought was out of place is the SNIP part ;-)

> SNIP

This one:


> +static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
> + struct perf_counts_values *count)
> +{
> + switch (aggr_mode) {
> + case AGGR_CORE:
> + case AGGR_SOCKET:
> + case AGGR_NONE:
> + perf_evsel__compute_deltas(evsel, cpu, count);
> + perf_counts_values__scale(count, scale, NULL);
> + evsel->counts->cpu[cpu] = *count;
> + update_shadow_stats(evsel, count->values);
> + break;
> + case AGGR_GLOBAL:
> + default:
> + break;
> + }
> +
> + return 0;

While the original code did a update_shadow_stats(...), the code that replaces
it calls perf_evsel__compute_deltas(), etc in addition to updating the shadow
stats.

Ok, I see, __perf_evsel__read_on_cpu() does that... my bad, will re-read it
with this in mind, but even then, now we have to make sure
perf_evsel__alloc_counts() was called before this, and also the original code
did it for all AGGR_ modes, will check.

- Arnaldo

> > > +
> > > /*
> > > * Read out the results of a single counter:
> > > * aggregate counts across CPUs in system-wide mode
> > > @@ -424,16 +444,11 @@ static int read_counter_aggr(struct perf_evsel *counter)
> > > */
> > > static int read_counter(struct perf_evsel *counter)
> > > {
> > > - u64 *count;
> > > int cpu;
> > >
> > > for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
> > > - if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
> > > + if (perf_evsel__read_cb(counter, cpu, 0, read_cb))
>
> right here ^^^
>
> > > return -1;
> > > -
> > > - count = counter->counts->cpu[cpu].values;
> > > -
> > > - update_shadow_stats(counter, count);
> > > }
> > >
> > > return 0;
> > > --
> > > 1.9.3

Subject: [tip:perf/core] perf evsel: Introduce perf_evsel__compute_deltas function

Commit-ID: 857a94a226d7d345c3f492d5679e802e59f824a9
Gitweb: http://git.kernel.org/tip/857a94a226d7d345c3f492d5679e802e59f824a9
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:05 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 24 Nov 2014 18:03:49 -0300

perf evsel: Introduce perf_evsel__compute_deltas function

Making compute_deltas functions global and renaming it to
perf_evsel__compute_deltas.

It will be used in stat command in later patch.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/evsel.c | 9 ++++-----
tools/perf/util/evsel.h | 3 +++
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index f2dc91f..1c73bc4 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -876,9 +876,8 @@ void perf_evsel__delete(struct perf_evsel *evsel)
free(evsel);
}

-static inline void compute_deltas(struct perf_evsel *evsel,
- int cpu,
- struct perf_counts_values *count)
+void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
+ struct perf_counts_values *count)
{
struct perf_counts_values tmp;

@@ -913,7 +912,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
return -errno;

- compute_deltas(evsel, cpu, &count);
+ perf_evsel__compute_deltas(evsel, cpu, &count);

if (scale) {
if (count.run == 0)
@@ -956,7 +955,7 @@ int __perf_evsel__read(struct perf_evsel *evsel,
}
}

- compute_deltas(evsel, -1, aggr);
+ perf_evsel__compute_deltas(evsel, -1, aggr);

evsel->counts->scaled = 0;
if (scale) {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 9797909..746b7ea 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_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
+ struct perf_counts_values *count);
+
int perf_evsel__object_config(size_t object_size,
int (*init)(struct perf_evsel *evsel),
void (*fini)(struct perf_evsel *evsel));

Subject: [tip:perf/core] perf evsel: Introduce perf_counts_values__scale function

Commit-ID: 13112bbf595d4081f291f7061bb096dbf4401d41
Gitweb: http://git.kernel.org/tip/13112bbf595d4081f291f7061bb096dbf4401d41
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:06 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 24 Nov 2014 18:03:50 -0300

perf evsel: Introduce perf_counts_values__scale function

Factoring out scale login into perf_counts_values__scale function.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
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 1c73bc4..6dc7a67 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 746b7ea..7af0377 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);

Subject: [tip:perf/core] perf evsel: Introduce perf_evsel__read_cb function

Commit-ID: 011dccbdd93b7022c5c67e7c55fa8b5030b5e03d
Gitweb: http://git.kernel.org/tip/011dccbdd93b7022c5c67e7c55fa8b5030b5e03d
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:07 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 24 Nov 2014 18:03:50 -0300

perf evsel: Introduce perf_evsel__read_cb function

Adding perf_evsel__read_cb read function that retuns count values via
callback. It will be used later in stat command as single way to
retrieve counter values.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/evsel.c | 16 ++++++++++++++++
tools/perf/util/evsel.h | 7 +++++++
2 files changed, 23 insertions(+)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6dc7a67..2d26b7a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -917,6 +917,22 @@ void perf_counts_values__scale(struct perf_counts_values *count,
*pscaled = scaled;
}

+int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
+ perf_evsel__read_cb_t cb)
+{
+ struct perf_counts_values count;
+
+ memset(&count, 0, sizeof(count));
+
+ if (FD(evsel, cpu, thread) < 0)
+ return -EINVAL;
+
+ if (readn(FD(evsel, cpu, thread), &count, sizeof(count)) < 0)
+ return -errno;
+
+ return cb(evsel, cpu, thread, &count);
+}
+
int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
int cpu, int thread, bool scale)
{
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 7af0377..5c93bed 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -233,6 +233,13 @@ static inline bool perf_evsel__match2(struct perf_evsel *e1,
(a)->attr.type == (b)->attr.type && \
(a)->attr.config == (b)->attr.config)

+typedef int (perf_evsel__read_cb_t)(struct perf_evsel *evsel,
+ int cpu, int thread,
+ struct perf_counts_values *count);
+
+int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
+ perf_evsel__read_cb_t cb);
+
int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
int cpu, int thread, bool scale);

Subject: [tip:perf/core] perf tools: Add per-pkg format file parsing

Commit-ID: 044330c1840e1ece97136d78a15484c867e2faaa
Gitweb: http://git.kernel.org/tip/044330c1840e1ece97136d78a15484c867e2faaa
Author: Matt Fleming <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:12 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 24 Nov 2014 18:03:51 -0300

perf tools: Add per-pkg format file parsing

The .per-pkg file indicates that all but one value per socket should be
discarded. Adding support to check up this file and set event flag
accordingly.

This patch is part of Matt's original patch:

http://marc.info/?l=linux-kernel&m=141527675002139&w=2 only the file
parsing part, the rest is solved differently.

Signed-off-by: Matt Fleming <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/evsel.h | 1 +
tools/perf/util/parse-events.c | 1 +
tools/perf/util/pmu.c | 27 +++++++++++++++++++++++++++
tools/perf/util/pmu.h | 2 ++
4 files changed, 31 insertions(+)

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 5c93bed..792b0ea 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -91,6 +91,7 @@ struct perf_evsel {
bool immediate;
bool system_wide;
bool tracking;
+ bool per_pkg;
/* parse modifier helper */
int exclude_GH;
int nr_members;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index c659a3c..5a373483 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -681,6 +681,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
if (evsel) {
evsel->unit = info.unit;
evsel->scale = info.scale;
+ evsel->per_pkg = info.per_pkg;
}

return evsel ? 0 : -ENOMEM;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 881b754..f003b5a 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -163,6 +163,24 @@ error:
return -1;
}

+static int
+perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
+{
+ char path[PATH_MAX];
+ int fd;
+
+ snprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ close(fd);
+
+ alias->per_pkg = true;
+ return 0;
+}
+
static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
{
struct perf_pmu_alias *alias;
@@ -181,6 +199,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
INIT_LIST_HEAD(&alias->terms);
alias->scale = 1.0;
alias->unit[0] = '\0';
+ alias->per_pkg = false;

ret = parse_events_terms(&alias->terms, buf);
if (ret) {
@@ -194,6 +213,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
*/
perf_pmu__parse_unit(alias, dir, name);
perf_pmu__parse_scale(alias, dir, name);
+ perf_pmu__parse_per_pkg(alias, dir, name);

list_add_tail(&alias->list, list);

@@ -209,6 +229,8 @@ static inline bool pmu_alias_info_file(char *name)
return true;
if (len > 6 && !strcmp(name + len - 6, ".scale"))
return true;
+ if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
+ return true;

return false;
}
@@ -649,6 +671,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
struct perf_pmu_alias *alias;
int ret;

+ info->per_pkg = false;
+
/*
* Mark unit and scale as not set
* (different from default values, see below)
@@ -668,6 +692,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
if (ret)
return ret;

+ if (alias->per_pkg)
+ info->per_pkg = true;
+
list_del(&term->list);
free(term);
}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 8092de7..c3a74e0 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -29,6 +29,7 @@ struct perf_pmu {
struct perf_pmu_info {
const char *unit;
double scale;
+ bool per_pkg;
};

#define UNIT_MAX_LEN 31 /* max length for event unit name */
@@ -39,6 +40,7 @@ struct perf_pmu_alias {
struct list_head list; /* ELEM */
char unit[UNIT_MAX_LEN+1];
double scale;
+ bool per_pkg;
};

struct perf_pmu *perf_pmu__find(const char *name);

Subject: [tip:perf/core] perf tools: Add snapshot format file parsing

Commit-ID: 1d9e446b91e182055d874fbb30150aad479a4981
Gitweb: http://git.kernel.org/tip/1d9e446b91e182055d874fbb30150aad479a4981
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:13 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 24 Nov 2014 18:03:51 -0300

perf tools: Add snapshot format file parsing

The .snapshot file indicates that the provided event value is a snapshot
value and we have to bypass the delta computation logic.

Adding support to check up this file and set event flag accordingly.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/evsel.h | 1 +
tools/perf/util/parse-events.c | 1 +
tools/perf/util/pmu.c | 47 ++++++++++++++++++++++++++++++++----------
tools/perf/util/pmu.h | 2 ++
4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 792b0ea..b18d58d 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -73,6 +73,7 @@ struct perf_evsel {
char *name;
double scale;
const char *unit;
+ bool snapshot;
struct event_format *tp_format;
union {
void *priv;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5a373483..77b43fe 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -682,6 +682,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
evsel->unit = info.unit;
evsel->scale = info.scale;
evsel->per_pkg = info.per_pkg;
+ evsel->snapshot = info.snapshot;
}

return evsel ? 0 : -ENOMEM;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index f003b5a..5c9c494 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -181,6 +181,23 @@ perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
return 0;
}

+static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
+ char *dir, char *name)
+{
+ char path[PATH_MAX];
+ int fd;
+
+ snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ alias->snapshot = true;
+ close(fd);
+ return 0;
+}
+
static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
{
struct perf_pmu_alias *alias;
@@ -214,6 +231,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
perf_pmu__parse_unit(alias, dir, name);
perf_pmu__parse_scale(alias, dir, name);
perf_pmu__parse_per_pkg(alias, dir, name);
+ perf_pmu__parse_snapshot(alias, dir, name);

list_add_tail(&alias->list, list);

@@ -231,6 +249,8 @@ static inline bool pmu_alias_info_file(char *name)
return true;
if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
return true;
+ if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
+ return true;

return false;
}
@@ -639,23 +659,27 @@ static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
}


-static int check_unit_scale(struct perf_pmu_alias *alias,
- const char **unit, double *scale)
+static int check_info_data(struct perf_pmu_alias *alias,
+ struct perf_pmu_info *info)
{
/*
* Only one term in event definition can
- * define unit and scale, fail if there's
- * more than one.
+ * define unit, scale and snapshot, fail
+ * if there's more than one.
*/
- if ((*unit && alias->unit) ||
- (*scale && alias->scale))
+ if ((info->unit && alias->unit) ||
+ (info->scale && alias->scale) ||
+ (info->snapshot && alias->snapshot))
return -EINVAL;

if (alias->unit)
- *unit = alias->unit;
+ info->unit = alias->unit;

if (alias->scale)
- *scale = alias->scale;
+ info->scale = alias->scale;
+
+ if (alias->snapshot)
+ info->snapshot = alias->snapshot;

return 0;
}
@@ -677,8 +701,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
* Mark unit and scale as not set
* (different from default values, see below)
*/
- info->unit = NULL;
- info->scale = 0.0;
+ info->unit = NULL;
+ info->scale = 0.0;
+ info->snapshot = false;

list_for_each_entry_safe(term, h, head_terms, list) {
alias = pmu_find_alias(pmu, term);
@@ -688,7 +713,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
if (ret)
return ret;

- ret = check_unit_scale(alias, &info->unit, &info->scale);
+ ret = check_info_data(alias, info);
if (ret)
return ret;

diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index c3a74e0..6b1249f 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -30,6 +30,7 @@ struct perf_pmu_info {
const char *unit;
double scale;
bool per_pkg;
+ bool snapshot;
};

#define UNIT_MAX_LEN 31 /* max length for event unit name */
@@ -41,6 +42,7 @@ struct perf_pmu_alias {
char unit[UNIT_MAX_LEN+1];
double scale;
bool per_pkg;
+ bool snapshot;
};

struct perf_pmu *perf_pmu__find(const char *name);

Subject: [tip:perf/core] perf stat: Use perf_evsel__read_cb in read_counter

Commit-ID: 060c4f9c8cc871a96dfacdc9306101e8b9195805
Gitweb: http://git.kernel.org/tip/060c4f9c8cc871a96dfacdc9306101e8b9195805
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:08 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 1 Dec 2014 20:00:30 -0300

perf stat: Use perf_evsel__read_cb in read_counter

Replacing __perf_evsel__read_on_cpu function with perf_evsel__read_cb
function. The read_cb callback will be used later for global aggregation
counter values as well.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-stat.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 055ce92..9cc0db1 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -388,6 +388,26 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
update_stats(&runtime_itlb_cache_stats[0], count[0]);
}

+static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
+ struct perf_counts_values *count)
+{
+ switch (aggr_mode) {
+ case AGGR_CORE:
+ case AGGR_SOCKET:
+ case AGGR_NONE:
+ perf_evsel__compute_deltas(evsel, cpu, count);
+ perf_counts_values__scale(count, scale, NULL);
+ evsel->counts->cpu[cpu] = *count;
+ update_shadow_stats(evsel, count->values);
+ break;
+ case AGGR_GLOBAL:
+ default:
+ break;
+ }
+
+ return 0;
+}
+
/*
* Read out the results of a single counter:
* aggregate counts across CPUs in system-wide mode
@@ -424,16 +444,11 @@ static int read_counter_aggr(struct perf_evsel *counter)
*/
static int read_counter(struct perf_evsel *counter)
{
- u64 *count;
int cpu;

for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
- if (__perf_evsel__read_on_cpu(counter, cpu, 0, scale) < 0)
+ if (perf_evsel__read_cb(counter, cpu, 0, read_cb))
return -1;
-
- count = counter->counts->cpu[cpu].values;
-
- update_shadow_stats(counter, count);
}

return 0;

Subject: [tip:perf/core] perf stat: Make read_counter work over the thread dimension

Commit-ID: 9bf1a52914c7e810091f7726790fc42242a2dafe
Gitweb: http://git.kernel.org/tip/9bf1a52914c7e810091f7726790fc42242a2dafe
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:09 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 1 Dec 2014 20:00:30 -0300

perf stat: Make read_counter work over the thread dimension

The read function will be used later for both aggr and cpu counters, so
we need to make it work over threads as well.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-stat.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9cc0db1..2511d3a 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -444,11 +444,18 @@ static int read_counter_aggr(struct perf_evsel *counter)
*/
static int read_counter(struct perf_evsel *counter)
{
- int cpu;
+ int nthreads = thread_map__nr(evsel_list->threads);
+ int ncpus = perf_evsel__nr_cpus(counter);
+ int cpu, thread;

- for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
- if (perf_evsel__read_cb(counter, cpu, 0, read_cb))
- return -1;
+ if (counter->system_wide)
+ nthreads = 1;
+
+ for (thread = 0; thread < nthreads; thread++) {
+ for (cpu = 0; cpu < ncpus; cpu++) {
+ if (perf_evsel__read_cb(counter, cpu, thread, read_cb))
+ return -1;
+ }
}

return 0;

Subject: [tip:perf/core] perf stat: Use read_counter in read_counter_aggr

Commit-ID: 1971f59f1a1e0e7f3efc25ce0597505626d9f7ed
Gitweb: http://git.kernel.org/tip/1971f59f1a1e0e7f3efc25ce0597505626d9f7ed
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:10 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 1 Dec 2014 20:00:30 -0300

perf stat: Use read_counter in read_counter_aggr

Use the read_counter function as the values retrieval function for aggr
counter values thus eliminating the use of __perf_evsel__read function.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-stat.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 2511d3a..b24a7a0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -391,6 +391,8 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
struct perf_counts_values *count)
{
+ struct perf_counts_values *aggr = &evsel->counts->aggr;
+
switch (aggr_mode) {
case AGGR_CORE:
case AGGR_SOCKET:
@@ -401,6 +403,11 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
update_shadow_stats(evsel, count->values);
break;
case AGGR_GLOBAL:
+ aggr->val += count->val;
+ if (scale) {
+ aggr->ena += count->ena;
+ aggr->run += count->run;
+ }
default:
break;
}
@@ -408,20 +415,27 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
return 0;
}

+static int read_counter(struct perf_evsel *counter);
+
/*
* Read out the results of a single counter:
* aggregate counts across CPUs in system-wide mode
*/
static int read_counter_aggr(struct perf_evsel *counter)
{
+ struct perf_counts_values *aggr = &counter->counts->aggr;
struct perf_stat *ps = counter->priv;
u64 *count = counter->counts->aggr.values;
int i;

- if (__perf_evsel__read(counter, perf_evsel__nr_cpus(counter),
- thread_map__nr(evsel_list->threads), scale) < 0)
+ aggr->val = aggr->ena = aggr->run = 0;
+
+ if (read_counter(counter))
return -1;

+ perf_evsel__compute_deltas(counter, -1, aggr);
+ perf_counts_values__scale(aggr, scale, &counter->counts->scaled);
+
for (i = 0; i < 3; i++)
update_stats(&ps->res_stats[i], count[i]);

Subject: [tip:perf/core] perf tools: Remove perf_evsel__read interface

Commit-ID: a5a7fd76b55a6e6916ff22e5c8fdb39a8381be2c
Gitweb: http://git.kernel.org/tip/a5a7fd76b55a6e6916ff22e5c8fdb39a8381be2c
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:11 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 1 Dec 2014 20:00:30 -0300

perf tools: Remove perf_evsel__read interface

Removing the perf_evsel__read interfaces because we replaced the only
user in the stat command code.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/evsel.c | 34 ----------------------------------
tools/perf/util/evsel.h | 29 -----------------------------
2 files changed, 63 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 2d26b7a..1e90c85 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -954,40 +954,6 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
return 0;
}

-int __perf_evsel__read(struct perf_evsel *evsel,
- int ncpus, int nthreads, bool scale)
-{
- size_t nv = scale ? 3 : 1;
- int cpu, thread;
- struct perf_counts_values *aggr = &evsel->counts->aggr, count;
-
- if (evsel->system_wide)
- nthreads = 1;
-
- aggr->val = aggr->ena = aggr->run = 0;
-
- for (cpu = 0; cpu < ncpus; cpu++) {
- for (thread = 0; thread < nthreads; thread++) {
- if (FD(evsel, cpu, thread) < 0)
- continue;
-
- if (readn(FD(evsel, cpu, thread),
- &count, nv * sizeof(u64)) < 0)
- return -errno;
-
- aggr->val += count.val;
- if (scale) {
- aggr->ena += count.ena;
- aggr->run += count.run;
- }
- }
- }
-
- perf_evsel__compute_deltas(evsel, -1, aggr);
- perf_counts_values__scale(aggr, scale, &evsel->counts->scaled);
- return 0;
-}
-
static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
{
struct perf_evsel *leader = evsel->leader;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index b18d58d..3207f48 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -271,35 +271,6 @@ static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
}

-int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
- bool scale);
-
-/**
- * perf_evsel__read - Read the aggregate results on all CPUs
- *
- * @evsel - event selector to read value
- * @ncpus - Number of cpus affected, from zero
- * @nthreads - Number of threads affected, from zero
- */
-static inline int perf_evsel__read(struct perf_evsel *evsel,
- int ncpus, int nthreads)
-{
- return __perf_evsel__read(evsel, ncpus, nthreads, false);
-}
-
-/**
- * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
- *
- * @evsel - event selector to read value
- * @ncpus - Number of cpus affected, from zero
- * @nthreads - Number of threads affected, from zero
- */
-static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
- int ncpus, int nthreads)
-{
- return __perf_evsel__read(evsel, ncpus, nthreads, true);
-}
-
int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
struct perf_sample *sample);

Subject: [tip:perf/core] perf stat: Add support for per-pkg counters

Commit-ID: 779d0b997e0787fc5f80110159b6c18ae0fae395
Gitweb: http://git.kernel.org/tip/779d0b997e0787fc5f80110159b6c18ae0fae395
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:14 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 1 Dec 2014 20:00:30 -0300

perf stat: Add support for per-pkg counters

The .per-pkg file indicates that all but one value per socket should be
discarded. Adding the logic of skipping the rest of the socket once
first value was read.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-stat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/evsel.h | 1 +
2 files changed, 50 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b24a7a0..860e8ad 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -388,10 +388,56 @@ static void update_shadow_stats(struct perf_evsel *counter, u64 *count)
update_stats(&runtime_itlb_cache_stats[0], count[0]);
}

+static void zero_per_pkg(struct perf_evsel *counter)
+{
+ if (counter->per_pkg_mask)
+ memset(counter->per_pkg_mask, 0, MAX_NR_CPUS);
+}
+
+static int check_per_pkg(struct perf_evsel *counter, int cpu, bool *skip)
+{
+ unsigned long *mask = counter->per_pkg_mask;
+ struct cpu_map *cpus = perf_evsel__cpus(counter);
+ int s;
+
+ *skip = false;
+
+ if (!counter->per_pkg)
+ return 0;
+
+ if (cpu_map__empty(cpus))
+ return 0;
+
+ if (!mask) {
+ mask = zalloc(MAX_NR_CPUS);
+ if (!mask)
+ return -ENOMEM;
+
+ counter->per_pkg_mask = mask;
+ }
+
+ s = cpu_map__get_socket(cpus, cpu);
+ if (s < 0)
+ return -1;
+
+ *skip = test_and_set_bit(s, mask) == 1;
+ return 0;
+}
+
static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
struct perf_counts_values *count)
{
struct perf_counts_values *aggr = &evsel->counts->aggr;
+ static struct perf_counts_values zero;
+ bool skip = false;
+
+ if (check_per_pkg(evsel, cpu, &skip)) {
+ pr_err("failed to read per-pkg counter\n");
+ return -1;
+ }
+
+ if (skip)
+ count = &zero;

switch (aggr_mode) {
case AGGR_CORE:
@@ -465,6 +511,9 @@ static int read_counter(struct perf_evsel *counter)
if (counter->system_wide)
nthreads = 1;

+ if (counter->per_pkg)
+ zero_per_pkg(counter);
+
for (thread = 0; thread < nthreads; thread++) {
for (cpu = 0; cpu < ncpus; cpu++) {
if (perf_evsel__read_cb(counter, cpu, thread, read_cb))
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 3207f48..3862274 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -93,6 +93,7 @@ struct perf_evsel {
bool system_wide;
bool tracking;
bool per_pkg;
+ unsigned long *per_pkg_mask;
/* parse modifier helper */
int exclude_GH;
int nr_members;

Subject: [tip:perf/core] perf stat: Add support for snapshot counters

Commit-ID: 6c0345b73b970078c3e71ecc614a007207a1428a
Gitweb: http://git.kernel.org/tip/6c0345b73b970078c3e71ecc614a007207a1428a
Author: Jiri Olsa <[email protected]>
AuthorDate: Fri, 21 Nov 2014 10:31:15 +0100
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 1 Dec 2014 20:00:31 -0300

perf stat: Add support for snapshot counters

The .snapshot file indicates that the provided event value is a snapshot
value. Bypassing the delta computation logic for such event.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Corey Ashford <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Matt Fleming <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-stat.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 860e8ad..8910863 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -443,7 +443,8 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
case AGGR_CORE:
case AGGR_SOCKET:
case AGGR_NONE:
- perf_evsel__compute_deltas(evsel, cpu, count);
+ if (!evsel->snapshot)
+ perf_evsel__compute_deltas(evsel, cpu, count);
perf_counts_values__scale(count, scale, NULL);
evsel->counts->cpu[cpu] = *count;
update_shadow_stats(evsel, count->values);
@@ -479,7 +480,8 @@ static int read_counter_aggr(struct perf_evsel *counter)
if (read_counter(counter))
return -1;

- perf_evsel__compute_deltas(counter, -1, aggr);
+ if (!counter->snapshot)
+ perf_evsel__compute_deltas(counter, -1, aggr);
perf_counts_values__scale(aggr, scale, &counter->counts->scaled);

for (i = 0; i < 3; i++)