summaryrefslogtreecommitdiff
path: root/samples/bpf/lwt_len_hist_kern.c
diff options
context:
space:
mode:
authorDaniel T. Lee <danieltimlee@gmail.com>2023-01-15 16:16:13 +0900
committerAlexei Starovoitov <ast@kernel.org>2023-01-15 13:32:45 -0800
commite04946f54cd99fa1bd92e22f4540720d76d88058 (patch)
tree059e4cedf8d2015617268672584b31c5db88c6ff /samples/bpf/lwt_len_hist_kern.c
parente8acf8f47a5d58a00fbfa0f3592bbaaff557cec3 (diff)
samples/bpf: change _kern suffix to .bpf with BPF test programs
This commit changes the _kern suffix to .bpf with the BPF test programs. With this modification, test programs will inherit the benefit of the new CLANG-BPF compile target. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Link: https://lore.kernel.org/r/20230115071613.125791-11-danieltimlee@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf/lwt_len_hist_kern.c')
-rw-r--r--samples/bpf/lwt_len_hist_kern.c62
1 files changed, 0 insertions, 62 deletions
diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_kern.c
deleted file mode 100644
index dbab80e813fe..000000000000
--- a/samples/bpf/lwt_len_hist_kern.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Copyright (c) 2016 Thomas Graf <tgraf@tgraf.ch>
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- */
-
-#include "vmlinux.h"
-#include <bpf/bpf_helpers.h>
-
-struct {
- __uint(type, BPF_MAP_TYPE_PERCPU_HASH);
- __type(key, u64);
- __type(value, u64);
- __uint(pinning, LIBBPF_PIN_BY_NAME);
- __uint(max_entries, 1024);
-} lwt_len_hist_map SEC(".maps");
-
-static unsigned int log2(unsigned int v)
-{
- unsigned int r;
- unsigned int shift;
-
- r = (v > 0xFFFF) << 4; v >>= r;
- shift = (v > 0xFF) << 3; v >>= shift; r |= shift;
- shift = (v > 0xF) << 2; v >>= shift; r |= shift;
- shift = (v > 0x3) << 1; v >>= shift; r |= shift;
- r |= (v >> 1);
- return r;
-}
-
-static unsigned int log2l(unsigned long v)
-{
- unsigned int hi = v >> 32;
- if (hi)
- return log2(hi) + 32;
- else
- return log2(v);
-}
-
-SEC("len_hist")
-int do_len_hist(struct __sk_buff *skb)
-{
- __u64 *value, key, init_val = 1;
-
- key = log2l(skb->len);
-
- value = bpf_map_lookup_elem(&lwt_len_hist_map, &key);
- if (value)
- __sync_fetch_and_add(value, 1);
- else
- bpf_map_update_elem(&lwt_len_hist_map, &key, &init_val, BPF_ANY);
-
- return BPF_OK;
-}
-
-char _license[] SEC("license") = "GPL";