parlib: Fix u32/u64 issue with pvcalarm
[akaros.git] / tests / lock_test.c
index 10dd978..6072153 100644 (file)
 /* OS dependent #incs */
 #ifdef __ros__
 
-#include <parlib.h>
-#include <vcore.h>
-#include <timing.h>
-#include <spinlock.h>
-#include <mcs.h>
-#include <arch/arch.h>
-#include <event.h>
-
-#include <tsc-compat.h>
-#include <measure.h>
+#include <parlib/parlib.h>
+#include <parlib/stdio.h>
+#include <parlib/vcore.h>
+#include <parlib/timing.h>
+#include <parlib/spinlock.h>
+#include <parlib/mcs.h>
+#include <parlib/arch/arch.h>
+#include <parlib/event.h>
+
+#include <parlib/tsc-compat.h>
+#include <benchutil/measure.h>
 
 #else
 
-#include "../user/parlib/include/tsc-compat.h"
+#include "../user/parlib/include/parlib/tsc-compat.h"
 #include "misc-compat.h"
 #include "linux-lock-hacks.h" /* TODO: have a build system and lib / C file */
 
-#include "../user/benchutil/include/measure.h"
+#include "../user/benchutil/include/benchutil/measure.h"
 #include "../user/benchutil/measure.c"
 
 static void os_prep_work(pthread_t *worker_threads, int nr_threads)
@@ -445,7 +446,7 @@ __thread int __vcore_context = 0;
  */
 
 const char *argp_program_version = "lock_test v0.1475263";
-const char *argp_program_bug_address = "<akaros@lists.eecs.berkeley.edu>";
+const char *argp_program_bug_address = "<akaros+subscribe@googlegroups.com>";
 
 static char doc[] = "lock_test -- spinlock benchmarking";
 static char args_doc[] = "-w NUM -l NUM -t LOCK";
@@ -523,7 +524,7 @@ void *lock_name##_thread(void *arg)                                            \
        int i;                                                                     \
        /* guessing a unique vcoreid for vcoreid for the __mcspdr test.  if the
         * program gets preempted for that test, things may go nuts */             \
-       pdro_qnode.vcoreid = thread_id - 1;                                        \
+       pdro_qnode.vcoreid = thread_id + 1 % pargs.nr_threads;                     \
        /* Wait til all threads are created.  Ideally, I'd like to busywait unless
         * absolutely critical to yield */                                         \
        pthread_barrier_wait(&start_test);                                         \
@@ -732,9 +733,9 @@ static void os_prep_work(pthread_t *worker_threads, int nr_threads)
        atomic_init(&indir_idx, 0);
        atomic_init(&preempt_cnt, 0);
        atomic_init(&indir_cnt, 0);
-       pthread_can_vcore_request(FALSE);       /* 2LS won't manage vcores */
+       parlib_never_yield = TRUE;
        pthread_need_tls(FALSE);
-       pthread_lib_init();                                     /* gives us one vcore */
+       pthread_mcp_init();                                     /* gives us one vcore */
        register_ev_handler(EV_VCORE_PREEMPT, trace_preempt, 0);
        register_ev_handler(EV_CHECK_MSGS, trace_indir, 0);
        if (pargs.fake_vc_ctx) {
@@ -743,11 +744,8 @@ static void os_prep_work(pthread_t *worker_threads, int nr_threads)
                clear_kevent_q(EV_VCORE_PREEMPT);
                clear_kevent_q(EV_CHECK_MSGS);
        }
-       if (vcore_request(nr_threads - 1)) {
-               printf("Failed to request %d more vcores, currently have %d\n",
-                      nr_threads - 1, num_vcores());
-               exit(-1);
-       }
+       vcore_request_total(nr_threads);
+       parlib_never_vc_request = TRUE;
        for (int i = 0; i < nr_threads; i++) {
                printd("Vcore %d mapped to pcore %d\n", i,
                       __procinfo.vcoremap[i].pcoreid);
@@ -969,6 +967,8 @@ int main(int argc, char** argv)
        }
        printf("Average number of loops done, per thread: %ld\n",
               total_loops / nr_threads);
+       for (int i = 0; i < nr_threads; i++)
+               printf("\tThread %d performed %lu loops\n", i, (long)loops_done[i]);
 
        if (pargs.outfile_path) {
                fprintf(outfile, "#");
@@ -979,6 +979,7 @@ int main(int argc, char** argv)
                                 "tsc_overhead\n");
                fprintf(outfile, "# acquire latency: acq - pre - tsc_overhead\n");
                fprintf(outfile, "# hold time: un - acq - tsc_overhead\n");
+               fprintf(outfile, "# tsc_frequency %llu\n", get_tsc_freq());
                fprintf(outfile, "# tsc_overhead is 0 on linux, hard code it with a "
                                 "value from akaros\n");
                for (int i = 0; i < nr_threads; i++) {