Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2018 Facebook
0003 
0004 #include <linux/bpf.h>
0005 #include <bpf/bpf_helpers.h>
0006 
0007 struct {
0008     __uint(type, BPF_MAP_TYPE_ARRAY);
0009     __uint(max_entries, 1);
0010     __type(key, __u32);
0011     __type(value, __u64);
0012 } cg_ids SEC(".maps");
0013 
0014 struct {
0015     __uint(type, BPF_MAP_TYPE_ARRAY);
0016     __uint(max_entries, 1);
0017     __type(key, __u32);
0018     __type(value, __u32);
0019 } pidmap SEC(".maps");
0020 
0021 SEC("tracepoint/syscalls/sys_enter_nanosleep")
0022 int trace(void *ctx)
0023 {
0024     __u32 pid = bpf_get_current_pid_tgid();
0025     __u32 key = 0, *expected_pid;
0026     __u64 *val;
0027 
0028     expected_pid = bpf_map_lookup_elem(&pidmap, &key);
0029     if (!expected_pid || *expected_pid != pid)
0030         return 0;
0031 
0032     val = bpf_map_lookup_elem(&cg_ids, &key);
0033     if (val)
0034         *val = bpf_get_current_cgroup_id();
0035 
0036     return 0;
0037 }
0038 
0039 char _license[] SEC("license") = "GPL";