Skip to content

Commit 0951abf

Browse files
Zhao Mengmenggregkh
authored andcommitted
tools/sched_ext: scx_pair: fix pair_ctx indexing for CPU pairs
[ Upstream commit f546c77 ] scx_pair sizes pair_ctx to nr_cpu_ids / 2, so valid pair_ctx keys are dense pair indexes in the range [0, nr_cpu_ids / 2). However, the userspace setup code stores pair_id as the first CPU number in each pair. On an 8-CPU system with "-S 1", that produces pair IDs 0, 2, 4 and 6 for pairs [0,1], [2,3], [4,5] and [6,7]. CPUs in the latter half then look up pair_ctx with out-of-range keys and the BPF scheduler aborts with: EXIT: scx_bpf_error (scx_pair.bpf.c:328: failed to lookup pairc and in_pair_mask for cpu[5]) Assign pair_id using a dense pair counter instead so that each CPU pair maps to a valid pair_ctx entry. Besides, reject odd CPU configuration, as scx_pair requires all CPUs to be paired. Fixes: f0262b1 ("tools/sched_ext: add scx_pair scheduler") Signed-off-by: Zhao Mengmeng <zhaomengmeng@kylinos.cn> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b76584c commit 0951abf

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tools/sched_ext/scx_pair.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int main(int argc, char **argv)
4848
struct bpf_link *link;
4949
__u64 seq = 0, ecode;
5050
__s32 stride, i, opt, outer_fd;
51+
__u32 pair_id = 0;
5152

5253
libbpf_set_print(libbpf_print_fn);
5354
signal(SIGINT, sigint_handler);
@@ -82,6 +83,14 @@ int main(int argc, char **argv)
8283
scx_pair__destroy(skel);
8384
return -1;
8485
}
86+
87+
if (skel->rodata->nr_cpu_ids & 1) {
88+
fprintf(stderr, "scx_pair requires an even CPU count, got %u\n",
89+
skel->rodata->nr_cpu_ids);
90+
scx_pair__destroy(skel);
91+
return -1;
92+
}
93+
8594
bpf_map__set_max_entries(skel->maps.pair_ctx, skel->rodata->nr_cpu_ids / 2);
8695

8796
/* Resize arrays so their element count is equal to cpu count. */
@@ -109,10 +118,11 @@ int main(int argc, char **argv)
109118

110119
skel->rodata_pair_cpu->pair_cpu[i] = j;
111120
skel->rodata_pair_cpu->pair_cpu[j] = i;
112-
skel->rodata_pair_id->pair_id[i] = i;
113-
skel->rodata_pair_id->pair_id[j] = i;
121+
skel->rodata_pair_id->pair_id[i] = pair_id;
122+
skel->rodata_pair_id->pair_id[j] = pair_id;
114123
skel->rodata_in_pair_idx->in_pair_idx[i] = 0;
115124
skel->rodata_in_pair_idx->in_pair_idx[j] = 1;
125+
pair_id++;
116126

117127
printf("[%d, %d] ", i, j);
118128
}

0 commit comments

Comments
 (0)