hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/bpf/bpftool/skeleton/profiler.bpf.c
....@@ -4,6 +4,12 @@
44 #include <bpf/bpf_helpers.h>
55 #include <bpf/bpf_tracing.h>
66
7
+struct bpf_perf_event_value___local {
8
+ __u64 counter;
9
+ __u64 enabled;
10
+ __u64 running;
11
+} __attribute__((preserve_access_index));
12
+
713 /* map of perf event fds, num_cpu * num_metric entries */
814 struct {
915 __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
....@@ -15,14 +21,14 @@
1521 struct {
1622 __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
1723 __uint(key_size, sizeof(u32));
18
- __uint(value_size, sizeof(struct bpf_perf_event_value));
24
+ __uint(value_size, sizeof(struct bpf_perf_event_value___local));
1925 } fentry_readings SEC(".maps");
2026
2127 /* accumulated readings */
2228 struct {
2329 __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
2430 __uint(key_size, sizeof(u32));
25
- __uint(value_size, sizeof(struct bpf_perf_event_value));
31
+ __uint(value_size, sizeof(struct bpf_perf_event_value___local));
2632 } accum_readings SEC(".maps");
2733
2834 /* sample counts, one per cpu */
....@@ -39,7 +45,7 @@
3945 SEC("fentry/XXX")
4046 int BPF_PROG(fentry_XXX)
4147 {
42
- struct bpf_perf_event_value *ptrs[MAX_NUM_MATRICS];
48
+ struct bpf_perf_event_value___local *ptrs[MAX_NUM_MATRICS];
4349 u32 key = bpf_get_smp_processor_id();
4450 u32 i;
4551
....@@ -53,10 +59,10 @@
5359 }
5460
5561 for (i = 0; i < num_metric && i < MAX_NUM_MATRICS; i++) {
56
- struct bpf_perf_event_value reading;
62
+ struct bpf_perf_event_value___local reading;
5763 int err;
5864
59
- err = bpf_perf_event_read_value(&events, key, &reading,
65
+ err = bpf_perf_event_read_value(&events, key, (void *)&reading,
6066 sizeof(reading));
6167 if (err)
6268 return 0;
....@@ -68,14 +74,14 @@
6874 }
6975
7076 static inline void
71
-fexit_update_maps(u32 id, struct bpf_perf_event_value *after)
77
+fexit_update_maps(u32 id, struct bpf_perf_event_value___local *after)
7278 {
73
- struct bpf_perf_event_value *before, diff;
79
+ struct bpf_perf_event_value___local *before, diff;
7480
7581 before = bpf_map_lookup_elem(&fentry_readings, &id);
7682 /* only account samples with a valid fentry_reading */
7783 if (before && before->counter) {
78
- struct bpf_perf_event_value *accum;
84
+ struct bpf_perf_event_value___local *accum;
7985
8086 diff.counter = after->counter - before->counter;
8187 diff.enabled = after->enabled - before->enabled;
....@@ -93,7 +99,7 @@
9399 SEC("fexit/XXX")
94100 int BPF_PROG(fexit_XXX)
95101 {
96
- struct bpf_perf_event_value readings[MAX_NUM_MATRICS];
102
+ struct bpf_perf_event_value___local readings[MAX_NUM_MATRICS];
97103 u32 cpu = bpf_get_smp_processor_id();
98104 u32 i, zero = 0;
99105 int err;
....@@ -102,7 +108,8 @@
102108 /* read all events before updating the maps, to reduce error */
103109 for (i = 0; i < num_metric && i < MAX_NUM_MATRICS; i++) {
104110 err = bpf_perf_event_read_value(&events, cpu + i * num_cpu,
105
- readings + i, sizeof(*readings));
111
+ (void *)(readings + i),
112
+ sizeof(*readings));
106113 if (err)
107114 return 0;
108115 }