On Wed, 10 Feb 2021, Daniel Wagner wrote: > Group thread realated data such as thread ID to struct thread_param. > > Signed-off-by: Daniel Wagner <dwagner@xxxxxxx> > --- > src/signaltest/signaltest.c | 44 ++++++++++++++++++------------------- > 1 file changed, 22 insertions(+), 22 deletions(-) > > diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c > index c34bc994d886..dd5633d5fc51 100644 > --- a/src/signaltest/signaltest.c > +++ b/src/signaltest/signaltest.c > @@ -40,6 +40,10 @@ > > /* Struct to transfer parameters to the thread */ > struct thread_param { > + pthread_t thread; > + pthread_t tothread; > + int threadstarted; > + int tid; > int id; > int prio; > int signal; > @@ -47,6 +51,7 @@ struct thread_param { > struct thread_stat *stats; > int bufmsk; > int cpu; > + int interrupted; > }; > > /* Struct for statistics */ > @@ -58,11 +63,6 @@ struct thread_stat { > long act; > double avg; > long *values; > - pthread_t thread; > - pthread_t tothread; > - int threadstarted; > - int tid; > - int interrupted; > }; > > static int shutdown; > @@ -86,7 +86,7 @@ void *signalthread(void *param) > pthread_t thread; > cpu_set_t mask; > > - stat->tid = gettid(); > + par->tid = gettid(); > > if (par->cpu != -1) { > CPU_ZERO(&mask); > @@ -105,7 +105,7 @@ void *signalthread(void *param) > schedp.sched_priority = par->prio; > sched_setscheduler(0, policy, &schedp); > > - stat->threadstarted++; > + par->threadstarted++; > > clock_gettime(CLOCK_MONOTONIC, &before); > > @@ -128,7 +128,7 @@ void *signalthread(void *param) > > /* Get current time */ > clock_gettime(CLOCK_MONOTONIC, &now); > - pthread_kill(stat->tothread, SIGUSR1); > + pthread_kill(par->tothread, SIGUSR1); > > /* Skip the first cycle */ > if (first) { > @@ -148,7 +148,7 @@ void *signalthread(void *param) > > if (!stopped && tracelimit && !par->id && (diff > tracelimit)) { > stat->act = diff; > - stat->interrupted = 1; > + par->interrupted = 1; > stopped++; > shutdown++; > } > @@ -167,7 +167,7 @@ void *signalthread(void *param) > schedp.sched_priority = 0; > sched_setscheduler(0, SCHED_OTHER, &schedp); > > - stat->threadstarted = -1; > + par->threadstarted = -1; > > return NULL; > } > @@ -298,7 +298,7 @@ static void print_stat(struct thread_param *par, int index, int verbose) > if (quiet != 1) { > printf("T:%2d (%5d) P:%2d C:%7lu " > "Min:%7ld Act:%5ld Avg:%5ld Max:%8ld\n", > - index, stat->tid, par->prio, > + index, par->tid, par->prio, > stat->cycles, stat->min, stat->act, > stat->cycles ? > (long)(stat->avg/stat->cycles) : 0, stat->max); > @@ -389,8 +389,8 @@ int main(int argc, char **argv) > stat[i].min = 1000000; > stat[i].max = -1000000; > stat[i].avg = 0.0; > - stat[i].threadstarted = 1; > - status = pthread_create(&stat[i].thread, NULL, signalthread, > + par[i].threadstarted = 1; > + status = pthread_create(&par[i].thread, NULL, signalthread, > &par[i]); > if (status) > fatal("failed to create thread %d: %s\n", i, > @@ -401,18 +401,18 @@ int main(int argc, char **argv) > int allstarted = 1; > > for (i = 0; i < num_threads; i++) { > - if (stat[i].threadstarted != 2) > + if (par[i].threadstarted != 2) > allstarted = 0; > } > if (!allstarted) > continue; > > for (i = 0; i < num_threads - 1; i++) > - stat[i].tothread = stat[i+1].thread; > - stat[i].tothread = stat[0].thread; > + par[i].tothread = par[i+1].thread; > + par[i].tothread = par[0].thread; > break; > } > - pthread_kill(stat[0].thread, signum); > + pthread_kill(par[0].thread, signum); > > while (!shutdown) { > char lavg[256]; > @@ -443,12 +443,12 @@ int main(int argc, char **argv) > if (quiet) > quiet = 2; > for (i = 0; i < num_threads; i++) { > - if (stat[i].threadstarted > 0) > - pthread_kill(stat[i].thread, SIGUSR1); > - if (stat[i].interrupted) > + if (par[i].threadstarted > 0) > + pthread_kill(par[i].thread, SIGUSR1); > + if (par[i].interrupted) > printf("Thread %d exceeded trace limit.\n", i); > - if (stat[i].threadstarted) { > - pthread_join(stat[i].thread, NULL); > + if (par[i].threadstarted) { > + pthread_join(par[i].thread, NULL); > print_stat(&par[i], i, 0); > } > if (stat[i].values) > -- > 2.30.0 > > No for the same reasons I gave for cyclictest. Unncessary churn, and it makes backporting fixes harder too. John