linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] sched_ext: Improve code modularization
@ 2025-06-04 14:33 Andrea Righi
  2025-06-04 14:33 ` [PATCH 1/4] sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node() Andrea Righi
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-04 14:33 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel

Despite the unusual structure of the scheduler code, where the source code
of all scheduler classes is included in a single .c file, we should still
structure the code as if each .c file were a standalone build unit. This
means marking internal functions as static, declaring shared symbols via
proper function prototypes in a header file, etc.

This patch series is a first step toward such cleanup for the sched_ext
code. There is more work to do, but these changes are intentionally small
to minimize potential disruption to the ongoing development, laying some
groundwork for a cleaner and more maintainable code.

Andrea Righi (4):
      sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node()
      sched_ext: idle: Make local functions static in ext_idle.c
      sched_ext: Make scx_rq_bypassing() inline
      sched_ext: Make scx_locked_rq() shared

 kernel/sched/ext.c      |  7 +------
 kernel/sched/ext.h      |  7 +++++++
 kernel/sched/ext_idle.c | 28 +++++++++++++++++-----------
 kernel/sched/ext_idle.h |  7 -------
 4 files changed, 25 insertions(+), 24 deletions(-)

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

* [PATCH 1/4] sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node()
  2025-06-04 14:33 [PATCH 0/4] sched_ext: Improve code modularization Andrea Righi
@ 2025-06-04 14:33 ` Andrea Righi
  2025-06-04 14:33 ` [PATCH 2/4] sched_ext: idle: Make local functions static in ext_idle.c Andrea Righi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-04 14:33 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel

There's no need to make scx_bpf_cpu_node() dependent on CONFIG_NUMA,
since cpu_to_node() can be used also in systems with CONFIG_NUMA
disabled.

This also allows to always validate the @cpu argument regardless of the
CONFIG_NUMA settings.

Fixes: 01059219b0cfd ("sched_ext: idle: Introduce node-aware idle cpu kfunc helpers")
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext_idle.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c
index 6d29d3cbc6707..1598681b681e7 100644
--- a/kernel/sched/ext_idle.c
+++ b/kernel/sched/ext_idle.c
@@ -929,14 +929,10 @@ s32 select_cpu_from_kfunc(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
  */
 __bpf_kfunc int scx_bpf_cpu_node(s32 cpu)
 {
-#ifdef CONFIG_NUMA
 	if (!kf_cpu_valid(cpu, NULL))
 		return NUMA_NO_NODE;
 
 	return cpu_to_node(cpu);
-#else
-	return 0;
-#endif
 }
 
 /**
-- 
2.49.0


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

* [PATCH 2/4] sched_ext: idle: Make local functions static in ext_idle.c
  2025-06-04 14:33 [PATCH 0/4] sched_ext: Improve code modularization Andrea Righi
  2025-06-04 14:33 ` [PATCH 1/4] sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node() Andrea Righi
@ 2025-06-04 14:33 ` Andrea Righi
  2025-06-04 14:33 ` [PATCH 3/4] sched_ext: Make scx_rq_bypassing() inline Andrea Righi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-04 14:33 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel

Functions that are only used within ext_idle.c can be marked as static
to limit their scope.

No functional changes.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext_idle.c | 24 +++++++++++++++++-------
 kernel/sched/ext_idle.h |  7 -------
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c
index 1598681b681e7..17802693e3043 100644
--- a/kernel/sched/ext_idle.c
+++ b/kernel/sched/ext_idle.c
@@ -75,7 +75,7 @@ static int scx_cpu_node_if_enabled(int cpu)
 	return cpu_to_node(cpu);
 }
 
-bool scx_idle_test_and_clear_cpu(int cpu)
+static bool scx_idle_test_and_clear_cpu(int cpu)
 {
 	int node = scx_cpu_node_if_enabled(cpu);
 	struct cpumask *idle_cpus = idle_cpumask(node)->cpu;
@@ -198,7 +198,7 @@ pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, int node, u6
 /*
  * Find an idle CPU in the system, starting from @node.
  */
-s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node, u64 flags)
+static s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node, u64 flags)
 {
 	s32 cpu;
 
@@ -794,6 +794,16 @@ static void reset_idle_masks(struct sched_ext_ops *ops)
 		cpumask_and(idle_cpumask(node)->smt, cpu_online_mask, node_mask);
 	}
 }
