Skip to content

Commit 7229268

Browse files
committed
scx_pair: Fix custom stride error handling
scx_pair uses the default stride value of nr_cpu_ids / 2, which matches most x86 SMT configurations. However, it does allow specifying a custom stride value with -S so that e.g. neighboring CPUs can be paired up. However, not all stride values work and errors were not reported very well. This patch improves error handling so that scx_pair fails with clear error message if CPUs can't be paired up with the specified stride value. scx_pair now also prints out how CPUs are paired on startup. This should address issues raspberrypi#28 and raspberrypi#29.
1 parent 68000ec commit 7229268

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

tools/sched_ext/scx_pair.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,37 @@ int main(int argc, char **argv)
6868
}
6969
}
7070

71+
printf("Pairs: ");
7172
for (i = 0; i < skel->rodata->nr_cpu_ids; i++) {
72-
if (skel->rodata->pair_cpu[i] < 0) {
73-
skel->rodata->pair_cpu[i] = i + stride;
74-
skel->rodata->pair_cpu[i + stride] = i;
75-
skel->rodata->pair_id[i] = i;
76-
skel->rodata->pair_id[i + stride] = i;
77-
skel->rodata->in_pair_idx[i] = 0;
78-
skel->rodata->in_pair_idx[i + stride] = 1;
73+
int j = (i + stride) % skel->rodata->nr_cpu_ids;
74+
75+
if (skel->rodata->pair_cpu[i] >= 0)
76+
continue;
77+
78+
if (i == j) {
79+
printf("\n");
80+
fprintf(stderr, "Invalid stride %d - CPU%d wants to be its own pair\n",
81+
stride, i);
82+
return 1;
83+
}
84+
85+
if (skel->rodata->pair_cpu[j] >= 0) {
86+
printf("\n");
87+
fprintf(stderr, "Invalid stride %d - three CPUs (%d, %d, %d) want to be a pair\n",
88+
stride, i, j, skel->rodata->pair_cpu[j]);
89+
return 1;
7990
}
91+
92+
skel->rodata->pair_cpu[i] = j;
93+
skel->rodata->pair_cpu[j] = i;
94+
skel->rodata->pair_id[i] = i;
95+
skel->rodata->pair_id[j] = i;
96+
skel->rodata->in_pair_idx[i] = 0;
97+
skel->rodata->in_pair_idx[j] = 1;
98+
99+
printf("[%d, %d] ", i, j);
80100
}
101+
printf("\n");
81102

82103
assert(!scx_pair__load(skel));
83104

0 commit comments

Comments
 (0)