Skip to contentSkip to conversation

perf augmented_raw_syscalls.bpf: Move 'struct timespec64' to vmlinux.h

PATCH Superseded Arnaldo Carvalho de Melo 2 participants 4 messages Feb 2, 2024 – Feb 16, 2024 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

PATCH 1/1 perf augmented_raw_syscalls.bpf: Move 'struct timespec64' to vmlinux.h

If we instead decide to generate vmlinux.h from BTF info, it will be there:

  $ pahole timespec64
  struct timespec64 {
  	time64_t                   tv_sec;               /*     0     8 */
  	long int                   tv_nsec;              /*     8     8 */
  	/* size: 16, cachelines: 1, members: 2 */
  	/* last cacheline: 16 bytes */
  };

$

pahole manages to find it from /sys/kernel/btf/vmlinux, that is generated from the kernel types.

---
 .../util/bpf_skel/augmented_raw_syscalls.bpf.c     | 14 +-------------
 tools/perf/util/bpf_skel/vmlinux/vmlinux.h         |  7 +++++++
 2 files changed, 8 insertions(+), 13 deletions(-)
tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +1 -13
index baecffbece14fb68..d3b672593c540259 100644
@@ -6,6 +6,7 @@
  * payload expected by the 'perf trace' beautifiers.
  */
 
+#include "vmlinux.h"
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 #include <linux/limits.h>
@@ -22,19 +23,6 @@
 
 #define MAX_CPUS  4096
 
-// FIXME: These should come from system headers
-#ifndef bool
-typedef char bool;
-#endif
-typedef int pid_t;
-typedef long long int __s64;
-typedef __s64 time64_t;
-
-struct timespec64 {
-	time64_t	tv_sec;
-	long int	tv_nsec;
-};
-
 /* bpf-output associated map */
 struct __augmented_syscalls__ {
 	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
tools/perf/util/bpf_skel/vmlinux/vmlinux.h +7 -0
index ab84a6e1da5eedb3..e9028235d7717b59 100644
@@ -20,6 +20,13 @@ typedef __s64 s64;
 
 typedef int pid_t;
 
+typedef __s64 time64_t;
+
+struct timespec64 {
+        time64_t        tv_sec;
+        long int        tv_nsec;
+};
+
 enum cgroup_subsys_id {
 	perf_event_cgrp_id  = 8,
 };
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Arnaldo Carvalho de Melo

If we instead decide to generate vmlinux.h from BTF info, it will be there:

  $ pahole timespec64
  struct timespec64 {
        time64_t                   tv_sec;               /*     0     8 */
        long int                   tv_nsec;              /*     8     8 */
        /* size: 16, cachelines: 1, members: 2 */
        /* last cacheline: 16 bytes */

};

$

pahole manages to find it from /sys/kernel/btf/vmlinux, that is generated from the kernel types.

Quoted 6 lines

Thanks,
Namhyung

Quoted 58 lines
---
 .../util/bpf_skel/augmented_raw_syscalls.bpf.c     | 14 +-------------
 tools/perf/util/bpf_skel/vmlinux/vmlinux.h         |  7 +++++++
 2 files changed, 8 insertions(+), 13 deletions(-)
tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +1 -13
index baecffbece14fb68..d3b672593c540259 100644
@@ -6,6 +6,7 @@
  * payload expected by the 'perf trace' beautifiers.
  */
 
+#include "vmlinux.h"
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 #include <linux/limits.h>
@@ -22,19 +23,6 @@
 
 #define MAX_CPUS  4096
 
-// FIXME: These should come from system headers
-#ifndef bool
-typedef char bool;
-#endif
-typedef int pid_t;
-typedef long long int __s64;
-typedef __s64 time64_t;
-
-struct timespec64 {
-       time64_t        tv_sec;
-       long int        tv_nsec;
-};
-
 /* bpf-output associated map */
 struct __augmented_syscalls__ {
        __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
tools/perf/util/bpf_skel/vmlinux/vmlinux.h +7 -1
index ab84a6e1da5eedb3..e9028235d7717b59 100644
@@ -20,6 +20,13 @@ typedef __s64 s64;
 
 typedef int pid_t;
 
+typedef __s64 time64_t;
+
+struct timespec64 {
+        time64_t        tv_sec;
+        long int        tv_nsec;
+};
+
 enum cgroup_subsys_id {
        perf_event_cgrp_id  = 8,
 };
--

2.43.0

maintainer
#2 lore raw
Quoted 21 lines · Namhyung Kim
Quoted 18 lines · Arnaldo Carvalho de Melo

If we instead decide to generate vmlinux.h from BTF info, it will be there:

  $ pahole timespec64
  struct timespec64 {
        time64_t                   tv_sec;               /*     0     8 */
        long int                   tv_nsec;              /*     8     8 */
        /* size: 16, cachelines: 1, members: 2 */
        /* last cacheline: 16 bytes */

};

$

pahole manages to find it from /sys/kernel/btf/vmlinux, that is generated from the kernel types.

Quoted 8 lines
Quoted 6 lines

Hmm.. but it makes it fail to build with GEN_VMLINUX_H=1.

Thanks,
Namhyung

CLANG linux/tools/perf/util/bpf_skel/.tmp/augmented_raw_syscalls.bpf.o
In file included from util/bpf_skel/augmented_raw_syscalls.bpf.c:10:
linux/tools/include/uapi/linux/bpf.h:55:2: error: redefinition of enumerator 'BPF_REG_0'

        BPF_REG_0 = 0,
        ^
linux/tools/perf/util/bpf_skel/.tmp/../vmlinux.h:46833:2: note:
previous definition is here
        BPF_REG_0 = 0,
        ^
author maintainer
#3 lore raw
Quoted 19 lines · Namhyung Kim
Quoted 11 lines · Namhyung Kim
Quoted 8 lines · Arnaldo Carvalho de Melo

If we instead decide to generate vmlinux.h from BTF info, it will be there:

  $ pahole timespec64
  struct timespec64 {
        time64_t                   tv_sec;               /*     0     8 */
        long int                   tv_nsec;              /*     8     8 */
  };

Hmm.. but it makes it fail to build with GEN_VMLINUX_H=1.

CLANG linux/tools/perf/util/bpf_skel/.tmp/augmented_raw_syscalls.bpf.o
In file included from util/bpf_skel/augmented_raw_syscalls.bpf.c:10:
linux/tools/include/uapi/linux/bpf.h:55:2: error: redefinition of enumerator 'BPF_REG_0'

Quoted 6 lines
        BPF_REG_0 = 0,
        ^
linux/tools/perf/util/bpf_skel/.tmp/../vmlinux.h:46833:2: note:
previous definition is here
        BPF_REG_0 = 0,
        ^

Right, the following oneliner fixes it (the minimalistic pre-built vmlinux.h we carry when not using GEN_VMLINUX_H=1 already has it), I'll squash it, do some container test builds and resend.

- Arnaldo

tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +0 -1
index d3b672593c540259..0acbd74e8c760956 100644
@@ -7,7 +7,6 @@
  */
 
 #include "vmlinux.h"
-#include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 #include <linux/limits.h>