linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libperf: Fix perf_cpu_map__for_each_cpu macro
@ 2022-02-15 15:37 Jiri Olsa
  2022-02-15 17:12 ` Ian Rogers
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2022-02-15 15:37 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Tzvetomir Stoyanov, lkml, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Namhyung Kim, Alexander Shishkin, Ian Rogers,
	linux-perf-users

Tzvetomir Stoyanov reported an issue with using macro
perf_cpu_map__for_each_cpu using private perf_cpu object.

The issue is caused by recent change that wrapped cpu in struct
perf_cpu to distinguish it from cpu indexes. We need to make
struct perf_cpu public.

Adding simple test for using perf_cpu_map__for_each_cpu
macro.

Fixes: 6d18804b963b ("perf cpumap: Give CPUs their own type")
Reported-by: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/perf/include/internal/cpumap.h |  6 +-----
 tools/lib/perf/include/perf/cpumap.h     |  5 +++++
 tools/lib/perf/libperf.map               |  1 +
 tools/lib/perf/tests/test-cpumap.c       | 11 +++++++++++
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h
index 581f9ffb4237..1973a18c096b 100644
--- a/tools/lib/perf/include/internal/cpumap.h
+++ b/tools/lib/perf/include/internal/cpumap.h
@@ -3,11 +3,7 @@
 #define __LIBPERF_INTERNAL_CPUMAP_H
 
 #include <linux/refcount.h>
-
-/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
-struct perf_cpu {
-	int cpu;
-};
+#include <perf/cpumap.h>
 
 /**
  * A sized, reference counted, sorted array of integers representing CPU
diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h
index 15b8faafd615..4a2edbdb5e2b 100644
--- a/tools/lib/perf/include/perf/cpumap.h
+++ b/tools/lib/perf/include/perf/cpumap.h
@@ -7,6 +7,11 @@
 #include <stdio.h>
 #include <stdbool.h>
 
+/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
+struct perf_cpu {
+	int cpu;
+};
+
 LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
 LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
 LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
index 93696affda2e..6fa0d651576b 100644
--- a/tools/lib/perf/libperf.map
+++ b/tools/lib/perf/libperf.map
@@ -2,6 +2,7 @@ LIBPERF_0.0.1 {
 	global:
 		libperf_init;
 		perf_cpu_map__dummy_new;
+		perf_cpu_map__default_new;
 		perf_cpu_map__get;
 		perf_cpu_map__put;
 		perf_cpu_map__new;
diff --git a/tools/lib/perf/tests/test-cpumap.c b/tools/lib/perf/tests/test-cpumap.c
index d39378eaf897..87b0510a556f 100644
--- a/tools/lib/perf/tests/test-cpumap.c
+++ b/tools/lib/perf/tests/test-cpumap.c
@@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level,
 int test_cpumap(int argc, char **argv)
 {
 	struct perf_cpu_map *cpus;
+	struct perf_cpu cpu;
+	int idx;
 
 	__T_START;
 
@@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv)
 	perf_cpu_map__put(cpus);
 	perf_cpu_map__put(cpus);
 
+	cpus = perf_cpu_map__default_new();
+	if (!cpus)
+		return -1;
+
+	perf_cpu_map__for_each_cpu(cpu, idx, cpus)
+		__T("wrong cpu number", cpu.cpu != -1);
+
+	perf_cpu_map__put(cpus);
+
 	__T_END;
 	return tests_failed == 0 ? 0 : -1;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] libperf: Fix perf_cpu_map__for_each_cpu macro
  2022-02-15 15:37 [PATCH] libperf: Fix perf_cpu_map__for_each_cpu macro Jiri Olsa
@ 2022-02-15 17:12 ` Ian Rogers
  2022-02-15 20:41   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2022-02-15 17:12 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, Tzvetomir Stoyanov, lkml,
	Peter Zijlstra, Ingo Molnar, Mark Rutland, Namhyung Kim,
	Alexander Shishkin, linux-perf-users

On Tue, Feb 15, 2022 at 7:37 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Tzvetomir Stoyanov reported an issue with using macro
> perf_cpu_map__for_each_cpu using private perf_cpu object.
>
> The issue is caused by recent change that wrapped cpu in struct
> perf_cpu to distinguish it from cpu indexes. We need to make
> struct perf_cpu public.
>
> Adding simple test for using perf_cpu_map__for_each_cpu
> macro.
>
> Fixes: 6d18804b963b ("perf cpumap: Give CPUs their own type")
> Reported-by: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/lib/perf/include/internal/cpumap.h |  6 +-----
>  tools/lib/perf/include/perf/cpumap.h     |  5 +++++
>  tools/lib/perf/libperf.map               |  1 +
>  tools/lib/perf/tests/test-cpumap.c       | 11 +++++++++++
>  4 files changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h
> index 581f9ffb4237..1973a18c096b 100644
> --- a/tools/lib/perf/include/internal/cpumap.h
> +++ b/tools/lib/perf/include/internal/cpumap.h
> @@ -3,11 +3,7 @@
>  #define __LIBPERF_INTERNAL_CPUMAP_H
>
>  #include <linux/refcount.h>
> -
> -/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
> -struct perf_cpu {
> -       int cpu;
> -};
> +#include <perf/cpumap.h>
>
>  /**
>   * A sized, reference counted, sorted array of integers representing CPU
> diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h
> index 15b8faafd615..4a2edbdb5e2b 100644
> --- a/tools/lib/perf/include/perf/cpumap.h
> +++ b/tools/lib/perf/include/perf/cpumap.h
> @@ -7,6 +7,11 @@
>  #include <stdio.h>
>  #include <stdbool.h>
>
> +/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
> +struct perf_cpu {
> +       int cpu;
> +};
> +
>  LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
>  LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
>  LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
> diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
> index 93696affda2e..6fa0d651576b 100644
> --- a/tools/lib/perf/libperf.map
> +++ b/tools/lib/perf/libperf.map
> @@ -2,6 +2,7 @@ LIBPERF_0.0.1 {
>         global:
>                 libperf_init;
>                 perf_cpu_map__dummy_new;
> +               perf_cpu_map__default_new;
>                 perf_cpu_map__get;
>                 perf_cpu_map__put;
>                 perf_cpu_map__new;
> diff --git a/tools/lib/perf/tests/test-cpumap.c b/tools/lib/perf/tests/test-cpumap.c
> index d39378eaf897..87b0510a556f 100644
> --- a/tools/lib/perf/tests/test-cpumap.c
> +++ b/tools/lib/perf/tests/test-cpumap.c
> @@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level,
>  int test_cpumap(int argc, char **argv)
>  {
>         struct perf_cpu_map *cpus;
> +       struct perf_cpu cpu;
> +       int idx;
>
>         __T_START;
>
> @@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv)
>         perf_cpu_map__put(cpus);
>         perf_cpu_map__put(cpus);
>
> +       cpus = perf_cpu_map__default_new();
> +       if (!cpus)
> +               return -1;
> +
> +       perf_cpu_map__for_each_cpu(cpu, idx, cpus)
> +               __T("wrong cpu number", cpu.cpu != -1);
> +
> +       perf_cpu_map__put(cpus);
> +
>         __T_END;
>         return tests_failed == 0 ? 0 : -1;
>  }
> --
> 2.35.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libperf: Fix perf_cpu_map__for_each_cpu macro
  2022-02-15 17:12 ` Ian Rogers
@ 2022-02-15 20:41   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-02-15 20:41 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Jiri Olsa, Tzvetomir Stoyanov, lkml, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Namhyung Kim, Alexander Shishkin, linux-perf-users

Em Tue, Feb 15, 2022 at 09:12:57AM -0800, Ian Rogers escreveu:
> On Tue, Feb 15, 2022 at 7:37 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Tzvetomir Stoyanov reported an issue with using macro
> > perf_cpu_map__for_each_cpu using private perf_cpu object.
> >
> > The issue is caused by recent change that wrapped cpu in struct
> > perf_cpu to distinguish it from cpu indexes. We need to make
> > struct perf_cpu public.
> >
> > Adding simple test for using perf_cpu_map__for_each_cpu
> > macro.
> >
> > Fixes: 6d18804b963b ("perf cpumap: Give CPUs their own type")
> > Reported-by: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> 
> Acked-by: Ian Rogers <irogers@google.com>

Thanks, applied.

- Arnaldo

 
> Thanks,
> Ian
> 
> > ---
> >  tools/lib/perf/include/internal/cpumap.h |  6 +-----
> >  tools/lib/perf/include/perf/cpumap.h     |  5 +++++
> >  tools/lib/perf/libperf.map               |  1 +
> >  tools/lib/perf/tests/test-cpumap.c       | 11 +++++++++++
> >  4 files changed, 18 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h
> > index 581f9ffb4237..1973a18c096b 100644
> > --- a/tools/lib/perf/include/internal/cpumap.h
> > +++ b/tools/lib/perf/include/internal/cpumap.h
> > @@ -3,11 +3,7 @@
> >  #define __LIBPERF_INTERNAL_CPUMAP_H
> >
> >  #include <linux/refcount.h>
> > -
> > -/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
> > -struct perf_cpu {
> > -       int cpu;
> > -};
> > +#include <perf/cpumap.h>
> >
> >  /**
> >   * A sized, reference counted, sorted array of integers representing CPU
> > diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h
> > index 15b8faafd615..4a2edbdb5e2b 100644
> > --- a/tools/lib/perf/include/perf/cpumap.h
> > +++ b/tools/lib/perf/include/perf/cpumap.h
> > @@ -7,6 +7,11 @@
> >  #include <stdio.h>
> >  #include <stdbool.h>
> >
> > +/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
> > +struct perf_cpu {
> > +       int cpu;
> > +};
> > +
> >  LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
> >  LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void);
> >  LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
> > diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
> > index 93696affda2e..6fa0d651576b 100644
> > --- a/tools/lib/perf/libperf.map
> > +++ b/tools/lib/perf/libperf.map
> > @@ -2,6 +2,7 @@ LIBPERF_0.0.1 {
> >         global:
> >                 libperf_init;
> >                 perf_cpu_map__dummy_new;
> > +               perf_cpu_map__default_new;
> >                 perf_cpu_map__get;
> >                 perf_cpu_map__put;
> >                 perf_cpu_map__new;
> > diff --git a/tools/lib/perf/tests/test-cpumap.c b/tools/lib/perf/tests/test-cpumap.c
> > index d39378eaf897..87b0510a556f 100644
> > --- a/tools/lib/perf/tests/test-cpumap.c
> > +++ b/tools/lib/perf/tests/test-cpumap.c
> > @@ -14,6 +14,8 @@ static int libperf_print(enum libperf_print_level level,
> >  int test_cpumap(int argc, char **argv)
> >  {
> >         struct perf_cpu_map *cpus;
> > +       struct perf_cpu cpu;
> > +       int idx;
> >
> >         __T_START;
> >
> > @@ -27,6 +29,15 @@ int test_cpumap(int argc, char **argv)
> >         perf_cpu_map__put(cpus);
> >         perf_cpu_map__put(cpus);
> >
> > +       cpus = perf_cpu_map__default_new();
> > +       if (!cpus)
> > +               return -1;
> > +
> > +       perf_cpu_map__for_each_cpu(cpu, idx, cpus)
> > +               __T("wrong cpu number", cpu.cpu != -1);
> > +
> > +       perf_cpu_map__put(cpus);
> > +
> >         __T_END;
> >         return tests_failed == 0 ? 0 : -1;
> >  }
> > --
> > 2.35.1
> >

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-15 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 15:37 [PATCH] libperf: Fix perf_cpu_map__for_each_cpu macro Jiri Olsa
2022-02-15 17:12 ` Ian Rogers
2022-02-15 20:41   ` Arnaldo Carvalho de Melo

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).