Skip to contentSkip to conversation

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

PATCH Superseded Zqiang 3 participants 4 messages Mar 24 – Mar 26

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zqiang

author
#0 lore raw

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

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

---
 kernel/sched/ext.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/sched/ext.c +6 -2
index 2472231ec556..5d670b50da3d 100644
@@ -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;
 
 	/*
Signature · 1 line
2.17.1
reviewer
#1 lore raw
Quoted 1 line · Zqiang

This commit use the scx_task_sched_rcu() to get task->scx.sched

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

Quoted 20 lines

structure to correctly output, instead of always using scx_root in the print_scx_info().

---
 kernel/sched/ext.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/sched/ext.c +1 -1
index 2472231ec556..5d670b50da3d 100644
@@ -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" : "";

kernel/sched/ext.c static void kick_cpus_irq_workfn(struct irq_work *irq_work) · line 7694

Quoted 10 lines
kernel/sched/ext.c +5 -1
 	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.

Signature · 1 line
tejun
#2 lore raw
In reply to Zqiang
kernel test robot noticed the following build errors:

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/[email protected]/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/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

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

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Zqiang
kernel test robot noticed the following build errors:

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/[email protected]/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/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

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

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki