On Wed, 15 Jun 2022, Sebastian Andrzej Siewior wrote: > Assuming the current affinity mask of the task is 0x31 (CPUs 0, 4, 5). > Starting cyclictest with '-S' option will fork the following threads: > - monitor, mask 0x31 > - measure thread 1, mask 0x01 > - measure thread 2, mask 0x10 > - measure thread 3, mask 0x20 > > works as expected. Using the options '-S --mainaffinity=0' leads to: > - monitor, mask 0x01 > - measure thread 1, mask 0x01 > - measure thread 2, mask 0x01 > - measure thread 3, mask 0x01 > > because the mask of the main thread has been reset early to 0x01 and > does not allow a CPU mask outside of this mask while setting the > affinity for the new threads. > > Delay setting the affinity of the main/ monitor thread after the > measuring threads have been deployed. This leads to the following > state: > - monitor, mask 0x01 > - measure thread 1, mask 0x01 > - measure thread 2, mask 0x10 > - measure thread 3, mask 0x20 > > Signed-off-by: Sebastian Andrzej Savior <bigeasy@xxxxxxxxxxxxx> > --- > src/cyclictest/cyclictest.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c > index be8285a072b4e..cbf8d00293ec6 100644 > --- a/src/cyclictest/cyclictest.c > +++ b/src/cyclictest/cyclictest.c > @@ -1816,10 +1816,7 @@ int main(int argc, char **argv) > printf("Online CPUs = %d\n", online_cpus); > } > > - /* Restrict the main pid to the affinity specified by the user */ > - if (main_affinity_mask != NULL) { > - set_main_thread_affinity(main_affinity_mask); > - } else if (affinity_mask != NULL) { > + if (affinity_mask != NULL) { > set_main_thread_affinity(affinity_mask); > if (verbose) > printf("Using %u cpus.\n", > @@ -2094,6 +2091,10 @@ int main(int argc, char **argv) > fatal("failed to create thread %d: %s\n", i, strerror(status)); > > } > + /* Restrict the main pid to the affinity specified by the user */ > + if (main_affinity_mask != NULL) > + set_main_thread_affinity(main_affinity_mask); > + > if (use_fifo) { > status = pthread_create(&fifo_threadid, NULL, fifothread, NULL); > if (status) > -- > 2.36.1 > > Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>