linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace: adjust code layout in get_recursion_context
@ 2017-08-22 14:40 Jesper Dangaard Brouer
  2017-08-22 15:14 ` Peter Zijlstra
  0 siblings, 1 reply; 9+ messages in thread
From: Jesper Dangaard Brouer @ 2017-08-22 14:40 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Jesper Dangaard Brouer, linux-kernel, Jiri Olsa,
	Ingo Molnar

In an XDP redirect applications using tracepoint xdp:xdp_redirect to
diagnose TX overrun, I noticed perf_swevent_get_recursion_context()
was consuming 2% CPU. This was reduced to 1.6% with this simple
change.

Looking at the annotated asm code, it was clear that the unlikely case
in_nmi() test was chosen (by the compiler) as the most likely
event/branch.  This small adjustment makes the compiler (gcc version
7.1.1 20170622 (Red Hat 7.1.1-3)) put in_nmi() as an unlikely branch.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
 kernel/events/internal.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index 486fd78eb8d5..56aa462760fa 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -208,12 +208,12 @@ static inline int get_recursion_context(int *recursion)
 {
 	int rctx;
 
-	if (in_nmi())
-		rctx = 3;
+	if (in_softirq())
+		rctx = 1;
 	else if (in_irq())
 		rctx = 2;
-	else if (in_softirq())
-		rctx = 1;
+	else if (in_nmi())
+		rctx = 3;
 	else
 		rctx = 0;
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-08-25 11:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-22 14:40 [PATCH] trace: adjust code layout in get_recursion_context Jesper Dangaard Brouer
2017-08-22 15:14 ` Peter Zijlstra
2017-08-22 15:20   ` Peter Zijlstra
2017-08-22 17:00     ` Jesper Dangaard Brouer
2017-08-22 17:10       ` Jesper Dangaard Brouer
2017-08-22 17:22         ` [PATCH V2] " Jesper Dangaard Brouer
2017-08-25 11:54           ` [tip:perf/core] tracing, perf: Adjust code layout in get_recursion_context() tip-bot for Jesper Dangaard Brouer
2017-08-22 17:55       ` [PATCH] trace: adjust code layout in get_recursion_context Peter Zijlstra
2017-08-23  8:12         ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).