x86: Try to fix MP table I/O interrupt assignment entries
[akaros.git] / tests / pthread_test.c
index 9731f35..e7f568d 100644 (file)
@@ -45,12 +45,13 @@ void *yield_thread(void* arg)
        /* Wait til all threads are created */
        pthread_barrier_wait(&barrier);
        for (int i = 0; i < nr_yield_loops; i++) {
-               printf_safe("[A] pthread %d %p on vcore %d, itr: %d\n", pthread_id(),
-                           pthread_self(), vcore_id(), i);
-               /* Fakes some work by spinning a bit.  Amount varies per uth/vcore,
-                * scaled by fake_work */
+               printf_safe("[A] pthread %d %p on vcore %d, itr: %d\n",
+                           pthread_id(), pthread_self(), vcore_id(), i);
+               /* Fakes some work by spinning a bit.  Amount varies per
+                * uth/vcore, scaled by fake_work */
                if (amt_fake_work)
-                       udelay(amt_fake_work * (pthread_id() * (vcore_id() + 2)));
+                       udelay(amt_fake_work * (pthread_id() * (vcore_id() +
+                                                               2)));
                pthread_yield();
                printf_safe("[A] pthread %p returned from yield on vcore %d, itr: %d\n",
                            pthread_self(), vcore_id(), i);
@@ -83,7 +84,7 @@ int main(int argc, char** argv)
                /* Only do the vcore trickery if requested */
                parlib_never_yield = TRUE;
                pthread_need_tls(FALSE);
-               pthread_mcp_init();                                     /* gives us one vcore */
+               pthread_mcp_init();             /* gives us one vcore */
                vcore_request_total(nr_vcores);
                parlib_never_vc_request = TRUE;
                for (int i = 0; i < nr_vcores; i++) {
@@ -91,6 +92,12 @@ int main(int argc, char** argv)
                                    __procinfo.vcoremap[i].pcoreid);
                }
        }
+       struct uth_join_request *join_reqs;
+
+       join_reqs = malloc(nr_yield_threads * sizeof(struct uth_join_request));
+       for (int i = 0; i < nr_yield_threads; i++)
+               join_reqs[i].retval_loc = &my_retvals[i];
+       assert(join_reqs);
 #endif /* __ros__ */
 
        pthread_barrier_init(&barrier, NULL, nr_yield_threads);
@@ -102,12 +109,20 @@ int main(int argc, char** argv)
        }
        if (gettimeofday(&start_tv, 0))
                perror("Start time error...");
+       /* Akaros supports parallel join */
+#ifdef __ros__
+       for (int i = 0; i < nr_yield_threads; i++)
+               join_reqs[i].uth = (struct uthread*)my_threads[i];
+       uthread_join_arr(join_reqs, nr_yield_threads);
+#else
        for (int i = 0; i < nr_yield_threads; i++) {
-               printf_safe("[A] About to join on thread %d(%p)\n", i, my_threads[i]);
+               printf_safe("[A] About to join on thread %d(%p)\n",
+                           i, my_threads[i]);
                pthread_join(my_threads[i], &my_retvals[i]);
-               printf_safe("[A] Successfully joined on thread %d (retval: %p)\n", i,
-                           my_retvals[i]);
+               printf_safe("[A] Successful join on thread %d (retval: %p)\n",
+                           i, my_retvals[i]);
        }
+#endif
        if (gettimeofday(&end_tv, 0))
                perror("End time error...");
        nr_ctx_switches = nr_yield_threads * nr_yield_loops;