diff options
author | Eric Dumazet <edumazet@google.com> | 2021-10-26 14:41:33 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-10-27 11:13:52 -0700 |
commit | 61a0abaee2092eee69e44fe60336aa2f5b578938 (patch) | |
tree | 5ee181827d5064079aaa77ce0e3523a70daf1e86 /kernel/bpf/trampoline.c | |
parent | d979617aa84d96acca44c2f5778892b4565e322f (diff) | |
download | lwn-61a0abaee2092eee69e44fe60336aa2f5b578938.tar.gz lwn-61a0abaee2092eee69e44fe60336aa2f5b578938.zip |
bpf: Use u64_stats_t in struct bpf_prog_stats
Commit 316580b69d0a ("u64_stats: provide u64_stats_t type")
fixed possible load/store tearing on 64bit arches.
For instance the following C code
stats->nsecs += sched_clock() - start;
Could be rightfully implemented like this by a compiler,
confusing concurrent readers a lot:
stats->nsecs += sched_clock();
// arbitrary delay
stats->nsecs -= start;
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211026214133.3114279-4-eric.dumazet@gmail.com
Diffstat (limited to 'kernel/bpf/trampoline.c')
-rw-r--r-- | kernel/bpf/trampoline.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index e5963de368ed..e98de5e73ba5 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -545,7 +545,7 @@ static void notrace inc_misses_counter(struct bpf_prog *prog) stats = this_cpu_ptr(prog->stats); u64_stats_update_begin(&stats->syncp); - stats->misses++; + u64_stats_inc(&stats->misses); u64_stats_update_end(&stats->syncp); } @@ -590,8 +590,8 @@ static void notrace update_prog_stats(struct bpf_prog *prog, stats = this_cpu_ptr(prog->stats); flags = u64_stats_update_begin_irqsave(&stats->syncp); - stats->cnt++; - stats->nsecs += sched_clock() - start; + u64_stats_inc(&stats->cnt); + u64_stats_add(&stats->nsecs, sched_clock() - start); u64_stats_update_end_irqrestore(&stats->syncp, flags); } } |