diff options
author | Peter Zijlstra <peterz@infradead.org> | 2020-10-30 13:43:16 +0100 |
---|---|---|
committer | Peter Zijlstra <peterz@infradead.org> | 2020-11-09 18:12:34 +0100 |
commit | 09da9c81253dd8e43e0d2d7cea02de6f9f19499d (patch) | |
tree | ed3c3929c7ceefb88bab0e7c35fcd238f5467ac4 /kernel/events | |
parent | perf: Fix get_recursion_context() (diff) | |
download | linux-09da9c81253dd8e43e0d2d7cea02de6f9f19499d.tar.xz linux-09da9c81253dd8e43e0d2d7cea02de6f9f19499d.zip |
perf: Optimize get_recursion_context()
"Look ma, no branches!"
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Link: https://lkml.kernel.org/r/20201030151955.187580298@infradead.org
Diffstat (limited to 'kernel/events')
-rw-r--r-- | kernel/events/internal.h | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/kernel/events/internal.h b/kernel/events/internal.h index 402054e755f2..228801e20788 100644 --- a/kernel/events/internal.h +++ b/kernel/events/internal.h @@ -205,16 +205,12 @@ DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user) static inline int get_recursion_context(int *recursion) { - int rctx; - - if (unlikely(in_nmi())) - rctx = 3; - else if (in_irq()) - rctx = 2; - else if (in_serving_softirq()) - rctx = 1; - else - rctx = 0; + unsigned int pc = preempt_count(); + unsigned char rctx = 0; + + rctx += !!(pc & (NMI_MASK)); + rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK)); + rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)); if (recursion[rctx]) return -1; |