[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzapLJbmhezw98S8udWO-atgLA2h6Lo9O_ss5Ka_xOR1mA@mail.gmail.com>
Date: Wed, 27 Jan 2021 13:30:39 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Song Liu <songliubraving@...com>
Cc: bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...hat.com>,
Peter Ziljstra <peterz@...radead.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>,
Kernel Team <kernel-team@...com>, Hao Luo <haoluo@...gle.com>
Subject: Re: [PATCH v2 bpf-next 4/4] bpf: runqslower: use task local storage
On Tue, Jan 26, 2021 at 1:11 AM Song Liu <songliubraving@...com> wrote:
>
> Replace hashtab with task local storage in runqslower. This improves the
> performance of these BPF programs. The following table summarizes average
> runtime of these programs, in nanoseconds:
>
> task-local hash-prealloc hash-no-prealloc
> handle__sched_wakeup 125 340 3124
> handle__sched_wakeup_new 2812 1510 2998
> handle__sched_switch 151 208 991
>
> Note that, task local storage gives better performance than hashtab for
> handle__sched_wakeup and handle__sched_switch. On the other hand, for
> handle__sched_wakeup_new, task local storage is slower than hashtab with
> prealloc. This is because handle__sched_wakeup_new accesses the data for
> the first time, so it has to allocate the data for task local storage.
> Once the initial allocation is done, subsequent accesses, as those in
> handle__sched_wakeup, are much faster with task local storage. If we
> disable hashtab prealloc, task local storage is much faster for all 3
> functions.
>
> Signed-off-by: Song Liu <songliubraving@...com>
> ---
Acked-by: Andrii Nakryiko <andrii@...nel.org>
> tools/bpf/runqslower/runqslower.bpf.c | 31 ++++++++++++++++-----------
> 1 file changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/tools/bpf/runqslower/runqslower.bpf.c b/tools/bpf/runqslower/runqslower.bpf.c
> index 1f18a409f0443..a597a23d79939 100644
> --- a/tools/bpf/runqslower/runqslower.bpf.c
> +++ b/tools/bpf/runqslower/runqslower.bpf.c
> @@ -11,9 +11,9 @@ const volatile __u64 min_us = 0;
> const volatile pid_t targ_pid = 0;
>
> struct {
> - __uint(type, BPF_MAP_TYPE_HASH);
> - __uint(max_entries, 10240);
> - __type(key, u32);
> + __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
> + __uint(map_flags, BPF_F_NO_PREALLOC);
> + __type(key, int);
> __type(value, u64);
> } start SEC(".maps");
>
> @@ -25,15 +25,18 @@ struct {
>
> /* record enqueue timestamp */
> __always_inline
> -static int trace_enqueue(u32 tgid, u32 pid)
> +static int trace_enqueue(struct task_struct *t)
> {
> - u64 ts;
> + u32 pid = t->pid;
> + u64 *ptr;
>
> if (!pid || (targ_pid && targ_pid != pid))
> return 0;
>
> - ts = bpf_ktime_get_ns();
> - bpf_map_update_elem(&start, &pid, &ts, 0);
> + ptr = bpf_task_storage_get(&start, t, 0,
> + BPF_LOCAL_STORAGE_GET_F_CREATE);
> + if (ptr)
> + *ptr = bpf_ktime_get_ns();
nit: if (!ptr) return 0; is more in line with general handling of
error/unusual conditions. Keeps main logic sequential (especially if
we need to add some extra steps later.
> return 0;
> }
>
> @@ -43,7 +46,7 @@ int handle__sched_wakeup(u64 *ctx)
> /* TP_PROTO(struct task_struct *p) */
> struct task_struct *p = (void *)ctx[0];
>
> - return trace_enqueue(p->tgid, p->pid);
> + return trace_enqueue(p);
> }
>
> SEC("tp_btf/sched_wakeup_new")
[...]
Powered by blists - more mailing lists