sched_ext: Add ops.sub_child_ecaps_updated()
Subsystems (2)
Tejun Heo
reviewerPATCH v2 1/1 sched_ext: Add ops.sub_child_ecaps_updated()
Hello,
v2: - A sub's disable no longer reports. The report ran the op outside the
dispatch path, which meant setting up that path's context for the op's kfuncs and gating the nested sub dispatch at runtime, and keeping the report clear of the PM bypass took a lock that could stall a suspend. The parent knows what it delegated, so ops.sub_detach() is where it restores it, and its kerneldoc now says so (#1).
- scx_qmap resets a detaching child's cids from ops.sub_detach() (#2).
v1: https://lore.kernel.org/r/[email protected]
A grant or revoke only records the target caps. They take effect on a cid at its next dispatch, and nothing tells the parent when. Without that the parent cannot act on a revoke, such as resetting the cpuperf target a child left on the cid.
Patch 1 adds ops.sub_child_ecaps_updated(), delivered to the direct parent right after the child's own ops.sub_ecaps_updated(), with the child's cgroup id and the same before and after caps. A sub's disable reports nothing; the parent restores what it delegated from ops.sub_detach(). Patch 2 makes scx_qmap reset a child's cpuperf target once its PERF revoke takes effect, and from sub_detach() for a detaching child.
Based on sched_ext/for-7.4 (3d7c2f550eef).
This patchset contains the following 2 patches.
0001 sched_ext: Add ops.sub_child_ecaps_updated() to report a child's effective cap changes 0002 sched_ext: scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
The patchset is also available in the following git branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git sub-child-ecaps-v2
diffstat follows. Thanks.
kernel/sched/ext/ext.c | 4 +++ kernel/sched/ext/internal.h | 30 ++++++++++++++++++--- kernel/sched/ext/sub.c | 59 +++++++++++++++++++++++++++++------------- tools/sched_ext/scx_qmap.bpf.c | 33 +++++++++++++++++++++-- tools/sched_ext/scx_qmap.c | 7 +++-- tools/sched_ext/scx_qmap.h | 1 + 6 files changed, 109 insertions(+), 25 deletions(-)
--
tejun
Tejun Heo
reviewerPATCH 1/2 sched_ext: Add ops.sub_child_ecaps_updated() to report a child's effective cap changes
A grant or revoke only records the target caps. They take effect on a cid at its next dispatch, and nothing tells the parent when. Without that the parent cannot act on a revoke: a child that ran a cid at a low cpuperf target leaves the target there when PERF is revoked, as the kernel resets targets only at root enable. Nor can the parent tell when it may schedule on the cid again.
Add ops.sub_child_ecaps_updated(), delivered to the direct parent right after the child's own ops.sub_ecaps_updated() with the child's cgroup id and the same before and after caps, in the same dispatch context. Both deliveries are suppressed while the child is bypassing and replayed together afterwards. A disabled child reports nothing: ops.sub_detach() is where the parent restores what it had delegated.
A sub is now bypassed before it is linked, so that the grants queued for it from ops.sub_attach() are consumed while it is bypassed and replayed to it and the parent once it is enabled. Otherwise a sync consumed before the sub's ops are registered would reach the parent but never the sub.
v2: Drop the disable report with its sleep lock and nested-dispatch gate, the parent restores from ops.sub_detach() instead.
--- kernel/sched/ext/ext.c | 4 +++ kernel/sched/ext/internal.h | 30 +++++++++++++++++-- kernel/sched/ext/sub.c | 59 ++++++++++++++++++++++++++----------- 3 files changed, 72 insertions(+), 21 deletions(-)
kernel/sched/ext/ext.c +4 -0
@@ -8921,6 +8921,7 @@ static void sched_ext_ops_cid__enable(struct task_struct *p, struct scx_enable_astatic void sched_ext_ops__sub_caps_updated (const struct scx_cmask *cmask__arena,u64 caps) {}static void sched_ext_ops__sub_ecaps_updated (s32 cid,u64 before,u64 after) {}static void sched_ext_ops__sub_cid_sched_updated (s32 cid,u64 sched) {} +static void sched_ext_ops__sub_child_ecaps_updated (u64 cgroup_id,s32 cid,u64 before,u64 after) {}static struct sched_ext_ops_cid __bpf_ops_sched_ext_ops_cid = { .select_cid = sched_ext_ops__select_cpu,
@@ -8956,6 +8957,7 @@ static struct sched_ext_ops_cid __bpf_ops_sched_ext_ops_cid = { .sub_caps_updated = sched_ext_ops__sub_caps_updated, .sub_ecaps_updated = sched_ext_ops__sub_ecaps_updated, .sub_cid_sched_updated = sched_ext_ops__sub_cid_sched_updated, + .sub_child_ecaps_updated = sched_ext_ops__sub_child_ecaps_updated, .cid_online = sched_ext_ops__cpu_online, .cid_offline = sched_ext_ops__cpu_offline, .init_cids = sched_ext_ops__init_cids,
@@ -11552,6 +11554,7 @@ static const u32 scx_kf_allow_flags[] = { [SCX_OP_IDX(sub_attach)] = SCX_KF_ALLOW_UNLOCKED, [SCX_OP_IDX(sub_detach)] = SCX_KF_ALLOW_UNLOCKED, [SCX_OP_IDX(sub_ecaps_updated)] = SCX_KF_ALLOW_ENQUEUE | SCX_KF_ALLOW_DISPATCH, + [SCX_OP_IDX(sub_child_ecaps_updated)] = SCX_KF_ALLOW_ENQUEUE | SCX_KF_ALLOW_DISPATCH, [SCX_OP_IDX(cpu_online)] = SCX_KF_ALLOW_UNLOCKED, [SCX_OP_IDX(cpu_offline)] = SCX_KF_ALLOW_UNLOCKED, [SCX_OP_IDX(init_cids)] = SCX_KF_ALLOW_UNLOCKED | SCX_KF_ALLOW_INIT_CIDS,
@@ -11696,6 +11699,7 @@ static int __init scx_init(void)CID_OFFSET_MATCH (sub_caps_updated, sub_caps_updated);CID_OFFSET_MATCH (sub_ecaps_updated, sub_ecaps_updated);CID_OFFSET_MATCH (sub_cid_sched_updated, sub_cid_sched_updated); +CID_OFFSET_MATCH (sub_child_ecaps_updated, sub_child_ecaps_updated);CID_OFFSET_MATCH (init_cids, init_cids);CID_OFFSET_MATCH (init, init);CID_OFFSET_MATCH (exit, exit);
kernel/sched/ext/internal.h +27 -3
@@ -878,8 +878,9 @@ struct sched_ext_ops {* @args: argument container, see the struct definition * * The sub-scheduler holds no caps by this point and can no longer -* affect any cid. Whatever was delegated to it, e.g. cpuperf targets, -* is the parent's to restore here. +* affect any cid. Its caps went away without a +* sub_child_ecaps_updated() report, so whatever was delegated to it, +* e.g. cpuperf targets, is the parent's to restore here. */ void (*sub_detach)(struct scx_sub_detach_args *args);
@@ -932,6 +933,25 @@ struct sched_ext_ops {*/ void (*sub_cid_sched_updated)(s32 cid,u64 sched); +/** +* @sub_child_ecaps_updated: A child's effective caps on a cid changed +* @cgroup_id: cgroup id of the direct child +* @cid: the cid whose effective caps changed +* @before: the child's effective caps as of the last delivery +* @after: the child's effective caps now +* +* Invoked right after the child's sub_ecaps_updated(), once a grant or +* revoke is in effect on the cpu. From here on the parent can act on a +* cap the child lost, e.g. reset the cpuperf target or schedule on the +* cid. A detaching child's caps go away without a report, see +* sub_detach(). A cpu going offline drops caps without a report. +* +* Runs in dispatch context with rq lock held, and can perform all +* operations allowed in ops.dispatch() including inserting/moving +* tasks. +*/ +void (*sub_child_ecaps_updated)(u64 cgroup_id,s32 cid,u64 before,u64 after); +/* * All online ops must come before ops.cpu_online(). */
@@ -1190,6 +1210,7 @@ struct sched_ext_ops_cid {void (*sub_caps_updated)(const struct scx_cmask *cmask__arena,u64 caps);void (*sub_ecaps_updated)(s32 cid,u64 before,u64 after);void (*sub_cid_sched_updated)(s32 cid,u64 sched); +void (*sub_child_ecaps_updated)(u64 cgroup_id,s32 cid,u64 before,u64 after);void (*cid_online)(s32 cid);void (*cid_offline)(s32 cid);s32 (*init_cids)(void);
@@ -1453,7 +1474,10 @@ struct scx_sched_pcpu {struct llist_node ecaps_to_sync_node;/* owed a forced update_idle() re-notify on this cpu */ bool idle_renotify; -/* effective caps as of the last sub_ecaps_updated() delivery */ +/* +* ecaps as of the last sub_ecaps_updated() and +* sub_child_ecaps_updated() delivery. See __scx_process_sync_ecaps(). +*/ u64 reported_ecaps;/*
kernel/sched/ext/sub.c +41 -18
82 lines not on this page · raw message
Signature · 1 line
2.55.0
Tejun Heo
reviewerPATCH 2/2 sched_ext: scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
In reply to Tejun HeoA child that ran a cid at a low cpuperf target leaves the target there when PERF is revoked, since the kernel resets targets only at root enable. Reset the target from ops.sub_child_ecaps_updated() once the revoke is in effect. A detach reports nothing, so ops.sub_detach() resets the child's cids, the pool included. Count the deliveries in the hier stats.
v2: Reset from ops.sub_detach() for a detaching child's cids.
--- tools/sched_ext/scx_qmap.bpf.c | 33 +++++++++++++++++++++++++++++++-- tools/sched_ext/scx_qmap.c | 7 +++++-- tools/sched_ext/scx_qmap.h | 1 + 3 files changed, 37 insertions(+), 4 deletions(-)
tools/sched_ext/scx_qmap.bpf.c +31 -2
@@ -2167,12 +2167,30 @@ s32 BPF_STRUCT_OPS(qmap_sub_attach, struct scx_sub_attach_args *args)void BPF_STRUCT_OPS (qmap_sub_detach ,struct scx_sub_detach_args *args) { -s32 i; +u64 cgid = args->ops->sub_cgroup_id; +s32 nr_cids = qa.nr_cids; +s32 i, cid; + +if (nr_cids <0 || nr_cids >SCX_QMAP_MAX_CPUS ) { +scx_bpf_error ("-ERANGE" ); +return ; + }for (i =0 ; i <MAX_SUB_SCHEDS ; i++) { -if (qa.sub_sched_ctxs[i].cgroup_id != args->ops->sub_cgroup_id) +if (qa.sub_sched_ctxs[i].cgroup_id != cgid)continue ; +/* +* The child's caps are gone without a report, see +* ops.sub_detach(). cpuperf targets persist until the next +* write, reset the child's excl cids and the pool it may have +* held. +*/ + bpf_arena_for(cid, 0, nr_cids) +if (cmask_test (cid, &qa.sub_sched_ctxs[i].granted_cids.mask) || +cmask_test (cid, &qa.rr_cids.mask)) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); + qa.sub_sched_ctxs[i].cgroup_id =0 ; qa.sub_sched_ctxs[i].weight =100 ;cmask_init (&qa.sub_sched_ctxs[i].granted_cids.mask,0 , qa.nr_cids);
@@ -2208,6 +2226,16 @@ void BPF_STRUCT_OPS(qmap_sub_ecaps_updated, s32 cid, u64 before, u64 after)execute_partition (); } +void BPF_STRUCT_OPS (qmap_sub_child_ecaps_updated ,u64 cgroup_id,s32 cid,u64 before, +u64 after) +{ +__sync_fetch_and_add (&qa.nr_child_ecaps,1 ); + +/* a child's last target must not outlive its PERF cap */ +if ((before & ~after) &SCX_CAP_PERF ) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); +} + SCX_OPS_CID_DEFINE(qmap_ops, .flags = SCX_OPS_ENQ_EXITING | SCX_OPS_TID_TO_TASK, .select_cid = (void *)qmap_select_cid,
@@ -2232,6 +2260,7 @@ SCX_OPS_CID_DEFINE(qmap_ops, .sub_caps_updated = (void *)qmap_sub_caps_updated, .sub_ecaps_updated = (void *)qmap_sub_ecaps_updated, .sub_cid_sched_updated = (void *)qmap_sub_cid_sched_updated, + .sub_child_ecaps_updated = (void *)qmap_sub_child_ecaps_updated, .init_cids = (void *)qmap_init_cids, .init = (void *)qmap_init, .exit = (void *)qmap_exit,
tools/sched_ext/scx_qmap.c +5 -2
@@ -113,6 +113,7 @@ struct hier_prev {u64 nr_enq_blocked;u64 nr_inject_attempts;u64 nr_rescue_dsp; +u64 nr_child_ecaps; };/* current wall-clock time as "HH:MM:SS" for the startup and interval headers */
@@ -208,18 +209,20 @@ static void print_hier(struct qmap_arena *qa, struct hier_prev *prev, u64 own_cg }format_cid_ranges (qa,CID_SHARED , ranges,sizeof (ranges)); -printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu\n" , +printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu child_ecaps=+%llu\n" , (unsigned long long )qa->nr_sub_scheds, qa->part.nr_excl, ranges, rr, (unsigned long long )(qa->nr_reenq_cap - prev->nr_reenq_cap), (unsigned long long )(qa->nr_reenq_immed - prev->nr_reenq_immed), (unsigned long long )(qa->nr_enq_blocked - prev->nr_enq_blocked), (unsigned long long )(qa->nr_inject_attempts - prev->nr_inject_attempts), - (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp)); + (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp), + (unsigned long long )(qa->nr_child_ecaps - prev->nr_child_ecaps)); prev->nr_reenq_cap = qa->nr_reenq_cap; prev->nr_reenq_immed = qa->nr_reenq_immed; prev->nr_enq_blocked = qa->nr_enq_blocked; prev->nr_inject_attempts = qa->nr_inject_attempts; prev->nr_rescue_dsp = qa->nr_rescue_dsp; + prev->nr_child_ecaps = qa->nr_child_ecaps;/* * alloc is the cid-time the partition handed each participant, and used
tools/sched_ext/scx_qmap.h +1 -0
@@ -195,6 +195,7 @@ struct qmap_arena {u64 nr_enq_blocked;/* SCX_ENQ_BLOCKED dispatches */ u64 nr_inject_attempts;/* fault-injection: dispatches to an unheld cid */ u64 nr_rescue_dsp;/* SCX_ENQ_RESCUE dispatch attempts */ +u64 nr_child_ecaps;/* ops.sub_child_ecaps_updated() deliveries */ u32 inject_mode;/* fault-injection mode (QMAP_INJ_*) */ };
Signature · 1 line
2.55.0
Andrea Righi
reviewerRe: [PATCH 1/2] sched_ext: Add ops.sub_child_ecaps_updated() to report a child's effective cap changes
In reply to Tejun HeoHi Tejun,
Quoted 24 lines · Tejun Heo
A grant or revoke only records the target caps. They take effect on a cid at its next dispatch, and nothing tells the parent when. Without that the parent cannot act on a revoke: a child that ran a cid at a low cpuperf target leaves the target there when PERF is revoked, as the kernel resets targets only at root enable. Nor can the parent tell when it may schedule on the cid again.
Add
ops.sub_child_ecaps_updated(), delivered to the direct parent right after the child's ownops.sub_ecaps_updated()with the child's cgroup id and the same before and after caps, in the same dispatch context. Both deliveries are suppressed while the child is bypassing and replayed together afterwards. A disabled child reports nothing:ops.sub_detach()is where the parent restores what it had delegated.A sub is now bypassed before it is linked, so that the grants queued for it from
ops.sub_attach()are consumed while it is bypassed and replayed to it and the parent once it is enabled. Otherwise a sync consumed before the sub's ops are registered would reach the parent but never the sub.v2: Drop the disable report with its sleep lock and nested-dispatch gate, the parent restores from
ops.sub_detach()instead.Signed-off-by Tejun Heo <[email protected]>---
...
Quoted 28 lines
kernel/sched/ext/sub.c +12
-8@@ -1121,27 +1121,43 @@ void __scx_process_sync_ecaps(struct rq *rq, struct task_struct *prev) lost_all |= lost;/* -* Tell the sched its effective caps on this cid changed. The -* invocation is equivalent to the dispatch path and may drop -* and re-acquire the rq lock temporarily while the rest of -* @batch is held privately, see scx_discard_ecaps_to_sync(). -* The dispatch kfuncs resolve their context on the executing -* cpu, which under core scheduling can differ from @rq's cpu, -* so the context is set up there. The rq recorded in it keeps -* the dispatches targeting @rq. +* Tell the sched and its parent that the sched's effective caps +* on this cid changed. The invocations are equivalent to the +* dispatch path and may drop and re-acquire the rq lock +* temporarily while the rest of @batch is held privately, see +* scx_discard_ecaps_to_sync(). The dispatch kfuncs resolve +* their context on the executing cpu, which under core +* scheduling can differ from @rq's cpu, so the context is set +* up there. The rq recorded in it keeps the dispatches +* targeting @rq. +* +* Bypass propagates down the hierarchy, so a sched that isn't +* bypassing has no bypassing parent. The child's bypass state
kernel/sched/ext/sub.c void __scx_process_sync_ecaps(struct rq *rq, struct task_struct *prev) · line 1141
Quoted 10 lines
kernel/sched/ext/sub.c +5
-4+* gates both deliveries. Both report the same before value, so +* one reported_ecaps covers them. */ -if (ecaps != pcpu->reported_ecaps && -SCX_HAS_OP (pcpu->sch, sub_ecaps_updated) && - !scx_bypassing (pcpu->sch, cpu)) { -struct scx_dsp_ctx *dspc = &this_cpu_ptr (pcpu->sch->pcpu)->dsp_ctx; +if (ecaps != pcpu->reported_ecaps && !scx_bypassing (pcpu->sch, cpu)) { +struct scx_sched *parent =scx_parent (pcpu->sch); +struct scx_dsp_ctx *dspc;
Should ops.sub_child_ecaps_updated() still be delivered to the parent when the child is bypassing but the parent is not?
For example, the shared pool may rotate away from a bypassing child. IIUC, its PERF revoke takes effect at the next dispatch, but the child's bypass state suppresses the parent notification too. If the child is being disabled, it never leaves bypass, so the parent only gets ops.sub_detach() and cannot tell when the revoke took effect.
Could we notify the parent when the revoke takes effect, even if the child is bypassing, while continuing to defer the child's own notification until it leaves bypass?
Thanks,
-Andrea
Quoted 54 lines
kernel/sched/ext/sub.c +24
-6- dspc->rq = rq;/* stash @prev so nested dispatches can access it */ rq->scx.sub_dispatch_prev = prev; -SCX_CALL_OP (pcpu->sch, sub_ecaps_updated, rq,scx_cpu_arg (cpu), - pcpu->reported_ecaps, ecaps); +if (SCX_HAS_OP (pcpu->sch, sub_ecaps_updated)) { + dspc = &this_cpu_ptr (pcpu->sch->pcpu)->dsp_ctx; + dspc->rq = rq; +SCX_CALL_OP (pcpu->sch, sub_ecaps_updated, rq, +scx_cpu_arg (cpu), pcpu->reported_ecaps, ecaps); +scx_flush_dispatch_buf (pcpu->sch, rq); + } +if (SCX_HAS_OP (parent, sub_child_ecaps_updated)) { + dspc = &this_cpu_ptr (parent->pcpu)->dsp_ctx; + dspc->rq = rq; +SCX_CALL_OP (parent, sub_child_ecaps_updated, rq, + pcpu->sch->ops.sub_cgroup_id,scx_cpu_arg (cpu), + pcpu->reported_ecaps, ecaps); +scx_flush_dispatch_buf (parent, rq); + } rq->scx.sub_dispatch_prev =NULL ; -scx_flush_dispatch_buf (pcpu->sch, rq); pcpu->reported_ecaps = ecaps; }@@ -1940,6 +1956,15 @@ void scx_sub_enable_workfn(struct kthread_work *work)if (ret) goto err_disable; +/* +* Bypass before @sch is linked and grants can reach it. The parent's +* delivery advances reported_ecaps, so a sync consumed before @sch's +* ops are registered would reach the parent and never be replayed to +* @sch. While bypassed, the syncs are consumed without a delivery and +* replayed to both at unbypass. +*/ +scx_bypass (sch, true); + ret =scx_link_sched (sch);if (ret) goto err_disable;@@ -1985,8 +2010,6 @@ void scx_sub_enable_workfn(struct kthread_work *work) } sch->sub_attached = true; -scx_bypass (sch, true); -for (i =SCX_OPI_BEGIN ; i <SCX_OPI_END ; i++)if (((void (**)(void ))ops)[i])set_bit (i, sch->has_op);Signature · 1 line
2.55.0
Andrea Righi
reviewerRe: [PATCH 2/2] sched_ext: scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
In reply to Tejun HeoHi Tejun,
Quoted 39 lines · Tejun Heo
A child that ran a cid at a low cpuperf target leaves the target there when PERF is revoked, since the kernel resets targets only at root enable. Reset the target from
ops.sub_child_ecaps_updated()once the revoke is in effect. A detach reports nothing, soops.sub_detach()resets the child's cids, the pool included. Count the deliveries in the hier stats.v2: Reset from
ops.sub_detach()for a detaching child's cids.Signed-off-by Tejun Heo <[email protected]>--- tools/sched_ext/scx_qmap.bpf.c | 33 +++++++++++++++++++++++++++++++-- tools/sched_ext/scx_qmap.c | 7 +++++-- tools/sched_ext/scx_qmap.h | 1 + 3 files changed, 37 insertions(+), 4 deletions(-)tools/sched_ext/scx_qmap.bpf.c +10
-2@@ -2167,12 +2167,30 @@ s32 BPF_STRUCT_OPS(qmap_sub_attach, struct scx_sub_attach_args *args)void BPF_STRUCT_OPS (qmap_sub_detach ,struct scx_sub_detach_args *args) { -s32 i; +u64 cgid = args->ops->sub_cgroup_id; +s32 nr_cids = qa.nr_cids; +s32 i, cid; + +if (nr_cids <0 || nr_cids >SCX_QMAP_MAX_CPUS ) { +scx_bpf_error ("-ERANGE" ); +return ; + }for (i =0 ; i <MAX_SUB_SCHEDS ; i++) { -if (qa.sub_sched_ctxs[i].cgroup_id != args->ops->sub_cgroup_id) +if (qa.sub_sched_ctxs[i].cgroup_id != cgid)continue ; +/*
tools/sched_ext/scx_qmap.bpf.c s32 BPF_STRUCT_OPS(qmap_sub_attach, struct scx_sub_attach_args *args) · line 2193
Quoted 10 lines
tools/sched_ext/scx_qmap.bpf.c +10
-0+* The child's caps are gone without a report, see +* ops.sub_detach(). cpuperf targets persist until the next +* write, reset the child's excl cids and the pool it may have +* held. +*/ + bpf_arena_for(cid, 0, nr_cids) +if (cmask_test (cid, &qa.sub_sched_ctxs[i].granted_cids.mask) || +cmask_test (cid, &qa.rr_cids.mask)) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); +
qa.rr_cids covers the entire shared pool, regardless of its current holder, right? If child A detaches during child B's turn, this resets the pool's cpuperf target even if B still holds PERF and has written its own target.
Should we avoid resetting the current holder's target here?
Thanks,
-Andrea
Quoted 78 lines
tools/sched_ext/scx_qmap.bpf.c +11
-0qa.sub_sched_ctxs[i].cgroup_id =0 ; qa.sub_sched_ctxs[i].weight =100 ;cmask_init (&qa.sub_sched_ctxs[i].granted_cids.mask,0 , qa.nr_cids);@@ -2208,6 +2226,16 @@ void BPF_STRUCT_OPS(qmap_sub_ecaps_updated, s32 cid, u64 before, u64 after)execute_partition (); } +void BPF_STRUCT_OPS (qmap_sub_child_ecaps_updated ,u64 cgroup_id,s32 cid,u64 before, +u64 after) +{ +__sync_fetch_and_add (&qa.nr_child_ecaps,1 ); + +/* a child's last target must not outlive its PERF cap */ +if ((before & ~after) &SCX_CAP_PERF ) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); +} + SCX_OPS_CID_DEFINE(qmap_ops, .flags = SCX_OPS_ENQ_EXITING | SCX_OPS_TID_TO_TASK, .select_cid = (void *)qmap_select_cid,@@ -2232,6 +2260,7 @@ SCX_OPS_CID_DEFINE(qmap_ops, .sub_caps_updated = (void *)qmap_sub_caps_updated, .sub_ecaps_updated = (void *)qmap_sub_ecaps_updated, .sub_cid_sched_updated = (void *)qmap_sub_cid_sched_updated, + .sub_child_ecaps_updated = (void *)qmap_sub_child_ecaps_updated, .init_cids = (void *)qmap_init_cids, .init = (void *)qmap_init, .exit = (void *)qmap_exit,tools/sched_ext/scx_qmap.c +5
-2@@ -113,6 +113,7 @@ struct hier_prev {u64 nr_enq_blocked;u64 nr_inject_attempts;u64 nr_rescue_dsp; +u64 nr_child_ecaps; };/* current wall-clock time as "HH:MM:SS" for the startup and interval headers */ @@ -208,18 +209,20 @@ static void print_hier(struct qmap_arena *qa, struct hier_prev *prev, u64 own_cg }format_cid_ranges (qa,CID_SHARED , ranges,sizeof (ranges)); -printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu\n" , +printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu child_ecaps=+%llu\n" , (unsigned long long )qa->nr_sub_scheds, qa->part.nr_excl, ranges, rr, (unsigned long long )(qa->nr_reenq_cap - prev->nr_reenq_cap), (unsigned long long )(qa->nr_reenq_immed - prev->nr_reenq_immed), (unsigned long long )(qa->nr_enq_blocked - prev->nr_enq_blocked), (unsigned long long )(qa->nr_inject_attempts - prev->nr_inject_attempts), - (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp)); + (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp), + (unsigned long long )(qa->nr_child_ecaps - prev->nr_child_ecaps)); prev->nr_reenq_cap = qa->nr_reenq_cap; prev->nr_reenq_immed = qa->nr_reenq_immed; prev->nr_enq_blocked = qa->nr_enq_blocked; prev->nr_inject_attempts = qa->nr_inject_attempts; prev->nr_rescue_dsp = qa->nr_rescue_dsp; + prev->nr_child_ecaps = qa->nr_child_ecaps;/* * alloc is the cid-time the partition handed each participant, and used tools/sched_ext/scx_qmap.h +1
-0@@ -195,6 +195,7 @@ struct qmap_arena {u64 nr_enq_blocked;/* SCX_ENQ_BLOCKED dispatches */ u64 nr_inject_attempts;/* fault-injection: dispatches to an unheld cid */ u64 nr_rescue_dsp;/* SCX_ENQ_RESCUE dispatch attempts */ +u64 nr_child_ecaps;/* ops.sub_child_ecaps_updated() deliveries */ u32 inject_mode;/* fault-injection mode (QMAP_INJ_*) */ };Signature · 1 line
2.55.0
Tejun Heo
reviewerRe: [PATCH 1/2] sched_ext: Add ops.sub_child_ecaps_updated() to report a child's effective cap changes
In reply to Andrea RighiHello, Andrea.
Quoted 9 lines · Andrea Righi
Should
ops.sub_child_ecaps_updated()still be delivered to the parent when the child is bypassing but the parent is not?For example, the shared pool may rotate away from a bypassing child. IIUC, its PERF revoke takes effect at the next dispatch, but the child's bypass state suppresses the parent notification too. If the child is being disabled, it never leaves bypass, so the parent only gets
ops.sub_detach()and cannot tell when the revoke took effect.
Quoted 3 lines
Could we notify the parent when the revoke takes effect, even if the child is bypassing, while continuing to defer the child's own notification until it leaves bypass?
A child can't enter and stay in bypass on its own. It bypasses during its own enable, which is lifted and replayed, during its own disable, or when the whole hierarchy is bypassing and so is the parent. That leaves disable. v1 reported the revokes of a disabling child and it got nasty because the calling context differs from the sync path: the dispatch kfuncs needed their context set up outside the dispatch path, the nested sub dispatch had to be gated, and keeping the report clear of the PM bypass took a lock that could stall a suspend. The simpler contract that works is that ops.sub_detach() covers a disabling child. All of the child's caps are gone by the time it runs, so the parent restores what it delegated from there.
Thanks.
--
tejun
Tejun Heo
reviewerRe: [PATCH 2/2] sched_ext: scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
In reply to Andrea RighiHello, Andrea.
Quoted 5 lines · Andrea Righi
qa.rr_cids covers the entire shared pool, regardless of its current holder, right? If child A detaches during child B's turn, this resets the pool's cpuperf target even if B still holds PERF and has written its own target.
Should we avoid resetting the current holder's target here?
Right. It's transient, the detach's repartition revokes the pool from B and the handler resets it again when that lands, but B's targets get clobbered in between. Will skip the pool when another child holds it in the next version.
Thanks.
--
tejun
Re: [PATCH 1/2] sched_ext: Add ops.sub_child_ecaps_updated() to report a child's effective cap changes
In reply to Tejun HeoQuoted 16 lines · Tejun Heo
Hello, Andrea.
Quoted 9 lines · Andrea Righi
Should
ops.sub_child_ecaps_updated()still be delivered to the parent when the child is bypassing but the parent is not?For example, the shared pool may rotate away from a bypassing child. IIUC, its PERF revoke takes effect at the next dispatch, but the child's bypass state suppresses the parent notification too. If the child is being disabled, it never leaves bypass, so the parent only gets
ops.sub_detach()and cannot tell when the revoke took effect.Quoted 3 lines
Could we notify the parent when the revoke takes effect, even if the child is bypassing, while continuing to defer the child's own notification until it leaves bypass?
Quoted 10 lines
A child can't enter and stay in bypass on its own. It bypasses during its own enable, which is lifted and replayed, during its own disable, or when the whole hierarchy is bypassing and so is the parent. That leaves disable. v1 reported the revokes of a disabling child and it got nasty because the calling context differs from the sync path: the dispatch kfuncs needed their context set up outside the dispatch path, the nested sub dispatch had to be gated, and keeping the report clear of the PM bypass took a lock that could stall a suspend. The simpler contract that works is that
ops.sub_detach()covers a disabling child. All of the child's caps are gone by the time it runs, so the parent restores what it delegated from there.
Ah yes, it makes sense, disable is the only case where a child remains bypassed while the parent is active. Handling final cleanup in ops.sub_detach() is reasonable given the different calling context.
Thanks,
-Andrea
Tejun Heo
reviewerPATCH v3 2/2 sched_ext: scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
In reply to Tejun HeoA child that ran a cid at a low cpuperf target leaves the target there when PERF is revoked, since the kernel resets targets only at root enable. Reset the target from ops.sub_child_ecaps_updated() once the revoke is in effect. A detach reports nothing, so ops.sub_detach() resets the child's cids, and the pool unless another child holds it. Count the deliveries in the hier stats.
v2: Reset from ops.sub_detach() for a detaching child's cids.
v3: Skip the pool at detach while another child holds it (Andrea Righi).
--- tools/sched_ext/scx_qmap.bpf.c | 39 +++++++++++++++++++++++++++++++++++++-- tools/sched_ext/scx_qmap.c | 7 +++++-- tools/sched_ext/scx_qmap.h | 1 + 3 files changed, 43 insertions(+), 4 deletions(-)
tools/sched_ext/scx_qmap.bpf.c +37 -2
@@ -2167,12 +2167,36 @@ s32 BPF_STRUCT_OPS(qmap_sub_attach, struvoid BPF_STRUCT_OPS (qmap_sub_detach ,struct scx_sub_detach_args *args) { -s32 i; +u64 cgid = args->ops->sub_cgroup_id; +s32 nr_cids = qa.nr_cids; +s32 pos = qa.part.rr_pos; +u64 holder_cgid; +bool reset_pool; +s32 i, cid; + +if (nr_cids <0 || nr_cids >SCX_QMAP_MAX_CPUS || pos <0 || pos >=MAX_PARTS ) { +scx_bpf_error ("-ERANGE" ); +return ; + } + +/* +* The child's caps are gone without a report, see ops.sub_detach(). +* cpuperf targets persist until the next write. Reset the child's excl +* cids, and the pool unless another child holds it: that child's revoke +* report or its own detach resets it then. +*/ + holder_cgid = qa.part.rr_slots[pos]; + reset_pool = !holder_cgid || holder_cgid == cgid;for (i =0 ; i <MAX_SUB_SCHEDS ; i++) { -if (qa.sub_sched_ctxs[i].cgroup_id != args->ops->sub_cgroup_id) +if (qa.sub_sched_ctxs[i].cgroup_id != cgid)continue ; + bpf_arena_for(cid, 0, nr_cids) +if (cmask_test (cid, &qa.sub_sched_ctxs[i].granted_cids.mask) || + (reset_pool &&cmask_test (cid, &qa.rr_cids.mask))) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); + qa.sub_sched_ctxs[i].cgroup_id =0 ; qa.sub_sched_ctxs[i].weight =100 ;cmask_init (&qa.sub_sched_ctxs[i].granted_cids.mask,0 , qa.nr_cids);
@@ -2208,6 +2232,16 @@ void BPF_STRUCT_OPS(qmap_sub_ecaps_updatexecute_partition (); } +void BPF_STRUCT_OPS (qmap_sub_child_ecaps_updated ,u64 cgroup_id,s32 cid,u64 before, +u64 after) +{ +__sync_fetch_and_add (&qa.nr_child_ecaps,1 ); + +/* a child's last target must not outlive its PERF cap */ +if ((before & ~after) &SCX_CAP_PERF ) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); +} + SCX_OPS_CID_DEFINE(qmap_ops, .flags = SCX_OPS_ENQ_EXITING | SCX_OPS_TID_TO_TASK, .select_cid = (void *)qmap_select_cid,
@@ -2232,6 +2266,7 @@ SCX_OPS_CID_DEFINE(qmap_ops, .sub_caps_updated = (void *)qmap_sub_caps_updated, .sub_ecaps_updated = (void *)qmap_sub_ecaps_updated, .sub_cid_sched_updated = (void *)qmap_sub_cid_sched_updated, + .sub_child_ecaps_updated = (void *)qmap_sub_child_ecaps_updated, .init_cids = (void *)qmap_init_cids, .init = (void *)qmap_init, .exit = (void *)qmap_exit,
tools/sched_ext/scx_qmap.c +5 -2
@@ -113,6 +113,7 @@ struct hier_prev {u64 nr_enq_blocked;u64 nr_inject_attempts;u64 nr_rescue_dsp; +u64 nr_child_ecaps; };/* current wall-clock time as "HH:MM:SS" for the startup and interval headers */
@@ -208,18 +209,20 @@ static void print_hier(struct qmap_arena }format_cid_ranges (qa,CID_SHARED , ranges,sizeof (ranges)); -printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu\n" , +printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu child_ecaps=+%llu\n" , (unsigned long long )qa->nr_sub_scheds, qa->part.nr_excl, ranges, rr, (unsigned long long )(qa->nr_reenq_cap - prev->nr_reenq_cap), (unsigned long long )(qa->nr_reenq_immed - prev->nr_reenq_immed), (unsigned long long )(qa->nr_enq_blocked - prev->nr_enq_blocked), (unsigned long long )(qa->nr_inject_attempts - prev->nr_inject_attempts), - (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp)); + (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp), + (unsigned long long )(qa->nr_child_ecaps - prev->nr_child_ecaps)); prev->nr_reenq_cap = qa->nr_reenq_cap; prev->nr_reenq_immed = qa->nr_reenq_immed; prev->nr_enq_blocked = qa->nr_enq_blocked; prev->nr_inject_attempts = qa->nr_inject_attempts; prev->nr_rescue_dsp = qa->nr_rescue_dsp; + prev->nr_child_ecaps = qa->nr_child_ecaps;/* * alloc is the cid-time the partition handed each participant, and used
tools/sched_ext/scx_qmap.h +1 -0
@@ -195,6 +195,7 @@ struct qmap_arena {u64 nr_enq_blocked;/* SCX_ENQ_BLOCKED dispatches */ u64 nr_inject_attempts;/* fault-injection: dispatches to an unheld cid */ u64 nr_rescue_dsp;/* SCX_ENQ_RESCUE dispatch attempts */ +u64 nr_child_ecaps;/* ops.sub_child_ecaps_updated() deliveries */ u32 inject_mode;/* fault-injection mode (QMAP_INJ_*) */ };
Re: [PATCH v3 2/2] sched_ext: scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
Hi Tejun,
Quoted 7 lines · Tejun Heo
A child that ran a cid at a low cpuperf target leaves the target there when PERF is revoked, since the kernel resets targets only at root enable. Reset the target from
ops.sub_child_ecaps_updated()once the revoke is in effect. A detach reports nothing, soops.sub_detach()resets the child's cids, and the pool unless another child holds it. Count the deliveries in the hier stats.
Quoted 5 lines
v2: Reset from
ops.sub_detach()for a detaching child's cids.v3: Skip the pool at detach while another child holds it (Andrea Righi).
Signed-off-by Tejun Heo <[email protected]>
This looks good to me.
Thanks,
-Andrea
Quoted 115 lines
--- tools/sched_ext/scx_qmap.bpf.c | 39 +++++++++++++++++++++++++++++++++++++-- tools/sched_ext/scx_qmap.c | 7 +++++-- tools/sched_ext/scx_qmap.h | 1 + 3 files changed, 43 insertions(+), 4 deletions(-)tools/sched_ext/scx_qmap.bpf.c +37
-2@@ -2167,12 +2167,36 @@ s32 BPF_STRUCT_OPS(qmap_sub_attach, struvoid BPF_STRUCT_OPS (qmap_sub_detach ,struct scx_sub_detach_args *args) { -s32 i; +u64 cgid = args->ops->sub_cgroup_id; +s32 nr_cids = qa.nr_cids; +s32 pos = qa.part.rr_pos; +u64 holder_cgid; +bool reset_pool; +s32 i, cid; + +if (nr_cids <0 || nr_cids >SCX_QMAP_MAX_CPUS || pos <0 || pos >=MAX_PARTS ) { +scx_bpf_error ("-ERANGE" ); +return ; + } + +/* +* The child's caps are gone without a report, see ops.sub_detach(). +* cpuperf targets persist until the next write. Reset the child's excl +* cids, and the pool unless another child holds it: that child's revoke +* report or its own detach resets it then. +*/ + holder_cgid = qa.part.rr_slots[pos]; + reset_pool = !holder_cgid || holder_cgid == cgid;for (i =0 ; i <MAX_SUB_SCHEDS ; i++) { -if (qa.sub_sched_ctxs[i].cgroup_id != args->ops->sub_cgroup_id) +if (qa.sub_sched_ctxs[i].cgroup_id != cgid)continue ; + bpf_arena_for(cid, 0, nr_cids) +if (cmask_test (cid, &qa.sub_sched_ctxs[i].granted_cids.mask) || + (reset_pool &&cmask_test (cid, &qa.rr_cids.mask))) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); + qa.sub_sched_ctxs[i].cgroup_id =0 ; qa.sub_sched_ctxs[i].weight =100 ;cmask_init (&qa.sub_sched_ctxs[i].granted_cids.mask,0 , qa.nr_cids);@@ -2208,6 +2232,16 @@ void BPF_STRUCT_OPS(qmap_sub_ecaps_updatexecute_partition (); } +void BPF_STRUCT_OPS (qmap_sub_child_ecaps_updated ,u64 cgroup_id,s32 cid,u64 before, +u64 after) +{ +__sync_fetch_and_add (&qa.nr_child_ecaps,1 ); + +/* a child's last target must not outlive its PERF cap */ +if ((before & ~after) &SCX_CAP_PERF ) +scx_bpf_cidperf_set (cid,SCX_CPUPERF_ONE ); +} + SCX_OPS_CID_DEFINE(qmap_ops, .flags = SCX_OPS_ENQ_EXITING | SCX_OPS_TID_TO_TASK, .select_cid = (void *)qmap_select_cid,@@ -2232,6 +2266,7 @@ SCX_OPS_CID_DEFINE(qmap_ops, .sub_caps_updated = (void *)qmap_sub_caps_updated, .sub_ecaps_updated = (void *)qmap_sub_ecaps_updated, .sub_cid_sched_updated = (void *)qmap_sub_cid_sched_updated, + .sub_child_ecaps_updated = (void *)qmap_sub_child_ecaps_updated, .init_cids = (void *)qmap_init_cids, .init = (void *)qmap_init, .exit = (void *)qmap_exit,tools/sched_ext/scx_qmap.c +5
-2@@ -113,6 +113,7 @@ struct hier_prev {u64 nr_enq_blocked;u64 nr_inject_attempts;u64 nr_rescue_dsp; +u64 nr_child_ecaps; };/* current wall-clock time as "HH:MM:SS" for the startup and interval headers */ @@ -208,18 +209,20 @@ static void print_hier(struct qmap_arena }format_cid_ranges (qa,CID_SHARED , ranges,sizeof (ranges)); -printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu\n" , +printf ("hier : nsub=%llu excl=%u shared=%s rr=%s reenq cap/immed +%llu/+%llu blocked=+%llu inj=+%llu rescue=+%llu child_ecaps=+%llu\n" , (unsigned long long )qa->nr_sub_scheds, qa->part.nr_excl, ranges, rr, (unsigned long long )(qa->nr_reenq_cap - prev->nr_reenq_cap), (unsigned long long )(qa->nr_reenq_immed - prev->nr_reenq_immed), (unsigned long long )(qa->nr_enq_blocked - prev->nr_enq_blocked), (unsigned long long )(qa->nr_inject_attempts - prev->nr_inject_attempts), - (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp)); + (unsigned long long )(qa->nr_rescue_dsp - prev->nr_rescue_dsp), + (unsigned long long )(qa->nr_child_ecaps - prev->nr_child_ecaps)); prev->nr_reenq_cap = qa->nr_reenq_cap; prev->nr_reenq_immed = qa->nr_reenq_immed; prev->nr_enq_blocked = qa->nr_enq_blocked; prev->nr_inject_attempts = qa->nr_inject_attempts; prev->nr_rescue_dsp = qa->nr_rescue_dsp; + prev->nr_child_ecaps = qa->nr_child_ecaps;/* * alloc is the cid-time the partition handed each participant, and used tools/sched_ext/scx_qmap.h +1
-0@@ -195,6 +195,7 @@ struct qmap_arena {u64 nr_enq_blocked;/* SCX_ENQ_BLOCKED dispatches */ u64 nr_inject_attempts;/* fault-injection: dispatches to an unheld cid */ u64 nr_rescue_dsp;/* SCX_ENQ_RESCUE dispatch attempts */ +u64 nr_child_ecaps;/* ops.sub_child_ecaps_updated() deliveries */ u32 inject_mode;/* fault-injection mode (QMAP_INJ_*) */ };
Quoted 2 lines · Tejun Heo
0001
sched_ext: Addops.sub_child_ecaps_updated()to report a child's effective cap changes 0002sched_ext:scx_qmap: Reset a child's cpuperf targets once its PERF revoke takes effect
Applied 1-2 to sched_ext/for-7.4, 2 from its v3, with the following tag added to both:
Thanks.
Signature · 1 line
tejun