[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201109121708.GK2594@hirez.programming.kicks-ass.net>
Date: Mon, 9 Nov 2020 13:17:08 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: linux-kernel@...r.kernel.org,
Masami Hiramatsu <mhiramat@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Ingo Molnar <mingo@...nel.org>,
Josh Poimboeuf <jpoimboe@...hat.com>,
Jiri Kosina <jikos@...nel.org>,
Miroslav Benes <mbenes@...e.cz>, Petr Mladek <pmladek@...e.com>
Subject: Re: [PATCH 03/11 v3] ftrace: Optimize testing what context current
is in
On Thu, Nov 05, 2020 at 09:32:38PM -0500, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@...dmis.org>
>
> The preempt_count() is not a simple location in memory, it could be part of
> per_cpu code or more. Each access to preempt_count(), or one of its accessor
> functions (like in_interrupt()) takes several cycles. By reading
> preempt_count() once, and then doing tests to find the context against the
> value return is slightly faster than using in_nmi() and in_interrupt().
>
> Link: https://lkml.kernel.org/r/20201028115612.780796355@goodmis.org
>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@...dmis.org>
> ---
> include/linux/trace_recursion.h | 33 ++++++++++++++++++++-------------
> 1 file changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h
> index f2a949dbfec7..ac3d73484cb2 100644
> --- a/include/linux/trace_recursion.h
> +++ b/include/linux/trace_recursion.h
> @@ -117,22 +117,29 @@ enum {
>
> #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
>
> +/*
> + * Used for setting context
> + * NMI = 0
> + * IRQ = 1
> + * SOFTIRQ = 2
> + * NORMAL = 3
> + */
> +enum {
> + TRACE_CTX_NMI,
> + TRACE_CTX_IRQ,
> + TRACE_CTX_SOFTIRQ,
> + TRACE_CTX_NORMAL,
> +};
> +
> static __always_inline int trace_get_context_bit(void)
> {
> - int bit;
> -
> - if (in_interrupt()) {
> - if (in_nmi())
> - bit = 0;
> -
> - else if (in_irq())
> - bit = 1;
> - else
> - bit = 2;
> - } else
> - bit = 3;
> + unsigned long pc = preempt_count();
>
> - return bit;
> + if (!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)))
> + return TRACE_CTX_NORMAL;
> + else
> + return pc & NMI_MASK ? TRACE_CTX_NMI :
> + pc & HARDIRQ_MASK ? TRACE_CTX_IRQ : TRACE_CTX_SOFTIRQ;
> }
This patch is misleading, it doesn't optimize it nearly as much as is
possible and actually fixes the softirq case, which isn't at all
mentioned.
Let me go do that other patch.
Powered by blists - more mailing lists