Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2026 Valve Corporation.
4 * Author: Changwoo Min <changwoo@igalia.com>
5 */
6
7#include "vmlinux.h"
8#include <bpf/bpf_helpers.h>
9#include <bpf/bpf_tracing.h>
10#include "bpf_experimental.h"
11
12char _license[] SEC("license") = "GPL";
13
14extern void bpf_kfunc_trigger_ctx_check(void) __ksym;
15
16int count_hardirq;
17int count_softirq;
18int count_task;
19
20/* Triggered via bpf_prog_test_run from user-space */
21SEC("syscall")
22int trigger_all_contexts(void *ctx)
23{
24 if (bpf_in_task())
25 __sync_fetch_and_add(&count_task, 1);
26
27 /* Trigger the firing of a hardirq and softirq for test. */
28 bpf_kfunc_trigger_ctx_check();
29 return 0;
30}
31
32/* Observer for HardIRQ */
33SEC("fentry/bpf_testmod_test_hardirq_fn")
34int BPF_PROG(on_hardirq)
35{
36 if (bpf_in_hardirq())
37 __sync_fetch_and_add(&count_hardirq, 1);
38 return 0;
39}
40
41/* Observer for SoftIRQ */
42SEC("fentry/bpf_testmod_test_softirq_fn")
43int BPF_PROG(on_softirq)
44{
45 if (bpf_in_serving_softirq())
46 __sync_fetch_and_add(&count_softirq, 1);
47 return 0;
48}