Re: [PATCH 4/6] perf: Optimize get_recursion_context()
From: Jesper Dangaard Brouer
Date: Fri Oct 30 2020 - 13:11:55 EST
On Fri, 30 Oct 2020 16:13:49 +0100
Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> "Look ma, no branches!"
>
> Cc: Jesper Dangaard Brouer <brouer@xxxxxxxxxx>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> ---
Cool trick! :-)
Acked-by: Jesper Dangaard Brouer <brouer@xxxxxxxxxx>
> kernel/events/internal.h | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> --- a/kernel/events/internal.h
> +++ b/kernel/events/internal.h
> @@ -205,16 +205,15 @@ DEFINE_OUTPUT_COPY(__output_copy_user, a
>
> static inline int get_recursion_context(int *recursion)
> {
> - int rctx;
> + unsigned int pc = preempt_count();
> + unsigned int rctx = 0;
>
> - if (unlikely(in_nmi()))
> - rctx = 3;
> - else if (in_irq())
> - rctx = 2;
> - else if (in_serving_softirq())
> - rctx = 1;
> - else
> - rctx = 0;
> + if (pc & (NMI_MASK))
> + rctx++;
> + if (pc & (NMI_MASK | HARDIRQ_MASK))
> + rctx++;
> + if (pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET))
> + rctx++;
>
> if (recursion[rctx])
> return -1;
>
>
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer