1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
5 #include "bpf_tracing_net.h"
6 #include <bpf/bpf_tracing.h>
7 #include <bpf/bpf_helpers.h>
11 long kmalloc_cnts = 0;
19 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
20 __uint(map_flags, BPF_F_NO_PREALLOC);
22 __type(value, struct storage);
23 } sk_storage_map SEC(".maps");
26 __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
27 __uint(map_flags, BPF_F_NO_PREALLOC);
29 __type(value, struct storage);
30 } task_storage_map SEC(".maps");
33 int BPF_PROG(kmalloc, unsigned long call_site, const void *ptr,
34 size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags,
37 __sync_fetch_and_add(&kmalloc_cnts, 1);
42 SEC("tp_btf/sched_process_fork")
43 int BPF_PROG(sched_process_fork, struct task_struct *parent, struct task_struct *child)
47 if (parent->tgid != bench_pid)
50 stg = bpf_task_storage_get(&task_storage_map, child, NULL,
51 BPF_LOCAL_STORAGE_GET_F_CREATE);
53 __sync_fetch_and_add(&create_cnts, 1);
55 __sync_fetch_and_add(&create_errs, 1);
60 SEC("lsm.s/socket_post_create")
61 int BPF_PROG(socket_post_create, struct socket *sock, int family, int type,
62 int protocol, int kern)
64 struct sock *sk = sock->sk;
68 pid = bpf_get_current_pid_tgid() >> 32;
69 if (pid != bench_pid || !sk)
72 stg = bpf_sk_storage_get(&sk_storage_map, sk, NULL,
73 BPF_LOCAL_STORAGE_GET_F_CREATE);
76 __sync_fetch_and_add(&create_cnts, 1);
78 __sync_fetch_and_add(&create_errs, 1);
83 char __license[] SEC("license") = "GPL";