mcs-queue: modifications for compiling
authorBrian Norris <banorris@uci.edu>
Tue, 5 Mar 2013 03:38:36 +0000 (19:38 -0800)
committerBrian Norris <banorris@uci.edu>
Tue, 5 Mar 2013 03:38:36 +0000 (19:38 -0800)
Remove backoff, shmem, fork, etc.

Moving closer to something that can compile.

mcs-queue/args.c
mcs-queue/backoff.c [deleted file]
mcs-queue/main.c
mcs-queue/main.h
mcs-queue/my_queue.c
mcs-queue/my_queue.h

index 4de179f..89101e5 100644 (file)
@@ -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 (file)
index b1b4f6f..0000000
+++ /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<<backoff_base_bits)-1;
-       backoff_cap = (1<<backoff_cap_bits)-1;
-       backoff_addend = (1<<backoff_shift_bits)-1;
-}
-
-unsigned backoff_delay()
-{
-       unsigned i;
-
-       for (i=0; i<backoff; i++) ;
-       backoff <<= backoff_shift_bits;
-       backoff += backoff_addend;
-       backoff &= backoff_cap;
-       return i;
-}
index 3827940..015fbd4 100644 (file)
@@ -1,57 +1,24 @@
 #include "main.h"
+#include <stdlib.h>
 
 #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<iterations;i++) {
                val = private.value;
                enqueue(val);
@@ -78,16 +39,6 @@ void time_test()
                for(j=0; j<work;) j++;
                private.value++;
        }
-       barrier(Barrier, procs*multi);
-       if(pid==0)
-       {
-               t2=times(&time_val);
-               printf("p%d  m%d  i%d  b%d c%d s%d  w%d time %.0f ms.\n",
-                               procs, multi, iterations*procs*multi,
-                               backoff_base_bits, backoff_cap_bits,
-                               backoff_shift_bits, work, ((t2-t1)*1000)/(double)HZ);
-               fflush(stdout);
-       }
 }
 
 void main_task()
@@ -97,48 +48,33 @@ void main_task()
 
        processor = (pid/multi)+1;
        processor %= NUM_PROCESSORS;
-       if(sysmp(MP_MUSTRUN, processor) == -1) { perror("Could not MUSTRUN"); }
-       if (pid==0) {
-               printf("--- %s\n", name);
-               fflush(stdout);
-       }
        for (i=0; i<repetitions; i++) {
                time_test();
        }
 }
 
-void setup_shmem()
+int user_main(int argc, char **argv)
 {
-       shmid = shmget(IPC_PRIVATE, sizeof(shared_mem_t), 511);
-       assert(shmid != -1);
-       smp = (shared_mem_t *)shmat(shmid, 0, 0);
-       assert((int)smp != -1);
-}
-
-void my_m_fork(void (*func)(), int num_procs)
-{
-       for (pid=1;pid<num_procs;pid++) {
-               if(fork()==0) /* Child */ {
-                       (*func)(); /* Call the program */
-                       return;
-               }
-       }
-       pid=0;
-       (*func)(); /* Call the program */
-}
+       int i, num_threads;
+       thrd_t *t;
 
-main(int argc,char **argv)
-{
        parse_args(argc, argv);
        name = argv[0];
        iterations = (iterations + ((procs*multi)>>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;
 }
index 8ec3cf9..7a7d2a7 100644 (file)
@@ -6,8 +6,6 @@
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <signal.h>
-#include <sys/cachectl.h>
-#include <sys/sysmp.h>
-#include <ulocks.h>
 #include <assert.h>
+#include <threads.h>
 #include "my_queue.h"
index a7c8a3b..1f8a446 100644 (file)
@@ -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();
                                }
                        }
                }
index 385db65..80e6958 100644 (file)
@@ -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();