Skip to contentSkip to conversation

Lazy preemption leftovers

PATCH Superseded Sebastian Andrzej Siewior 8 participants 18 messages Oct 9, 2024 – Dec 11, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Lazy preemption leftovers

This is a followup to PeterZ'

	https://lore.kernel.org/[email protected]

in PREEMPT_RT we had initially "LAZY preempt" this then morphed into PREEMPT_AUTO and is becoming "Lazy preemption".
These are the tracing bits from that time that were used up to PREEMPT_AUTO. With RT's RiscV support, they also contributed PREEMPT_AUTO support which I just updated to current edition.

I used to have ARM* and POWERPC*, too support for the "LAZY preempt" but this relied on assembly support and I dropped this during the switch to PREEMPT_AUTO.

Sebastian

#1 lore raw

PATCH 1/3 tracing: Replace TRACE_FLAG_IRQS_NOSUPPORT with its config option.

The TRACE_FLAG_IRQS_NOSUPPORT flag is used by tracing_gen_ctx.*() to signal that CONFIG_TRACE_IRQFLAGS_SUPPORT is not enabled and tracing IRQ flags is not supported.

This could be replaced by using the 0 as flags and then deducting that there is no IRQFLAGS_SUPPORT based on the config option. The downside is that without CONFIG_TRACE_IRQFLAGS_SUPPORT we can not distinguish between no-IRQ passed flags and callers which passed 0. On the upside we have room for one additional flags which could be used for LAZY_PREEMPTION.

Remove TRACE_FLAG_IRQS_NOSUPPORT and set it flags are 0 and CONFIG_TRACE_IRQFLAGS_SUPPORT is not set.

---
 include/linux/trace_events.h | 7 +++----
 kernel/trace/trace_output.c  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
include/linux/trace_events.h +3 -4
index 42bedcddd5113..d5c0fcf20f024 100644
@@ -184,8 +184,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status);
 
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
-	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
-	TRACE_FLAG_NEED_RESCHED		= 0x04,
+	TRACE_FLAG_NEED_RESCHED		= 0x02,
 	TRACE_FLAG_HARDIRQ		= 0x08,
 	TRACE_FLAG_SOFTIRQ		= 0x10,
 	TRACE_FLAG_PREEMPT_RESCHED	= 0x20,
@@ -211,11 +210,11 @@ static inline unsigned int tracing_gen_ctx(void)
 
 static inline unsigned int tracing_gen_ctx_flags(unsigned long irqflags)
 {
-	return tracing_gen_ctx_irq_test(TRACE_FLAG_IRQS_NOSUPPORT);
+	return tracing_gen_ctx_irq_test(0);
 }
 static inline unsigned int tracing_gen_ctx(void)
 {
-	return tracing_gen_ctx_irq_test(TRACE_FLAG_IRQS_NOSUPPORT);
+	return tracing_gen_ctx_irq_test(0);
 }
 #endif
 
kernel/trace/trace_output.c +1 -1
index 868f2f912f280..829daa0764dd9 100644
@@ -460,7 +460,7 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
 		(entry->flags & TRACE_FLAG_IRQS_OFF && bh_off) ? 'D' :
 		(entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
 		bh_off ? 'b' :
-		(entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
+		!IS_ENABLED(CONFIG_TRACE_IRQFLAGS_SUPPORT) ? 'X' :
 		'.';
 
 	switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/3 tracing: Record task flag NEED_RESCHED_LAZY.

In reply to Sebastian Andrzej Siewior

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.

---
 include/linux/trace_events.h |  1 +
 kernel/trace/trace.c         |  2 ++
 kernel/trace/trace_output.c  | 14 +++++++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)
include/linux/trace_events.h +1 -0
index d5c0fcf20f024..4cae6f2581379 100644
@@ -185,6 +185,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status);
 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,
kernel/trace/trace.c +2 -0
index 1c69ca1f10886..29d7703751aa9 100644
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		trace_flags |= TRACE_FLAG_NEED_RESCHED;
 	if (test_preempt_need_resched())
 		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (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;
 }
