Merge tag 'mmc-v4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
[linux/fpc-iii.git] / samples / bpf / map_perf_test_kern.c
blob311538e5a7016e7bfdd250779d60491051ef8b4b
1 /* Copyright (c) 2016 Facebook
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7 #include <linux/skbuff.h>
8 #include <linux/netdevice.h>
9 #include <linux/version.h>
10 #include <uapi/linux/bpf.h>
11 #include "bpf_helpers.h"
13 #define MAX_ENTRIES 1000
15 struct bpf_map_def SEC("maps") hash_map = {
16 .type = BPF_MAP_TYPE_HASH,
17 .key_size = sizeof(u32),
18 .value_size = sizeof(long),
19 .max_entries = MAX_ENTRIES,
22 struct bpf_map_def SEC("maps") percpu_hash_map = {
23 .type = BPF_MAP_TYPE_PERCPU_HASH,
24 .key_size = sizeof(u32),
25 .value_size = sizeof(long),
26 .max_entries = MAX_ENTRIES,
29 struct bpf_map_def SEC("maps") hash_map_alloc = {
30 .type = BPF_MAP_TYPE_HASH,
31 .key_size = sizeof(u32),
32 .value_size = sizeof(long),
33 .max_entries = MAX_ENTRIES,
34 .map_flags = BPF_F_NO_PREALLOC,
37 struct bpf_map_def SEC("maps") percpu_hash_map_alloc = {
38 .type = BPF_MAP_TYPE_PERCPU_HASH,
39 .key_size = sizeof(u32),
40 .value_size = sizeof(long),
41 .max_entries = MAX_ENTRIES,
42 .map_flags = BPF_F_NO_PREALLOC,
45 SEC("kprobe/sys_getuid")
46 int stress_hmap(struct pt_regs *ctx)
48 u32 key = bpf_get_current_pid_tgid();
49 long init_val = 1;
50 long *value;
52 bpf_map_update_elem(&hash_map, &key, &init_val, BPF_ANY);
53 value = bpf_map_lookup_elem(&hash_map, &key);
54 if (value)
55 bpf_map_delete_elem(&hash_map, &key);
56 return 0;
59 SEC("kprobe/sys_geteuid")
60 int stress_percpu_hmap(struct pt_regs *ctx)
62 u32 key = bpf_get_current_pid_tgid();
63 long init_val = 1;
64 long *value;
66 bpf_map_update_elem(&percpu_hash_map, &key, &init_val, BPF_ANY);
67 value = bpf_map_lookup_elem(&percpu_hash_map, &key);
68 if (value)
69 bpf_map_delete_elem(&percpu_hash_map, &key);
70 return 0;
72 SEC("kprobe/sys_getgid")
73 int stress_hmap_alloc(struct pt_regs *ctx)
75 u32 key = bpf_get_current_pid_tgid();
76 long init_val = 1;
77 long *value;
79 bpf_map_update_elem(&hash_map_alloc, &key, &init_val, BPF_ANY);
80 value = bpf_map_lookup_elem(&hash_map_alloc, &key);
81 if (value)
82 bpf_map_delete_elem(&hash_map_alloc, &key);
83 return 0;
86 SEC("kprobe/sys_getegid")
87 int stress_percpu_hmap_alloc(struct pt_regs *ctx)
89 u32 key = bpf_get_current_pid_tgid();
90 long init_val = 1;
91 long *value;
93 bpf_map_update_elem(&percpu_hash_map_alloc, &key, &init_val, BPF_ANY);
94 value = bpf_map_lookup_elem(&percpu_hash_map_alloc, &key);
95 if (value)
96 bpf_map_delete_elem(&percpu_hash_map_alloc, &key);
97 return 0;
99 char _license[] SEC("license") = "GPL";
100 u32 _version SEC("version") = LINUX_VERSION_CODE;