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
13int test_pid;
14
15struct {
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
22struct {
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
29struct {
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
36struct {
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
43struct {
44	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
45	__type(key, __u32);
46	__type(value, __u32);
47} perfbuf SEC(".maps");
48
49struct {
50	__uint(type, BPF_MAP_TYPE_RINGBUF);
51	__uint(max_entries, 1 << 12);
52} ringbuf SEC(".maps");
53
54struct {
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
61SEC("fentry/" SYS_PREFIX "sys_nanosleep")
62int 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
77SEC("perf_event")
78int handle_perf_event(void *ctx)
79{
80	return 0;
81}
82
83char _license[] SEC("license") = "GPL";
84