With TRACE_IRQFLAGS, we call trace_ API too many times. We don't need to if local_irq_restore or local_irq_save didn't actually do anything.
This gives around a 4% improvement in performance when doing the following command: "time find / > /dev/null" Also its best to avoid these calls where possible, since in this series, the RCU code in tracepoint.h seems to be call these quite a bit and I'd like to keep this overhead low. Cc: Steven Rostedt <rost...@goodmis.org> Cc: Peter Zilstra <pet...@infradead.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Mathieu Desnoyers <mathieu.desnoy...@efficios.com> Cc: Tom Zanussi <tom.zanu...@linux.intel.com> Cc: Namhyung Kim <namhy...@kernel.org> Cc: Thomas Glexiner <t...@linutronix.de> Cc: Boqun Feng <boqun.f...@gmail.com> Cc: Paul McKenney <paul...@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweis...@gmail.com> Cc: Randy Dunlap <rdun...@infradead.org> Cc: Masami Hiramatsu <mhira...@kernel.org> Cc: Fenguang Wu <fengguang...@intel.com> Cc: Baohong Liu <baohong....@intel.com> Cc: Vedang Patel <vedang.pa...@intel.com> Signed-off-by: Joel Fernandes <joe...@google.com> --- include/linux/irqflags.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h index 9700f00bbc04..ea8df0ac57d3 100644 --- a/include/linux/irqflags.h +++ b/include/linux/irqflags.h @@ -104,19 +104,20 @@ do { \ #define local_irq_save(flags) \ do { \ raw_local_irq_save(flags); \ - trace_hardirqs_off(); \ + if (!raw_irqs_disabled_flags(flags)) \ + trace_hardirqs_off(); \ } while (0) -#define local_irq_restore(flags) \ - do { \ - if (raw_irqs_disabled_flags(flags)) { \ - raw_local_irq_restore(flags); \ - trace_hardirqs_off(); \ - } else { \ - trace_hardirqs_on(); \ - raw_local_irq_restore(flags); \ - } \ +#define local_irq_restore(flags) \ + do { \ + if (raw_irqs_disabled_flags(flags) && !irqs_disabled()) { \ + raw_local_irq_restore(flags); \ + trace_hardirqs_off(); \ + } else if (!raw_irqs_disabled_flags(flags) && irqs_disabled()) {\ + trace_hardirqs_on(); \ + raw_local_irq_restore(flags); \ + } \ } while (0) #define safe_halt() \ -- 2.17.0.484.g0c8726318c-goog