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

Configure Feed

Select the types of activity you want to include in your feed.

sched_ext: Use time helpers in BPF schedulers

Modify the BPF schedulers to use time helpers defined in common.bpf.h

Signed-off-by: Changwoo Min <changwoo@igalia.com>
Acked-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Changwoo Min and committed by
Tejun Heo
62addc6d 0f130bc3

+11 -26
+1 -6
tools/sched_ext/scx_central.bpf.c
··· 87 87 __type(value, struct central_timer); 88 88 } central_timer SEC(".maps"); 89 89 90 - static bool vtime_before(u64 a, u64 b) 91 - { 92 - return (s64)(a - b) < 0; 93 - } 94 - 95 90 s32 BPF_STRUCT_OPS(central_select_cpu, struct task_struct *p, 96 91 s32 prev_cpu, u64 wake_flags) 97 92 { ··· 274 279 /* kick iff the current one exhausted its slice */ 275 280 started_at = ARRAY_ELEM_PTR(cpu_started_at, cpu, nr_cpu_ids); 276 281 if (started_at && *started_at && 277 - vtime_before(now, *started_at + slice_ns)) 282 + time_before(now, *started_at + slice_ns)) 278 283 continue; 279 284 280 285 /* and there's something pending */
+8 -13
tools/sched_ext/scx_flatcg.bpf.c
··· 137 137 return (dividend + divisor - 1) / divisor; 138 138 } 139 139 140 - static bool vtime_before(u64 a, u64 b) 141 - { 142 - return (s64)(a - b) < 0; 143 - } 144 - 145 140 static bool cgv_node_less(struct bpf_rb_node *a, const struct bpf_rb_node *b) 146 141 { 147 142 struct cgv_node *cgc_a, *cgc_b; ··· 266 271 */ 267 272 max_budget = (cgrp_slice_ns * nr_cpus * cgc->hweight) / 268 273 (2 * FCG_HWEIGHT_ONE); 269 - if (vtime_before(cvtime, cvtime_now - max_budget)) 274 + if (time_before(cvtime, cvtime_now - max_budget)) 270 275 cvtime = cvtime_now - max_budget; 271 276 272 277 cgv_node->cvtime = cvtime; ··· 396 401 * Limit the amount of budget that an idling task can accumulate 397 402 * to one slice. 398 403 */ 399 - if (vtime_before(tvtime, cgc->tvtime_now - SCX_SLICE_DFL)) 404 + if (time_before(tvtime, cgc->tvtime_now - SCX_SLICE_DFL)) 400 405 tvtime = cgc->tvtime_now - SCX_SLICE_DFL; 401 406 402 407 scx_bpf_dsq_insert_vtime(p, cgrp->kn->id, SCX_SLICE_DFL, ··· 530 535 * from multiple CPUs and thus racy. Any error should be 531 536 * contained and temporary. Let's just live with it. 532 537 */ 533 - if (vtime_before(cgc->tvtime_now, p->scx.dsq_vtime)) 538 + if (time_before(cgc->tvtime_now, p->scx.dsq_vtime)) 534 539 cgc->tvtime_now = p->scx.dsq_vtime; 535 540 } 536 541 bpf_cgroup_release(cgrp); ··· 640 645 cgv_node = container_of(rb_node, struct cgv_node, rb_node); 641 646 cgid = cgv_node->cgid; 642 647 643 - if (vtime_before(cvtime_now, cgv_node->cvtime)) 648 + if (time_before(cvtime_now, cgv_node->cvtime)) 644 649 cvtime_now = cgv_node->cvtime; 645 650 646 651 /* ··· 739 744 if (!cpuc->cur_cgid) 740 745 goto pick_next_cgroup; 741 746 742 - if (vtime_before(now, cpuc->cur_at + cgrp_slice_ns)) { 747 + if (time_before(now, cpuc->cur_at + cgrp_slice_ns)) { 743 748 if (scx_bpf_dsq_move_to_local(cpuc->cur_cgid)) { 744 749 stat_inc(FCG_STAT_CNS_KEEP); 745 750 return; ··· 915 920 struct cgroup *from, struct cgroup *to) 916 921 { 917 922 struct fcg_cgrp_ctx *from_cgc, *to_cgc; 918 - s64 vtime_delta; 923 + s64 delta; 919 924 920 925 /* find_cgrp_ctx() triggers scx_ops_error() on lookup failures */ 921 926 if (!(from_cgc = find_cgrp_ctx(from)) || !(to_cgc = find_cgrp_ctx(to))) 922 927 return; 923 928 924 - vtime_delta = p->scx.dsq_vtime - from_cgc->tvtime_now; 925 - p->scx.dsq_vtime = to_cgc->tvtime_now + vtime_delta; 929 + delta = time_delta(p->scx.dsq_vtime, from_cgc->tvtime_now); 930 + p->scx.dsq_vtime = to_cgc->tvtime_now + delta; 926 931 } 927 932 928 933 s32 BPF_STRUCT_OPS_SLEEPABLE(fcg_init)
+2 -7
tools/sched_ext/scx_simple.bpf.c
··· 52 52 (*cnt_p)++; 53 53 } 54 54 55 - static inline bool vtime_before(u64 a, u64 b) 56 - { 57 - return (s64)(a - b) < 0; 58 - } 59 - 60 55 s32 BPF_STRUCT_OPS(simple_select_cpu, struct task_struct *p, s32 prev_cpu, u64 wake_flags) 61 56 { 62 57 bool is_idle = false; ··· 79 84 * Limit the amount of budget that an idling task can accumulate 80 85 * to one slice. 81 86 */ 82 - if (vtime_before(vtime, vtime_now - SCX_SLICE_DFL)) 87 + if (time_before(vtime, vtime_now - SCX_SLICE_DFL)) 83 88 vtime = vtime_now - SCX_SLICE_DFL; 84 89 85 90 scx_bpf_dsq_insert_vtime(p, SHARED_DSQ, SCX_SLICE_DFL, vtime, ··· 103 108 * thus racy. Any error should be contained and temporary. Let's just 104 109 * live with it. 105 110 */ 106 - if (vtime_before(vtime_now, p->scx.dsq_vtime)) 111 + if (time_before(vtime_now, p->scx.dsq_vtime)) 107 112 vtime_now = p->scx.dsq_vtime; 108 113 } 109 114