2024-02-13 05:58:50

by Ankur Arora

[permalink] [raw]
Subject: [PATCH 02/30] thread_info: selector for TIF_NEED_RESCHED[_LAZY]

Define tif_resched() to serve as selector for the specific
need-resched flag: tif_resched(NR_now) mapping to TIF_NEED_RESCHED
and tif_resched(NR_lazy) to TIF_NEED_RESCHED_LAZY.

Note that, for !CONFIG_PREEMPT_AUTO, tif_resched() always evaluates
to TIF_NEED_RESCHED, preserving existing scheduling behaviour.

Cc: Peter Ziljstra <[email protected]>
Originally-by: Thomas Gleixner <[email protected]>
Link: https://lore.kernel.org/lkml/87jzshhexi.ffs@tglx/
Signed-off-by: Ankur Arora <[email protected]>
---
include/linux/thread_info.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 7b1d9185aac6..99043cbbb6b0 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -67,6 +67,30 @@ enum syscall_work_bit {
#define _TIF_NEED_RESCHED_LAZY _TIF_NEED_RESCHED
#endif

+#define TIF_NEED_RESCHED_LAZY_OFFSET (TIF_NEED_RESCHED_LAZY - TIF_NEED_RESCHED)
+
+typedef enum {
+ NR_now = 0,
+ NR_lazy = 1,
+} resched_t;
+
+/*
+ * tif_resched(r) maps to TIF_NEED_RESCHED[_LAZY] with CONFIG_PREEMPT_AUTO.
+ *
+ * With !CONFIG_PREEMPT_AUTO, both tif_resched(NR_now) and tif_resched(NR_lazy)
+ * reduce to the same value (TIF_NEED_RESCHED) leaving any scheduling behaviour
+ * unchanged.
+ */
+static inline int tif_resched(resched_t rs)
+{
+ return TIF_NEED_RESCHED + rs * TIF_NEED_RESCHED_LAZY_OFFSET;
+}
+
+static inline int _tif_resched(resched_t rs)
+{
+ return 1 << tif_resched(rs);
+}
+
#ifdef __KERNEL__

#ifndef arch_set_restart_data
--
2.31.1



2024-02-19 15:17:41

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 02/30] thread_info: selector for TIF_NEED_RESCHED[_LAZY]

On Mon, Feb 12 2024 at 21:55, Ankur Arora wrote:
>
> +#define TIF_NEED_RESCHED_LAZY_OFFSET (TIF_NEED_RESCHED_LAZY - TIF_NEED_RESCHED)
> +
> +typedef enum {
> + NR_now = 0,
> + NR_lazy = 1,

Just a nitpick. Please don't camel case the constant. Can you please
write out NEED_RESCHED_* as NR is generally associated with number?

Thanks,

tglx

2024-02-20 22:52:20

by Ankur Arora

[permalink] [raw]
Subject: Re: [PATCH 02/30] thread_info: selector for TIF_NEED_RESCHED[_LAZY]


Thomas Gleixner <[email protected]> writes:

> On Mon, Feb 12 2024 at 21:55, Ankur Arora wrote:
>>
>> +#define TIF_NEED_RESCHED_LAZY_OFFSET (TIF_NEED_RESCHED_LAZY - TIF_NEED_RESCHED)
>> +
>> +typedef enum {
>> + NR_now = 0,
>> + NR_lazy = 1,
>
> Just a nitpick. Please don't camel case the constant. Can you please
> write out NEED_RESCHED_* as NR is generally associated with number?

That's a good point. But,

__set_tsk_need_resched(NEED_RESCHED_LAZY/_NOW), or
__tif_need_resched(NEED_RESCHED_LAZY/_NOW) seems a little repetitive.
Plus, there's the risk of confusing it with the TIF_NEED_RESCHED_LAZY
flag.

How about, something like this?

+typedef enum {
+ RESCHED_NOW = 0,
+ RESCHED_LAZY = 1,
+} resched_t;

Still, not ideal. But I think it's an improvement over those two.


Thanks

--
ankur

2024-02-21 17:05:16

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 02/30] thread_info: selector for TIF_NEED_RESCHED[_LAZY]

On Tue, Feb 20 2024 at 14:50, Ankur Arora wrote:
> How about, something like this?
>
> +typedef enum {
> + RESCHED_NOW = 0,
> + RESCHED_LAZY = 1,
> +} resched_t;
>
> Still, not ideal. But I think it's an improvement over those two.

Fine with me.

2024-02-21 18:36:42

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 02/30] thread_info: selector for TIF_NEED_RESCHED[_LAZY]

On Mon, 12 Feb 2024 21:55:26 -0800
Ankur Arora <[email protected]> wrote:

> +/*
> + * tif_resched(r) maps to TIF_NEED_RESCHED[_LAZY] with CONFIG_PREEMPT_AUTO.
> + *
> + * With !CONFIG_PREEMPT_AUTO, both tif_resched(NR_now) and tif_resched(NR_lazy)
> + * reduce to the same value (TIF_NEED_RESCHED) leaving any scheduling behaviour
> + * unchanged.
> + */
> +static inline int tif_resched(resched_t rs)
> +{
> + return TIF_NEED_RESCHED + rs * TIF_NEED_RESCHED_LAZY_OFFSET;
> +}
> +
> +static inline int _tif_resched(resched_t rs)
> +{
> + return 1 << tif_resched(rs);
> +}
> +

This may have been mentioned in another thread (don't remember) but please
make the above __always_inline, as that also matches tif_need_resched() as
it is today.

-- Steve

2024-02-21 20:04:09

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 02/30] thread_info: selector for TIF_NEED_RESCHED[_LAZY]

On Wed, Feb 21 2024 at 13:26, Steven Rostedt wrote:
> On Mon, 12 Feb 2024 21:55:26 -0800
> Ankur Arora <[email protected]> wrote:
>
>> +/*
>> + * tif_resched(r) maps to TIF_NEED_RESCHED[_LAZY] with CONFIG_PREEMPT_AUTO.
>> + *
>> + * With !CONFIG_PREEMPT_AUTO, both tif_resched(NR_now) and tif_resched(NR_lazy)
>> + * reduce to the same value (TIF_NEED_RESCHED) leaving any scheduling behaviour
>> + * unchanged.
>> + */
>> +static inline int tif_resched(resched_t rs)
>> +{
>> + return TIF_NEED_RESCHED + rs * TIF_NEED_RESCHED_LAZY_OFFSET;
>> +}
>> +
>> +static inline int _tif_resched(resched_t rs)
>> +{
>> + return 1 << tif_resched(rs);
>> +}
>> +
>
> This may have been mentioned in another thread (don't remember) but please
> make the above __always_inline, as that also matches tif_need_resched() as
> it is today.

It's required as this is used in noinstr sections.