1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2022, Oracle and/or its affiliates. */
3
4 #include "vmlinux.h"
5
6 #include <bpf/bpf_helpers.h>
7 #include <bpf/bpf_tracing.h>
8 #include "bpf_misc.h"
9
10 __u32 perfbuf_val = 0;
11 __u32 ringbuf_val = 0;
12
13 int test_pid;
14
15 struct {
16 __uint(type, BPF_MAP_TYPE_ARRAY);
17 __uint(max_entries, 1);
18 __type(key, __u32);
19 __type(value, __u32);
20 } array SEC(".maps");
21
22 struct {
23 __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
24 __uint(max_entries, 1);
25 __type(key, __u32);
26 __type(value, __u32);
27 } percpu_array SEC(".maps");
28
29 struct {
30 __uint(type, BPF_MAP_TYPE_HASH);
31 __uint(max_entries, 1);
32 __type(key, __u32);
33 __type(value, __u32);
34 } hash SEC(".maps");
35
36 struct {
37 __uint(type, BPF_MAP_TYPE_PERCPU_HASH);
38 __uint(max_entries, 1);
39 __type(key, __u32);
40 __type(value, __u32);
41 } percpu_hash SEC(".maps");
42
43 struct {
44 __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
45 __type(key, __u32);
46 __type(value, __u32);
47 } perfbuf SEC(".maps");
48
49 struct {
50 __uint(type, BPF_MAP_TYPE_RINGBUF);
51 __uint(max_entries, 1 << 12);
52 } ringbuf SEC(".maps");
53
54 struct {
55 __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
56 __uint(max_entries, 1);
57 __uint(key_size, sizeof(__u32));
58 __uint(value_size, sizeof(__u32));
59 } prog_array SEC(".maps");
60
61 SEC("fentry/" SYS_PREFIX "sys_nanosleep")
sys_nanosleep_enter(void * ctx)62 int sys_nanosleep_enter(void *ctx)
63 {
64 int cur_pid;
65
66 cur_pid = bpf_get_current_pid_tgid() >> 32;
67
68 if (cur_pid != test_pid)
69 return 0;
70
71 bpf_perf_event_output(ctx, &perfbuf, BPF_F_CURRENT_CPU, &perfbuf_val, sizeof(perfbuf_val));
72 bpf_ringbuf_output(&ringbuf, &ringbuf_val, sizeof(ringbuf_val), 0);
73
74 return 0;
75 }
76
77 SEC("perf_event")
handle_perf_event(void * ctx)78 int handle_perf_event(void *ctx)
79 {
80 return 0;
81 }
82
83 char _license[] SEC("license") = "GPL";
84