[PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()

Zqiang posted 1 patch 1 week, 2 days ago
There is a newer version of this series
kernel/sched/ext.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()
Posted by Zqiang 1 week, 2 days ago
This commit use the scx_task_sched_rcu() to get task->scx.sched
structure to correctly output, instead of always using scx_root
in the print_scx_info().

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 kernel/sched/ext.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 2472231ec556..5d670b50da3d 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -7680,14 +7680,18 @@ static void kick_cpus_irq_workfn(struct irq_work *irq_work)
  */
 void print_scx_info(const char *log_lvl, struct task_struct *p)
 {
-	struct scx_sched *sch = scx_root;
+	struct scx_sched *sch;
 	enum scx_enable_state state = scx_enable_state();
 	const char *all = READ_ONCE(scx_switching_all) ? "+all" : "";
 	char runnable_at_buf[22] = "?";
 	struct sched_class *class;
 	unsigned long runnable_at;
 
-	if (state == SCX_DISABLED)
+	guard(rcu)();
+
+	sch = scx_task_sched_rcu(p);
+
+	if (!sch || state == SCX_DISABLED)
 		return;
 
 	/*
-- 
2.17.1
Re: [PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()
Posted by kernel test robot 1 week, 1 day ago
Hi Zqiang,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on linus/master v7.0-rc5]
[cannot apply to next-20260325]
[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/Zqiang/sched_ext-Choose-the-right-sch-ops-name-to-output-in-the-print_scx_info/20260326-043528
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20260324120313.12632-1-qiang.zhang%40linux.dev
patch subject: [PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()
config: x86_64-rhel-9.4-bpf (https://download.01.org/0day-ci/archive/20260326/202603261453.8kiJImYo-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260326/202603261453.8kiJImYo-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603261453.8kiJImYo-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/sched/build_policy.c:62:
   kernel/sched/ext.c: In function 'scx_vexit':
   kernel/sched/ext.c:4800:9: warning: function 'scx_vexit' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
    4800 |         vscnprintf(ei->msg, SCX_EXIT_MSG_LEN, fmt, args);
         |         ^~~~~~~~~~
   kernel/sched/ext.c: In function 'print_scx_info':
>> kernel/sched/ext.c:5719:15: error: implicit declaration of function 'scx_task_sched_rcu' [-Wimplicit-function-declaration]
    5719 |         sch = scx_task_sched_rcu(p);
         |               ^~~~~~~~~~~~~~~~~~
>> kernel/sched/ext.c:5719:13: error: assignment to 'struct scx_sched *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    5719 |         sch = scx_task_sched_rcu(p);
         |             ^


vim +/scx_task_sched_rcu +5719 kernel/sched/ext.c

  5695	
  5696	/**
  5697	 * print_scx_info - print out sched_ext scheduler state
  5698	 * @log_lvl: the log level to use when printing
  5699	 * @p: target task
  5700	 *
  5701	 * If a sched_ext scheduler is enabled, print the name and state of the
  5702	 * scheduler. If @p is on sched_ext, print further information about the task.
  5703	 *
  5704	 * This function can be safely called on any task as long as the task_struct
  5705	 * itself is accessible. While safe, this function isn't synchronized and may
  5706	 * print out mixups or garbages of limited length.
  5707	 */
  5708	void print_scx_info(const char *log_lvl, struct task_struct *p)
  5709	{
  5710		struct scx_sched *sch;
  5711		enum scx_enable_state state = scx_enable_state();
  5712		const char *all = READ_ONCE(scx_switching_all) ? "+all" : "";
  5713		char runnable_at_buf[22] = "?";
  5714		struct sched_class *class;
  5715		unsigned long runnable_at;
  5716	
  5717		guard(rcu)();
  5718	
> 5719		sch = scx_task_sched_rcu(p);
  5720	
  5721		if (!sch || state == SCX_DISABLED)
  5722			return;
  5723	
  5724		/*
  5725		 * Carefully check if the task was running on sched_ext, and then
  5726		 * carefully copy the time it's been runnable, and its state.
  5727		 */
  5728		if (copy_from_kernel_nofault(&class, &p->sched_class, sizeof(class)) ||
  5729		    class != &ext_sched_class) {
  5730			printk("%sSched_ext: %s (%s%s)", log_lvl, sch->ops.name,
  5731			       scx_enable_state_str[state], all);
  5732			return;
  5733		}
  5734	
  5735		if (!copy_from_kernel_nofault(&runnable_at, &p->scx.runnable_at,
  5736					      sizeof(runnable_at)))
  5737			scnprintf(runnable_at_buf, sizeof(runnable_at_buf), "%+ldms",
  5738				  jiffies_delta_msecs(runnable_at, jiffies));
  5739	
  5740		/* print everything onto one line to conserve console space */
  5741		printk("%sSched_ext: %s (%s%s), task: runnable_at=%s",
  5742		       log_lvl, sch->ops.name, scx_enable_state_str[state], all,
  5743		       runnable_at_buf);
  5744	}
  5745	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()
Posted by kernel test robot 1 week, 1 day ago
Hi Zqiang,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on linus/master v7.0-rc5]
[cannot apply to next-20260325]
[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/Zqiang/sched_ext-Choose-the-right-sch-ops-name-to-output-in-the-print_scx_info/20260326-043528
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20260324120313.12632-1-qiang.zhang%40linux.dev
patch subject: [PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()
config: x86_64-rhel-9.4-bpf (https://download.01.org/0day-ci/archive/20260326/202603260700.UT38KZHC-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260326/202603260700.UT38KZHC-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603260700.UT38KZHC-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/sched/build_policy.c:62:
   kernel/sched/ext.c: In function 'scx_vexit':
   kernel/sched/ext.c:4800:9: warning: function 'scx_vexit' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
    4800 |         vscnprintf(ei->msg, SCX_EXIT_MSG_LEN, fmt, args);
         |         ^~~~~~~~~~
   kernel/sched/ext.c: In function 'print_scx_info':
>> kernel/sched/ext.c:5719:15: error: implicit declaration of function 'scx_task_sched_rcu' [-Wimplicit-function-declaration]
    5719 |         sch = scx_task_sched_rcu(p);
         |               ^~~~~~~~~~~~~~~~~~
>> kernel/sched/ext.c:5719:13: error: assignment to 'struct scx_sched *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    5719 |         sch = scx_task_sched_rcu(p);
         |             ^


vim +/scx_task_sched_rcu +5719 kernel/sched/ext.c

  5695	
  5696	/**
  5697	 * print_scx_info - print out sched_ext scheduler state
  5698	 * @log_lvl: the log level to use when printing
  5699	 * @p: target task
  5700	 *
  5701	 * If a sched_ext scheduler is enabled, print the name and state of the
  5702	 * scheduler. If @p is on sched_ext, print further information about the task.
  5703	 *
  5704	 * This function can be safely called on any task as long as the task_struct
  5705	 * itself is accessible. While safe, this function isn't synchronized and may
  5706	 * print out mixups or garbages of limited length.
  5707	 */
  5708	void print_scx_info(const char *log_lvl, struct task_struct *p)
  5709	{
  5710		struct scx_sched *sch;
  5711		enum scx_enable_state state = scx_enable_state();
  5712		const char *all = READ_ONCE(scx_switching_all) ? "+all" : "";
  5713		char runnable_at_buf[22] = "?";
  5714		struct sched_class *class;
  5715		unsigned long runnable_at;
  5716	
  5717		guard(rcu)();
  5718	
> 5719		sch = scx_task_sched_rcu(p);
  5720	
  5721		if (!sch || state == SCX_DISABLED)
  5722			return;
  5723	
  5724		/*
  5725		 * Carefully check if the task was running on sched_ext, and then
  5726		 * carefully copy the time it's been runnable, and its state.
  5727		 */
  5728		if (copy_from_kernel_nofault(&class, &p->sched_class, sizeof(class)) ||
  5729		    class != &ext_sched_class) {
  5730			printk("%sSched_ext: %s (%s%s)", log_lvl, sch->ops.name,
  5731			       scx_enable_state_str[state], all);
  5732			return;
  5733		}
  5734	
  5735		if (!copy_from_kernel_nofault(&runnable_at, &p->scx.runnable_at,
  5736					      sizeof(runnable_at)))
  5737			scnprintf(runnable_at_buf, sizeof(runnable_at_buf), "%+ldms",
  5738				  jiffies_delta_msecs(runnable_at, jiffies));
  5739	
  5740		/* print everything onto one line to conserve console space */
  5741		printk("%sSched_ext: %s (%s%s), task: runnable_at=%s",
  5742		       log_lvl, sch->ops.name, scx_enable_state_str[state], all,
  5743		       runnable_at_buf);
  5744	}
  5745	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] sched_ext: Choose the right sch->ops.name to output in the print_scx_info()
Posted by Tejun Heo 1 week, 2 days ago
On Tue, Mar 24, 2026 at 08:03:13PM +0800, Zqiang wrote:
> This commit use the scx_task_sched_rcu() to get task->scx.sched

"This commit uses", but that just do imperative - "Use the...".

> structure to correctly output, instead of always using scx_root
> in the print_scx_info().
> 
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> ---
>  kernel/sched/ext.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 2472231ec556..5d670b50da3d 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -7680,14 +7680,18 @@ static void kick_cpus_irq_workfn(struct irq_work *irq_work)
>   */
>  void print_scx_info(const char *log_lvl, struct task_struct *p)
>  {
> -	struct scx_sched *sch = scx_root;
> +	struct scx_sched *sch;
>  	enum scx_enable_state state = scx_enable_state();
>  	const char *all = READ_ONCE(scx_switching_all) ? "+all" : "";
>  	char runnable_at_buf[22] = "?";
>  	struct sched_class *class;
>  	unsigned long runnable_at;
>  
> -	if (state == SCX_DISABLED)
> +	guard(rcu)();
> +
> +	sch = scx_task_sched_rcu(p);
> +
> +	if (!sch || state == SCX_DISABLED)

I think you can drop the state test w/ scx_task_sched_rcu() usage.

Thanks.

-- 
tejun