Skip to content

Commit 1e5fa72

Browse files
committed
scx_layered: Fix queue delay output underflow in debug dump
The first task in a DSQ may have been queued after dump has started. In such cases, the current dump implementation would underflow and print out something non-sensical: LAYER[3][Unprivileged]DSQ[30001] nr_cpus=70 nr_queued=1 -18446744073599ms cpus= Fix by using signed calculations. Note that BPF doesn't allow s64 divisions, so the signedness is handled explicitly.
1 parent 8ade00e commit 1e5fa72

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scheds/rust/scx_layered/src/bpf/main.bpf.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,15 +2789,21 @@ void BPF_STRUCT_OPS(layered_disable, struct task_struct *p)
27892789
task_uncharge_qrt(taskc);
27902790
}
27912791

2792-
static u64 dsq_first_runnable_for_ms(u64 dsq_id, u64 now)
2792+
static s64 dsq_first_runnable_at_ms(u64 dsq_id, u64 now)
27932793
{
27942794
struct task_struct *p;
27952795

27962796
bpf_for_each(scx_dsq, p, dsq_id, 0) {
27972797
struct task_ctx *taskc;
27982798

2799-
if ((taskc = lookup_task_ctx(p)))
2800-
return (now - taskc->runnable_at) / 1000000;
2799+
if ((taskc = lookup_task_ctx(p))) {
2800+
u64 runnable_at = taskc->runnable_at;
2801+
2802+
if (runnable_at >= now)
2803+
return ((taskc->runnable_at - now) / 1000000);
2804+
else
2805+
return -((now - taskc->runnable_at) / 1000000);
2806+
}
28012807
}
28022808

28032809
return 0;
@@ -2846,24 +2852,24 @@ void BPF_STRUCT_OPS(layered_dump, struct scx_dump_ctx *dctx)
28462852
continue;
28472853

28482854
dsq_id = layer_dsq_id(layer->id, j);
2849-
scx_bpf_dump("LAYER[%d][%s]DSQ[%llx] nr_cpus=%u nr_queued=%d -%llums cpus=",
2855+
scx_bpf_dump("LAYER[%d][%s]DSQ[%llx] nr_cpus=%u nr_queued=%d %+lldms cpus=",
28502856
i, layer->name, dsq_id, layer->nr_cpus,
28512857
scx_bpf_dsq_nr_queued(dsq_id),
2852-
dsq_first_runnable_for_ms(dsq_id, now));
2858+
dsq_first_runnable_at_ms(dsq_id, now));
28532859
scx_bpf_dump("\n");
28542860
}
28552861
dump_layer_cpumask(i);
28562862
scx_bpf_dump("\n");
28572863
}
28582864
bpf_for(i, 0, nr_llcs) {
28592865
dsq_id = hi_fb_dsq_id(i);
2860-
scx_bpf_dump("HI_[%llx] nr_queued=%d -%llums\n",
2866+
scx_bpf_dump("HI_[%llx] nr_queued=%d %+lldms\n",
28612867
dsq_id, scx_bpf_dsq_nr_queued(dsq_id),
2862-
dsq_first_runnable_for_ms(dsq_id, now));
2868+
dsq_first_runnable_at_ms(dsq_id, now));
28632869
dsq_id = lo_fb_dsq_id(i);
2864-
scx_bpf_dump("LO_FALLBACK[%llx] nr_queued=%d -%llums\n",
2870+
scx_bpf_dump("LO_FALLBACK[%llx] nr_queued=%d %+lldms\n",
28652871
dsq_id, scx_bpf_dsq_nr_queued(dsq_id),
2866-
dsq_first_runnable_for_ms(dsq_id, now));
2872+
dsq_first_runnable_at_ms(dsq_id, now));
28672873
}
28682874
}
28692875

0 commit comments

Comments
 (0)