From: Brian Norris Date: Tue, 5 Mar 2013 03:38:36 +0000 (-0800) Subject: mcs-queue: modifications for compiling X-Git-Tag: oopsla2013-final~40 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=commitdiff_plain;h=e4a48c7b09fa1ba3757aa6eb7e3df2513549b6b6;ds=sidebyside mcs-queue: modifications for compiling Remove backoff, shmem, fork, etc. Moving closer to something that can compile. --- diff --git a/mcs-queue/args.c b/mcs-queue/args.c index 4de179f..89101e5 100644 --- a/mcs-queue/args.c +++ b/mcs-queue/args.c @@ -1,13 +1,10 @@ #include "main.h" -extern unsigned backoff_base_bits; -extern unsigned backoff_cap_bits; extern unsigned iterations; extern unsigned multi; extern unsigned initial_nodes; extern unsigned procs; extern unsigned repetitions; -extern unsigned backoff_shift_bits; extern unsigned work; void parse_args(int argc, char **argv) @@ -15,16 +12,13 @@ void parse_args(int argc, char **argv) extern char * optarg; int c; - while ((c = getopt(argc, argv, "b:c:i:m:n:p:r:s:w:")) != EOF) + while ((c = getopt(argc, argv, "i:m:n:p:r:w:")) != EOF) switch(c) { - case 'b': backoff_base_bits = atoi(optarg); break; - case 'c': backoff_cap_bits = atoi(optarg); break; case 'i': iterations = atoi(optarg); break; case 'm': multi = atoi(optarg); break; case 'n': initial_nodes = atoi(optarg); break; case 'p': procs = atoi(optarg); break; case 'r': repetitions = atoi(optarg); break; - case 's': backoff_shift_bits = atoi(optarg); break; case 'w': work = atoi(optarg); break; default: assert(0); diff --git a/mcs-queue/backoff.c b/mcs-queue/backoff.c deleted file mode 100644 index b1b4f6f..0000000 --- a/mcs-queue/backoff.c +++ /dev/null @@ -1,25 +0,0 @@ -extern unsigned backoff; -extern unsigned backoff_base_bits; -extern unsigned backoff_cap_bits; -extern unsigned backoff_shift_bits; -extern unsigned backoff_base; -extern unsigned backoff_cap; -extern unsigned backoff_addend; - -void init_backoff() -{ - backoff_base = (1< #define NUM_PROCESSORS 12 struct tms tim; struct tms tim1; -usptr_t *Handle; -barrier_t *Barrier; -usptr_t *lock_handle; -ulock_t native_lock; - int shmid; unsigned pid; -unsigned backoff; -unsigned backoff_base; -unsigned backoff_cap; -unsigned backoff_addend; char* name = ""; -unsigned backoff_base_bits = 0; -unsigned backoff_cap_bits = 0; unsigned procs = 1; unsigned multi = 1; unsigned iterations = 1; unsigned initial_nodes = 0; unsigned repetitions = 1; -unsigned backoff_shift_bits = 0; unsigned work = 0; private_t private; shared_mem_t *smp; -void native_acquire() -{ - ussetlock(native_lock); -} - -void native_release() -{ - usunsetlock(native_lock); -} - -void tts_acq(unsigned* plock) -{ - do { - if (*plock == 1) { - backoff = backoff_base; - do { - backoff_delay(); - } while(*plock == 1); - } - } while (tas(plock) == 1); -} - void time_test() { unsigned i,j; @@ -64,12 +31,6 @@ void time_test() } init_memory(); init_private(); - init_backoff(); - barrier(Barrier, procs*multi); - if(pid==0) - { - t1=times(&time_val); - } for(i=0;i>1))/(procs*multi); - setup_shmem(); - Handle = usinit("/tmp/foo_barrier"); - Barrier = new_barrier(Handle); - init_barrier(Barrier); - lock_handle = usinit("/tmp/foo_lock"); - native_lock = usnewlock(lock_handle); - my_m_fork(main_task, procs*multi); - shmctl(shmid, IPC_RMID, smp); - exit(0); + + smp = (shared_mem_t *)calloc(1, sizeof(shared_mem_t)); + assert(smp); + + num_threads = procs * multi; + t = malloc(num_threads * sizeof(thrd_t)); + + for (i = 0; i < num_threads; i++) + thrd_create(&t[i], main_task, NULL); + for (i = 0; i < num_threads; i++) + thrd_join(t[i]); + + free(t); + free(smp); + + return 0; } diff --git a/mcs-queue/main.h b/mcs-queue/main.h index 8ec3cf9..7a7d2a7 100644 --- a/mcs-queue/main.h +++ b/mcs-queue/main.h @@ -6,8 +6,6 @@ #include #include #include -#include -#include -#include #include +#include #include "my_queue.h" diff --git a/mcs-queue/my_queue.c b/mcs-queue/my_queue.c index a7c8a3b..1f8a446 100644 --- a/mcs-queue/my_queue.c +++ b/mcs-queue/my_queue.c @@ -3,8 +3,6 @@ extern unsigned pid; extern unsigned iterations; extern unsigned initial_nodes; -extern unsigned backoff; -extern unsigned backoff_base; extern private_t private; extern shared_mem_t* smp; @@ -19,12 +17,12 @@ void init_memory() { } -unsigned new_node() +static unsigned new_node() { return private.node; } -void reclaim(unsigned node) +static void reclaim(unsigned node) { private.node = node; } @@ -72,13 +70,11 @@ void enqueue(unsigned val) smp->nodes[node].value = val; smp->nodes[node].next.sep.ptr = NULL; - backoff = backoff_base; for (success = FALSE; success == FALSE; ) { tail.con = smp->tail.con; next.con = smp->nodes[tail.sep.ptr].next.con; if (tail.con == smp->tail.con) { if (next.sep.ptr == NULL) { - backoff = backoff_base; success = cas(&smp->nodes[tail.sep.ptr].next, next.con, MAKE_LONG(node, next.sep.count+1)); @@ -88,7 +84,7 @@ void enqueue(unsigned val) tail.con, MAKE_LONG(smp->nodes[tail.sep.ptr].next.sep.ptr, tail.sep.count+1)); - backoff_delay(); + thrd_yield(); } } } @@ -105,7 +101,6 @@ unsigned dequeue() pointer_t tail; pointer_t next; - backoff = backoff_base; for (success = FALSE; success == FALSE; ) { head.con = smp->head.con; tail.con = smp->tail.con; @@ -118,14 +113,14 @@ unsigned dequeue() cas(&smp->tail, tail.con, MAKE_LONG(next.sep.ptr, tail.sep.count+1)); - backoff_delay(); + thrd_yield(); } else { value = smp->nodes[next.sep.ptr].value; success = cas(&smp->head, head.con, MAKE_LONG(next.sep.ptr, head.sep.count+1)); if (success == FALSE) { - backoff_delay(); + thrd_yield(); } } } diff --git a/mcs-queue/my_queue.h b/mcs-queue/my_queue.h index 385db65..80e6958 100644 --- a/mcs-queue/my_queue.h +++ b/mcs-queue/my_queue.h @@ -1,6 +1,5 @@ #define TRUE 1 #define FALSE 0 -#define NULL 0 #define MAX_NODES 0xff #define MAX_SERIAL 10000 @@ -35,3 +34,8 @@ typedef struct shared_mem { node_t nodes[MAX_NODES+1]; unsigned serial; } shared_mem_t; + +void init_private(); +void init_memory(); +void init_queue(); +unsigned dequeue();