All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] libperf: Add perf_evsel__id() function
@ 2024-09-10  6:26 Charlie Jenkins
  2024-09-26  5:29 ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Charlie Jenkins @ 2024-09-10  6:26 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter
  Cc: linux-perf-users, linux-kernel, Charlie Jenkins

Introduce perf_evsel__id() to collect the id of an evsel. This allows
applications to determine the allocated id of an evsel for each fd. The
"ids" argument is expected to be an array the size of the number of open
fd's for the evsel.  This will allow applications to link the id
returned by PERF_SAMPLE_ID to the event being sampled.

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
---
Changes in v2:
- Replaced id argument with array of ids for perf_evsel__id() to support
  the id for each fd.
- Link to v1: https://lore.kernel.org/r/20240823-perf_evsel_get_id-v1-1-0ffa204c4164@rivosinc.com
---
 tools/lib/perf/Documentation/libperf.txt |  2 ++
 tools/lib/perf/evsel.c                   | 10 ++++++++++
 tools/lib/perf/include/perf/evsel.h      |  1 +
 3 files changed, 13 insertions(+)

diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
index fcfb9499ef9c..754c103f7b13 100644
--- a/tools/lib/perf/Documentation/libperf.txt
+++ b/tools/lib/perf/Documentation/libperf.txt
@@ -94,6 +94,8 @@ SYNOPSIS
   void perf_evlist__enable(struct perf_evlist *evlist);
   void perf_evlist__disable(struct perf_evlist *evlist);
 
+  void perf_evsel__id(struct perf_evsel *evsel, __u64 ids[]);
+
   #define perf_evlist__for_each_evsel(evlist, pos)
 
   void perf_evlist__set_maps(struct perf_evlist *evlist,
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index c07160953224..d10dfcb605ba 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -484,6 +484,16 @@ int perf_evsel__disable(struct perf_evsel *evsel)
 	return err;
 }
 
+int perf_evsel__id(struct perf_evsel *evsel, __u64 ids[])
+{
+	int i;
+	int err = 0;
+
+	for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
+		err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ID, (unsigned long)&ids[i], i);
+	return err;
+}
+
 int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
 {
 	int err = 0, i;
diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
index 6f92204075c2..13f19189839a 100644
--- a/tools/lib/perf/include/perf/evsel.h
+++ b/tools/lib/perf/include/perf/evsel.h
@@ -41,6 +41,7 @@ LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx
 LIBPERF_API int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread);
 LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
+LIBPERF_API int perf_evsel__id(struct perf_evsel *evsel, __u64 ids[]);
 LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
 LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
 LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);

---
base-commit: 47ac09b91befbb6a235ab620c32af719f8208399
change-id: 20240822-perf_evsel_get_id-f7e11f15504b
-- 
- Charlie


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

* Re: [PATCH v2] libperf: Add perf_evsel__id() function
@ 2024-09-11  6:33 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2024-09-11  6:33 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20240909-perf_evsel_get_id-v2-1-b26eae02f606@rivosinc.com>
References: <20240909-perf_evsel_get_id-v2-1-b26eae02f606@rivosinc.com>
TO: Charlie Jenkins <charlie@rivosinc.com>
TO: Peter Zijlstra <peterz@infradead.org>
TO: Ingo Molnar <mingo@redhat.com>
TO: Arnaldo Carvalho de Melo <acme@kernel.org>
TO: Namhyung Kim <namhyung@kernel.org>
TO: Mark Rutland <mark.rutland@arm.com>
TO: Alexander Shishkin <alexander.shishkin@linux.intel.com>
TO: Jiri Olsa <jolsa@kernel.org>
TO: Ian Rogers <irogers@google.com>
TO: Adrian Hunter <adrian.hunter@intel.com>
CC: linux-perf-users@vger.kernel.org
CC: linux-kernel@vger.kernel.org
CC: Charlie Jenkins <charlie@rivosinc.com>

Hi Charlie,

kernel test robot noticed the following build errors:

[auto build test ERROR on 47ac09b91befbb6a235ab620c32af719f8208399]

url:    https://github.com/intel-lab-lkp/linux/commits/Charlie-Jenkins/libperf-Add-perf_evsel__id-function/20240910-142806
base:   47ac09b91befbb6a235ab620c32af719f8208399
patch link:    https://lore.kernel.org/r/20240909-perf_evsel_get_id-v2-1-b26eae02f606%40rivosinc.com
patch subject: [PATCH v2] libperf: Add perf_evsel__id() function
:::::: branch date: 24 hours ago
:::::: commit date: 24 hours ago
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240911/202409111408.NA8mGIbf-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202409111408.NA8mGIbf-lkp@intel.com/

All errors (new ones prefixed by >>):

   Makefile.config:671: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
     PERF_VERSION = 6.11.rc4.ge8b423023fcf