+#else	/* !CONFIG_SMP */
+static bool scx_idle_test_and_clear_cpu(int cpu)
+{
+	return -EBUSY;
+}
+
+static s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node, u64 flags)
+{
+	return -EBUSY;
+}
 #endif	/* CONFIG_SMP */
 
 void scx_idle_enable(struct sched_ext_ops *ops)
@@ -860,8 +870,8 @@ static bool check_builtin_idle_enabled(void)
 	return false;
 }
 
-s32 select_cpu_from_kfunc(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
-			  const struct cpumask *allowed, u64 flags)
+static s32 select_cpu_from_kfunc(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
+				 const struct cpumask *allowed, u64 flags)
 {
 	struct rq *rq;
 	struct rq_flags rf;
@@ -1121,10 +1131,10 @@ __bpf_kfunc bool scx_bpf_test_and_clear_cpu_idle(s32 cpu)
 	if (!check_builtin_idle_enabled())
 		return false;
 
-	if (kf_cpu_valid(cpu, NULL))
-		return scx_idle_test_and_clear_cpu(cpu);
-	else
+	if (!kf_cpu_valid(cpu, NULL))
 		return false;
+
+	return scx_idle_test_and_clear_cpu(cpu);
 }
 
 /**
diff --git a/kernel/sched/ext_idle.h b/kernel/sched/ext_idle.h
index 37be78a7502b3..05e389ed72e4c 100644
--- a/kernel/sched/ext_idle.h
+++ b/kernel/sched/ext_idle.h
@@ -15,16 +15,9 @@ struct sched_ext_ops;
 #ifdef CONFIG_SMP
 void scx_idle_update_selcpu_topology(struct sched_ext_ops *ops);
 void scx_idle_init_masks(void);
-bool scx_idle_test_and_clear_cpu(int cpu);
-s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node, u64 flags);
 #else /* !CONFIG_SMP */
 static inline void scx_idle_update_selcpu_topology(struct sched_ext_ops *ops) {}
 static inline void scx_idle_init_masks(void) {}
-static inline bool scx_idle_test_and_clear_cpu(int cpu) { return false; }
-static inline s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node, u64 flags)
-{
-	return -EBUSY;
-}
 #endif /* CONFIG_SMP */
 
 s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
-- 
2.49.0


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

* [PATCH 3/4] sched_ext: Make scx_rq_bypassing() inline
  2025-06-04 14:33 [PATCH 0/4] sched_ext: Improve code modularization Andrea Righi
  2025-06-04 14:33 ` [PATCH 1/4] sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node() Andrea Righi
  2025-06-04 14:33 ` [PATCH 2/4] sched_ext: idle: Make local functions static in ext_idle.c Andrea Righi
@ 2025-06-04 14:33 ` Andrea Righi
  2025-06-04 14:33 ` [PATCH 4/4] sched_ext: Make scx_locked_rq() shared Andrea Righi
  2025-06-09 16:26 ` [PATCH 0/4] sched_ext: Improve code modularization Tejun Heo
  4 siblings, 0 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-04 14:33 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel

scx_rq_bypassing() is used both from ext.c and ext_idle.c, move it to
ext.h as a static inline function.

No functional changes.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c | 5 -----
 kernel/sched/ext.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 2c41c78be61eb..3e483138dff60 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1701,11 +1701,6 @@ static bool scx_tryset_enable_state(enum scx_enable_state to,
 	return atomic_try_cmpxchg(&scx_enable_state_var, &from_v, to);
 }
 
-static bool scx_rq_bypassing(struct rq *rq)
-{
-	return unlikely(rq->scx.flags & SCX_RQ_BYPASSING);
-}
-
 /**
  * wait_ops_state - Busy-wait the specified ops state to end
  * @p: target task
diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h
index 6e5072f577718..d30f2d1bc00d5 100644
--- a/kernel/sched/ext.h
+++ b/kernel/sched/ext.h
@@ -13,6 +13,11 @@ static inline bool scx_kf_allowed_if_unlocked(void)
 	return !current->scx.kf_mask;
 }
 
+static inline bool scx_rq_bypassing(struct rq *rq)
+{
+	return unlikely(rq->scx.flags & SCX_RQ_BYPASSING);
+}
+
 DECLARE_STATIC_KEY_FALSE(scx_ops_allow_queued_wakeup);
 
 void scx_tick(struct rq *rq);
-- 
2.49.0


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

* [PATCH 4/4] sched_ext: Make scx_locked_rq() shared
  2025-06-04 14:33 [PATCH 0/4] sched_ext: Improve code modularization Andrea Righi
                   ` (2 preceding siblings ...)
  2025-06-04 14:33 ` [PATCH 3/4] sched_ext: Make scx_rq_bypassing() inline Andrea Righi
@ 2025-06-04 14:33 ` Andrea Righi
  2025-06-04 18:48   ` Tejun Heo
                     ` (2 more replies)
  2025-06-09 16:26 ` [PATCH 0/4] sched_ext: Improve code modularization Tejun Heo
  4 siblings, 3 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-04 14:33 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel

scx_locked_rq() is used both from ext.c and ext_idle.c, so make it
public and declare its prototype in ext.h.

No functional changes.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c | 2 +-
 kernel/sched/ext.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 3e483138dff60..941603ec67e27 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1265,7 +1265,7 @@ static inline void update_locked_rq(struct rq *rq)
  * Return the rq currently locked from an scx callback, or NULL if no rq is
  * locked.
  */
-static inline struct rq *scx_locked_rq(void)
+struct rq *scx_locked_rq(void)
 {
 	return __this_cpu_read(locked_rq);
 }
diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h
index d30f2d1bc00d5..cda5dfa4dad09 100644
--- a/kernel/sched/ext.h
+++ b/kernel/sched/ext.h
@@ -18,6 +18,8 @@ static inline bool scx_rq_bypassing(struct rq *rq)
 	return unlikely(rq->scx.flags & SCX_RQ_BYPASSING);
 }
 
+struct rq *scx_locked_rq(void);
+
 DECLARE_STATIC_KEY_FALSE(scx_ops_allow_queued_wakeup);
 
 void scx_tick(struct rq *rq);
-- 
2.49.0


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

* Re: [PATCH 4/4] sched_ext: Make scx_locked_rq() shared
  2025-06-04 14:33 ` [PATCH 4/4] sched_ext: Make scx_locked_rq() shared Andrea Righi
@ 2025-06-04 18:48   ` Tejun Heo
  2025-06-04 18:49     ` Tejun Heo
  2025-06-05  5:28   ` Changwoo Min
  2025-06-05  9:30   ` [PATCH v2 4/4] sched_ext: Make scx_locked_rq() inline Andrea Righi
  2 siblings, 1 reply; 11+ messages in thread
From: Tejun Heo @ 2025-06-04 18:48 UTC (permalink / raw)
  To: Andrea Righi; +Cc: David Vernet, Changwoo Min, linux-kernel

On Wed, Jun 04, 2025 at 04:33:14PM +0200, Andrea Righi wrote:
> scx_locked_rq() is used both from ext.c and ext_idle.c, so make it
> public and declare its prototype in ext.h.
> 
> No functional changes.
> 
> Signed-off-by: Andrea Righi <arighi@nvidia.com>
> ---
>  kernel/sched/ext.c | 2 +-
>  kernel/sched/ext.h | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 3e483138dff60..941603ec67e27 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -1265,7 +1265,7 @@ static inline void update_locked_rq(struct rq *rq)
>   * Return the rq currently locked from an scx callback, or NULL if no rq is
>   * locked.
>   */
> -static inline struct rq *scx_locked_rq(void)
> +struct rq *scx_locked_rq(void)
>  {
>  	return __this_cpu_read(locked_rq);

Can you rename locked_rq to scx_locked_rq_var (or something else), expose it
and then make scx_locked_rq() an inline function in ext.h. Alternatively, I
think it'd be fine to drop the wrapper and let each user do
__this_cpu_read(scx_locked_rq) too.

Thanks.

-- 
tejun

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

* Re: [PATCH 4/4] sched_ext: Make scx_locked_rq() shared
  2025-06-04 18:48   ` Tejun Heo
@ 2025-06-04 18:49     ` Tejun Heo
  0 siblings, 0 replies; 11+ messages in thread
From: Tejun Heo @ 2025-06-04 18:49 UTC (permalink / raw)
  To: Andrea Righi; +Cc: David Vernet, Changwoo Min, linux-kernel

On Wed, Jun 04, 2025 at 08:48:56AM -1000, Tejun Heo wrote:
> On Wed, Jun 04, 2025 at 04:33:14PM +0200, Andrea Righi wrote:
> > scx_locked_rq() is used both from ext.c and ext_idle.c, so make it
> > public and declare its prototype in ext.h.
> > 
> > No functional changes.
> > 
> > Signed-off-by: Andrea Righi <arighi@nvidia.com>
> > ---
> >  kernel/sched/ext.c | 2 +-
> >  kernel/sched/ext.h | 2 ++
> >  2 files changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> > index 3e483138dff60..941603ec67e27 100644
> > --- a/kernel/sched/ext.c
> > +++ b/kernel/sched/ext.c
> > @@ -1265,7 +1265,7 @@ static inline void update_locked_rq(struct rq *rq)
> >   * Return the rq currently locked from an scx callback, or NULL if no rq is
> >   * locked.
> >   */
> > -static inline struct rq *scx_locked_rq(void)
> > +struct rq *scx_locked_rq(void)
> >  {
> >  	return __this_cpu_read(locked_rq);
> 
> Can you rename locked_rq to scx_locked_rq_var (or something else), expose it
> and then make scx_locked_rq() an inline function in ext.h. Alternatively, I
> think it'd be fine to drop the wrapper and let each user do
> __this_cpu_read(scx_locked_rq) too.

BTW, if you update this patch, no need to resend 1-3. Just send the updated
patch as a reply to this one.

Thanks.

-- 
tejun

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

* Re: [PATCH 4/4] sched_ext: Make scx_locked_rq() shared
  2025-06-04 14:33 ` [PATCH 4/4] sched_ext: Make scx_locked_rq() shared Andrea Righi
  2025-06-04 18:48   ` Tejun Heo
@ 2025-06-05  5:28   ` Changwoo Min
  2025-06-05  6:17     ` Andrea Righi
  2025-06-05  9:30   ` [PATCH v2 4/4] sched_ext: Make scx_locked_rq() inline Andrea Righi
  2 siblings, 1 reply; 11+ messages in thread
From: Changwoo Min @ 2025-06-05  5:28 UTC (permalink / raw)
  To: Andrea Righi, Tejun Heo, David Vernet; +Cc: linux-kernel

Hi Andrea,

On 6/4/25 23:33, Andrea Righi wrote:
> scx_locked_rq() is used both from ext.c and ext_idle.c, so make it
> public and declare its prototype in ext.h.

scx_rq_bypassing() is the same, but it is defined with "static inline".
Would it be better to define with "static inline" for consistency? And,
anyway scx_rq_bypassing() is used only within ext*.

Regards,
Changwoo Min

> 
> No functional changes.
> 
> Signed-off-by: Andrea Righi <arighi@nvidia.com>
> ---
>   kernel/sched/ext.c | 2 +-
>   kernel/sched/ext.h | 2 ++
>   2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 3e483138dff60..941603ec67e27 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -1265,7 +1265,7 @@ static inline void update_locked_rq(struct rq *rq)
>    * Return the rq currently locked from an scx callback, or NULL if no rq is
>    * locked.
>    */
> -static inline struct rq *scx_locked_rq(void)
> +struct rq *scx_locked_rq(void)
>   {
>   	return __this_cpu_read(locked_rq);
>   }
> diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h
> index d30f2d1bc00d5..cda5dfa4dad09 100644
> --- a/kernel/sched/ext.h
> +++ b/kernel/sched/ext.h
> @@ -18,6 +18,8 @@ static inline bool scx_rq_bypassing(struct rq *rq)
>   	return unlikely(rq->scx.flags & SCX_RQ_BYPASSING);
>   }
>   
> +struct rq *scx_locked_rq(void);
> +
>   DECLARE_STATIC_KEY_FALSE(scx_ops_allow_queued_wakeup);
>   
>   void scx_tick(struct rq *rq);


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

* Re: [PATCH 4/4] sched_ext: Make scx_locked_rq() shared
  2025-06-05  5:28   ` Changwoo Min
@ 2025-06-05  6:17     ` Andrea Righi
  0 siblings, 0 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-05  6:17 UTC (permalink / raw)
  To: Changwoo Min; +Cc: Tejun Heo, David Vernet, linux-kernel

Hi Changwoo,

On Thu, Jun 05, 2025 at 07:28:36AM +0200, Changwoo Min wrote:
> Hi Andrea,
> 
> On 6/4/25 23:33, Andrea Righi wrote:
> > scx_locked_rq() is used both from ext.c and ext_idle.c, so make it
> > public and declare its prototype in ext.h.
> 
> scx_rq_bypassing() is the same, but it is defined with "static inline".
> Would it be better to define with "static inline" for consistency? And,
> anyway scx_rq_bypassing() is used only within ext*.

Yep, I'll make scx_locked_rq() static inline as well as suggested by Tejun.
About scx_rq_bypassing(), it is currently used both in ext.c and
ext_idle.c, so we need to move that to ext.h.

Thanks,
-Andrea

> 
> Regards,
> Changwoo Min
> 
> > 
> > No functional changes.
> > 
> > Signed-off-by: Andrea Righi <arighi@nvidia.com>
> > ---
> >   kernel/sched/ext.c | 2 +-
> >   kernel/sched/ext.h | 2 ++
> >   2 files changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> > index 3e483138dff60..941603ec67e27 100644
> > --- a/kernel/sched/ext.c
> > +++ b/kernel/sched/ext.c
> > @@ -1265,7 +1265,7 @@ static inline void update_locked_rq(struct rq *rq)
> >    * Return the rq currently locked from an scx callback, or NULL if no rq is
> >    * locked.
> >    */
> > -static inline struct rq *scx_locked_rq(void)
> > +struct rq *scx_locked_rq(void)
> >   {
> >   	return __this_cpu_read(locked_rq);
> >   }
> > diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h
> > index d30f2d1bc00d5..cda5dfa4dad09 100644
> > --- a/kernel/sched/ext.h
> > +++ b/kernel/sched/ext.h
> > @@ -18,6 +18,8 @@ static inline bool scx_rq_bypassing(struct rq *rq)
> >   	return unlikely(rq->scx.flags & SCX_RQ_BYPASSING);
> >   }
> > +struct rq *scx_locked_rq(void);
> > +
> >   DECLARE_STATIC_KEY_FALSE(scx_ops_allow_queued_wakeup);
> >   void scx_tick(struct rq *rq);
> 

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

* [PATCH v2 4/4] sched_ext: Make scx_locked_rq() inline
  2025-06-04 14:33 ` [PATCH 4/4] sched_ext: Make scx_locked_rq() shared Andrea Righi
  2025-06-04 18:48   ` Tejun Heo
  2025-06-05  5:28   ` Changwoo Min
@ 2025-06-05  9:30   ` Andrea Righi
  2 siblings, 0 replies; 11+ messages in thread
From: Andrea Righi @ 2025-06-05  9:30 UTC (permalink / raw)
  To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel

scx_locked_rq() is used both from ext.c and ext_idle.c, move it to ext.h
as a static inline function.

No functional changes.

v2: Rename locked_rq to scx_locked_rq_state, expose it and make
    scx_locked_rq() inline, as suggested by Tejun.

Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
 kernel/sched/ext.c | 13 ++-----------
 kernel/sched/ext.h | 11 +++++++++++
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 3e483138dff60..3623ba98d7d83 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1247,7 +1247,7 @@ static void scx_kf_disallow(u32 mask)
  * This allows kfuncs to safely operate on rq from any scx ops callback,
  * knowing which rq is already locked.
  */
-static DEFINE_PER_CPU(struct rq *, locked_rq);
+DEFINE_PER_CPU(struct rq *, scx_locked_rq_state);
 
 static inline void update_locked_rq(struct rq *rq)
 {
@@ -1258,16 +1258,7 @@ static inline void update_locked_rq(struct rq *rq)
 	 */
 	if (rq)
 		lockdep_assert_rq_held(rq);
-	__this_cpu_write(locked_rq, rq);
-}
-
-/*
- * Return the rq currently locked from an scx callback, or NULL if no rq is
- * locked.
- */
-static inline struct rq *scx_locked_rq(void)
-{
-	return __this_cpu_read(locked_rq);
+	__this_cpu_write(scx_locked_rq_state, rq);
 }
 
 #define SCX_CALL_OP(sch, mask, op, rq, args...)					\
diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h
index d30f2d1bc00d5..6d6d00e9de20f 100644
--- a/kernel/sched/ext.h
+++ b/kernel/sched/ext.h
@@ -20,6 +20,17 @@ static inline bool scx_rq_bypassing(struct rq *rq)
 
 DECLARE_STATIC_KEY_FALSE(scx_ops_allow_queued_wakeup);
 
+DECLARE_PER_CPU(struct rq *, scx_locked_rq_state);
+
+/*
+ * Return the rq currently locked from an scx callback, or NULL if no rq is
+ * locked.
+ */
+static inline struct rq *scx_locked_rq(void)
+{
+	return __this_cpu_read(scx_locked_rq_state);
+}
+
 void scx_tick(struct rq *rq);
 void init_scx_entity(struct sched_ext_entity *scx);
 void scx_pre_fork(struct task_struct *p);
-- 
2.49.0


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

* Re: [PATCH 0/4] sched_ext: Improve code modularization
  2025-06-04 14:33 [PATCH 0/4] sched_ext: Improve code modularization Andrea Righi
                   ` (3 preceding siblings ...)
  2025-06-04 14:33 ` [PATCH 4/4] sched_ext: Make scx_locked_rq() shared Andrea Righi
@ 2025-06-09 16:26 ` Tejun Heo
  4 siblings, 0 replies; 11+ messages in thread
From: Tejun Heo @ 2025-06-09 16:26 UTC (permalink / raw)
  To: Andrea Righi; +Cc: David Vernet, Changwoo Min, linux-kernel

On Wed, Jun 04, 2025 at 04:33:10PM +0200, Andrea Righi wrote:
> Despite the unusual structure of the scheduler code, where the source code
> of all scheduler classes is included in a single .c file, we should still
> structure the code as if each .c file were a standalone build unit. This
> means marking internal functions as static, declaring shared symbols via
> proper function prototypes in a header file, etc.
> 
> This patch series is a first step toward such cleanup for the sched_ext
> code. There is more work to do, but these changes are intentionally small
> to minimize potential disruption to the ongoing development, laying some
> groundwork for a cleaner and more maintainable code.
> 
> Andrea Righi (4):
>       sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node()
>       sched_ext: idle: Make local functions static in ext_idle.c
>       sched_ext: Make scx_rq_bypassing() inline
>       sched_ext: Make scx_locked_rq() shared

Applied to sched_ext/for-6.17.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2025-06-09 16:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04 14:33 [PATCH 0/4] sched_ext: Improve code modularization Andrea Righi
2025-06-04 14:33 ` [PATCH 1/4] sched_ext: idle: Remove unnecessary ifdef in scx_bpf_cpu_node() Andrea Righi
2025-06-04 14:33 ` [PATCH 2/4] sched_ext: idle: Make local functions static in ext_idle.c Andrea Righi
2025-06-04 14:33 ` [PATCH 3/4] sched_ext: Make scx_rq_bypassing() inline Andrea Righi
2025-06-04 14:33 ` [PATCH 4/4] sched_ext: Make scx_locked_rq() shared Andrea Righi
2025-06-04 18:48   ` Tejun Heo
2025-06-04 18:49     ` Tejun Heo
2025-06-05  5:28   ` Changwoo Min
2025-06-05  6:17     ` Andrea Righi
2025-06-05  9:30   ` [PATCH v2 4/4] sched_ext: Make scx_locked_rq() inline Andrea Righi
2025-06-09 16:26 ` [PATCH 0/4] sched_ext: Improve code modularization Tejun Heo

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