Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2020 Facebook
0003 
0004 #include <linux/bpf.h>
0005 #include <stdint.h>
0006 #include <bpf/bpf_helpers.h>
0007 #include "bpf_misc.h"
0008 
0009 char _license[] SEC("license") = "GPL";
0010 
0011 struct {
0012     __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
0013     __uint(value_size, sizeof(int));
0014     __uint(key_size, sizeof(int));
0015 } perfbuf SEC(".maps");
0016 
0017 const volatile int batch_cnt = 0;
0018 
0019 long sample_val = 42;
0020 long dropped __attribute__((aligned(128))) = 0;
0021 
0022 SEC("fentry/" SYS_PREFIX "sys_getpgid")
0023 int bench_perfbuf(void *ctx)
0024 {
0025     __u64 *sample;
0026     int i;
0027 
0028     for (i = 0; i < batch_cnt; i++) {
0029         if (bpf_perf_event_output(ctx, &perfbuf, BPF_F_CURRENT_CPU,
0030                       &sample_val, sizeof(sample_val)))
0031             __sync_add_and_fetch(&dropped, 1);
0032     }
0033     return 0;
0034 }