You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- switch perf_event attachment to the perf_options builtin struct
- add type checking and userspace codegen for attach, perf_read, and perf_print
- update docs, examples, and tests for the new @perf_event workflow
**Description:** Attach a loaded eBPF program to a target interface or attachment point, or attach it to a perf event described by `perf_event_attr`.
92
+
**Description:** Attach a loaded eBPF program to a target interface or attachment point, or to a perf event counter described by `perf_options`. Both forms take three arguments, keeping a uniform call shape across all program types.
93
93
94
94
**Parameters:**
95
95
- Standard form:
@@ -98,7 +98,8 @@ fn main() -> i32 {
98
98
-`flags`: Attachment flags (context-dependent)
99
99
- Perf event form:
100
100
-`handle`: Program handle returned from `load()`
101
-
-`attr`: `perf_event_attr` value describing counter, pid, cpu, period, and filter flags
101
+
-`opts`: `perf_options` value — only `counter` is required; all other fields have defaults
102
+
-`flags`: Reserved (pass `0`)
102
103
103
104
**Return Value:**
104
105
- Returns `0` on success
@@ -112,24 +113,17 @@ if (result != 0) {
112
113
print("Failed to attach program")
113
114
}
114
115
115
-
var perf_attr = perf_event_attr {
116
-
counter: branch_misses,
117
-
pid: -1,
118
-
cpu: 0,
119
-
period: 1000000,
120
-
wakeup: 1,
121
-
inherit: false,
122
-
exclude_kernel: false,
123
-
exclude_user: false
124
-
}
125
-
116
+
// Minimal perf attach — all non-counter fields use defaults:
Copy file name to clipboardExpand all lines: README.md
+10-14Lines changed: 10 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -270,7 +270,7 @@ fn main() -> i32 {
270
270
271
271
### Hardware Performance Counter Programs
272
272
273
-
Use `@perf_event` to attach eBPF programs to hardware or software performance counters. The userspace side describes the counter via a `perf_event_attr` struct literal and calls `attach(prog, attr)`:
273
+
Use `@perf_event` to attach eBPF programs to hardware or software performance counters. Only `counter` is required in the `perf_options` struct; all other fields have sensible defaults. Call `attach(prog, perf_options { ... }, 0)` and read back the counter with `perf_read(prog)`:
274
274
275
275
```kernelscript
276
276
// eBPF program fires on every hardware branch-miss sample
`@perf_event` programs attach eBPF logic to hardware or software performance counters via `perf_event_open(2)`. The eBPF function is invoked for every counter sample; the userspace side controls which counter to monitor through a `perf_event_attr` struct literal passed to `attach()`.
445
+
`@perf_event` programs attach eBPF logic to hardware or software performance counters via `perf_event_open(2)`. The eBPF function is invoked for every counter sample; the userspace side controls which counter to monitor through a `perf_options` struct literal passed to the standard 3-argument`attach()`.
446
446
447
447
**Syntax:**
448
448
```kernelscript
@@ -458,25 +458,41 @@ The context type is always `*bpf_perf_event_data` (from `vmlinux.h`).
458
458
**Userspace lifecycle:**
459
459
```kernelscript
460
460
fn main() -> i32 {
461
-
var attr = perf_event_attr {
462
-
counter: branch_misses, // perf_counter enum value
463
-
pid: -1, // -1 = all processes; ≥0 = specific PID
464
-
cpu: 0, // ≥0 = specific CPU; -1 = any CPU (pid must be ≥0)
465
-
period: 1000000, // sample after this many events (0 → default 1000000)
466
-
wakeup: 1, // wake userspace after N samples (0 → default 1)
0 commit comments