[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201030230152.GT2594@hirez.programming.kicks-ass.net>
Date: Sat, 31 Oct 2020 00:01:52 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Jesper Dangaard Brouer <brouer@...hat.com>, mingo@...nel.org,
tglx@...utronix.de, linux-kernel@...r.kernel.org,
kan.liang@...ux.intel.com, acme@...nel.org, mark.rutland@....com,
alexander.shishkin@...ux.intel.com, jolsa@...hat.com,
namhyung@...nel.org, ak@...ux.intel.com, eranian@...gle.com
Subject: Re: [PATCH 4/6] perf: Optimize get_recursion_context()
On Fri, Oct 30, 2020 at 04:22:48PM -0400, Steven Rostedt wrote:
> As this is something that ftrace recursion also does, perhaps we should
> move this into interrupt.h so that anyone that needs a counter can get
> it quickly, and not keep re-implementing it.
Works for me, however:
> /*
> * Quickly find what context you are in.
> * 0 - normal
> * 1 - softirq
> * 2 - hard interrupt
> * 3 - NMI
> */
> static inline int irq_context()
> {
> unsigned int pc = preempt_count();
> int rctx = 0;
unsigned
>
> if (pc & (NMI_MASK))
> rctx++;
> if (pc & (NMI_MASK | HARDIRQ_MASK))
> rctx++;
> if (pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET))
> rctx++;
>
> return rctx;
> }
otherwise you'll get an extra instruction to sign extend it, which is
daft (yes, i've been staring at GCC output far too much).
Also, gcc-9 does worse (like 1 byte iirc) with:
rctx += !!(pc & (NMI_MASK));
rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK));
rctx += !!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET));
but gcc-10 doesn't seem to care.
Powered by blists - more mailing lists