linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Lazy preemption leftovers
@ 2024-10-09 10:50 Sebastian Andrzej Siewior
  2024-10-09 10:50 ` [PATCH 1/3] tracing: Replace TRACE_FLAG_IRQS_NOSUPPORT with its config option Sebastian Andrzej Siewior
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-09 10:50 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel
  Cc: Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	ankur.a.arora, efault, Masami Hiramatsu, Mathieu Desnoyers

This is a followup to PeterZ'
	https://lore.kernel.org/20241007074609.447006177@infradead.org

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


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

* [PATCH 1/3] tracing: Replace TRACE_FLAG_IRQS_NOSUPPORT with its config option.
  2024-10-09 10:50 [PATCH 0/3] Lazy preemption leftovers Sebastian Andrzej Siewior
@ 2024-10-09 10:50 ` Sebastian Andrzej Siewior
  2024-10-09 10:50 ` [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY Sebastian Andrzej Siewior
  2024-10-09 10:50 ` [PATCH 3/3] riscv: add PREEMPT_LAZY support Sebastian Andrzej Siewior
  2 siblings, 0 replies; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-09 10:50 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel
  Cc: Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	ankur.a.arora, efault, Masami Hiramatsu, Mathieu Desnoyers,
	Sebastian Andrzej Siewior

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.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/trace_events.h | 7 +++----
 kernel/trace/trace_output.c  | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 42bedcddd5113..d5c0fcf20f024 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -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
 
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 868f2f912f280..829daa0764dd9 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -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 |
-- 
2.45.2


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

