public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Cc: Ben Segall <bsegall@google.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>, Mel Gorman <mgorman@suse.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Will Deacon <will@kernel.org>
Subject: Re: [PATCH v2 1/9] sched: Add a generic function to return the preemption string.
Date: Sat, 8 Feb 2025 13:31:27 +0530	[thread overview]
Message-ID: <0d4418ab-d531-413c-bbbd-6c97ea320490@linux.ibm.com> (raw)
In-Reply-To: <20250203141632.440554-2-bigeasy@linutronix.de>



On 2/3/25 19:46, Sebastian Andrzej Siewior wrote:
> The individual architectures often add the preemption model to the begin
> of the backtrace. This is the case on X86 or ARM64 for the "die" case
> but not for regular warning. With the addition of DYNAMIC_PREEMPT for
> PREEMPT_RT we end up with CONFIG_PREEMPT and CONFIG_PREEMPT_RT set
> simultaneously. That means that everyone who tried to add that piece of
> information gets it wrong for PREEMPT_RT because PREEMPT is checked
> first.
> 
> Provide a generic function which returns the current scheduling model
> considering LAZY preempt and the current state of PREEMPT_DYNAMIC.
> [ The dynamic building of the string can lead to an empty string if the
>    function is invoked simultaneously on two CPUs. ]
> 
> Co-developed-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Co-developed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>   include/linux/preempt.h |  2 ++
>   kernel/sched/core.c     | 47 +++++++++++++++++++++++++++++++++++++++++
>   kernel/sched/debug.c    | 10 +++++----
>   kernel/sched/sched.h    |  1 +
>   4 files changed, 56 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/preempt.h b/include/linux/preempt.h
> index ca86235ac15c0..3e9808f2b5491 100644
> --- a/include/linux/preempt.h
> +++ b/include/linux/preempt.h
> @@ -515,6 +515,8 @@ static inline bool preempt_model_rt(void)
>   	return IS_ENABLED(CONFIG_PREEMPT_RT);
>   }
>   
> +extern const char *preempt_model_str(void);
> +
>   /*
>    * Does the preemption model allow non-cooperative preemption?
>    *
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 165c90ba64ea9..bd2664755b09a 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7646,10 +7646,57 @@ PREEMPT_MODEL_ACCESSOR(lazy);
>   
>   #else /* !CONFIG_PREEMPT_DYNAMIC: */
>   
> +#define preempt_dynamic_mode -1
> +
>   static inline void preempt_dynamic_init(void) { }
>   
>   #endif /* CONFIG_PREEMPT_DYNAMIC */
>   
> +const char *preempt_modes[] = {
> +	"none", "voluntary", "full", "lazy", NULL,
> +};
> +
> +const char *preempt_model_str(void)
> +{
> +	bool brace = IS_ENABLED(CONFIG_PREEMPT_RT) &&
> +		(IS_ENABLED(CONFIG_PREEMPT_DYNAMIC) ||
> +		 IS_ENABLED(CONFIG_PREEMPT_LAZY));
> +	static char buf[128];
> +
> +	if (IS_ENABLED(CONFIG_PREEMPT_BUILD)) {
> +		struct seq_buf s;
> +
> +		seq_buf_init(&s, buf, 128);
> +		seq_buf_puts(&s, "PREEMPT");
> +
> +		if (IS_ENABLED(CONFIG_PREEMPT_RT))
> +			seq_buf_printf(&s, "%sRT%s",
> +				       brace ? "_{" : "_",
> +				       brace ? "," : "");
> +
> +		if (IS_ENABLED(CONFIG_PREEMPT_DYNAMIC)) {
> +			seq_buf_printf(&s, "(%s)%s",
> +				       preempt_dynamic_mode > 0 ?
> +				       preempt_modes[preempt_dynamic_mode] : "undef",
> +				       brace ? "}" : "");
> +			return seq_buf_str(&s);
> +		}
> +
> +		if (IS_ENABLED(CONFIG_PREEMPT_LAZY)) {
> +			seq_buf_printf(&s, "LAZY%s",
> +				       brace ? "}" : "");
> +			return seq_buf_str(&s);
> +		}
> +
> +		return seq_buf_str(&s);
> +	}
> +
> +	if (IS_ENABLED(CONFIG_PREEMPT_VOLUNTARY_BUILD))
> +		return "VOLUNTARY";
> +
> +	return "NONE";
> +}

nit: This means when it preempt=full, it is going to show PREEMPT or 
PREEMPT_RT. Maybe that could be put into changelog or add code similar 
to lazy for full as well, so it is easier for user to know if it is in 
preempt=full model. In all other models, there is a suffix like 
PREEMPTLAZY. Dynamic modes looks good.

Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>

