Created
January 18, 2017 14:28
-
-
Save dvdhrm/4c90e61a1c39746d5c55ab9e0e29315e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/samples/bpf/map_perf_test_kern.c b/samples/bpf/map_perf_test_kern.c | |
index 311538e5a701..f712ad3528ea 100644 | |
--- a/samples/bpf/map_perf_test_kern.c | |
+++ b/samples/bpf/map_perf_test_kern.c | |
@@ -42,6 +42,14 @@ struct bpf_map_def SEC("maps") percpu_hash_map_alloc = { | |
.map_flags = BPF_F_NO_PREALLOC, | |
}; | |
+struct bpf_map_def SEC("maps") lpm_trie_map_alloc = { | |
+ .type = BPF_MAP_TYPE_LPM_TRIE, | |
+ .key_size = 8, | |
+ .value_size = sizeof(long), | |
+ .max_entries = 10000, | |
+ .map_flags = BPF_F_NO_PREALLOC, | |
+}; | |
+ | |
SEC("kprobe/sys_getuid") | |
int stress_hmap(struct pt_regs *ctx) | |
{ | |
@@ -96,5 +104,27 @@ int stress_percpu_hmap_alloc(struct pt_regs *ctx) | |
bpf_map_delete_elem(&percpu_hash_map_alloc, &key); | |
return 0; | |
} | |
+ | |
+SEC("kprobe/sys_gettid") | |
+int stress_lpm_trie_map_alloc(struct pt_regs *ctx) | |
+{ | |
+ union { | |
+ u32 b32[2]; | |
+ u8 b8[8]; | |
+ } key; | |
+ unsigned int i; | |
+ | |
+ key.b32[0] = 32; | |
+ key.b8[4] = 192; | |
+ key.b8[5] = 168; | |
+ key.b8[6] = 0; | |
+ key.b8[7] = 1; | |
+ | |
+ for (i = 0; i < 8; ++i) | |
+ bpf_map_lookup_elem(&lpm_trie_map_alloc, &key); | |
+ | |
+ return 0; | |
+} | |
+ | |
char _license[] SEC("license") = "GPL"; | |
u32 _version SEC("version") = LINUX_VERSION_CODE; | |
diff --git a/samples/bpf/map_perf_test_user.c b/samples/bpf/map_perf_test_user.c | |
index 3147377e8fd3..938aaf6cc210 100644 | |
--- a/samples/bpf/map_perf_test_user.c | |
+++ b/samples/bpf/map_perf_test_user.c | |
@@ -35,6 +35,7 @@ static __u64 time_get_ns(void) | |
#define PERCPU_HASH_PREALLOC (1 << 1) | |
#define HASH_KMALLOC (1 << 2) | |
#define PERCPU_HASH_KMALLOC (1 << 3) | |
+#define LPM_KMALLOC (1 << 4) | |
static int test_flags = ~0; | |
@@ -86,6 +87,18 @@ static void test_percpu_hash_kmalloc(int cpu) | |
cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); | |
} | |
+static void test_lpm_kmalloc(int cpu) | |
+{ | |
+ __u64 start_time; | |
+ int i; | |
+ | |
+ start_time = time_get_ns(); | |
+ for (i = 0; i < MAX_CNT; i++) | |
+ syscall(__NR_gettid); | |
+ printf("%d:lpm_perf kmalloc %lld events per sec\n", | |
+ cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); | |
+} | |
+ | |
static void loop(int cpu) | |
{ | |
cpu_set_t cpuset; | |
@@ -105,6 +118,9 @@ static void loop(int cpu) | |
if (test_flags & PERCPU_HASH_KMALLOC) | |
test_percpu_hash_kmalloc(cpu); | |
+ | |
+ if (test_flags & LPM_KMALLOC) | |
+ test_lpm_kmalloc(cpu); | |
} | |
static void run_perf_test(int tasks) | |
@@ -130,6 +146,37 @@ static void run_perf_test(int tasks) | |
} | |
} | |
+static void fill_lpm_trie(void) | |
+{ | |
+ struct bpf_lpm_trie_key *key; | |
+ unsigned long value = 0; | |
+ unsigned int i; | |
+ int r; | |
+ | |
+ key = alloca(sizeof(*key) + 4); | |
+ key->prefixlen = 32; | |
+ | |
+ for (i = 0; i < 0; ++i) { | |
+ key->prefixlen = rand() % 33; | |
+ key->data[0] = rand() & 0xff; | |
+ key->data[1] = rand() & 0xff; | |
+ key->data[2] = rand() & 0xff; | |
+ key->data[3] = rand() & 0xff; | |
+ r = bpf_update_elem(map_fd[4], key, &value, 0); | |
+ assert(!r); | |
+ } | |
+ | |
+ key->prefixlen = 32; | |
+ key->data[0] = 192; | |
+ key->data[1] = 168; | |
+ key->data[2] = 0; | |
+ key->data[3] = 1; | |
+ value = 128; | |
+ | |
+ r = bpf_update_elem(map_fd[4], key, &value, 0); | |
+ assert(!r); | |
+} | |
+ | |
int main(int argc, char **argv) | |
{ | |
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; | |
@@ -150,6 +197,8 @@ int main(int argc, char **argv) | |
return 1; | |
} | |
+ fill_lpm_trie(); | |
+ | |
run_perf_test(num_cpu); | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment