[PATCH v2 2/3] tracing: Record task flag NEED_RESCHED_LAZY.

Sebastian Andrzej Siewior posted 3 patches 1 month ago
[PATCH v2 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
Posted by Sebastian Andrzej Siewior 1 month ago
From: Thomas Gleixner <tglx@linutronix.de>

The scheduler added NEED_RESCHED_LAZY scheduling. Record this state as
part of trace flags and expose it in the need_resched field.

Record and expose NEED_RESCHED_LAZY.

[bigeasy: Commit description, documentation bits.]

Reviewed-by: Ankur Arora <ankur.a.arora@oracle.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 Documentation/trace/ftrace.rst |    4 ++++
 include/linux/trace_events.h   |    1 +
 kernel/trace/trace.c           |    2 ++
 kernel/trace/trace_output.c    |   14 +++++++++++++-
 4 files changed, 20 insertions(+), 1 deletion(-)

--- a/Documentation/trace/ftrace.rst
+++ b/Documentation/trace/ftrace.rst
@@ -1036,9 +1036,13 @@ explains which is which.
 		be printed here.
 
   need-resched:
+	- 'B' all, TIF_NEED_RESCHED, PREEMPT_NEED_RESCHED and TIF_RESCHED_LAZY is set,
 	- 'N' both TIF_NEED_RESCHED and PREEMPT_NEED_RESCHED is set,
 	- 'n' only TIF_NEED_RESCHED is set,
 	- 'p' only PREEMPT_NEED_RESCHED is set,
+	- 'L' borg PREEMPT_NEED_RESCHED and TIF_RESCHED_LAZY is set,
+	- 'b' borg TIF_NEED_RESCHED and TIF_RESCHED_LAZY is set,
+	- 'l' only TIF_RESCHED_LAZY is set
 	- '.' otherwise.
 
   hardirq/softirq:
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -185,6 +185,7 @@ unsigned int tracing_gen_ctx_irq_test(un
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
 	TRACE_FLAG_NEED_RESCHED		= 0x02,
+	TRACE_FLAG_NEED_RESCHED_LAZY	= 0x04,
 	TRACE_FLAG_HARDIRQ		= 0x08,
 	TRACE_FLAG_SOFTIRQ		= 0x10,
 	TRACE_FLAG_PREEMPT_RESCHED	= 0x20,
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(un
 		trace_flags |= TRACE_FLAG_NEED_RESCHED;
 	if (test_preempt_need_resched())
 		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY) && tif_test_bit(TIF_NEED_RESCHED_LAZY))
+		trace_flags |= TRACE_FLAG_NEED_RESCHED_LAZY;
 	return (trace_flags << 16) | (min_t(unsigned int, pc & 0xff, 0xf)) |
 		(min_t(unsigned int, migration_disable_value(), 0xf)) << 4;
 }
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -463,17 +463,29 @@ int trace_print_lat_fmt(struct trace_seq
 		!IS_ENABLED(CONFIG_TRACE_IRQFLAGS_SUPPORT) ? 'X' :
 		'.';
 
-	switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
+	switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY |
 				TRACE_FLAG_PREEMPT_RESCHED)) {
+	case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY | TRACE_FLAG_PREEMPT_RESCHED:
+		need_resched = 'B';
+		break;
 	case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
 		need_resched = 'N';
 		break;
+	case TRACE_FLAG_NEED_RESCHED_LAZY | TRACE_FLAG_PREEMPT_RESCHED:
+		need_resched = 'L';
+		break;
+	case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY:
+		need_resched = 'b';
+		break;
 	case TRACE_FLAG_NEED_RESCHED:
 		need_resched = 'n';
 		break;
 	case TRACE_FLAG_PREEMPT_RESCHED:
 		need_resched = 'p';
 		break;
+	case TRACE_FLAG_NEED_RESCHED_LAZY:
+		need_resched = 'l';
+		break;
 	default:
 		need_resched = '.';
 		break;
Re: [PATCH v2 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
Posted by Steven Rostedt 1 month ago
On Mon, 21 Oct 2024 17:08:41 +0200
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

>  enum trace_flag_type {
>  	TRACE_FLAG_IRQS_OFF		= 0x01,
>  	TRACE_FLAG_NEED_RESCHED		= 0x02,
> +	TRACE_FLAG_NEED_RESCHED_LAZY	= 0x04,
>  	TRACE_FLAG_HARDIRQ		= 0x08,
>  	TRACE_FLAG_SOFTIRQ		= 0x10,
>  	TRACE_FLAG_PREEMPT_RESCHED	= 0x20,

As I stated in the other email, these are user visible. Should probably
make the LAZY flag 0x100, as the trace_flags are 16 bits worth.

-- Steve
Re: [PATCH v2 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
Posted by Sebastian Andrzej Siewior 1 month ago
On 2024-10-22 03:18:27 [-0400], Steven Rostedt wrote:
> On Mon, 21 Oct 2024 17:08:41 +0200
> Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> 
> >  enum trace_flag_type {
> >  	TRACE_FLAG_IRQS_OFF		= 0x01,
> >  	TRACE_FLAG_NEED_RESCHED		= 0x02,
> > +	TRACE_FLAG_NEED_RESCHED_LAZY	= 0x04,
> >  	TRACE_FLAG_HARDIRQ		= 0x08,
> >  	TRACE_FLAG_SOFTIRQ		= 0x10,
> >  	TRACE_FLAG_PREEMPT_RESCHED	= 0x20,
> 
> As I stated in the other email, these are user visible. Should probably
> make the LAZY flag 0x100, as the trace_flags are 16 bits worth.

What about struct trace_entry? That flags is stored as 8bit in
tracing_generic_entry_update().

> 
> -- Steve

Sebastian