[RFC PATCH 5/7] trace: Use early task context tracking if available
From: Daniel Bristot de Oliveira
Date: Tue Apr 02 2019 - 16:04:32 EST
Use the early task context tracking to detect the current context,
if the arch supports it.
Signed-off-by: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: "Joel Fernandes (Google)" <joel@xxxxxxxxxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Tommaso Cucinotta <tommaso.cucinotta@xxxxxxxxxxxxxxx>
Cc: Romulo Silva de Oliveira <romulo.deoliveira@xxxxxxx>
Cc: Clark Williams <williams@xxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: x86@xxxxxxxxxx
---
kernel/trace/trace.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 09318748fab8..62ba4bd0e436 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -632,7 +632,18 @@ enum {
TRACE_CTX_NORMAL,
TRACE_CTX_MAX
};
+#ifdef ARCH_HAS_TASK_CONTEXT
+static __always_inline int trace_get_context_bit(void)
+{
+ unsigned long tc = this_cpu_read(task_context);
+ if (tc)
+ return tc & TASK_CTX_NMI ? TRACE_CTX_NMI :
+ tc & TASK_CTX_IRQ ? TRACE_CTX_IRQ : TRACE_CTX_SOFTIRQ;
+ else
+ return TRACE_CTX_NORMAL;
+}
+#else /* ARCH_HAS_TASK_CONTEXT */
static __always_inline int trace_get_context_bit(void)
{
unsigned long pc = preempt_count();
@@ -643,6 +654,7 @@ static __always_inline int trace_get_context_bit(void)
else
return TRACE_CTX_NORMAL;
}
+#endif /* ARCH_HAS_TASK_CONTEXT */
static __always_inline int trace_test_and_set_recursion(int start, int max)
{
--
2.20.1