Re: [PATCH V3 11/14] perf tools: Fix perf_evlist__add() not propagating maps

Arnaldo Carvalho de Melo
2015-09-15T14:18:25Z

[-- Attachment #1: Type: text/plain, Size: 3531 bytes --]

Em Tue, Sep 08, 2015 at 10:58:59AM +0300, Adrian Hunter escreveu:
> If evsels are added after maps are created, then they won't
> have any maps propagated to them. Fix that.

Next time please consider, when introducing this a new function A() that
will be needed by a function B() in a subsequent patch to introduce A()
before B() if A() is static, i.e. to avoid making the patch making B()
use A() be larger than necessary by having to move A() to before B().

When reviewing I went, "oh, but this function was introduced already in
the previous patch?!" only to figure out that it was unchanged, just
being moved.

I did it this time, please see the two attached patches.

Thanks,

- Arnaldo

> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> tools/perf/util/evlist.c | 56 +++++++++++++++++++++++++-----------------------
> 1 file changed, 29 insertions(+), 27 deletions(-)
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index fcaabd1e5dbb..99267ab0d24a 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -124,6 +124,33 @@ void perf_evlist__delete(struct perf_evlist *evlist)
> free(evlist);
> }
>
> +static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
> + struct perf_evsel *evsel)
> +{
> + /*
> + * We already have cpus for evsel (via PMU sysfs) so
> + * keep it, if there's no target cpu list defined.
> + */
> + if (!evsel->own_cpus || evlist->has_user_cpus) {
> + cpu_map__put(evsel->cpus);
> + evsel->cpus = cpu_map__get(evlist->cpus);
> + } else if (evsel->cpus != evsel->own_cpus) {
> + cpu_map__put(evsel->cpus);
> + evsel->cpus = cpu_map__get(evsel->own_cpus);
> + }
> +
> + thread_map__put(evsel->threads);
> + evsel->threads = thread_map__get(evlist->threads);
> +}
> +
> +static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
> +{
> + struct perf_evsel *evsel;
> +
> + evlist__for_each(evlist, evsel)
> + __perf_evlist__propagate_maps(evlist, evsel);
> +}
> +
> void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
> {
> entry->evlist = evlist;
> @@ -133,6 +160,8 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
>
> if (!evlist->nr_entries++)
> perf_evlist__set_id_pos(evlist);
> +
> + __perf_evlist__propagate_maps(evlist, entry);
> }
>
> void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
> @@ -1102,33 +1131,6 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
> return perf_evlist__mmap_ex(evlist, pages, overwrite, 0, false);
> }
>
> -static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
> - struct perf_evsel *evsel)
> -{
> - /*
> - * We already have cpus for evsel (via PMU sysfs) so
> - * keep it, if there's no target cpu list defined.
> - */
> - if (!evsel->own_cpus || evlist->has_user_cpus) {
> - cpu_map__put(evsel->cpus);
> - evsel->cpus = cpu_map__get(evlist->cpus);
> - } else if (evsel->cpus != evsel->own_cpus) {
> - cpu_map__put(evsel->cpus);
> - evsel->cpus = cpu_map__get(evsel->own_cpus);
> - }
> -
> - thread_map__put(evsel->threads);
> - evsel->threads = thread_map__get(evlist->threads);
> -}
> -
> -static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
> -{
> - struct perf_evsel *evsel;
> -
> - evlist__for_each(evlist, evsel)
> - __perf_evlist__propagate_maps(evlist, evsel);
> -}
> -
> int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
> {
> struct cpu_map *cpus;
> --
> 1.9.1

[-- Attachment #2: 0001-perf-evlist-Factor-out-a-function-to-propagate-maps-.patch --]
[-- Type: text/plain, Size: 2898 bytes --]

>From adc0c3e87b0e1baeccabe09b6dba738f17d0e91d Mon Sep 17 00:00:00 2001
From: Adrian Hunter <adrian.hunter@intel.com>
Date: Tue, 8 Sep 2015 10:58:58 +0300
Subject: [PATCH 1/2] perf evlist: Factor out a function to propagate maps for
a single evsel

Subsequent fixes will need a function that just propagates maps for a
single evsel so factor it out.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Link: http://lkml.kernel.org/r/1441699142-18905-11-git-send-email-adrian.hunter@intel.com
[ Moved them to before perf_evlist__add() to avoid having to move it in the next patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/evlist.c | 49 ++++++++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c17f3558a37a..4e840bfc19ef 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -124,6 +124,33 @@ void perf_evlist__delete(struct perf_evlist *evlist)
free(evlist);
}

+static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
+ struct perf_evsel *evsel)
+{
+ /*
+ * We already have cpus for evsel (via PMU sysfs) so
+ * keep it, if there's no target cpu list defined.
+ */
+ if (!evsel->own_cpus || evlist->has_user_cpus) {
+ cpu_map__put(evsel->cpus);
+ evsel->cpus = cpu_map__get(evlist->cpus);
+ } else if (evsel->cpus != evsel->own_cpus) {
+ cpu_map__put(evsel->cpus);
+ evsel->cpus = cpu_map__get(evsel->own_cpus);
+ }
+
+ thread_map__put(evsel->threads);
+ evsel->threads = thread_map__get(evlist->threads);
+}
+
+static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
+{
+ struct perf_evsel *evsel;
+
+ evlist__for_each(evlist, evsel)
+ __perf_evlist__propagate_maps(evlist, evsel);
+}
+
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
{
entry->evlist = evlist;
@@ -1102,28 +1129,6 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
return perf_evlist__mmap_ex(evlist, pages, overwrite, 0, false);
}

-static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
-{
- struct perf_evsel *evsel;
-
- evlist__for_each(evlist, evsel) {
- /*
- * We already have cpus for evsel (via PMU sysfs) so
- * keep it, if there's no target cpu list defined.
- */
- if (!evsel->own_cpus || evlist->has_user_cpus) {
- cpu_map__put(evsel->cpus);
- evsel->cpus = cpu_map__get(evlist->cpus);
- } else if (evsel->cpus != evsel->own_cpus) {
- cpu_map__put(evsel->cpus);
- evsel->cpus = cpu_map__get(evsel->own_cpus);
- }
-
- thread_map__put(evsel->threads);
- evsel->threads = thread_map__get(evlist->threads);
- }
-}
-
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
{
struct cpu_map *cpus;
--
2.1.0

[-- Attachment #3: 0002-perf-evlist-Fix-add-not-propagating-maps.patch --]
[-- Type: text/plain, Size: 1262 bytes --]

>From 44c42d71c659527c81bf169808959c9339116d85 Mon Sep 17 00:00:00 2001
From: Adrian Hunter <adrian.hunter@intel.com>
Date: Tue, 8 Sep 2015 10:58:59 +0300
Subject: [PATCH 2/2] perf evlist: Fix add() not propagating maps

If evsels are added after maps are created, then they won't have any
maps propagated to them. Fix that.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Link: http://lkml.kernel.org/r/1441699142-18905-12-git-send-email-adrian.hunter@intel.com
[ Moved the moving of propagate_maps() to the patch before, so that this
one does _just_ the one lile fix calling in add()]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/evlist.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4e840bfc19ef..99267ab0d24a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -160,6 +160,8 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)

if (!evlist->nr_entries++)
perf_evlist__set_id_pos(evlist);
+
+ __perf_evlist__propagate_maps(evlist, entry);
}

void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
--
2.1.0