x86: Try to fix MP table I/O interrupt assignment entries
[akaros.git] / tests / pthread_test.c
index bfd7037..e7f568d 100644 (file)
@@ -38,20 +38,20 @@ int amt_fake_work = 0;
 pthread_t my_threads[MAX_NR_TEST_THREADS];
 void *my_retvals[MAX_NR_TEST_THREADS];
 
-bool ready = FALSE;
+pthread_barrier_t barrier;
 
 void *yield_thread(void* arg)
 {      
        /* Wait til all threads are created */
-       while (!ready)
-               cpu_relax();
+       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);
@@ -84,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++) {
@@ -92,8 +92,15 @@ 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);
        /* create and join on yield */
        for (int i = 0; i < nr_yield_threads; i++) {
                printf_safe("[A] About to create thread %d\n", i);
@@ -102,13 +109,20 @@ int main(int argc, char** argv)
        }
        if (gettimeofday(&start_tv, 0))
                perror("Start time error...");
-       ready = TRUE;                   /* signal to any spinning uthreads to start */
+       /* 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;