* [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 10:50 [PATCH 0/3] Lazy preemption leftovers Sebastian Andrzej Siewior
  2024-10-09 10:50 ` [PATCH 1/3] tracing: Replace TRACE_FLAG_IRQS_NOSUPPORT with its config option Sebastian Andrzej Siewior
@ 2024-10-09 10:50 ` Sebastian Andrzej Siewior
  2024-10-09 14:25   ` Steven Rostedt
                     ` (2 more replies)
  2024-10-09 10:50 ` [PATCH 3/3] riscv: add PREEMPT_LAZY support Sebastian Andrzej Siewior
  2 siblings, 3 replies; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-09 10:50 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel
  Cc: Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	ankur.a.arora, efault, Masami Hiramatsu, Mathieu Desnoyers,
	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.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/trace_events.h |  1 +
 kernel/trace/trace.c         |  2 ++
 kernel/trace/trace_output.c  | 14 +++++++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index d5c0fcf20f024..4cae6f2581379 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -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,
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 1c69ca1f10886..29d7703751aa9 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -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;
 }
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 829daa0764dd9..23ca2155306b1 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -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;
-- 
2.45.2


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

* [PATCH 3/3] riscv: add PREEMPT_LAZY support
  2024-10-09 10:50 [PATCH 0/3] Lazy preemption leftovers Sebastian Andrzej Siewior
  2024-10-09 10:50 ` [PATCH 1/3] tracing: Replace TRACE_FLAG_IRQS_NOSUPPORT with its config option Sebastian Andrzej Siewior
  2024-10-09 10:50 ` [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY Sebastian Andrzej Siewior
@ 2024-10-09 10:50 ` Sebastian Andrzej Siewior
  2024-10-09 13:03   ` Peter Zijlstra
  2 siblings, 1 reply; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-09 10:50 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel
  Cc: Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	ankur.a.arora, efault, Masami Hiramatsu, Mathieu Desnoyers,
	Jisheng Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	linux-riscv, Sebastian Andrzej Siewior

From: Jisheng Zhang <jszhang@kernel.org>

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 ]

Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-riscv@lists.infradead.org
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/riscv/Kconfig                   | 1 +
 arch/riscv/include/asm/thread_info.h | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 62545946ecf43..3516c58480612 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -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
diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
index 9c10fb180f438..8b5a5ddea4293 100644
--- a/arch/riscv/include/asm/thread_info.h
+++ b/arch/riscv/include/asm/thread_info.h
@@ -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)
-- 
2.45.2


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

* Re: [PATCH 3/3] riscv: add PREEMPT_LAZY support
  2024-10-09 10:50 ` [PATCH 3/3] riscv: add PREEMPT_LAZY support Sebastian Andrzej Siewior
@ 2024-10-09 13:03   ` Peter Zijlstra
  2024-10-09 13:05     ` Sebastian Andrzej Siewior
  2024-10-10 12:25     ` [PATCH v2 " Sebastian Andrzej Siewior
  0 siblings, 2 replies; 19+ messages in thread
From: Peter Zijlstra @ 2024-10-09 13:03 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-trace-kernel, linux-kernel, tglx, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, ankur.a.arora, efault, Masami Hiramatsu,
	Mathieu Desnoyers, Jisheng Zhang, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, linux-riscv

On Wed, Oct 09, 2024 at 12:50:57PM +0200, Sebastian Andrzej Siewior wrote:
> From: Jisheng Zhang <jszhang@kernel.org>
> 
> 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 ]
> 
> Cc: Paul Walmsley <paul.walmsley@sifive.com>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: linux-riscv@lists.infradead.org
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  arch/riscv/Kconfig                   | 1 +
>  arch/riscv/include/asm/thread_info.h | 2 ++
>  2 files changed, 3 insertions(+)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 62545946ecf43..3516c58480612 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -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
> diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
> index 9c10fb180f438..8b5a5ddea4293 100644
> --- a/arch/riscv/include/asm/thread_info.h
> +++ b/arch/riscv/include/asm/thread_info.h
> @@ -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...

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

* Re: [PATCH 3/3] riscv: add PREEMPT_LAZY support
  2024-10-09 13:03   ` Peter Zijlstra
@ 2024-10-09 13:05     ` Sebastian Andrzej Siewior
  2024-10-17 21:49       ` Palmer Dabbelt
  2024-10-10 12:25     ` [PATCH v2 " Sebastian Andrzej Siewior
  1 sibling, 1 reply; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-09 13:05 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-trace-kernel, linux-kernel, tglx, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, ankur.a.arora, efault, Masami Hiramatsu,
	Mathieu Desnoyers, Jisheng Zhang, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, linux-riscv

On 2024-10-09 15:03:07 [+0200], Peter Zijlstra wrote:
> > diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
> > index 9c10fb180f438..8b5a5ddea4293 100644
> > --- a/arch/riscv/include/asm/thread_info.h
> > +++ b/arch/riscv/include/asm/thread_info.h
> > @@ -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...

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

Sebastian

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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 10:50 ` [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY Sebastian Andrzej Siewior
@ 2024-10-09 14:25   ` Steven Rostedt
  2024-10-09 17:30   ` Ankur Arora
  2024-10-16  9:17   ` Shrikanth Hegde
  2 siblings, 0 replies; 19+ messages in thread
From: Steven Rostedt @ 2024-10-09 14:25 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-trace-kernel, linux-kernel, Peter Zijlstra, tglx, mingo,
	juri.lelli, vincent.guittot, dietmar.eggemann, bsegall, mgorman,
	vschneid, ankur.a.arora, efault, Masami Hiramatsu,
	Mathieu Desnoyers

On Wed,  9 Oct 2024 12:50:56 +0200
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> 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.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

> ---
>  include/linux/trace_events.h |  1 +
>  kernel/trace/trace.c         |  2 ++
>  kernel/trace/trace_output.c  | 14 +++++++++++++-
>  3 files changed, 16 insertions(+), 1 deletion(-)


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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 10:50 ` [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY Sebastian Andrzej Siewior
  2024-10-09 14:25   ` Steven Rostedt
@ 2024-10-09 17:30   ` Ankur Arora
  2024-10-09 17:33     ` Steven Rostedt
  2024-10-16  9:17   ` Shrikanth Hegde
  2 siblings, 1 reply; 19+ messages in thread
From: Ankur Arora @ 2024-10-09 17:30 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-trace-kernel, linux-kernel, Peter Zijlstra, tglx, mingo,
	juri.lelli, vincent.guittot, dietmar.eggemann, rostedt, bsegall,
	mgorman, vschneid, ankur.a.arora, efault, Masami Hiramatsu,
	Mathieu Desnoyers


Sebastian Andrzej Siewior <bigeasy@linutronix.de> writes:

> 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.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  include/linux/trace_events.h |  1 +
>  kernel/trace/trace.c         |  2 ++
>  kernel/trace/trace_output.c  | 14 +++++++++++++-
>  3 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
> index d5c0fcf20f024..4cae6f2581379 100644
> --- a/include/linux/trace_events.h
> +++ b/include/linux/trace_events.h
> @@ -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,
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 1c69ca1f10886..29d7703751aa9 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -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,
 Reviewed-by: Ankur Arora <ankur.a.arora@oracle.com>

Ankur

> +		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;
>  }
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 829daa0764dd9..23ca2155306b1 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -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;


--
ankur

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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 17:30   ` Ankur Arora
@ 2024-10-09 17:33     ` Steven Rostedt
  2024-10-09 18:49       ` Ankur Arora
  0 siblings, 1 reply; 19+ messages in thread
From: Steven Rostedt @ 2024-10-09 17:33 UTC (permalink / raw)
  To: Ankur Arora
  Cc: Sebastian Andrzej Siewior, linux-trace-kernel, linux-kernel,
	Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, bsegall, mgorman, vschneid, efault,
	Masami Hiramatsu, Mathieu Desnoyers

On Wed, 09 Oct 2024 10:30:28 -0700
Ankur Arora <ankur.a.arora@oracle.com> wrote:

> > +++ b/kernel/trace/trace.c
> > @@ -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,
>  Reviewed-by: Ankur Arora <ankur.a.arora@oracle.com>
> 
> Ankur
> 

So this should be:

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

?

-- Steve


> > +		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;
> >  }
> > diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> > index 829daa0764dd9..23ca2155306b1 100644
> > --- a/kernel/trace/trace_output.c
> > +++ b/kernel/trace/trace_output.c
> > @@ -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;  

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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 17:33     ` Steven Rostedt
@ 2024-10-09 18:49       ` Ankur Arora
  2024-10-10 10:56         ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 19+ messages in thread
From: Ankur Arora @ 2024-10-09 18:49 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Ankur Arora, Sebastian Andrzej Siewior, linux-trace-kernel,
	linux-kernel, Peter Zijlstra, tglx, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, bsegall, mgorman, vschneid,
	efault, Masami Hiramatsu, Mathieu Desnoyers


Steven Rostedt <rostedt@goodmis.org> writes:

> On Wed, 09 Oct 2024 10:30:28 -0700
> Ankur Arora <ankur.a.arora@oracle.com> wrote:
>
>> > +++ b/kernel/trace/trace.c
>> > @@ -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,
>>  Reviewed-by: Ankur Arora <ankur.a.arora@oracle.com>
>>
>> Ankur
>>
>
> So this should be:
>
> 	if (IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY) &&
> 	    tif_test_bit(TIF_NEED_RESCHED_LAZY))
>
> ?

Yeah, exactly that.

--
ankur

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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 18:49       ` Ankur Arora
@ 2024-10-10 10:56         ` Sebastian Andrzej Siewior
  2024-10-10 14:52           ` Steven Rostedt
  0 siblings, 1 reply; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-10 10:56 UTC (permalink / raw)
  To: Ankur Arora
  Cc: Steven Rostedt, linux-trace-kernel, linux-kernel, Peter Zijlstra,
	tglx, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
	bsegall, mgorman, vschneid, efault, Masami Hiramatsu,
	Mathieu Desnoyers

On 2024-10-09 11:49:41 [-0700], Ankur Arora wrote:
> > 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:

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index d5c0fcf20f024..4cae6f2581379 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -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,
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 1c69ca1f10886..fb839d00aad12 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -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;
 }
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 829daa0764dd9..23ca2155306b1 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -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;
-- 
2.45.2


Sebastian

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

* [PATCH v2 3/3] riscv: add PREEMPT_LAZY support
  2024-10-09 13:03   ` Peter Zijlstra
  2024-10-09 13:05     ` Sebastian Andrzej Siewior
@ 2024-10-10 12:25     ` Sebastian Andrzej Siewior
  2024-12-11 22:32       ` patchwork-bot+linux-riscv
  1 sibling, 1 reply; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-10 12:25 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-trace-kernel, linux-kernel, tglx, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, ankur.a.arora, efault, Masami Hiramatsu,
	Mathieu Desnoyers, Jisheng Zhang, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, linux-riscv

From: Jisheng Zhang <jszhang@kernel.org>

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 ]

Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-riscv@lists.infradead.org
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---

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(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 62545946ecf43..3516c58480612 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -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
diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
index 9c10fb180f438..f5916a70879a8 100644
--- a/arch/riscv/include/asm/thread_info.h
+++ b/arch/riscv/include/asm/thread_info.h
@@ -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)
-- 
2.45.2


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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-10 10:56         ` Sebastian Andrzej Siewior
@ 2024-10-10 14:52           ` Steven Rostedt
  2024-10-10 14:55             ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 19+ messages in thread
From: Steven Rostedt @ 2024-10-10 14:52 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Ankur Arora, linux-trace-kernel, linux-kernel, Peter Zijlstra,
	tglx, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
	bsegall, mgorman, vschneid, efault, Masami Hiramatsu,
	Mathieu Desnoyers

On Thu, 10 Oct 2024 12:56:11 +0200
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> +++ b/kernel/trace/trace.c
> @@ -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

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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-10 14:52           ` Steven Rostedt
@ 2024-10-10 14:55             ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-10 14:55 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Ankur Arora, linux-trace-kernel, linux-kernel, Peter Zijlstra,
	tglx, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
	bsegall, mgorman, vschneid, efault, Masami Hiramatsu,
	Mathieu Desnoyers

On 2024-10-10 10:52:14 [-0400], Steven Rostedt wrote:
> On Thu, 10 Oct 2024 12:56:11 +0200
> Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> 
> > +++ b/kernel/trace/trace.c
> > @@ -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.

> If so, my reviewed-by stands.

Let me add your's and Ankur's.

> -- Steve

Sebastian

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

* Re: [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY.
  2024-10-09 10:50 ` [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY Sebastian Andrzej Siewior
  2024-10-09 14:25   ` Steven Rostedt
  2024-10-09 17:30   ` Ankur Arora
@ 2024-10-16  9:17   ` Shrikanth Hegde
  2 siblings, 0 replies; 19+ messages in thread
From: Shrikanth Hegde @ 2024-10-16  9:17 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-trace-kernel, linux-kernel
  Cc: Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	ankur.a.arora, efault, Masami Hiramatsu, Mathieu Desnoyers



On 10/9/24 16:20, Sebastian Andrzej Siewior wrote:
> 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.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>   include/linux/trace_events.h |  1 +
>   kernel/trace/trace.c         |  2 ++
>   kernel/trace/trace_output.c  | 14 +++++++++++++-
>   3 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
> index d5c0fcf20f024..4cae6f2581379 100644
> --- a/include/linux/trace_events.h
> +++ b/include/linux/trace_events.h
> @@ -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,
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 1c69ca1f10886..29d7703751aa9 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -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;
>   }
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 829daa0764dd9..23ca2155306b1 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -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;


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

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

* Re: [PATCH 3/3] riscv: add PREEMPT_LAZY support
  2024-10-09 13:05     ` Sebastian Andrzej Siewior
@ 2024-10-17 21:49       ` Palmer Dabbelt
  0 siblings, 0 replies; 19+ messages in thread
From: Palmer Dabbelt @ 2024-10-17 21:49 UTC (permalink / raw)
  To: bigeasy
  Cc: peterz, linux-trace-kernel, linux-kernel, tglx, mingo, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, ankur.a.arora, efault, mhiramat, mathieu.desnoyers,
	jszhang, Paul Walmsley, aou, linux-riscv

On Wed, 09 Oct 2024 06:05:30 PDT (-0700), bigeasy@linutronix.de wrote:
> On 2024-10-09 15:03:07 [+0200], Peter Zijlstra wrote:
>> > diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
>> > index 9c10fb180f438..8b5a5ddea4293 100644
>> > --- a/arch/riscv/include/asm/thread_info.h
>> > +++ b/arch/riscv/include/asm/thread_info.h
>> > @@ -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...
>
> I can shuffle them. I don't think the riscv camp will complain (saying
> this for them to actual complain if so).

Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

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

* [PATCH v2 3/3] riscv: add PREEMPT_LAZY support
  2024-10-21 15:08 [PATCH v2 0/3] Lazy preemption leftovers Sebastian Andrzej Siewior
@ 2024-10-21 15:08 ` Sebastian Andrzej Siewior
  2024-12-11 22:32   ` patchwork-bot+linux-riscv
  0 siblings, 1 reply; 19+ messages in thread
From: Sebastian Andrzej Siewior @ 2024-10-21 15:08 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel
  Cc: Peter Zijlstra, tglx, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	ankur.a.arora, efault, Masami Hiramatsu, Mathieu Desnoyers,
	Jisheng Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	linux-riscv, Palmer Dabbelt, Sebastian Andrzej Siewior

From: Jisheng Zhang <jszhang@kernel.org>

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 ]

Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-riscv@lists.infradead.org
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/riscv/Kconfig                   |    1 +
 arch/riscv/include/asm/thread_info.h |   10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -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
--- a/arch/riscv/include/asm/thread_info.h
+++ b/arch/riscv/include/asm/thread_info.h
@@ -107,9 +107,10 @@ int arch_dup_task_struct(struct task_str
  * - 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_str
 #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)

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

* Re: [PATCH v2 3/3] riscv: add PREEMPT_LAZY support
  2024-10-10 12:25     ` [PATCH v2 " Sebastian Andrzej Siewior
@ 2024-12-11 22:32       ` patchwork-bot+linux-riscv
  0 siblings, 0 replies; 19+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-12-11 22:32 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-riscv, peterz, linux-trace-kernel, linux-kernel, tglx,
	mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, vschneid, ankur.a.arora, efault, mhiramat,
	mathieu.desnoyers, jszhang, paul.walmsley, palmer, aou

Hello:

This patch was applied to riscv/linux.git (fixes)
by Peter Zijlstra <peterz@infradead.org>:

On Thu, 10 Oct 2024 14:25:45 +0200 you wrote:
> From: Jisheng Zhang <jszhang@kernel.org>
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH v2 3/3] riscv: add PREEMPT_LAZY support
  2024-10-21 15:08 ` [PATCH v2 3/3] riscv: add PREEMPT_LAZY support Sebastian Andrzej Siewior
@ 2024-12-11 22:32   ` patchwork-bot+linux-riscv
  0 siblings, 0 replies; 19+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-12-11 22:32 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-riscv, linux-trace-kernel, linux-kernel, peterz, tglx,
	mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, vschneid, ankur.a.arora, efault, mhiramat,
	mathieu.desnoyers, jszhang, paul.walmsley, palmer, aou, palmer

Hello:

This patch was applied to riscv/linux.git (fixes)
by Peter Zijlstra <peterz@infradead.org>:

On Mon, 21 Oct 2024 17:08:42 +0200 you wrote:
> From: Jisheng Zhang <jszhang@kernel.org>
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-12-11 22:32 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 10:50 [PATCH 0/3] Lazy preemption leftovers Sebastian Andrzej Siewior
2024-10-09 10:50 ` [PATCH 1/3] tracing: Replace TRACE_FLAG_IRQS_NOSUPPORT with its config option Sebastian Andrzej Siewior
2024-10-09 10:50 ` [PATCH 2/3] tracing: Record task flag NEED_RESCHED_LAZY Sebastian Andrzej Siewior
2024-10-09 14:25   ` Steven Rostedt
2024-10-09 17:30   ` Ankur Arora
2024-10-09 17:33     ` Steven Rostedt
2024-10-09 18:49       ` Ankur Arora
2024-10-10 10:56         ` Sebastian Andrzej Siewior
2024-10-10 14:52           ` Steven Rostedt
2024-10-10 14:55             ` Sebastian Andrzej Siewior
2024-10-16  9:17   ` Shrikanth Hegde
2024-10-09 10:50 ` [PATCH 3/3] riscv: add PREEMPT_LAZY support Sebastian Andrzej Siewior
2024-10-09 13:03   ` Peter Zijlstra
2024-10-09 13:05     ` Sebastian Andrzej Siewior
2024-10-17 21:49       ` Palmer Dabbelt
2024-10-10 12:25     ` [PATCH v2 " Sebastian Andrzej Siewior
2024-12-11 22:32       ` patchwork-bot+linux-riscv
  -- strict thread matches above, loose matches on Subject: below --
2024-10-21 15:08 [PATCH v2 0/3] Lazy preemption leftovers Sebastian Andrzej Siewior
2024-10-21 15:08 ` [PATCH v2 3/3] riscv: add PREEMPT_LAZY support Sebastian Andrzej Siewior
2024-12-11 22:32   ` patchwork-bot+linux-riscv

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).