sched_ext: Add ops.sub_child_ecaps_updated()
Subsystems (2)
Tejun Heo
reviewerPATCH 1/1 sched_ext: Add ops.sub_child_ecaps_updated()
Hello,
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. Until then 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 the caps it still held as revoked before the parent's ops.sub_detach(). Patch 2 makes scx_qmap reset a child's cpuperf target once its PERF revoke takes effect.
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
diffstat follows. Thanks.
kernel/sched/ext/ext.c | 4 ++ kernel/sched/ext/internal.h | 29 ++++++++- kernel/sched/ext/sub.c | 130 ++++++++++++++++++++++++++++++++++------- tools/sched_ext/scx_qmap.bpf.c | 15 +++++ tools/sched_ext/scx_qmap.c | 7 ++- tools/sched_ext/scx_qmap.h | 1 + 6 files changed, 161 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. Until then the parent cannot act on a revoke: a cid a child ran at a low cpuperf target keeps that target after PERF is revoked, as the kernel resets targets only at root enable, and the parent cannot 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 sub's disable reports the caps it still held as revoked before the parent's ops.sub_detach(), so the parent needs no record of its own for a detach. A cpu going offline drops its caps without a report, as for the child.
The following behavior changes are made to support the deliveries:
- The disable report runs outside the dispatch path, with the clock updated and the rq lock unpinned for the op's kfuncs. scx_bpf_sub_dispatch() needs a pick in progress and triggers an scx_error() there.
- scx_sub_disable() holds the system sleep lock so that a disable never runs during a PM transition. The transition bypasses the whole hierarchy, which would suppress the report to a parent that stays enabled.
- A sub enters its enable bypass 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 be delivered to the parent but not to the sub, and the shared before value would move past it.
--- kernel/sched/ext/ext.c | 4 ++ kernel/sched/ext/internal.h | 29 +++++++- kernel/sched/ext/sub.c | 130 ++++++++++++++++++++++++++++++------ 3 files changed, 140 insertions(+), 23 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 cgid,s32 cid,u64 old,u64 new) {}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 +28 -1
@@ -932,6 +932,29 @@ 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 +* +* A grant or revoke records the target caps and the cid applies them at +* its next dispatch, which is when the child's kfuncs start seeing the +* change. Invoked at that point, right after the child's +* sub_ecaps_updated(). From here on the parent can act on a cap the +* child lost: reset what the child set under it, such as the cpuperf +* target, and schedule on the cid, since the child no longer can. The +* caps a child holds when it is disabled are reported revoked before +* sub_detach() runs. A cpu going offline drops caps without a report. +* +* Runs with the cid's rq lock held, and can perform all operations +* allowed in ops.dispatch() including inserting/moving tasks. The +* disable report runs outside the dispatch path, where a nested sub +* dispatch triggers an scx_error(). +*/ +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 +1213,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 +1477,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 +108 -22
204 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 it to SCX_CPUPERF_ONE from ops.sub_child_ecaps_updated() once the revoke is in effect, a detach included. Count the deliveries in the hier stats.
--- tools/sched_ext/scx_qmap.bpf.c | 15 +++++++++++++++ tools/sched_ext/scx_qmap.c | 7 +++++-- tools/sched_ext/scx_qmap.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-)
tools/sched_ext/scx_qmap.bpf.c +15 -0
@@ -2208,6 +2208,20 @@ 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 cid's cpuperf target stays where the last write put it. Reset it +* once a child's PERF revoke is in effect so that the child's last +* target doesn't outlive the 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 +2246,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