perf: Reveal PMU type in fdinfo
PATCH v4 1/2 perf: Reveal PMU type in fdinfo
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:
$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0
Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536
---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.
v3: lore.kernel.org/[email protected]
kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/events/core.c +10 -0
@@ -56,6 +56,7 @@#include <linux/buildid.h> #include <linux/task_work.h> #include <linux/percpu-rwsem.h> +#include <linux/seq_file.h> #include "internal.h"
@@ -7077,6 +7078,14 @@ static int perf_fasync(int fd, struct file *filp, int on)return 0 ; } +static void perf_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct perf_event *event = f->private_data; + +seq_printf (m,"perf_event_attr.type:\t%u\n" , event->orig_type); +seq_printf (m,"perf_event_attr.config:\t%llu\n" , (unsigned long long )event->attr.config); +} +static const struct file_operations perf_fops = { .release = perf_release, .read = perf_read,
@@ -7085,6 +7094,7 @@ static const struct file_operations perf_fops = { .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, + .show_fdinfo = perf_show_fdinfo, };/*
--
2.49.0.1204.g71687c7c1d-goog
PATCH v4 2/2 perf evsel: Find process with busy PMUs for EBUSY
It parses fdinfo with PMU type, comparing with the event which failed to open, and report the processes causing EBUSY error.
Testing cycles and intel_pt//
$ ./perf stat -e cycles & [1] 55569 $ ./perf stat -e intel_pt// & [2] 55683 $ ./perf stat -e intel_pt// Error: The PMU intel_pt counters are busy and in use by another process. Possible processes: 55683 ./perf stat -e intel_pt//
Only perf with intel_pt was reported.
---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.
v3: lore.kernel.org/[email protected]/
tools/perf/util/evsel.c | 79 +++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 22 deletions(-)
tools/perf/util/evsel.c +57 -22
@@ -3619,7 +3619,8 @@ static bool find_process(const char *name)return ret ? false : true; } -static int dump_perf_event_processes (char *msg,size_t size) +static int dump_perf_event_processes (const struct perf_event_attr *failed_attr, +char *msg,size_t size) {DIR *proc_dir;struct dirent *proc_entry;
@@ -3660,29 +3661,61 @@ static int dump_perf_event_processes(char *msg, size_t size)continue ;/* Take care as readlink doesn't null terminate the string. */ if (!strncmp (buf,"anon_inode:[perf_event]" , link_size)) { -int cmdline_fd; -ssize_t cmdline_size; - -scnprintf (buf,sizeof (buf),"%s/cmdline" , proc_entry->d_name); - cmdline_fd =openat (dirfd (proc_dir), buf,O_RDONLY ); -if (cmdline_fd ==-1 ) -continue ; - cmdline_size =read (cmdline_fd, buf,sizeof (buf) -1 ); -close (cmdline_fd); -if (cmdline_size <0 ) +int fdinfo_fd; +ssize_t fdinfo_size; +char *line; +u32 perf_event_type =UINT32_MAX ; + +/* Let's check the PMU type reserved by this process */ +scnprintf (buf,sizeof (buf),"%s/fdinfo/%s" , + proc_entry->d_name, fd_entry->d_name); + fdinfo_fd =openat (dirfd (proc_dir), buf,O_RDONLY ); + fdinfo_size =read (fdinfo_fd, buf,sizeof (buf) -1 ); +if (fdinfo_size <0 )continue ; - buf[cmdline_size] ='\0' ; -for (ssize_t i =0 ; i < cmdline_size; i++) { -if (buf[i] =='\0' ) - buf[i] =' ' ; + buf[fdinfo_size] ='\0' ; + + line =strtok (buf,"\n" ); +while (line !=NULL ) { +if (sscanf (line, +"perf_event_attr.type:\t%u" , + &perf_event_type) ==1 ) +break ; + line =strtok (NULL ,"\n" ); } -if (printed ==0 ) - printed +=scnprintf (msg, size,"Possible processes:\n" ); - - printed +=scnprintf (msg + printed, size - printed, -"%s %s\n" , proc_entry->d_name, buf); -break ; +/* Report the process which reserves the conflicted PMU. */ +/* If fdinfo does not contain PMU type, report it too. */ +if (perf_event_type == failed_attr->type || + perf_event_type ==UINT32_MAX ) { +int cmdline_fd; +ssize_t cmdline_size; + +scnprintf (buf,sizeof (buf), +"%s/cmdline" , + proc_entry->d_name); + cmdline_fd =openat (dirfd (proc_dir), buf,O_RDONLY ); +if (cmdline_fd ==-1 ) +continue ; + cmdline_size =read (cmdline_fd, buf,sizeof (buf) -1 ); +close (cmdline_fd); +if (cmdline_size <0 ) +continue ; + buf[cmdline_size] ='\0' ; +for (ssize_t i =0 ; i < cmdline_size; i++) { +if (buf[i] =='\0' ) + buf[i] =' ' ; + } + +if (printed ==0 ) + printed +=scnprintf ( + msg, size, +"Possible processes:\n" ); + + printed +=scnprintf (msg + printed, size - printed, +"%s %s\n" , proc_entry->d_name, buf); +break ; + } } }closedir (fd_dir);
@@ -3799,7 +3832,9 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, msg, size,"The PMU %s counters are busy and in use by another process.\n" , evsel->pmu ? evsel->pmu->name : ""); -return printed +dump_perf_event_processes (msg + printed, size - printed); +return printed +dump_perf_event_processes (&evsel->core.attr, + msg + printed, + size - printed);break ;case EINVAL :if (evsel->core.attr.sample_type &PERF_SAMPLE_CODE_PAGE_SIZE && perf_missing_features.code_page_size)
--
2.49.0.1204.g71687c7c1d-goog
Ian Rogers
reviewerQuoted 25 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536
Quoted 2 lines
Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>
Ping.
Thanks,
Ian
Quoted 48 lines
---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.v3: lore.kernel.org/[email protected]
kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/events/core.c +10
-1@@ -56,6 +56,7 @@#include <linux/buildid.h> #include <linux/task_work.h> #include <linux/percpu-rwsem.h> +#include <linux/seq_file.h> #include "internal.h" @@ -7077,6 +7078,14 @@ static int perf_fasync(int fd, struct file *filp, int on)return 0 ; } +static void perf_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct perf_event *event = f->private_data; + +seq_printf (m,"perf_event_attr.type:\t%u\n" , event->orig_type); +seq_printf (m,"perf_event_attr.config:\t%llu\n" , (unsigned long long )event->attr.config); +} +static const struct file_operations perf_fops = { .release = perf_release, .read = perf_read,@@ -7085,6 +7094,7 @@ static const struct file_operations perf_fops = { .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, + .show_fdinfo = perf_show_fdinfo, };/* -- 2.49.0.1204.g71687c7c1d-goog
Ian Rogers
reviewerQuoted 27 lines · Ian Rogers
Quoted 25 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536
Quoted 7 lines
Quoted 2 lines
Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>Ping.
Thanks,
Ian
Hi Peter and Ingo,
This small kernel change enables being able to better diagnose which processes are using perf events for what. In the series it is used in perf to blame EBUSY for PMUs like intel-pt on which processes are using that PMU.
Are there issues that need resolving before the patch can be considered for inclusion?
The original patch was sent in October 2024:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Ian
Quoted 48 lines
Quoted 48 lines
---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.v3: lore.kernel.org/[email protected]
kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/events/core.c +10
-1@@ -56,6 +56,7 @@#include <linux/buildid.h> #include <linux/task_work.h> #include <linux/percpu-rwsem.h> +#include <linux/seq_file.h> #include "internal.h" @@ -7077,6 +7078,14 @@ static int perf_fasync(int fd, struct file *filp, int on)return 0 ; } +static void perf_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct perf_event *event = f->private_data; + +seq_printf (m,"perf_event_attr.type:\t%u\n" , event->orig_type); +seq_printf (m,"perf_event_attr.config:\t%llu\n" , (unsigned long long )event->attr.config); +} +static const struct file_operations perf_fops = { .release = perf_release, .read = perf_read,@@ -7085,6 +7094,7 @@ static const struct file_operations perf_fops = { .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, + .show_fdinfo = perf_show_fdinfo, };/* -- 2.49.0.1204.g71687c7c1d-goog
Ian Rogers
reviewerQuoted 46 lines · Ian Rogers
Quoted 27 lines · Ian Rogers
Quoted 25 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536Quoted 7 lines
Quoted 2 lines
Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>Ping.
Thanks,
IanHi Peter and Ingo,
This small kernel change enables being able to better diagnose which processes are using perf events for what. In the series it is used in perf to blame EBUSY for PMUs like intel-pt on which processes are using that PMU.
Are there issues that need resolving before the patch can be considered for inclusion?
Quoted 2 lines
The original patch was sent in October 2024:
https://lore.kernel.org/lkml/[email protected]/
Ping. We're nearly up to a 1 year anniversary on this 10 line change.
Thanks,
Ian
Ian Rogers
reviewerQuoted 48 lines · Ian Rogers
Quoted 46 lines · Ian Rogers
Quoted 27 lines · Ian Rogers
Quoted 25 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536Quoted 7 lines
Quoted 2 lines
Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>Ping.
Thanks,
IanHi Peter and Ingo,
This small kernel change enables being able to better diagnose which processes are using perf events for what. In the series it is used in perf to blame EBUSY for PMUs like intel-pt on which processes are using that PMU.
Are there issues that need resolving before the patch can be considered for inclusion?
Quoted 4 lines
Quoted 2 lines
The original patch was sent in October 2024:
https://lore.kernel.org/lkml/[email protected]/Ping. We're nearly up to a 1 year anniversary on this 10 line change.
Ping.
Thanks,
Ian
Quoted 49 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.v3: lore.kernel.org/[email protected]
kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/events/core.c +1
-0@@ -56,6 +56,7 @@#include <linux/buildid.h> #include <linux/task_work.h> #include <linux/percpu-rwsem.h> +#include <linux/seq_file.h> #include "internal.h"
kernel/events/core.c static int perf_fasync(int fd, struct file *filp, int on) · line 7086
Quoted 9 lines
kernel/events/core.c +6
-0@@ -7077,6 +7078,14 @@ static int perf_fasync(int fd, struct file *filp, int on)return 0 ; } +static void perf_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct perf_event *event = f->private_data; + +seq_printf (m,"perf_event_attr.type:\t%u\n" , event->orig_type); +seq_printf (m,"perf_event_attr.config:\t%llu\n" , (unsigned long long )event->attr.config);
Could we print the config field with hexadecimal format? It makes the event is more easily recognized. Thanks.
Quoted 17 lines
kernel/events/core.c +3
-1+} +static const struct file_operations perf_fops = { .release = perf_release, .read = perf_read,@@ -7085,6 +7094,7 @@ static const struct file_operations perf_fops = { .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, + .show_fdinfo = perf_show_fdinfo, };/* -- 2.49.0.1204.g71687c7c1d-goog
Ian Rogers
reviewerQuoted 55 lines · Dapeng
Quoted 52 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.v3: lore.kernel.org/[email protected]
kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/events/core.c +1
-0@@ -56,6 +56,7 @@#include <linux/buildid.h> #include <linux/task_work.h> #include <linux/percpu-rwsem.h> +#include <linux/seq_file.h> #include "internal.h" @@ -7077,6 +7078,14 @@ static int perf_fasync(int fd, struct file *filp, int on)return 0 ; }
Quoted 9 lines
kernel/events/core.c static int perf_fasync(int fd, struct file *filp, int on) · line 7086
Quoted 6 lines
kernel/events/core.c +6
-0+static void perf_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct perf_event *event = f->private_data; + +seq_printf (m,"perf_event_attr.type:\t%u\n" , event->orig_type); +seq_printf (m,"perf_event_attr.config:\t%llu\n" , (unsigned long long )event->attr.config);Could we print the config field with hexadecimal format? It makes the event is more easily recognized. Thanks.
I think this is a reasonable suggestion. I think it would also be useful to dump the config1, config2 and config3 values. I also think the state of the event would be useful for debugging.
Thanks,
Ian
Quoted 17 lines
Quoted 17 lines
kernel/events/core.c +3
-1+} +static const struct file_operations perf_fops = { .release = perf_release, .read = perf_read,@@ -7085,6 +7094,7 @@ static const struct file_operations perf_fops = { .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, + .show_fdinfo = perf_show_fdinfo, };/* -- 2.49.0.1204.g71687c7c1d-goog
Ian Rogers
reviewerQuoted 67 lines · Ian Rogers
Quoted 55 lines · Dapeng
Quoted 52 lines · Chun-Tse Shao
It gives useful info on knowing which PMUs are reserved by this process. Also add config which would be useful.
Testing cycles:$ ./perf stat -e cycles & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 3081 perf_event_attr.type: 0 perf_event_attr.config: 0Testing L1-dcache-load-misses:
$ ./perf stat -e L1-dcache-load-misses & $ cat /proc/`pidof perf`/fdinfo/3 pos: 0 flags: 02000002 mnt_id: 16 ino: 1072 perf_event_attr.type: 3 perf_event_attr.config: 65536Reviewed-by Ian Rogers <[email protected]>Signed-off-by Chun-Tse Shao <[email protected]>---
v4:
Removed the first patch in v3 since it is merged. Retested to make sure the patch still work.v3: lore.kernel.org/[email protected]
kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kernel/events/core.c +1
-0@@ -56,6 +56,7 @@#include <linux/buildid.h> #include <linux/task_work.h> #include <linux/percpu-rwsem.h> +#include <linux/seq_file.h> #include "internal.h" @@ -7077,6 +7078,14 @@ static int perf_fasync(int fd, struct file *filp, int on)return 0 ; }Quoted 9 lines
kernel/events/core.c static int perf_fasync(int fd, struct file *filp, int on) · line 7086
Quoted 6 lines
kernel/events/core.c +6
-0+static void perf_show_fdinfo (struct seq_file *m,struct file *f) +{ +struct perf_event *event = f->private_data; + +seq_printf (m,"perf_event_attr.type:\t%u\n" , event->orig_type); +seq_printf (m,"perf_event_attr.config:\t%llu\n" , (unsigned long long )event->attr.config);Could we print the config field with hexadecimal format? It makes the event is more easily recognized. Thanks.
Quoted 3 lines
I think this is a reasonable suggestion. I think it would also be useful to dump the config1, config2 and config3 values. I also think the state of the event would be useful for debugging.
Any updates on this? It seems to have been forgotten about.
Thanks,
Ian
Quoted 20 lines
Thanks,
IanQuoted 17 lines
Quoted 17 lines
kernel/events/core.c +3
-1+} +static const struct file_operations perf_fops = { .release = perf_release, .read = perf_read,@@ -7085,6 +7094,7 @@ static const struct file_operations perf_fops = { .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, + .show_fdinfo = perf_show_fdinfo, };/* -- 2.49.0.1204.g71687c7c1d-goog