Skip to content

Commit a0ba52a

Browse files
htejungregkh
authored andcommitted
sched_ext: Make qmap dump operation non-destructive
[ Upstream commit d452972858e5cfa4262320ab74fe8f016460b96f ] The qmap dump operation was destructively consuming queue entries while displaying them. As dump can be triggered anytime, this can easily lead to stalls. Add a temporary dump_store queue and modify the dump logic to pop entries, display them, and then restore them back to the original queue. This allows dump operations to be performed without affecting the scheduler's queue state. Note that if racing against new enqueues during dump, ordering can get mixed up, but this is acceptable for debugging purposes. Acked-by: Andrea Righi <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent feec2bf commit a0ba52a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

tools/sched_ext/scx_qmap.bpf.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ struct qmap {
5656
queue1 SEC(".maps"),
5757
queue2 SEC(".maps"),
5858
queue3 SEC(".maps"),
59-
queue4 SEC(".maps");
59+
queue4 SEC(".maps"),
60+
dump_store SEC(".maps");
6061

6162
struct {
6263
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
@@ -578,11 +579,26 @@ void BPF_STRUCT_OPS(qmap_dump, struct scx_dump_ctx *dctx)
578579
return;
579580

580581
scx_bpf_dump("QMAP FIFO[%d]:", i);
582+
583+
/*
584+
* Dump can be invoked anytime and there is no way to iterate in
585+
* a non-destructive way. Pop and store in dump_store and then
586+
* restore afterwards. If racing against new enqueues, ordering
587+
* can get mixed up.
588+
*/
581589
bpf_repeat(4096) {
582590
if (bpf_map_pop_elem(fifo, &pid))
583591
break;
592+
bpf_map_push_elem(&dump_store, &pid, 0);
584593
scx_bpf_dump(" %d", pid);
585594
}
595+
596+
bpf_repeat(4096) {
597+
if (bpf_map_pop_elem(&dump_store, &pid))
598+
break;
599+
bpf_map_push_elem(fifo, &pid, 0);
600+
}
601+
586602
scx_bpf_dump("\n");
587603
}
588604
}

0 commit comments

Comments
 (0)