hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/samples/bpf/offwaketime_kern.c
....@@ -5,13 +5,19 @@
55 * License as published by the Free Software Foundation.
66 */
77 #include <uapi/linux/bpf.h>
8
-#include "bpf_helpers.h"
98 #include <uapi/linux/ptrace.h>
109 #include <uapi/linux/perf_event.h>
1110 #include <linux/version.h>
1211 #include <linux/sched.h>
12
+#include <bpf/bpf_helpers.h>
13
+#include <bpf/bpf_tracing.h>
1314
14
-#define _(P) ({typeof(P) val; bpf_probe_read(&val, sizeof(val), &P); val;})
15
+#define _(P) \
16
+ ({ \
17
+ typeof(P) val; \
18
+ bpf_probe_read_kernel(&val, sizeof(val), &(P)); \
19
+ val; \
20
+ })
1521
1622 #define MINBLOCK_US 1
1723
....@@ -22,38 +28,38 @@
2228 u32 tret;
2329 };
2430
25
-struct bpf_map_def SEC("maps") counts = {
26
- .type = BPF_MAP_TYPE_HASH,
27
- .key_size = sizeof(struct key_t),
28
- .value_size = sizeof(u64),
29
- .max_entries = 10000,
30
-};
31
+struct {
32
+ __uint(type, BPF_MAP_TYPE_HASH);
33
+ __type(key, struct key_t);
34
+ __type(value, u64);
35
+ __uint(max_entries, 10000);
36
+} counts SEC(".maps");
3137
32
-struct bpf_map_def SEC("maps") start = {
33
- .type = BPF_MAP_TYPE_HASH,
34
- .key_size = sizeof(u32),
35
- .value_size = sizeof(u64),
36
- .max_entries = 10000,
37
-};
38
+struct {
39
+ __uint(type, BPF_MAP_TYPE_HASH);
40
+ __type(key, u32);
41
+ __type(value, u64);
42
+ __uint(max_entries, 10000);
43
+} start SEC(".maps");
3844
3945 struct wokeby_t {
4046 char name[TASK_COMM_LEN];
4147 u32 ret;
4248 };
4349
44
-struct bpf_map_def SEC("maps") wokeby = {
45
- .type = BPF_MAP_TYPE_HASH,
46
- .key_size = sizeof(u32),
47
- .value_size = sizeof(struct wokeby_t),
48
- .max_entries = 10000,
49
-};
50
+struct {
51
+ __uint(type, BPF_MAP_TYPE_HASH);
52
+ __type(key, u32);
53
+ __type(value, struct wokeby_t);
54
+ __uint(max_entries, 10000);
55
+} wokeby SEC(".maps");
5056
51
-struct bpf_map_def SEC("maps") stackmap = {
52
- .type = BPF_MAP_TYPE_STACK_TRACE,
53
- .key_size = sizeof(u32),
54
- .value_size = PERF_MAX_STACK_DEPTH * sizeof(u64),
55
- .max_entries = 10000,
56
-};
57
+struct {
58
+ __uint(type, BPF_MAP_TYPE_STACK_TRACE);
59
+ __uint(key_size, sizeof(u32));
60
+ __uint(value_size, PERF_MAX_STACK_DEPTH * sizeof(u64));
61
+ __uint(max_entries, 10000);
62
+} stackmap SEC(".maps");
5763
5864 #define STACKID_FLAGS (0 | BPF_F_FAST_STACK_CMP)
5965