]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commit
selftests/bpf: cgroup local storage-based network counters
authorRoman Gushchin <guro@fb.com>
Fri, 28 Sep 2018 14:46:00 +0000 (14:46 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 1 Oct 2018 14:18:33 +0000 (16:18 +0200)
commit371e4fcc9d96ab1c8d72d59ca4ee3537402d1584
tree1b48dce888a0bcd3b8b4a747dc661b6e079e3f26
parent5fcbd29b372402c96b182e0e80b3d95463431490
selftests/bpf: cgroup local storage-based network counters

This commit adds a bpf kselftest, which demonstrates how percpu
and shared cgroup local storage can be used for efficient lookup-free
network accounting.

Cgroup local storage provides generic memory area with a very efficient
lookup free access. To avoid expensive atomic operations for each
packet, per-cpu cgroup local storage is used. Each packet is initially
charged to a per-cpu counter, and only if the counter reaches certain
value (32 in this case), the charge is moved into the global atomic
counter. This allows to amortize atomic operations, keeping reasonable
accuracy.

The test also implements a naive network traffic throttling, mostly to
demonstrate the possibility of bpf cgroup--based network bandwidth
control.

Expected output:
  ./test_netcnt
  test_netcnt:PASS

Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/netcnt_common.h [new file with mode: 0644]
tools/testing/selftests/bpf/netcnt_prog.c [new file with mode: 0644]
tools/testing/selftests/bpf/test_netcnt.c [new file with mode: 0644]