1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2025. Huawei Technologies Co., Ltd */
5 #include <bpf/bpf_tracing.h>
6 #include <bpf/bpf_helpers.h>
11 struct bpf_timer timer;
15 __uint(type, BPF_MAP_TYPE_HASH);
17 __type(value, struct map_value);
18 __uint(max_entries, MAX_ENTRIES);
21 static int timer_cb(void *map, void *key, struct map_value *value)
26 bpf_for(i, 0, 1024 * 1024) sum += i;
31 static int start_cb(int key)
33 struct map_value *value;
35 value = bpf_map_lookup_elem(&map, (void *)&key);
39 bpf_timer_init(&value->timer, &map, CLOCK_MONOTONIC);
40 bpf_timer_set_callback(&value->timer, timer_cb);
41 /* Hope 100us will be enough to wake-up and run the overwrite thread */
42 bpf_timer_start(&value->timer, 100000, BPF_F_TIMER_CPU_PIN);
47 static int overwrite_cb(int key)
49 struct map_value zero = {};
51 /* Free the timer which may run on other CPU */
52 bpf_map_update_elem(&map, (void *)&key, &zero, BPF_ANY);
58 int BPF_PROG(start_timer)
60 bpf_loop(MAX_ENTRIES, start_cb, NULL, 0);
65 int BPF_PROG(overwrite_timer)
67 bpf_loop(MAX_ENTRIES, overwrite_cb, NULL, 0);
71 char _license[] SEC("license") = "GPL";