Skip to content

Commit b448bbd

Browse files
authored
Merge pull request raspberrypi#50 from sched-ext/rusty-fix-all_cpus
2 parents 2a3532d + c70e7d3 commit b448bbd

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

tools/sched_ext/scx_rusty/src/bpf/rusty.bpf.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct tune_input{
155155
} tune_input;
156156

157157
__u64 tune_params_gen;
158+
private(A) struct bpf_cpumask __kptr *all_cpumask;
158159
private(A) struct bpf_cpumask __kptr *direct_greedy_cpumask;
159160
private(A) struct bpf_cpumask __kptr *kick_greedy_cpumask;
160161

@@ -790,7 +791,8 @@ void BPF_STRUCT_OPS(rusty_set_cpumask, struct task_struct *p,
790791
}
791792

792793
task_pick_and_set_domain(task_ctx, p, cpumask, false);
793-
task_ctx->all_cpus = bpf_cpumask_full(cpumask);
794+
if (all_cpumask)
795+
task_ctx->all_cpus = bpf_cpumask_subset(all_cpumask, cpumask);
794796
}
795797

796798
s32 BPF_STRUCT_OPS(rusty_prep_enable, struct task_struct *p,
@@ -890,8 +892,14 @@ static s32 create_dom(u32 dom_id)
890892
return -ENOENT;
891893
}
892894

893-
if (*dmask & (1LLU << (cpu % 64)))
895+
if (*dmask & (1LLU << (cpu % 64))) {
894896
bpf_cpumask_set_cpu(cpu, cpumask);
897+
898+
bpf_rcu_read_lock();
899+
if (all_cpumask)
900+
bpf_cpumask_set_cpu(cpu, all_cpumask);
901+
bpf_rcu_read_unlock();
902+
}
895903
}
896904

897905
cpumask = bpf_kptr_xchg(&domc->cpumask, cpumask);
@@ -924,17 +932,12 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(rusty_init)
924932
struct bpf_cpumask *cpumask;
925933
s32 i, ret;
926934

927-
if (!switch_partial)
928-
scx_bpf_switch_all();
929-
930-
bpf_for(i, 0, nr_doms) {
931-
ret = create_dom(i);
932-
if (ret)
933-
return ret;
934-
}
935-
936-
bpf_for(i, 0, nr_cpus)
937-
pcpu_ctx[i].dom_rr_cur = i;
935+
cpumask = bpf_cpumask_create();
936+
if (!cpumask)
937+
return -ENOMEM;
938+
cpumask = bpf_kptr_xchg(&all_cpumask, cpumask);
939+
if (cpumask)
940+
bpf_cpumask_release(cpumask);
938941

939942
cpumask = bpf_cpumask_create();
940943
if (!cpumask)
@@ -950,6 +953,18 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(rusty_init)
950953
if (cpumask)
951954
bpf_cpumask_release(cpumask);
952955

956+
if (!switch_partial)
957+
scx_bpf_switch_all();
958+
959+
bpf_for(i, 0, nr_doms) {
960+
ret = create_dom(i);
961+
if (ret)
962+
return ret;
963+
}
964+
965+
bpf_for(i, 0, nr_cpus)
966+
pcpu_ctx[i].dom_rr_cur = i;
967+
953968
return 0;
954969
}
955970

0 commit comments

Comments
 (0)