From: Roman Gushchin <guro@fb.com>
To: <netdev@vger.kernel.org>
Cc: <kernel-team@fb.com>, <tj@kernel.org>,
Roman Gushchin <guro@fb.com>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH bpf-net 11/14] bpf/test_run: support cgroup local storage
Date: Thu, 28 Jun 2018 09:34:55 -0700 [thread overview]
Message-ID: <20180628163458.27193-12-guro@fb.com> (raw)
In-Reply-To: <20180628163458.27193-1-guro@fb.com>
Allocate a temporary cgroup storage to use for bpf program test runs.
Because the test program is not actually attached to a cgroup,
the storage is allocated manually just for the execution
of the bpf program.
If the program is executed multiple times, the storage is not zeroed
on each run, emulating multiple runs of the program, attached to
a real cgroup.
Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
---
net/bpf/test_run.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 68c3578343b4..74971a9b7cfb 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -11,12 +11,14 @@
#include <linux/filter.h>
#include <linux/sched/signal.h>
-static __always_inline u32 bpf_test_run_one(struct bpf_prog *prog, void *ctx)
+static __always_inline u32 bpf_test_run_one(struct bpf_prog *prog, void *ctx,
+ struct bpf_cgroup_storage *storage)
{
u32 ret;
preempt_disable();
rcu_read_lock();
+ bpf_cgroup_storage_set(storage);
ret = BPF_PROG_RUN(prog, ctx);
rcu_read_unlock();
preempt_enable();
@@ -26,14 +28,19 @@ static __always_inline u32 bpf_test_run_one(struct bpf_prog *prog, void *ctx)
static u32 bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat, u32 *time)
{
+ struct bpf_cgroup_storage *storage = NULL;
u64 time_start, time_spent = 0;
u32 ret = 0, i;
+ storage = bpf_cgroup_storage_alloc(prog);
+ if (IS_ERR(storage))
+ return PTR_ERR(storage);
+
if (!repeat)
repeat = 1;
time_start = ktime_get_ns();
for (i = 0; i < repeat; i++) {
- ret = bpf_test_run_one(prog, ctx);
+ ret = bpf_test_run_one(prog, ctx, storage);
if (need_resched()) {
if (signal_pending(current))
break;
@@ -46,6 +53,8 @@ static u32 bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat, u32 *time)
do_div(time_spent, repeat);
*time = time_spent > U32_MAX ? U32_MAX : (u32)time_spent;
+ bpf_cgroup_storage_free(storage);
+
return ret;
}
--
2.14.4
next prev parent reply other threads:[~2018-06-28 16:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 16:34 [PATCH bpf-net 00/14] bpf: cgroup local storage Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 01/14] bpf: add ability to charge bpf maps memory dynamically Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 02/14] bpf: introduce cgroup storage maps Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 03/14] bpf: pass a pointer to a cgroup storage using pcpu variable Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 04/14] bpf: allocate cgroup storage entries on attaching bpf programs Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 05/14] bpf: extend bpf_prog_array to store pointers to the cgroup storage Roman Gushchin
2018-06-28 22:21 ` kbuild test robot
2018-06-28 16:34 ` [PATCH bpf-net 06/14] bpf/verifier: introduce BPF_PTR_TO_MAP_VALUE Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 07/14] bpf: don't allow create maps of cgroup local storages Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 08/14] bpf: introduce the bpf_get_local_storage() helper function Roman Gushchin
2018-06-29 4:37 ` kbuild test robot
2018-06-28 16:34 ` [PATCH bpf-net 09/14] bpf: sync bpf.h to tools/ Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 10/14] bpftool: add support for CGROUP_STORAGE maps Roman Gushchin
2018-06-28 16:34 ` Roman Gushchin [this message]
2018-06-28 16:34 ` [PATCH bpf-net 12/14] selftests/bpf: add verifier cgroup storage tests Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 13/14] selftests/bpf: add a cgroup storage test Roman Gushchin
2018-06-28 16:34 ` [PATCH bpf-net 14/14] samples/bpf: extend test_cgrp2_attach2 test to use cgroup storage Roman Gushchin
2018-06-28 16:46 ` [PATCH bpf-net 00/14] bpf: cgroup local storage Roman Gushchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180628163458.27193-12-guro@fb.com \
--to=guro@fb.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).