summaryrefslogtreecommitdiff
path: root/targets/kernel_touch.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:49:22 -0300
committerGabriel Schneider <[email protected]>2026-11-10 12:19:06 -0300
commit297943b01e18bb3d1dd41a8d3e220811de25228b (patch)
tree4938e643abada811d3ab28b14c0e31dc94ebda62 /targets/kernel_touch.c
parentdb923fa823354270217362db06356f2b1a41315e (diff)
downloadcomputeranim-297943b01e18bb3d1dd41a8d3e220811de25228b.tar.gz
computeranim-297943b01e18bb3d1dd41a8d3e220811de25228b.zip
ztrace probe: BPF on syscalls, scheduling, kprobes, uprobes and USDT
Programs built as instruction arrays for one process (no compiler, no libbpf), writing Events into a BPF ring buffer; a drop counter in a map; task_struct offsets from the kernel's BTF; a USDT probe's arguments read in the kernel at the probe. Without CAP_BPF and CAP_PERFMON it says so; --dry-run builds and lists everything. Tested offline by running the programs in a small BPF machine, and for real by test-kernel-vm, which boots this kernel in QEMU where we are root. ztrace perf: moments are no longer cut per event unless --cut; --max-size, and a full recording stops the target and says so. perf.Sorted merges two backends' events by time. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'targets/kernel_touch.c')
-rw-r--r--targets/kernel_touch.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/targets/kernel_touch.c b/targets/kernel_touch.c
index b2db1ce..c0399a9 100644
--- a/targets/kernel_touch.c
+++ b/targets/kernel_touch.c
@@ -1,7 +1,8 @@
// One of everything the kernel can report about a program, in this order:
// fresh pages touched one by one (argv[1] of them, default 64), a global
-// written and a function called (argv[2] times, default 100), a file opened
-// and written, a sleep, a thread that calls the function three more times.
+// written and a function called (argv[2] times, default 100), a block
+// allocated, a file opened and written, a sleep, a thread that calls the
+// function three more times.
#include <fcntl.h>
#include <pthread.h>
#include <stdlib.h>
@@ -27,11 +28,16 @@ int main(int argc, char **argv) {
unsigned long steps = argc > 2 ? strtoul(argv[2], 0, 0) : 100;
volatile char *fresh = mmap(0, pages * 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ // A page a fault, however many: no huge ones.
+ madvise((void *)fresh, pages * 4096, MADV_NOHUGEPAGE);
for (unsigned long i = 0; i < pages; i++) fresh[i * 4096] = 1;
unsigned long acc = 0;
for (unsigned long i = 0; i < steps; i++) acc = step(i, acc);
+ void *volatile block = malloc(1000 + steps);
+ free(block);
+
int fd = open("/dev/null", O_WRONLY);
if (write(fd, "hello", 5) != 5) return 1;
close(fd);