> +
>   int io_schedule_prepare(void)
>   {
>   	int old_iowait = current->in_iowait;
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index fd7e852207157..755232ac88de9 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -244,11 +244,13 @@ static ssize_t sched_dynamic_write(struct file *filp, const char __user *ubuf,
>   
>   static int sched_dynamic_show(struct seq_file *m, void *v)
>   {
> -	static const char * preempt_modes[] = {
> -		"none", "voluntary", "full", "lazy",
> -	};
> -	int j = ARRAY_SIZE(preempt_modes) - !IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY);
>   	int i = IS_ENABLED(CONFIG_PREEMPT_RT) * 2;
> +	int j;
> +
> +	/* Count entries in NULL terminated preempt_modes */
> +	for (j = 0; preempt_modes[j]; j++)
> +		;
> +	j -= !IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY);
>   
>   	for (; i < j; i++) {
>   		if (preempt_dynamic_mode == i)
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 38e0e323dda26..fb4486ceb978a 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -3619,6 +3619,7 @@ extern int preempt_dynamic_mode;
>   extern int sched_dynamic_mode(const char *str);
>   extern void sched_dynamic_update(int mode);
>   #endif
> +extern const char *preempt_modes[];
>   
>   #ifdef CONFIG_SCHED_MM_CID
>   


  reply	other threads:[~2025-02-08  8:01 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03 14:16 [PATCH v2 0/9] preempt: Add a generic function to return the preemption string Sebastian Andrzej Siewior
2025-02-03 14:16 ` [PATCH v2 1/9] sched: " Sebastian Andrzej Siewior
2025-02-08  8:01   ` Shrikanth Hegde [this message]
2025-02-10 10:52     ` Sebastian Andrzej Siewior
2025-02-10 14:21       ` Shrikanth Hegde
2025-02-10 14:25         ` Sebastian Andrzej Siewior
2025-02-03 14:16 ` [PATCH v2 2/9] lib/dump_stack: Use preempt_model_str() Sebastian Andrzej Siewior
2025-02-03 14:16 ` [PATCH v2 3/9] arm: Rely on generic printing of preemption model Sebastian Andrzej Siewior
2025-02-10 12:04   ` Sebastian Andrzej Siewior
2025-02-10 15:16     ` Russell King (Oracle)
2025-02-10 15:39       ` Sebastian Andrzej Siewior
2025-02-10 16:26         ` Russell King (Oracle)
2025-02-11 14:52           ` Sebastian Andrzej Siewior
2025-02-11 15:05             ` Russell King (Oracle)
2025-02-11 15:21               ` Sebastian Andrzej Siewior
2025-02-03 14:16 ` [PATCH v2 4/9] arm64: " Sebastian Andrzej Siewior
2025-02-10 12:05   ` Sebastian Andrzej Siewior
2025-02-10 15:03     ` Will Deacon
2025-02-03 14:16 ` [PATCH v2 5/9] powerpc: Use preempt_model_str() Sebastian Andrzej Siewior
2025-02-03 15:19   ` Christophe Leroy
2025-02-03 16:01     ` Sebastian Andrzej Siewior
2025-02-03 16:37       ` Christophe Leroy
2025-02-04  8:22         ` [PATCH v3 " Sebastian Andrzej Siewior
2025-02-05  6:48           ` Christophe Leroy
2025-02-08  7:35           ` Shrikanth Hegde
2025-02-08 12:55             ` Christophe Leroy
2025-02-08 13:42               ` Shrikanth Hegde
2025-02-08 17:55                 ` Christophe Leroy
2025-02-09 14:38                   ` Shrikanth Hegde
2025-02-09 18:42                     ` Christophe Leroy
2025-02-10 10:59             ` Sebastian Andrzej Siewior
2025-02-10 14:23               ` Sebastian Andrzej Siewior
2025-02-10 17:32                 ` Shrikanth Hegde
2025-02-03 14:16 ` [PATCH v2 6/9] s390: Rely on generic printing of preemption model Sebastian Andrzej Siewior
2025-02-03 14:28   ` Heiko Carstens
2025-02-03 14:16 ` [PATCH v2 7/9] x86: " Sebastian Andrzej Siewior
2025-02-10 12:06   ` Sebastian Andrzej Siewior
2025-02-03 14:16 ` [PATCH v2 8/9] xtensa: Use preempt_model_str() Sebastian Andrzej Siewior
2025-02-03 17:55   ` Max Filippov
2025-02-03 14:16 ` [PATCH v2 9/9] tracing: " Sebastian Andrzej Siewior
2025-02-03 17:20   ` Steven Rostedt
2025-02-03 14:25 ` [PATCH v2 0/9] preempt: Add a generic function to return the preemption string Peter Zijlstra
2025-02-03 14:39   ` Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d4418ab-d531-413c-bbbd-6c97ea320490@linux.ibm.com \
    --to=sshegde@linux.ibm.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox