Skip to contentSkip to conversation

sched_ext: Add error logging for dsq creation failures

PATCH Superseded George Guo 3 participants 5 messages Jan 7 – Jan 9 Scheduler - sched_ext

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

George Guo

author
#0 lore raw

PATCH 1/1 sched_ext: Add error logging for dsq creation failures

From: George Guo <[email protected]>

Add scx_bpf_error() calls when scx_bpf_create_dsq() fails in multiple schedulers to improve debuggability:

- scx_central.bpf.c: central_init()
- scx_flatcg.bpf.c: fcg_cgroup_init() and fcg_init()
- scx_qmap.bpf.c: qmap_init()
- scx_simple.bpf.c: simple_init()

---
 tools/sched_ext/scx_central.bpf.c |  4 +++-
 tools/sched_ext/scx_flatcg.bpf.c  | 12 ++++++++++--
 tools/sched_ext/scx_qmap.bpf.c    |  8 ++++++--
 tools/sched_ext/scx_simple.bpf.c  |  8 +++++++-
 4 files changed, 26 insertions(+), 6 deletions(-)
tools/sched_ext/scx_central.bpf.c +3 -1
index 55df8b798865..1c2376b75b5d 100644
@@ -301,8 +301,10 @@ int BPF_STRUCT_OPS_SLEEPABLE(central_init)
 	int ret;
 
 	ret = scx_bpf_create_dsq(FALLBACK_DSQ_ID, -1);
-	if (ret)
+	if (ret) {
+		scx_bpf_error("scx_bpf_create_dsq failed (%d)", ret);
 		return ret;
+	}
 
 	timer = bpf_map_lookup_elem(&central_timer, &key);
 	if (!timer)
