+ cthreads = malloc(nr_cpus * sizeof(struct clock_thread));
+ tentries = nr_entries * nr_cpus;
+ entries = malloc(tentries * sizeof(struct clock_entry));
+
+ if (debug)
+ log_info("cs: Testing %u CPUs\n", nr_cpus);
+
+ for (i = 0; i < nr_cpus; i++) {
+ struct clock_thread *t = &cthreads[i];
+
+ t->cpu = i;
+ t->debug = debug;
+ t->seq = &seq;
+ t->nr_entries = nr_entries;
+ t->entries = &entries[i * nr_entries];
+ pthread_mutex_init(&t->lock, NULL);
+ pthread_mutex_init(&t->started, NULL);
+ pthread_mutex_lock(&t->lock);
+ if (pthread_create(&t->thread, NULL, clock_thread_fn, t)) {
+ failed++;
+ nr_cpus = i;
+ break;
+ }
+ }
+
+ for (i = 0; i < nr_cpus; i++) {
+ struct clock_thread *t = &cthreads[i];
+
+ pthread_mutex_lock(&t->started);
+ }
+
+ for (i = 0; i < nr_cpus; i++) {
+ struct clock_thread *t = &cthreads[i];
+
+ pthread_mutex_unlock(&t->lock);
+ }
+
+ for (i = 0; i < nr_cpus; i++) {
+ struct clock_thread *t = &cthreads[i];
+ void *ret;
+
+ pthread_join(t->thread, &ret);
+ if (ret)
+ failed++;
+ }
+ free(cthreads);
+
+ if (failed) {
+ if (debug)
+ log_err("Clocksource test: %lu threads failed\n", failed);