Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched_ext: Make qmap dump operation non-destructive

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 <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

Tejun Heo d4529728 f3aec2ad

+17 -1
+17 -1
tools/sched_ext/scx_qmap.bpf.c
··· 56 56 queue1 SEC(".maps"), 57 57 queue2 SEC(".maps"), 58 58 queue3 SEC(".maps"), 59 - queue4 SEC(".maps"); 59 + queue4 SEC(".maps"), 60 + dump_store SEC(".maps"); 60 61 61 62 struct { 62 63 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); ··· 579 578 return; 580 579 581 580 scx_bpf_dump("QMAP FIFO[%d]:", i); 581 + 582 + /* 583 + * Dump can be invoked anytime and there is no way to iterate in 584 + * a non-destructive way. Pop and store in dump_store and then 585 + * restore afterwards. If racing against new enqueues, ordering 586 + * can get mixed up. 587 + */ 582 588 bpf_repeat(4096) { 583 589 if (bpf_map_pop_elem(fifo, &pid)) 584 590 break; 591 + bpf_map_push_elem(&dump_store, &pid, 0); 585 592 scx_bpf_dump(" %d", pid); 586 593 } 594 + 595 + bpf_repeat(4096) { 596 + if (bpf_map_pop_elem(&dump_store, &pid)) 597 + break; 598 + bpf_map_push_elem(fifo, &pid, 0); 599 + } 600 + 587 601 scx_bpf_dump("\n"); 588 602 } 589 603 }