tools/sched_ext/scx_flatcg.bpf.c +10 -2
index 2c720e3ecad5..f7830e14b9af 100644
@@ -842,8 +842,10 @@ int BPF_STRUCT_OPS_SLEEPABLE(fcg_cgroup_init, struct cgroup *cgrp,
 	 * unlikely case that it breaks.
 	 */
 	ret = scx_bpf_create_dsq(cgid, -1);
-	if (ret)
+	if (ret) {
+		scx_bpf_error("scx_bpf_create_dsq failed (%d)", ret);
 		return ret;
+	}
 
 	cgc = bpf_cgrp_storage_get(&cgrp_ctx, cgrp, 0,
 				   BPF_LOCAL_STORAGE_GET_F_CREATE);
@@ -927,7 +929,13 @@ void BPF_STRUCT_OPS(fcg_cgroup_move, struct task_struct *p,
 
 s32 BPF_STRUCT_OPS_SLEEPABLE(fcg_init)
 {
-	return scx_bpf_create_dsq(FALLBACK_DSQ, -1);
+	s32 ret;
+
+	ret = scx_bpf_create_dsq(FALLBACK_DSQ, -1);
+	if (ret)
+		scx_bpf_error("scx_bpf_create_dsq failed (%d)", ret);
+
+	return ret;
 }
 
 void BPF_STRUCT_OPS(fcg_exit, struct scx_exit_info *ei)
tools/sched_ext/scx_qmap.bpf.c +6 -2
index 3072b593f898..16ed8f867ad9 100644
@@ -852,12 +852,16 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(qmap_init)
 		print_cpus();
 
 	ret = scx_bpf_create_dsq(SHARED_DSQ, -1);
-	if (ret)
+	if (ret) {
+		scx_bpf_error("scx_bpf_create_dsq failed (%d)", ret);
 		return ret;
+	}
 
 	ret = scx_bpf_create_dsq(HIGHPRI_DSQ, -1);
-	if (ret)
+	if (ret) {
+		scx_bpf_error("scx_bpf_create_dsq failed (%d)", ret);
 		return ret;
+	}
 
 	timer = bpf_map_lookup_elem(&monitor_timer, &key);
 	if (!timer)
tools/sched_ext/scx_simple.bpf.c +7 -1
index e6de99dba7db..50e4555459de 100644
@@ -131,7 +131,13 @@ void BPF_STRUCT_OPS(simple_enable, struct task_struct *p)
 
 s32 BPF_STRUCT_OPS_SLEEPABLE(simple_init)
 {
-	return scx_bpf_create_dsq(SHARED_DSQ, -1);
+	s32 ret;
+
+	ret = scx_bpf_create_dsq(SHARED_DSQ, -1);
+	if (ret)
+		scx_bpf_error("scx_bpf_create_dsq failed (%d)", ret);
+
+	return ret;
 }
 
 void BPF_STRUCT_OPS(simple_exit, struct scx_exit_info *ei)
Signature · 1 line
2.43.0
#1 lore raw

Hi George,

(sorry for the formatting, my email client has decided not to indent the email)

________________________________________
From: George Guo <[email protected]>
Sent: Wednesday, January 7, 2026 1:28 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; George Guo
Subject: [PATCH 1/1] sched_ext: Add error logging for dsq creation failures

From: George Guo <[email protected]>

Add scx_bpf_error() calls when scx_bpf_create_dsq() fails in multiple schedulers to improve debuggability:

- scx_central.bpf.c: central_init()
- scx_flatcg.bpf.c: fcg_cgroup_init() and fcg_init()
- scx_qmap.bpf.c: qmap_init()
- scx_simple.bpf.c: simple_init()

---

While the change looks correct, is there any benefit to it?

- Failing to create a dsq will already cause init() to fail with the error code from the failed call. In scx_simple in particular, the change adds no new info because the function amounts to a single scx_bpf_create_dsq() call.

- Regressions to scx_bpf_dsq_create() from kernel-side (as opposed to BPF scheduler-side) changes will be caught by the selftests.

Not opposed to it, just curious what the advantages are.

author
#2 lore raw

Hi Etsal,
Thanks for reviewing!

Quoted 1 line

While the change looks correct, is there any benefit to it?

Yes, definitely. I found this issue while adding sched_ext support for LoongArch. When scx_bpf_create_dsq() failed during my development, there were no error messages at all, which made debugging difficult.

Specifically:
1. The failure was silent - no log, no error message in dmesg
2. I had to add bpf_printk() temporarily to confirm it was dsq creation failing

So the benefit is improved debuggability and faster issue diagnosis.

Thanks!

reviewer
#3 lore raw

Hi George,

Quoted 10 lines · George Guo

Hi Etsal,
Thanks for reviewing!

Quoted 1 line

While the change looks correct, is there any benefit to it?

Yes, definitely. I found this issue while adding sched_ext support for LoongArch. When scx_bpf_create_dsq() failed during my development, there were no error messages at all, which made debugging difficult.

Specifically:
1. The failure was silent - no log, no error message in dmesg

Which kernel is that?

In theory you should get a clear message in dmesg. For example, if I try to create an invalid DSQ in scx_simple I get this in dmesg:

  [690301.673313] sched_ext: BPF scheduler "simple" disabled (runtime error)
  [690301.673324] sched_ext: simple: ops.init() failed (-22)
  [690301.673327]    scx_enable.isra.0+0xc8b/0x11f0
  [690301.673343]    bpf_struct_ops_link_create+0x141/0x1b0
  [690301.673352]    __sys_bpf+0x1c0c/0x2de0
  [690301.673357]    __x64_sys_bpf+0x21/0x30
  [690301.673359]    do_syscall_64+0x81/0x820
  [690301.673368]    entry_SYSCALL_64_after_hwframe+0x76/0x7e

And in stdout:

DEBUG DUMP
================================================================================

scx_simple[364999] triggered exit kind 1024:
runtime error (ops.init() failed (-22))

Backtrace:
  scx_enable.isra.0+0xc8b/0x11f0
  bpf_struct_ops_link_create+0x141/0x1b0
  __sys_bpf+0x1c0c/0x2de0
  __x64_sys_bpf+0x21/0x30
  do_syscall_64+0x81/0x820
  entry_SYSCALL_64_after_hwframe+0x76/0x7e

CPU states
----------

CPU 2 : nr_run=0 flags=0x1 cpu_rel=0 ops_qseq=87907495 pnt_seq=66861592

          curr=scx_simple[364999] class=fair_sched_class

CPU 3 : nr_run=0 flags=0x1 cpu_rel=0 ops_qseq=85461608 pnt_seq=64229201

          curr=pacman[364201] class=fair_sched_class

Event counters
--------------

              SCX_EV_SELECT_CPU_FALLBACK:                0
       SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE:                0
               SCX_EV_DISPATCH_KEEP_LAST:                0
                 SCX_EV_ENQ_SKIP_EXITING:                0
      SCX_EV_ENQ_SKIP_MIGRATION_DISABLED:                0
                 SCX_EV_REFILL_SLICE_DFL:                0
                  SCX_EV_BYPASS_DURATION:                0
                  SCX_EV_BYPASS_DISPATCH:                0
                  SCX_EV_BYPASS_ACTIVATE:                0

================================================================================

EXIT: runtime error (ops.init() failed (-22))

Quoted 6 lines

2. I had to add bpf_printk() temporarily to confirm it was dsq creation failing

So the benefit is improved debuggability and faster issue diagnosis.

Thanks!

Thanks,
-Andrea

author
#4 lore raw

Hi Andrea,
I got the similar dmesg too.
It seems that it's not necessry in scx_simple.bpf.c indeed. I will send v2 later for your review.