>> evsel.c:493:57: error: incompatible integer to pointer conversion passing 'unsigned long' to parameter of type 'void *' [-Wint-conversion]
     493 |                 err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ID, (unsigned long)&ids[i], i);
         |                                                                       ^~~~~~~~~~~~~~~~~~~~~~
   evsel.c:427:22: note: passing argument to parameter 'arg' here
     427 |                                  int ioc,  void *arg,
         |                                                  ^
   1 error generated.
   make[7]: *** [tools/build/Makefile.build:105: tools/perf/libperf/evsel.o] Error 1
   make[7]: *** Waiting for unfinished jobs....
   make[6]: *** [Makefile:122: tools/perf/libperf/libperf-in.o] Error 2
   make[5]: *** [Makefile.perf:961: tools/perf/libperf/libperf.a] Error 2
   make[5]: *** Waiting for unfinished jobs....
   make[4]: *** [Makefile.perf:290: sub-make] Error 2
   make[3]: *** [Makefile:70: all] Error 2

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v2] libperf: Add perf_evsel__id() function
  2024-09-10  6:26 [PATCH v2] libperf: Add perf_evsel__id() function Charlie Jenkins
@ 2024-09-26  5:29 ` Namhyung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-09-26  5:29 UTC (permalink / raw)
  To: Charlie Jenkins
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, linux-perf-users, linux-kernel

Hello Charlie,

Sorry for the late reply.

On Mon, Sep 09, 2024 at 11:26:52PM -0700, Charlie Jenkins wrote:
> Introduce perf_evsel__id() to collect the id of an evsel. This allows
> applications to determine the allocated id of an evsel for each fd. The
> "ids" argument is expected to be an array the size of the number of open
> fd's for the evsel.  This will allow applications to link the id
> returned by PERF_SAMPLE_ID to the event being sampled.
> 
> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> ---
> Changes in v2:
> - Replaced id argument with array of ids for perf_evsel__id() to support
>   the id for each fd.
> - Link to v1: https://lore.kernel.org/r/20240823-perf_evsel_get_id-v1-1-0ffa204c4164@rivosinc.com
> ---
>  tools/lib/perf/Documentation/libperf.txt |  2 ++
>  tools/lib/perf/evsel.c                   | 10 ++++++++++
>  tools/lib/perf/include/perf/evsel.h      |  1 +
>  3 files changed, 13 insertions(+)
> 
> diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt
> index fcfb9499ef9c..754c103f7b13 100644
> --- a/tools/lib/perf/Documentation/libperf.txt
> +++ b/tools/lib/perf/Documentation/libperf.txt
> @@ -94,6 +94,8 @@ SYNOPSIS
>    void perf_evlist__enable(struct perf_evlist *evlist);
>    void perf_evlist__disable(struct perf_evlist *evlist);
>  
> +  void perf_evsel__id(struct perf_evsel *evsel, __u64 ids[]);
> +
>    #define perf_evlist__for_each_evsel(evlist, pos)
>  
>    void perf_evlist__set_maps(struct perf_evlist *evlist,
> diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
> index c07160953224..d10dfcb605ba 100644
> --- a/tools/lib/perf/evsel.c
> +++ b/tools/lib/perf/evsel.c
> @@ -484,6 +484,16 @@ int perf_evsel__disable(struct perf_evsel *evsel)
>  	return err;
>  }
>  
> +int perf_evsel__id(struct perf_evsel *evsel, __u64 ids[])
> +{
> +	int i;
> +	int err = 0;
> +
> +	for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
> +		err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ID, (unsigned long)&ids[i], i);

This won't work correctly since perf_evsel__run_ioctl() has a loop
inside.  You should traverse xyarray correctly.

Now I think about the interface and it should look like this.

  struct perf_cpu_map *cpus = perf_evsel__cpus(evsel);
  struct perf_thread_map *threads = perf_evsel__threads(evsel);
  int x, y;
  u64 id;

  for (x = 0; x < perf_cpu_map__nr(cpus); x++) {
    for (y = 0; y < perf_thread_map__nr(threads); y++)
      perf_evsel__get_id(evsel, x, y, &id);
  }

I also found there's perf_evsel__{alloc,free}_id() but it doesn't seem
like to be exposed as API.  Maybe we can just use it internally to run
the ioctl and save the result.

Also it has the sample_id xyarray and id array (with ids size) but I
think they are the same and we need to get rid of one.

This is the implementation details and can be done separately.  For now
you can simply do like below:

  int perf_evsel__get_id(struct perf_evsel *evsel, int cpu_map_idx, int thread, u64 *id)
  {
      return perf_evsel__ioctl(evsel, PERF_EVENT_IOC_ID, id, cpu_map_idx, thread);
  }

Thanks,
Namhyung


> +	return err;
> +}
> +
>  int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
>  {
>  	int err = 0, i;
> diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
> index 6f92204075c2..13f19189839a 100644
> --- a/tools/lib/perf/include/perf/evsel.h
> +++ b/tools/lib/perf/include/perf/evsel.h
> @@ -41,6 +41,7 @@ LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx
>  LIBPERF_API int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread);
>  LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
>  LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
> +LIBPERF_API int perf_evsel__id(struct perf_evsel *evsel, __u64 ids[]);
>  LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
>  LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
>  LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
> 
> ---
> base-commit: 47ac09b91befbb6a235ab620c32af719f8208399
> change-id: 20240822-perf_evsel_get_id-f7e11f15504b
> -- 
> - Charlie
> 

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

end of thread, other threads:[~2024-09-26  5:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10  6:26 [PATCH v2] libperf: Add perf_evsel__id() function Charlie Jenkins
2024-09-26  5:29 ` Namhyung Kim
  -- strict thread matches above, loose matches on Subject: below --
2024-09-11  6:33 kernel test robot

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.