]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf: Reveal PMU type in fdinfo
authorChun-Tse Shao <ctshao@google.com>
Tue, 2 Jun 2026 18:13:48 +0000 (11:13 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 4 Jun 2026 09:38:38 +0000 (11:38 +0200)
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: 0x0
  perf_event_attr.config1:        0x0
  perf_event_attr.config2:        0x0
  perf_event_attr.config3:        0x0
  perf_event_attr.config4:        0x0

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: 0x10000
  perf_event_attr.config1:        0x0
  perf_event_attr.config2:        0x0
  perf_event_attr.config3:        0x0
  perf_event_attr.config4:        0x0

Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Assisted-by: Gemini:gemini-3.1-pro-preview
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://patch.msgid.link/20260602181349.3969429-1-ctshao@google.com
kernel/events/core.c

index 7935d5663944ee1cbaf38cf8018c3347635e8d31..95d806bba65414889138181bb375e5870f5b7d95 100644 (file)
@@ -58,6 +58,7 @@
 #include <linux/percpu-rwsem.h>
 #include <linux/unwind_deferred.h>
 #include <linux/kvm_types.h>
+#include <linux/seq_file.h>
 
 #include "internal.h"
 
@@ -7546,6 +7547,33 @@ 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;
+       struct perf_event_context *ctx;
+       struct mutex *child_mutex;
+
+       ctx = perf_event_ctx_lock(event);
+       child_mutex = event->parent ? &event->parent->child_mutex : &event->child_mutex;
+       mutex_lock(child_mutex);
+
+       seq_printf(m, "perf_event_attr.type:\t%u\n", event->orig_type);
+       if (event->pmu)
+               seq_printf(m, "pmu_type:\t%u\n", event->pmu->type);
+       seq_printf(m, "perf_event_attr.config:\t0x%llx\n", (unsigned long long)event->attr.config);
+       seq_printf(m, "perf_event_attr.config1:\t0x%llx\n",
+                  (unsigned long long)event->attr.config1);
+       seq_printf(m, "perf_event_attr.config2:\t0x%llx\n",
+                  (unsigned long long)event->attr.config2);
+       seq_printf(m, "perf_event_attr.config3:\t0x%llx\n",
+                  (unsigned long long)event->attr.config3);
+       seq_printf(m, "perf_event_attr.config4:\t0x%llx\n",
+                  (unsigned long long)event->attr.config4);
+
+       mutex_unlock(child_mutex);
+       perf_event_ctx_unlock(event, ctx);
+}
+
 static const struct file_operations perf_fops = {
        .release                = perf_release,
        .read                   = perf_read,
@@ -7554,6 +7582,7 @@ static const struct file_operations perf_fops = {
        .compat_ioctl           = perf_compat_ioctl,
        .mmap                   = perf_mmap,
        .fasync                 = perf_fasync,
+       .show_fdinfo            = perf_show_fdinfo,
 };
 
 /*