kernel/trace/trace_output.c +13 -1
index 829daa0764dd9..23ca2155306b1 100644
@@ -463,17 +463,29 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
 		!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;
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 2/3
#3 lore raw

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

Quoted 6 lines · On Wed, 9 Oct 2024 12:50:56 +0200 Sebastian Andrzej Siewior…

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.

-- Steve

Quoted 5 lines
---
 include/linux/trace_events.h |  1 +
 kernel/trace/trace.c         |  2 ++
 kernel/trace/trace_output.c  | 14 +++++++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)
Reviewed-by on v1 2/3
#4 lore raw

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

In reply to Sebastian Andrzej Siewior
Quoted 29 lines · Sebastian Andrzej Siewior

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.

---
 include/linux/trace_events.h |  1 +
 kernel/trace/trace.c         |  2 ++
 kernel/trace/trace_output.c  | 14 +++++++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)
include/linux/trace_events.h +1 -0
index d5c0fcf20f024..4cae6f2581379 100644
@@ -185,6 +185,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status);
 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,
kernel/trace/trace.c +0 -0
index 1c69ca1f10886..29d7703751aa9 100644

kernel/trace/trace.c unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) · line 2547

Quoted 4 lines
kernel/trace/trace.c +1 -0
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		trace_flags |= TRACE_FLAG_NEED_RESCHED;
 	if (test_preempt_need_resched())
 		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (tif_test_bit(TIF_NEED_RESCHED_LAZY))

TIF_NEED_RESCHED_LAZY falls back to TIF_NEED_RESCHED without CONFIG_ARCH_HAS_PREEMPT_LAZY. So, you might need to add an explicit check for that as well.

With that,

Ankur

Quoted 29 lines
kernel/trace/trace.c +1 -0
+		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;
 }
kernel/trace/trace_output.c +10 -1
index 829daa0764dd9..23ca2155306b1 100644
@@ -463,17 +463,29 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
 		!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';

kernel/trace/trace_output.c int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) · line 491

Quoted 10 lines
kernel/trace/trace_output.c +3 -0
 		break;
 	case TRACE_FLAG_PREEMPT_RESCHED:
 		need_resched = 'p';
 		break;
+	case TRACE_FLAG_NEED_RESCHED_LAZY:
+		need_resched = 'l';
+		break;
 	default:
 		need_resched = '.';
 		break;

--
ankur

maintainer
#5 lore raw

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

Quoted 11 lines · On Wed, 09 Oct 2024 10:30:28 -0700 Ankur Arora <[email protected]> wrote:

kernel/trace/trace.c unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) · line 2547

Quoted 6 lines

+++ b/kernel/trace/trace.c

kernel/trace/trace.c +1 -0
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		trace_flags |= TRACE_FLAG_NEED_RESCHED;
 	if (test_preempt_need_resched())
 		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (tif_test_bit(TIF_NEED_RESCHED_LAZY))  

TIF_NEED_RESCHED_LAZY falls back to TIF_NEED_RESCHED without CONFIG_ARCH_HAS_PREEMPT_LAZY. So, you might need to add an explicit check for that as well.

Quoted 5 lines

With that,

Ankur

So this should be:

	if (IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY) &&
	    tif_test_bit(TIF_NEED_RESCHED_LAZY))

?

-- Steve

Quoted 39 lines
Quoted 39 lines
kernel/trace/trace.c +1 -0
+		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;
 }
kernel/trace/trace_output.c +13 -1
index 829daa0764dd9..23ca2155306b1 100644
@@ -463,17 +463,29 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
 		!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;  
#6 lore raw

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

Quoted 20 lines · Steven Rostedt
Quoted 11 lines · On Wed, 09 Oct 2024 10:30:28 -0700 Ankur Arora <[email protected]> wrote:

kernel/trace/trace.c unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) · line 2547

Quoted 6 lines

+++ b/kernel/trace/trace.c

kernel/trace/trace.c +1 -0
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		trace_flags |= TRACE_FLAG_NEED_RESCHED;
 	if (test_preempt_need_resched())
 		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (tif_test_bit(TIF_NEED_RESCHED_LAZY))

TIF_NEED_RESCHED_LAZY falls back to TIF_NEED_RESCHED without CONFIG_ARCH_HAS_PREEMPT_LAZY. So, you might need to add an explicit check for that as well.

Quoted 5 lines

With that,

Ankur

Quoted 6 lines

So this should be:

	if (IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY) &&
	    tif_test_bit(TIF_NEED_RESCHED_LAZY))

?

Yeah, exactly that.

--
ankur

#7 lore raw

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

Quoted 8 lines · Ankur Arora
Quoted 6 lines

So this should be:

	if (IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY) &&
	    tif_test_bit(TIF_NEED_RESCHED_LAZY))

?

Yeah, exactly that.

Okay, this makes sense, this is what I ended up with:

include/linux/trace_events.h +1 -0
index d5c0fcf20f024..4cae6f2581379 100644
@@ -185,6 +185,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status);
 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,
kernel/trace/trace.c +2 -0
index 1c69ca1f10886..fb839d00aad12 100644
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		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;
 }
kernel/trace/trace_output.c +13 -1
index 829daa0764dd9..23ca2155306b1 100644
@@ -463,17 +463,29 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
 		!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;
Signature · 4 lines
2.45.2


Sebastian
maintainer
#8 lore raw

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

kernel/trace/trace.c unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) · line 2551

Quoted 10 lines · On Thu, 10 Oct 2024 12:56:11 +0200 Sebastian Andrzej Siewior…

+++ b/kernel/trace/trace.c

kernel/trace/trace.c +2 -0
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		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;
 }

This is the only update you made from your previous version right?

If so, my reviewed-by stands.

-- Steve

#9 lore raw

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

Quoted 15 lines · Steven Rostedt

kernel/trace/trace.c unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) · line 2551

Quoted 10 lines · On Thu, 10 Oct 2024 12:56:11 +0200 Sebastian Andrzej Siewior…

+++ b/kernel/trace/trace.c

kernel/trace/trace.c +2 -0
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		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;
 }

This is the only update you made from your previous version right?

Yes.

Quoted 1 line

If so, my reviewed-by stands.

Let me add your's and Ankur's.

Quoted 1 line

-- Steve

Sebastian

#10 lore raw

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

In reply to Sebastian Andrzej Siewior
kernel test robot noticed the following build errors:

Hi Sebastian,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on rostedt-trace/for-next v6.12-rc2 next-20241011] [cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sebastian-Andrzej-Siewior/tracing-Replace-TRACE_FLAG_IRQS_NOSUPPORT-with-its-config-option/20241011-002703
base:   linus/master
patch link:    https://lore.kernel.org/r/20241009105709.887510-3-bigeasy%40linutronix.de
patch subject: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
config: arm64-randconfig-002-20241012 (https://download.01.org/0day-ci/archive/20241013/[email protected]/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241013/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> kernel/trace/trace.c:2547:6: error: call to undeclared function 'tif_test_bit'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
           if (tif_test_bit(TIF_NEED_RESCHED_LAZY))
               ^
   kernel/trace/trace.c:2547:19: error: use of undeclared identifier 'TIF_NEED_RESCHED_LAZY'
           if (tif_test_bit(TIF_NEED_RESCHED_LAZY))
                            ^

2 errors generated.

vim +/tif_test_bit +2547 kernel/trace/trace.c

2526
2527 unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
2528 {
2529 unsigned int trace_flags = irqs_status;
2530 unsigned int pc;
2531
2532 pc = preempt_count();
2533
2534 if (pc & NMI_MASK)
2535 trace_flags |= TRACE_FLAG_NMI;
2536 if (pc & HARDIRQ_MASK)
2537 trace_flags |= TRACE_FLAG_HARDIRQ;
2538 if (in_serving_softirq())
2539 trace_flags |= TRACE_FLAG_SOFTIRQ;
2540 if (softirq_count() >> (SOFTIRQ_SHIFT + 1))
2541 trace_flags |= TRACE_FLAG_BH_OFF;
2542
2543 if (tif_need_resched())
2544 trace_flags |= TRACE_FLAG_NEED_RESCHED;
2545 if (test_preempt_need_resched())
2546 trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;

> 2547		if (tif_test_bit(TIF_NEED_RESCHED_LAZY))

2548 trace_flags |= TRACE_FLAG_NEED_RESCHED_LAZY;
2549 return (trace_flags << 16) | (min_t(unsigned int, pc & 0xff, 0xf)) |
2550 (min_t(unsigned int, migration_disable_value(), 0xf)) << 4;
2551 }
2552

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw

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

In reply to Sebastian Andrzej Siewior
Quoted 62 lines · Sebastian Andrzej Siewior

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.

---
  include/linux/trace_events.h |  1 +
  kernel/trace/trace.c         |  2 ++
  kernel/trace/trace_output.c  | 14 +++++++++++++-
  3 files changed, 16 insertions(+), 1 deletion(-)
include/linux/trace_events.h +1 -0
index d5c0fcf20f024..4cae6f2581379 100644
@@ -185,6 +185,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status);
  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,
kernel/trace/trace.c +2 -0
index 1c69ca1f10886..29d7703751aa9 100644
@@ -2544,6 +2544,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
  		trace_flags |= TRACE_FLAG_NEED_RESCHED;
  	if (test_preempt_need_resched())
  		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (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;
  }
kernel/trace/trace_output.c +10 -1
index 829daa0764dd9..23ca2155306b1 100644
@@ -463,17 +463,29 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
  		!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';

kernel/trace/trace_output.c int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) · line 491

Quoted 10 lines
kernel/trace/trace_output.c +3 -0
  		break;
  	case TRACE_FLAG_PREEMPT_RESCHED:
  		need_resched = 'p';
  		break;
+	case TRACE_FLAG_NEED_RESCHED_LAZY:
+		need_resched = 'l';
+		break;
  	default:
  		need_resched = '.';
  		break;

Could you please update in Documentation/trace/ftrace.rst as well?

#12 lore raw

PATCH 3/3 riscv: add PREEMPT_LAZY support

In reply to Sebastian Andrzej Siewior

From: Jisheng Zhang <[email protected]>

riscv has switched to GENERIC_ENTRY, so adding PREEMPT_LAZY is as simple as adding TIF_NEED_RESCHED_LAZY related definitions and enabling ARCH_HAS_PREEMPT_LAZY.

[bigeasy: Replace old PREEMPT_AUTO bits with new PREEMPT_LAZY ]

---
 arch/riscv/Kconfig                   | 1 +
 arch/riscv/include/asm/thread_info.h | 2 ++
 2 files changed, 3 insertions(+)
arch/riscv/Kconfig +1 -0
index 62545946ecf43..3516c58480612 100644
@@ -39,6 +39,7 @@ config RISCV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_PMEM_API
+	select ARCH_HAS_PREEMPT_LAZY
 	select ARCH_HAS_PREPARE_SYNC_CORE_CMD
 	select ARCH_HAS_PTE_DEVMAP if 64BIT && MMU
 	select ARCH_HAS_PTE_SPECIAL
arch/riscv/include/asm/thread_info.h +2 -0
index 9c10fb180f438..8b5a5ddea4293 100644
@@ -107,6 +107,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  * - pending work-to-be-done flags are in lowest half-word
  * - other flags in upper half-word(s)
  */
+#define TIF_NEED_RESCHED_LAZY	0       /* Lazy rescheduling needed */
 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
 #define TIF_SIGPENDING		2	/* signal pending */
 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
@@ -117,6 +118,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
 #define TIF_32BIT		11	/* compat-mode 32bit process */
 #define TIF_RISCV_V_DEFER_RESTORE	12 /* restore Vector before returing to user */
 
+#define _TIF_NEED_RESCHED_LAZY	(1 << TIF_NEED_RESCHED_LAZY)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
Signature · 1 line
2.45.2
#13 lore raw

Re: [PATCH 3/3] riscv: add PREEMPT_LAZY support

Quoted 36 lines · Sebastian Andrzej Siewior

From: Jisheng Zhang <[email protected]>

riscv has switched to GENERIC_ENTRY, so adding PREEMPT_LAZY is as simple as adding TIF_NEED_RESCHED_LAZY related definitions and enabling ARCH_HAS_PREEMPT_LAZY.

[bigeasy: Replace old PREEMPT_AUTO bits with new PREEMPT_LAZY ]

---
 arch/riscv/Kconfig                   | 1 +
 arch/riscv/include/asm/thread_info.h | 2 ++
 2 files changed, 3 insertions(+)
arch/riscv/Kconfig +1 -0
index 62545946ecf43..3516c58480612 100644
@@ -39,6 +39,7 @@ config RISCV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_PMEM_API
+	select ARCH_HAS_PREEMPT_LAZY
 	select ARCH_HAS_PREPARE_SYNC_CORE_CMD
 	select ARCH_HAS_PTE_DEVMAP if 64BIT && MMU
 	select ARCH_HAS_PTE_SPECIAL
arch/riscv/include/asm/thread_info.h +0 -0
index 9c10fb180f438..8b5a5ddea4293 100644

arch/riscv/include/asm/thread_info.h int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); · line 113

Quoted 7 lines
arch/riscv/include/asm/thread_info.h +1 -0
@@ -107,6 +107,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  * - pending work-to-be-done flags are in lowest half-word
  * - other flags in upper half-word(s)
  */
+#define TIF_NEED_RESCHED_LAZY	0       /* Lazy rescheduling needed */
 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
 #define TIF_SIGPENDING		2	/* signal pending */
 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */

So for x86 I shuffled the flags around to have the two NEED_RESCHED ones side-by-side. Not strictly required ofcourse, but...

#14 lore raw

Re: [PATCH 3/3] riscv: add PREEMPT_LAZY support

Quoted 7 lines · Peter Zijlstra
Quoted 7 lines
arch/riscv/include/asm/thread_info.h +0 -0
index 9c10fb180f438..8b5a5ddea4293 100644
@@ -107,6 +107,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  * - pending work-to-be-done flags are in lowest half-word
  * - other flags in upper half-word(s)
Quoted 8 lines

arch/riscv/include/asm/thread_info.h int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); · line 113

Quoted 5 lines
arch/riscv/include/asm/thread_info.h +1 -0
  */
+#define TIF_NEED_RESCHED_LAZY	0       /* Lazy rescheduling needed */
 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
 #define TIF_SIGPENDING		2	/* signal pending */
 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */

So for x86 I shuffled the flags around to have the two NEED_RESCHED ones side-by-side. Not strictly required ofcourse, but...

I can shuffle them. I don't think the riscv camp will complain (saying this for them to actual complain if so).

Sebastian

maintainer Acked-by
#15 lore raw

Re: [PATCH 3/3] riscv: add PREEMPT_LAZY support

Quoted 17 lines · On Wed, 09 Oct 2024 06:05:30 PDT (-0700), [email protected] wrote:
Quoted 7 lines · Peter Zijlstra
Quoted 7 lines
arch/riscv/include/asm/thread_info.h +0 -0
index 9c10fb180f438..8b5a5ddea4293 100644
@@ -107,6 +107,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  * - pending work-to-be-done flags are in lowest half-word
  * - other flags in upper half-word(s)
Quoted 8 lines

arch/riscv/include/asm/thread_info.h int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); · line 113

Quoted 5 lines
arch/riscv/include/asm/thread_info.h +1 -0
  */
+#define TIF_NEED_RESCHED_LAZY	0       /* Lazy rescheduling needed */
 #define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
 #define TIF_SIGPENDING		2	/* signal pending */
 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */

So for x86 I shuffled the flags around to have the two NEED_RESCHED ones side-by-side. Not strictly required ofcourse, but...

Quoted 2 lines

I can shuffle them. I don't think the riscv camp will complain (saying this for them to actual complain if so).

#16 lore raw

PATCH v2 3/3 riscv: add PREEMPT_LAZY support

In reply to Peter Zijlstra

From: Jisheng Zhang <[email protected]>

riscv has switched to GENERIC_ENTRY, so adding PREEMPT_LAZY is as simple as adding TIF_NEED_RESCHED_LAZY related definitions and enabling ARCH_HAS_PREEMPT_LAZY.

[bigeasy: Replace old PREEMPT_AUTO bits with new PREEMPT_LAZY ]

---

v1…v2:
- shuffle TIF bits around to make RESCHED next to RESCHED_LAZY. Compiles & boots.

 arch/riscv/Kconfig                   |  1 +
 arch/riscv/include/asm/thread_info.h | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
arch/riscv/Kconfig +1 -0
index 62545946ecf43..3516c58480612 100644
@@ -39,6 +39,7 @@ config RISCV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_PMEM_API
+	select ARCH_HAS_PREEMPT_LAZY
 	select ARCH_HAS_PREPARE_SYNC_CORE_CMD
 	select ARCH_HAS_PTE_DEVMAP if 64BIT && MMU
 	select ARCH_HAS_PTE_SPECIAL
arch/riscv/include/asm/thread_info.h +6 -4
index 9c10fb180f438..f5916a70879a8 100644
@@ -107,9 +107,10 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  * - pending work-to-be-done flags are in lowest half-word
  * - other flags in upper half-word(s)
  */
-#define TIF_NOTIFY_RESUME	1	/* callback before returning to user */
-#define TIF_SIGPENDING		2	/* signal pending */
-#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
+#define TIF_NEED_RESCHED	0	/* rescheduling necessary */
+#define TIF_NEED_RESCHED_LAZY	1       /* Lazy rescheduling needed */
+#define TIF_NOTIFY_RESUME	2	/* callback before returning to user */
+#define TIF_SIGPENDING		3	/* signal pending */
 #define TIF_RESTORE_SIGMASK	4	/* restore signal mask in do_signal() */
 #define TIF_MEMDIE		5	/* is terminating due to OOM killer */
 #define TIF_NOTIFY_SIGNAL	9	/* signal notifications exist */
@@ -117,9 +118,10 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
 #define TIF_32BIT		11	/* compat-mode 32bit process */
 #define TIF_RISCV_V_DEFER_RESTORE	12 /* restore Vector before returing to user */
 
+#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
+#define _TIF_NEED_RESCHED_LAZY	(1 << TIF_NEED_RESCHED_LAZY)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
 #define _TIF_NOTIFY_SIGNAL	(1 << TIF_NOTIFY_SIGNAL)
 #define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_RISCV_V_DEFER_RESTORE	(1 << TIF_RISCV_V_DEFER_RESTORE)
Signature · 1 line
2.45.2
#17 lore raw

Re: [PATCH v2 3/3] riscv: add PREEMPT_LAZY support

This patch was applied to riscv/linux.git (fixes) by Peter Zijlstra <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Peter Zijlstra <[email protected]>:

Quoted 9 lines · On Thu, 10 Oct 2024 14:25:45 +0200 you wrote:

From: Jisheng Zhang <[email protected]>

riscv has switched to GENERIC_ENTRY, so adding PREEMPT_LAZY is as simple as adding TIF_NEED_RESCHED_LAZY related definitions and enabling ARCH_HAS_PREEMPT_LAZY.

[bigeasy: Replace old PREEMPT_AUTO bits with new PREEMPT_LAZY ]

[...]

Here is the summary with links:
- [v2,3/3] riscv: add PREEMPT_LAZY support

    https://git.kernel.org/riscv/c/22aaec357c1f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html