Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2022 Bytedance */
0003 
0004 #include "vmlinux.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include "bpf_misc.h"
0007 
0008 char _license[] SEC("license") = "GPL";
0009 
0010 #define MAX_ENTRIES 1000
0011 
0012 struct {
0013     __uint(type, BPF_MAP_TYPE_HASH);
0014     __type(key, u32);
0015     __type(value, u64);
0016     __uint(max_entries, MAX_ENTRIES);
0017 } hash_map_bench SEC(".maps");
0018 
0019 u64 __attribute__((__aligned__(256))) percpu_time[256];
0020 u64 nr_loops;
0021 
0022 static int loop_update_callback(__u32 index, u32 *key)
0023 {
0024     u64 init_val = 1;
0025 
0026     bpf_map_update_elem(&hash_map_bench, key, &init_val, BPF_ANY);
0027     return 0;
0028 }
0029 
0030 SEC("fentry/" SYS_PREFIX "sys_getpgid")
0031 int benchmark(void *ctx)
0032 {
0033     u32 cpu = bpf_get_smp_processor_id();
0034     u32 key = cpu + MAX_ENTRIES;
0035     u64 start_time = bpf_ktime_get_ns();
0036 
0037     bpf_loop(nr_loops, loop_update_callback, &key, 0);
0038     percpu_time[cpu & 255] = bpf_ktime_get_ns() - start_time;
0039     return 0;
0040 }