Linux Audio

Check our new training course

Loading...
v4.6
  1/* Copyright (c) 2016 Facebook
  2 *
  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"
 12
 13#define MAX_ENTRIES 1000
 14
 15struct 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,
 20};
 21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 22struct 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,
 27};
 28
 29struct 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,
 35};
 36
 37struct 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,
 43};
 44
 45SEC("kprobe/sys_getuid")
 46int stress_hmap(struct pt_regs *ctx)
 47{
 48	u32 key = bpf_get_current_pid_tgid();
 49	long init_val = 1;
 50	long *value;
 51
 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;
 57}
 58
 59SEC("kprobe/sys_geteuid")
 60int stress_percpu_hmap(struct pt_regs *ctx)
 61{
 62	u32 key = bpf_get_current_pid_tgid();
 63	long init_val = 1;
 64	long *value;
 65
 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;
 71}
 72SEC("kprobe/sys_getgid")
 73int stress_hmap_alloc(struct pt_regs *ctx)
 74{
 75	u32 key = bpf_get_current_pid_tgid();
 76	long init_val = 1;
 77	long *value;
 78
 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;
 84}
 85
 86SEC("kprobe/sys_getegid")
 87int stress_percpu_hmap_alloc(struct pt_regs *ctx)
 88{
 89	u32 key = bpf_get_current_pid_tgid();
 90	long init_val = 1;
 91	long *value;
 92
 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;
 98}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 99char _license[] SEC("license") = "GPL";
100u32 _version SEC("version") = LINUX_VERSION_CODE;
v4.10.11
  1/* Copyright (c) 2016 Facebook
  2 *
  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"
 12
 13#define MAX_ENTRIES 1000
 14
 15struct 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,
 20};
 21
 22struct bpf_map_def SEC("maps") lru_hash_map = {
 23	.type = BPF_MAP_TYPE_LRU_HASH,
 24	.key_size = sizeof(u32),
 25	.value_size = sizeof(long),
 26	.max_entries = 10000,
 27};
 28
 29struct bpf_map_def SEC("maps") percpu_lru_hash_map = {
 30	.type = BPF_MAP_TYPE_LRU_HASH,
 31	.key_size = sizeof(u32),
 32	.value_size = sizeof(long),
 33	.max_entries = 10000,
 34	.map_flags = BPF_F_NO_COMMON_LRU,
 35};
 36
 37struct bpf_map_def SEC("maps") percpu_hash_map = {
 38	.type = BPF_MAP_TYPE_PERCPU_HASH,
 39	.key_size = sizeof(u32),
 40	.value_size = sizeof(long),
 41	.max_entries = MAX_ENTRIES,
 42};
 43
 44struct bpf_map_def SEC("maps") hash_map_alloc = {
 45	.type = BPF_MAP_TYPE_HASH,
 46	.key_size = sizeof(u32),
 47	.value_size = sizeof(long),
 48	.max_entries = MAX_ENTRIES,
 49	.map_flags = BPF_F_NO_PREALLOC,
 50};
 51
 52struct bpf_map_def SEC("maps") percpu_hash_map_alloc = {
 53	.type = BPF_MAP_TYPE_PERCPU_HASH,
 54	.key_size = sizeof(u32),
 55	.value_size = sizeof(long),
 56	.max_entries = MAX_ENTRIES,
 57	.map_flags = BPF_F_NO_PREALLOC,
 58};
 59
 60SEC("kprobe/sys_getuid")
 61int stress_hmap(struct pt_regs *ctx)
 62{
 63	u32 key = bpf_get_current_pid_tgid();
 64	long init_val = 1;
 65	long *value;
 66
 67	bpf_map_update_elem(&hash_map, &key, &init_val, BPF_ANY);
 68	value = bpf_map_lookup_elem(&hash_map, &key);
 69	if (value)
 70		bpf_map_delete_elem(&hash_map, &key);
 71
 72	return 0;
 73}
 74
 75SEC("kprobe/sys_geteuid")
 76int stress_percpu_hmap(struct pt_regs *ctx)
 77{
 78	u32 key = bpf_get_current_pid_tgid();
 79	long init_val = 1;
 80	long *value;
 81
 82	bpf_map_update_elem(&percpu_hash_map, &key, &init_val, BPF_ANY);
 83	value = bpf_map_lookup_elem(&percpu_hash_map, &key);
 84	if (value)
 85		bpf_map_delete_elem(&percpu_hash_map, &key);
 86	return 0;
 87}
 88SEC("kprobe/sys_getgid")
 89int stress_hmap_alloc(struct pt_regs *ctx)
 90{
 91	u32 key = bpf_get_current_pid_tgid();
 92	long init_val = 1;
 93	long *value;
 94
 95	bpf_map_update_elem(&hash_map_alloc, &key, &init_val, BPF_ANY);
 96	value = bpf_map_lookup_elem(&hash_map_alloc, &key);
 97	if (value)
 98		bpf_map_delete_elem(&hash_map_alloc, &key);
 99	return 0;
100}
101
102SEC("kprobe/sys_getegid")
103int stress_percpu_hmap_alloc(struct pt_regs *ctx)
104{
105	u32 key = bpf_get_current_pid_tgid();
106	long init_val = 1;
107	long *value;
108
109	bpf_map_update_elem(&percpu_hash_map_alloc, &key, &init_val, BPF_ANY);
110	value = bpf_map_lookup_elem(&percpu_hash_map_alloc, &key);
111	if (value)
112		bpf_map_delete_elem(&percpu_hash_map_alloc, &key);
113	return 0;
114}
115
116SEC("kprobe/sys_getpid")
117int stress_lru_hmap_alloc(struct pt_regs *ctx)
118{
119	u32 key = bpf_get_prandom_u32();
120	long val = 1;
121
122	bpf_map_update_elem(&lru_hash_map, &key, &val, BPF_ANY);
123
124	return 0;
125}
126
127SEC("kprobe/sys_getppid")
128int stress_percpu_lru_hmap_alloc(struct pt_regs *ctx)
129{
130	u32 key = bpf_get_prandom_u32();
131	long val = 1;
132
133	bpf_map_update_elem(&percpu_lru_hash_map, &key, &val, BPF_ANY);
134
135	return 0;
136}
137
138char _license[] SEC("license") = "GPL";
139u32 _version SEC("version") = LINUX_VERSION_CODE;