Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (c) 2018 Facebook
 3
 4#include <linux/bpf.h>
 5#include <bpf/bpf_helpers.h>
 6
 7__u64 cg_id;
 8__u64 expected_pid;
 
 
 
 
 
 
 
 
 
 
 
 9
10SEC("tracepoint/syscalls/sys_enter_nanosleep")
11int trace(void *ctx)
12{
13	__u32 pid = bpf_get_current_pid_tgid();
 
 
 
 
 
 
14
15	if (expected_pid == pid)
16		cg_id = bpf_get_current_cgroup_id();
 
17
18	return 0;
19}
20
21char _license[] SEC("license") = "GPL";
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (c) 2018 Facebook
 3
 4#include <linux/bpf.h>
 5#include <bpf/bpf_helpers.h>
 6
 7struct {
 8	__uint(type, BPF_MAP_TYPE_ARRAY);
 9	__uint(max_entries, 1);
10	__type(key, __u32);
11	__type(value, __u64);
12} cg_ids SEC(".maps");
13
14struct {
15	__uint(type, BPF_MAP_TYPE_ARRAY);
16	__uint(max_entries, 1);
17	__type(key, __u32);
18	__type(value, __u32);
19} pidmap SEC(".maps");
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";