linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: acme@kernel.org
Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 05/12] perf evsel: Add iterator to iterate over events ordered by CPU
Date: Wed, 20 Nov 2019 16:15:15 -0800	[thread overview]
Message-ID: <20191121001522.180827-6-andi@firstfloor.org> (raw)
In-Reply-To: <20191121001522.180827-1-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

Add some common code that is needed to iterate over all events
in CPU order. Used in followon patches

Signed-off-by: Andi Kleen <ak@linux.intel.com>

---

v2: Add cpumap__for_each_cpu macro to factor out some common code
v3: Drop cpumap__for_each_cpu macro again, replace with evlist__for_each_cpu
Add new evlist__for_each_cpu
Don't compute cpus nr in cpu_index iterator init, just use all_cpus
v4:
Remove __next, move into skip
Add _no_inc
Move initialization into iterator macro
Rename cpu_index to cpu_iter
---
 tools/perf/util/cpumap.h |  1 +
 tools/perf/util/evlist.c | 32 ++++++++++++++++++++++++++++++++
 tools/perf/util/evlist.h |  8 ++++++++
 tools/perf/util/evsel.h  |  1 +
 4 files changed, 42 insertions(+)

diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 57943f3685f8..3a442f021468 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -63,4 +63,5 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res,
 
 int cpu_map__cpu(struct perf_cpu_map *cpus, int idx);
 bool cpu_map__has(struct perf_cpu_map *cpus, int cpu);
+
 #endif /* __PERF_CPUMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index fdce590d2278..dae6e846b2f8 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -342,6 +342,38 @@ static int perf_evlist__nr_threads(struct evlist *evlist,
 		return perf_thread_map__nr(evlist->core.threads);
 }
 
+void evlist__cpu_iter_start(struct evlist *evlist)
+{
+	struct evsel *pos;
+
+	/*
+	 * Reset the per evsel cpu_iter. This is needed because
+	 * each evsel's cpumap may have a different index space,
+	 * and some operations need the index to modify
+	 * the FD xyarray (e.g. open, close)
+	 */
+	evlist__for_each_entry(evlist, pos)
+		pos->cpu_iter = 0;
+}
+
+bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu)
+{
+	if (ev->cpu_iter >= ev->core.cpus->nr)
+		return true;
+	if (cpu >= 0 && ev->core.cpus->map[ev->cpu_iter] != cpu)
+		return true;
+	return false;
+}
+
+bool evsel__cpu_iter_skip(struct evsel *ev, int cpu)
+{
+	if (!evsel__cpu_iter_skip_no_inc(ev, cpu)) {
+		ev->cpu_iter++;
+		return false;
+	}
+	return true;
+}
+
 void evlist__disable(struct evlist *evlist)
 {
 	struct evsel *pos;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 13051409fd22..12606efc1f7c 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -333,9 +333,17 @@ void perf_evlist__to_front(struct evlist *evlist,
 #define evlist__for_each_entry_safe(evlist, tmp, evsel) \
 	__evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
 
+#define evlist__for_each_cpu(evlist, index, cpu)	\
+	evlist__cpu_iter_start(evlist);			\
+	perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
+
 void perf_evlist__set_tracking_event(struct evlist *evlist,
 				     struct evsel *tracking_evsel);
 
+void evlist__cpu_iter_start(struct evlist *evlist);
+bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
+bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);
+
 struct evsel *
 perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
 
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index ddc5ee6f6592..b10d5ba21966 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -95,6 +95,7 @@ struct evsel {
 	bool			collect_stat;
 	bool			weak_group;
 	bool			percore;
+	int			cpu_iter;
 	const char		*pmu_name;
 	struct {
 		perf_evsel__sb_cb_t	*cb;
-- 
2.23.0


  parent reply	other threads:[~2019-11-21  0:15 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-21  0:15 Optimize perf stat for large number of events/cpus Andi Kleen
2019-11-21  0:15 ` [PATCH 01/12] perf pmu: Use file system cache to optimize sysfs access Andi Kleen
2019-11-29  6:02   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 02/12] perf affinity: Add infrastructure to save/restore affinity Andi Kleen
2019-11-29  6:02   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 03/12] perf cpumap: Maintain cpumaps ordered and without dups Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 04/12] perf evlist: Maintain evlist->all_cpus Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` Andi Kleen [this message]
2019-12-04  7:53   ` [tip: perf/urgent] perf evsel: Add iterator to iterate over events ordered by CPU tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 06/12] perf evsel: Add functions to close evsel on a CPU Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 07/12] perf stat: Use affinity for closing file descriptors Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 08/12] perf stat: Factor out open error handling Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 09/12] perf stat: Use affinity for opening events Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-12-18  9:29   ` [perf stat] cc9cdf40ae: perf-sanity-tests.Event_times.fail kernel test robot
2019-11-21  0:15 ` [PATCH 10/12] perf stat: Use affinity for reading Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 11/12] perf evsel: Add functions to enable/disable for a specific CPU Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21  0:15 ` [PATCH 12/12] perf stat: Use affinity for enabling/disabling events Andi Kleen
2019-12-04  7:53   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-11-21 12:47 ` Optimize perf stat for large number of events/cpus Andi Kleen
2019-11-21 14:32   ` Arnaldo Carvalho de Melo
2019-11-27 15:16 ` Arnaldo Carvalho de Melo
2019-11-27 15:43   ` Arnaldo Carvalho de Melo
2019-11-27 23:26     ` Andi Kleen
2019-11-28  0:01       ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191121001522.180827-6-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).