mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
bpf: Optimize program stats
Move bpf_prog_stats from prog->aux into prog to avoid one extra load in critical path of program execution. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210210033634.62081-2-alexei.starovoitov@gmail.com
This commit is contained in:
committed by
Daniel Borkmann
parent
6df8fb8330
commit
700d4796ef
@@ -114,8 +114,8 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
|
||||
if (!prog)
|
||||
return NULL;
|
||||
|
||||
prog->aux->stats = alloc_percpu_gfp(struct bpf_prog_stats, gfp_flags);
|
||||
if (!prog->aux->stats) {
|
||||
prog->stats = alloc_percpu_gfp(struct bpf_prog_stats, gfp_flags);
|
||||
if (!prog->stats) {
|
||||
kfree(prog->aux);
|
||||
vfree(prog);
|
||||
return NULL;
|
||||
@@ -124,7 +124,7 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
|
||||
for_each_possible_cpu(cpu) {
|
||||
struct bpf_prog_stats *pstats;
|
||||
|
||||
pstats = per_cpu_ptr(prog->aux->stats, cpu);
|
||||
pstats = per_cpu_ptr(prog->stats, cpu);
|
||||
u64_stats_init(&pstats->syncp);
|
||||
}
|
||||
return prog;
|
||||
@@ -249,10 +249,10 @@ void __bpf_prog_free(struct bpf_prog *fp)
|
||||
if (fp->aux) {
|
||||
mutex_destroy(&fp->aux->used_maps_mutex);
|
||||
mutex_destroy(&fp->aux->dst_mutex);
|
||||
free_percpu(fp->aux->stats);
|
||||
kfree(fp->aux->poke_tab);
|
||||
kfree(fp->aux);
|
||||
}
|
||||
free_percpu(fp->stats);
|
||||
vfree(fp);
|
||||
}
|
||||
|
||||
|
@@ -1739,7 +1739,7 @@ static void bpf_prog_get_stats(const struct bpf_prog *prog,
|
||||
unsigned int start;
|
||||
u64 tnsecs, tcnt;
|
||||
|
||||
st = per_cpu_ptr(prog->aux->stats, cpu);
|
||||
st = per_cpu_ptr(prog->stats, cpu);
|
||||
do {
|
||||
start = u64_stats_fetch_begin_irq(&st->syncp);
|
||||
tnsecs = st->nsecs;
|
||||
|
@@ -412,7 +412,7 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start)
|
||||
* Hence check that 'start' is not zero.
|
||||
*/
|
||||
start) {
|
||||
stats = this_cpu_ptr(prog->aux->stats);
|
||||
stats = this_cpu_ptr(prog->stats);
|
||||
u64_stats_update_begin(&stats->syncp);
|
||||
stats->cnt++;
|
||||
stats->nsecs += sched_clock() - start;
|
||||
|
@@ -11253,7 +11253,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
|
||||
/* BPF_PROG_RUN doesn't call subprogs directly,
|
||||
* hence main prog stats include the runtime of subprogs.
|
||||
* subprogs don't have IDs and not reachable via prog_get_next_id
|
||||
* func[i]->aux->stats will never be accessed and stays NULL
|
||||
* func[i]->stats will never be accessed and stays NULL
|
||||
*/
|
||||
func[i] = bpf_prog_alloc_no_stats(bpf_prog_size(len), GFP_USER);
|
||||
if (!func[i])
|
||||
|
Reference in New Issue
Block a user