/* Copyright (c) 2016 Facebook * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation.
*/ #include"vmlinux.h" #include <errno.h> #include <linux/version.h> #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> #include <bpf/bpf_core_read.h>
SEC("ksyscall/getuid") int BPF_KSYSCALL(stress_hmap)
{
u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; int i;
for (i = 0; i < 10; i++) {
bpf_map_update_elem(&hash_map, &key, &init_val, BPF_ANY);
value = bpf_map_lookup_elem(&hash_map, &key); if (value)
bpf_map_delete_elem(&hash_map, &key);
}
return 0;
}
SEC("ksyscall/geteuid") int BPF_KSYSCALL(stress_percpu_hmap)
{
u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; int i;
for (i = 0; i < 10; i++) {
bpf_map_update_elem(&percpu_hash_map, &key, &init_val, BPF_ANY);
value = bpf_map_lookup_elem(&percpu_hash_map, &key); if (value)
bpf_map_delete_elem(&percpu_hash_map, &key);
} return 0;
}
SEC("ksyscall/getgid") int BPF_KSYSCALL(stress_hmap_alloc)
{
u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; int i;
for (i = 0; i < 10; i++) {
bpf_map_update_elem(&hash_map_alloc, &key, &init_val, BPF_ANY);
value = bpf_map_lookup_elem(&hash_map_alloc, &key); if (value)
bpf_map_delete_elem(&hash_map_alloc, &key);
} return 0;
}
SEC("ksyscall/getegid") int BPF_KSYSCALL(stress_percpu_hmap_alloc)
{
u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; int i;
for (i = 0; i < 10; i++) {
bpf_map_update_elem(&percpu_hash_map_alloc, &key, &init_val, BPF_ANY);
value = bpf_map_lookup_elem(&percpu_hash_map_alloc, &key); if (value)
bpf_map_delete_elem(&percpu_hash_map_alloc, &key);
} return 0;
}
SEC("ksyscall/connect") int BPF_KSYSCALL(stress_lru_hmap_alloc, int fd, struct sockaddr_in *uservaddr, int addrlen)
{ char fmt[] = "Failed at stress_lru_hmap_alloc. ret:%dn"; union {
u16 dst6[8]; struct {
u16 magic0;
u16 magic1;
u16 tcase;
u16 unused16;
u32 unused32;
u32 key;
};
} test_params; struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)uservaddr;
u16 test_case; long val = 1;
u32 key = 0; int ret;
if (addrlen != sizeof(*in6)) return 0;
ret = bpf_probe_read_user(test_params.dst6, sizeof(test_params.dst6),
&in6->sin6_addr); if (ret) goto done;
if (test_params.magic0 != 0xdead ||
test_params.magic1 != 0xbeef) return 0;
test_case = test_params.tcase; if (test_case != 3)
key = bpf_get_prandom_u32();
if (test_case == 0) {
ret = bpf_map_update_elem(&lru_hash_map, &key, &val, BPF_ANY);
} elseif (test_case == 1) {
ret = bpf_map_update_elem(&nocommon_lru_hash_map, &key, &val,
BPF_ANY);
} elseif (test_case == 2) { void *nolocal_lru_map; int cpu = bpf_get_smp_processor_id();
nolocal_lru_map = bpf_map_lookup_elem(&array_of_lru_hashs,
&cpu); if (!nolocal_lru_map) {
ret = -ENOENT; goto done;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.