Skip to content

Commit

Permalink
scx_pair: Fix custom stride error handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
htejun committed Jun 27, 2023
1 parent 68000ec commit 7229268
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions tools/sched_ext/scx_pair.c
Expand Up @@ -68,16 +68,37 @@ int main(int argc, char **argv)
}
}

printf("Pairs: ");
for (i = 0; i < skel->rodata->nr_cpu_ids; i++) {
if (skel->rodata->pair_cpu[i] < 0) {
skel->rodata->pair_cpu[i] = i + stride;
skel->rodata->pair_cpu[i + stride] = i;
skel->rodata->pair_id[i] = i;
skel->rodata->pair_id[i + stride] = i;
skel->rodata->in_pair_idx[i] = 0;
skel->rodata->in_pair_idx[i + stride] = 1;
int j = (i + stride) % skel->rodata->nr_cpu_ids;

if (skel->rodata->pair_cpu[i] >= 0)
continue;

if (i == j) {
printf("\n");
fprintf(stderr, "Invalid stride %d - CPU%d wants to be its own pair\n",
stride, i);
return 1;
}

if (skel->rodata->pair_cpu[j] >= 0) {
printf("\n");
fprintf(stderr, "Invalid stride %d - three CPUs (%d, %d, %d) want to be a pair\n",
stride, i, j, skel->rodata->pair_cpu[j]);
return 1;
}

skel->rodata->pair_cpu[i] = j;
skel->rodata->pair_cpu[j] = i;
skel->rodata->pair_id[i] = i;
skel->rodata->pair_id[j] = i;
skel->rodata->in_pair_idx[i] = 0;
skel->rodata->in_pair_idx[j] = 1;

printf("[%d, %d] ", i, j);
}
printf("\n");

assert(!scx_pair__load(skel));

Expand Down

0 comments on commit 7229268

Please sign in to comment.