Skip to content

Commit c9c809f

Browse files
committed
scx_flatcg: Use a user DSQ for fallback instead of SCX_DSQ_GLOBAL
scx_flatcg was using SCX_DSQ_GLOBAL for fallback handling. However, it is assuming that SCX_DSQ_GLOBAL isn't automatically consumed, which was true a while ago but is no longer the case. Also, there are further changes planned for SCX_DSQ_GLOBAL which will disallow explicit consumption from it. Switch to a user DSQ for fallback. Signed-off-by: Tejun Heo <[email protected]> Acked-by: David Vernet <[email protected]>
1 parent a748db0 commit c9c809f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tools/sched_ext/scx_flatcg.bpf.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
/*
5050
* Maximum amount of retries to find a valid cgroup.
5151
*/
52-
#define CGROUP_MAX_RETRIES 1024
52+
enum {
53+
FALLBACK_DSQ = 0,
54+
CGROUP_MAX_RETRIES = 1024,
55+
};
5356

5457
char _license[] SEC("license") = "GPL";
5558

@@ -377,7 +380,7 @@ void BPF_STRUCT_OPS(fcg_enqueue, struct task_struct *p, u64 enq_flags)
377380
scx_bpf_dispatch(p, SCX_DSQ_LOCAL, SCX_SLICE_DFL, enq_flags);
378381
} else {
379382
stat_inc(FCG_STAT_GLOBAL);
380-
scx_bpf_dispatch(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
383+
scx_bpf_dispatch(p, FALLBACK_DSQ, SCX_SLICE_DFL, enq_flags);
381384
}
382385
return;
383386
}
@@ -780,7 +783,7 @@ void BPF_STRUCT_OPS(fcg_dispatch, s32 cpu, struct task_struct *prev)
780783
pick_next_cgroup:
781784
cpuc->cur_at = now;
782785

783-
if (scx_bpf_consume(SCX_DSQ_GLOBAL)) {
786+
if (scx_bpf_consume(FALLBACK_DSQ)) {
784787
cpuc->cur_cgid = 0;
785788
return;
786789
}
@@ -837,7 +840,7 @@ int BPF_STRUCT_OPS_SLEEPABLE(fcg_cgroup_init, struct cgroup *cgrp,
837840
int ret;
838841

839842
/*
840-
* Technically incorrect as cgroup ID is full 64bit while dq ID is
843+
* Technically incorrect as cgroup ID is full 64bit while dsq ID is
841844
* 63bit. Should not be a problem in practice and easy to spot in the
842845
* unlikely case that it breaks.
843846
*/
@@ -925,6 +928,11 @@ void BPF_STRUCT_OPS(fcg_cgroup_move, struct task_struct *p,
925928
p->scx.dsq_vtime = to_cgc->tvtime_now + vtime_delta;
926929
}
927930

931+
s32 BPF_STRUCT_OPS_SLEEPABLE(fcg_init)
932+
{
933+
return scx_bpf_create_dsq(FALLBACK_DSQ, -1);
934+
}
935+
928936
void BPF_STRUCT_OPS(fcg_exit, struct scx_exit_info *ei)
929937
{
930938
UEI_RECORD(uei, ei);
@@ -943,6 +951,7 @@ SCX_OPS_DEFINE(flatcg_ops,
943951
.cgroup_init = (void *)fcg_cgroup_init,
944952
.cgroup_exit = (void *)fcg_cgroup_exit,
945953
.cgroup_move = (void *)fcg_cgroup_move,
954+
.init = (void *)fcg_init,
946955
.exit = (void *)fcg_exit,
947956
.flags = SCX_OPS_HAS_CGROUP_WEIGHT | SCX_OPS_ENQ_EXITING,
948957
.name = "flatcg");

0 commit comments

Comments
 (0)