All of lore.kernel.org
 help / color / mirror / Atom feed
* libperf: CPU map question
@ 2022-02-14 16:54 Tzvetomir Stoyanov
  2022-02-14 19:51 ` Arnaldo Carvalho de Melo
  2022-02-14 21:22 ` Jiri Olsa
  0 siblings, 2 replies; 5+ messages in thread
From: Tzvetomir Stoyanov @ 2022-02-14 16:54 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, linux-perf-users

Hello,
I'm trying to use libperf as an interface to perf from an application,
but I face some difficulties.  I cannot understand how perf_cpu_map_
APIs should be used. My use case is:
 I want to iterate over the CPUs from the map. I'm using
perf_evsel__cpus() API to get the map and perf_cpu_map__for_each_cpu()
macros to iterate over the map. However, using that logic I get a
struct perf_cpu for each CPU from the map. That structure seems to be
private and I cannot access the actual .cpu id. Am I missing something
?
Will be glad for any help and clarification.

Thanks!
-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

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

* Re: libperf: CPU map question
  2022-02-14 16:54 libperf: CPU map question Tzvetomir Stoyanov
@ 2022-02-14 19:51 ` Arnaldo Carvalho de Melo
  2022-02-14 21:22 ` Jiri Olsa
  1 sibling, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-02-14 19:51 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Jiri Olsa, linux-perf-users

Em Mon, Feb 14, 2022 at 06:54:38PM +0200, Tzvetomir Stoyanov escreveu:
> Hello,
> I'm trying to use libperf as an interface to perf from an application,
> but I face some difficulties.  I cannot understand how perf_cpu_map_
> APIs should be used. My use case is:
>  I want to iterate over the CPUs from the map. I'm using
> perf_evsel__cpus() API to get the map and perf_cpu_map__for_each_cpu()
> macros to iterate over the map. However, using that logic I get a
> struct perf_cpu for each CPU from the map. That structure seems to be
> private and I cannot access the actual .cpu id. Am I missing something
> ?
> Will be glad for any help and clarification.

Jiri, can you help?

- Arnaldo

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

* Re: libperf: CPU map question
  2022-02-14 16:54 libperf: CPU map question Tzvetomir Stoyanov
  2022-02-14 19:51 ` Arnaldo Carvalho de Melo
@ 2022-02-14 21:22 ` Jiri Olsa
  2022-02-14 22:18   ` Ian Rogers
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2022-02-14 21:22 UTC (permalink / raw)
  To: Tzvetomir Stoyanov, Ian Rogers; +Cc: Arnaldo Carvalho de Melo, linux-perf-users

On Mon, Feb 14, 2022 at 06:54:38PM +0200, Tzvetomir Stoyanov wrote:
> Hello,
> I'm trying to use libperf as an interface to perf from an application,
> but I face some difficulties.  I cannot understand how perf_cpu_map_
> APIs should be used. My use case is:
>  I want to iterate over the CPUs from the map. I'm using
> perf_evsel__cpus() API to get the map and perf_cpu_map__for_each_cpu()
> macros to iterate over the map. However, using that logic I get a
> struct perf_cpu for each CPU from the map. That structure seems to be
> private and I cannot access the actual .cpu id. Am I missing something
> ?
> Will be glad for any help and clarification.

yea it's a bug ;-) there was a change recently that wrapped cpu
in struct perf_cpu to distinguish it from cpu indexes

  6d18804b963b perf cpumap: Give CPUs their own type

not sure there's workaround for that.. but I think change below should fix it

Ian, would this be ok? we need to add some test for this

jirka


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

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

* Re: libperf: CPU map question
  2022-02-14 21:22 ` Jiri Olsa
@ 2022-02-14 22:18   ` Ian Rogers
  2022-02-15  4:46     ` Tzvetomir Stoyanov
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2022-02-14 22:18 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: Tzvetomir Stoyanov, Arnaldo Carvalho de Melo, linux-perf-users

On Mon, Feb 14, 2022 at 1:22 PM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Mon, Feb 14, 2022 at 06:54:38PM +0200, Tzvetomir Stoyanov wrote:
> > Hello,
> > I'm trying to use libperf as an interface to perf from an application,
> > but I face some difficulties.  I cannot understand how perf_cpu_map_
> > APIs should be used. My use case is:
> >  I want to iterate over the CPUs from the map. I'm using
> > perf_evsel__cpus() API to get the map and perf_cpu_map__for_each_cpu()
> > macros to iterate over the map. However, using that logic I get a
> > struct perf_cpu for each CPU from the map. That structure seems to be
> > private and I cannot access the actual .cpu id. Am I missing something
> > ?
> > Will be glad for any help and clarification.
>
> yea it's a bug ;-) there was a change recently that wrapped cpu
> in struct perf_cpu to distinguish it from cpu indexes
>
>   6d18804b963b perf cpumap: Give CPUs their own type
>
> not sure there's workaround for that.. but I think change below should fix it
>
> Ian, would this be ok? we need to add some test for this

This looks good to me, thanks! Agreed on the test.

Thanks,
Ian

> jirka
>
>
> ---
> 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);

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

* Re: libperf: CPU map question
  2022-02-14 22:18   ` Ian Rogers
@ 2022-02-15  4:46     ` Tzvetomir Stoyanov
  0 siblings, 0 replies; 5+ messages in thread
From: Tzvetomir Stoyanov @ 2022-02-15  4:46 UTC (permalink / raw)
  To: Ian Rogers; +Cc: Jiri Olsa, Arnaldo Carvalho de Melo, linux-perf-users

On Tue, Feb 15, 2022 at 12:18 AM Ian Rogers <irogers@google.com> wrote:
>
> On Mon, Feb 14, 2022 at 1:22 PM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > On Mon, Feb 14, 2022 at 06:54:38PM +0200, Tzvetomir Stoyanov wrote:
> > > Hello,
> > > I'm trying to use libperf as an interface to perf from an application,
> > > but I face some difficulties.  I cannot understand how perf_cpu_map_
> > > APIs should be used. My use case is:
> > >  I want to iterate over the CPUs from the map. I'm using
> > > perf_evsel__cpus() API to get the map and perf_cpu_map__for_each_cpu()
> > > macros to iterate over the map. However, using that logic I get a
> > > struct perf_cpu for each CPU from the map. That structure seems to be
> > > private and I cannot access the actual .cpu id. Am I missing something
> > > ?
> > > Will be glad for any help and clarification.
> >
> > yea it's a bug ;-) there was a change recently that wrapped cpu
> > in struct perf_cpu to distinguish it from cpu indexes
> >
> >   6d18804b963b perf cpumap: Give CPUs their own type
> >
> > not sure there's workaround for that.. but I think change below should fix it
> >
> > Ian, would this be ok? we need to add some test for this
>
> This looks good to me, thanks! Agreed on the test.
>
> Thanks,
> Ian
>
> > jirka
> >

I applied the patch, it solves my problem. Thanks!

I have one more problem, related to thread map allocation. I submitted
a patch a few days ago. Do not know if you have time to look at it,
I'll ping you on the other thread. Will be glad for any help or
comments on the patch.

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



-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14 16:54 libperf: CPU map question Tzvetomir Stoyanov
2022-02-14 19:51 ` Arnaldo Carvalho de Melo
2022-02-14 21:22 ` Jiri Olsa
2022-02-14 22:18   ` Ian Rogers
2022-02-15  4:46     ` Tzvetomir Stoyanov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.