Re: [PATCH v2 2/3] perf: Reveal PMU type in fdinfo
From: Namhyung Kim
Date: Mon Nov 04 2024 - 19:12:19 EST
On Fri, Nov 01, 2024 at 09:17:56PM +0000, Chun-Tse Shao wrote:
> It gives useful info on knowing which PMUs are reserved by this process.
> Also add extra attributes 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
Maybe 'perf_event_attr' would be appropriate as it's the name of the
struct.
> perf_event-attr.config: 0
> perf_event-attr.config1: 0
> perf_event-attr.config2: 0
> perf_event-attr.config3: 0
It's hard to pick which fields to show here but I'd say that those
config[123] are not used frequently at least for regular events.
Maybe just showing type and config is fine.
>
> 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
> perf_event-attr.config1: 0
> perf_event-attr.config2: 0
> perf_event-attr.config3: 0
> ```
>
> Signed-off-by: Chun-Tse Shao <ctshao@xxxxxxxxxx>
> ---
> kernel/events/core.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
FYI usually the kernel changes are applied to a different tree than the
tools.
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index cdd09769e6c56..c950b6fc92cda 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -55,6 +55,7 @@
> #include <linux/pgtable.h>
> #include <linux/buildid.h>
> #include <linux/task_work.h>
> +#include <linux/seq_file.h>
>
> #include "internal.h"
>
> @@ -6820,6 +6821,17 @@ 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", event->attr.config);
I'm not sure if all archs are happy with treating it as %llu.
Thanks,
Namhyung
> + seq_printf(m, "perf_event-attr.config1:\t%llu\n", event->attr.config1);
> + seq_printf(m, "perf_event-attr.config2:\t%llu\n", event->attr.config2);
> + seq_printf(m, "perf_event-attr.config3:\t%llu\n", event->attr.config3);
> +}
> +
> static const struct file_operations perf_fops = {
> .release = perf_release,
> .read = perf_read,
> @@ -6828,6 +6840,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.47.0.163.g1226f6d8fa-goog
>