10Sduke// SPDX-License-Identifier: GPL-2.0 211217Sjuh// Copyright (c) 2018 Facebook 30Sduke 40Sduke#include <linux/bpf.h> 50Sduke#include <bpf/bpf_helpers.h> 60Sduke 70Sdukestruct { 80Sduke __uint(type, BPF_MAP_TYPE_ARRAY); 90Sduke __uint(max_entries, 1); 100Sduke __type(key, __u32); 110Sduke __type(value, __u64); 120Sduke} cg_ids SEC(".maps"); 130Sduke 140Sdukestruct { 150Sduke __uint(type, BPF_MAP_TYPE_ARRAY); 160Sduke __uint(max_entries, 1); 170Sduke __type(key, __u32); 180Sduke __type(value, __u32); 192362Sohair} pidmap SEC(".maps"); 202362Sohair 212362SohairSEC("tracepoint/syscalls/sys_enter_nanosleep") 220Sdukeint trace(void *ctx) 230Sduke{ 240Sduke __u32 pid = bpf_get_current_pid_tgid(); 250Sduke __u32 key = 0, *expected_pid; 2611001Smullan __u64 *val; 2712016Sjuh 280Sduke expected_pid = bpf_map_lookup_elem(&pidmap, &key); 2912057Smchung if (!expected_pid || *expected_pid != pid) 3012057Smchung return 0; 3112057Smchung 3212410Sasmotrak val = bpf_map_lookup_elem(&cg_ids, &key); 330Sduke if (val) 340Sduke *val = bpf_get_current_cgroup_id(); 357449Smullan 360Sduke return 0; 370Sduke} 380Sduke 3912410Sasmotrakchar _license[] SEC("license") = "GPL"; 4012410Sasmotrak