Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.19-rc7 40 lines 918 B view raw
1// SPDX-License-Identifier: GPL-2.0 2// Copyright (c) 2018 Facebook 3 4#include <linux/bpf.h> 5#include "bpf_helpers.h" 6 7struct bpf_map_def SEC("maps") cg_ids = { 8 .type = BPF_MAP_TYPE_ARRAY, 9 .key_size = sizeof(__u32), 10 .value_size = sizeof(__u64), 11 .max_entries = 1, 12}; 13 14struct bpf_map_def SEC("maps") pidmap = { 15 .type = BPF_MAP_TYPE_ARRAY, 16 .key_size = sizeof(__u32), 17 .value_size = sizeof(__u32), 18 .max_entries = 1, 19}; 20 21SEC("tracepoint/syscalls/sys_enter_nanosleep") 22int trace(void *ctx) 23{ 24 __u32 pid = bpf_get_current_pid_tgid(); 25 __u32 key = 0, *expected_pid; 26 __u64 *val; 27 28 expected_pid = bpf_map_lookup_elem(&pidmap, &key); 29 if (!expected_pid || *expected_pid != pid) 30 return 0; 31 32 val = bpf_map_lookup_elem(&cg_ids, &key); 33 if (val) 34 *val = bpf_get_current_cgroup_id(); 35 36 return 0; 37} 38 39char _license[] SEC("license") = "GPL"; 40__u32 _version SEC("version") = 1; /* ignored by tracepoints, required by libbpf.a */