edits
authorPeizhao Ou <peizhaoo@uci.edu>
Tue, 17 Nov 2015 02:30:05 +0000 (18:30 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Tue, 17 Nov 2015 02:30:05 +0000 (18:30 -0800)
benchmark/ms-queue/Makefile
benchmark/ms-queue/testcase2.c [new file with mode: 0644]
output/Makefile
output/ms-queue/Makefile
src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java
src/edu/uci/eecs/specCompiler/codeGenerator/CodeVariables.java

index ac8427698f44318631cd1c3bebcc32b74ad0fc03..c697477bb65473d6df993ce0c74ed7e22922b473 100644 (file)
@@ -1,20 +1,18 @@
-include ../benchmarks.mk
+#DIRS := barrier mcs-lock mpmc-queue spsc-queue spsc-bugfix linuxrwlocks \
+       dekker-fences chase-lev-deque ms-queue chase-lev-deque-bugfix \
+       concurrent-hashmap seqlock spsc-example spsc-queue-scfence \
+       treiber-stack
 
-TESTNAME = main testcase1
+DIRS := ms-queue concurrent-hashmap
 
-HEADERS = my_queue.h
-OBJECTS = main.o my_queue.o
+.PHONY: $(DIRS)
 
-all: $(TESTNAME)
+all: $(DIRS)
 
-main: $(HEADERS) $(OBJECTS)
-       $(CC) -o $@ $(OBJECTS) $(CFLAGS) $(LDFLAGS)
+clean: $(DIRS:%=clean-%)
 
-testcase1: $(HEADERS) my_queue.o testcase1.o 
-       $(CC) -o $@ my_queue.o testcase1.o $(CFLAGS) $(LDFLAGS)
+$(DIRS):
+       $(MAKE) -C $@
 
-%.o: %.c
-       $(CC) -c -o $@ $< $(CFLAGS)
-
-clean:
-       rm -f $(TESTNAME) *.o
+clean-%:
+       -$(MAKE) -C $* clean
diff --git a/benchmark/ms-queue/testcase2.c b/benchmark/ms-queue/testcase2.c
new file mode 100644 (file)
index 0000000..8ab6dbf
--- /dev/null
@@ -0,0 +1,96 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <threads.h>
+
+#include "my_queue.h"
+#include "model-assert.h"
+
+static int procs = 2;
+static queue_t *queue;
+static thrd_t *threads;
+static unsigned int *input;
+static unsigned int *output;
+static int num_threads;
+
+int get_thread_num()
+{
+       thrd_t curr = thrd_current();
+       int i;
+       for (i = 0; i < num_threads; i++)
+               if (curr.priv == threads[i].priv)
+                       return i;
+       //MODEL_ASSERT(0);
+       return -1;
+}
+
+/** Be careful, we must make these variables to be global so that they will be
+ * 'available' when the execution is generated */
+bool succ1, succ2;
+unsigned int output1, output2;
+
+static void main_task(void *param)
+{
+       int pid = *((int *)param);
+       if (pid % 4 == 0) {
+               output1 = 1;
+               succ1 = dequeue(queue, &output1);
+               if (succ1)
+                       printf("Thrd 1: Dequeue %d.\n", output1);
+               else
+                       printf("Thrd 1: Dequeue NULL.\n");
+       } else if (pid % 4 == 1) {
+               enqueue(queue, 2);
+               output2 = 1;
+               succ2 = dequeue(queue, &output2);
+               if (succ2)
+                       printf("Thrd 2: Dequeue %d.\n", output2);
+               else
+                       printf("Thrd 2: Dequeue NULL.\n");
+       }
+}
+
+int user_main(int argc, char **argv)
+{
+       /**
+               @Begin
+               @Entry_point
+               @End
+       */
+       int i;
+       int *param;
+       unsigned int in_sum = 0, out_sum = 0;
+
+       queue = calloc(1, sizeof(*queue));
+       //MODEL_ASSERT(queue);
+
+       num_threads = procs;
+       threads = malloc(num_threads * sizeof(thrd_t));
+       param = malloc(num_threads * sizeof(*param));
+       input = calloc(num_threads, sizeof(*input));
+       output = calloc(num_threads, sizeof(*output));
+
+       init_queue(queue, num_threads);
+       for (i = 0; i < num_threads; i++) {
+               param[i] = i;
+               thrd_create(&threads[i], main_task, &param[i]);
+       }
+       for (i = 0; i < num_threads; i++)
+               thrd_join(threads[i]);
+/*
+       for (i = 0; i < num_threads; i++) {
+               in_sum += input[i];
+               out_sum += output[i];
+       }
+       for (i = 0; i < num_threads; i++)
+               printf("input[%d] = %u\n", i, input[i]);
+       for (i = 0; i < num_threads; i++)
+               printf("output[%d] = %u\n", i, output[i]);
+       //MODEL_ASSERT(in_sum == out_sum);
+       */
+
+       free(param);
+       free(threads);
+       free(queue);
+
+       return 0;
+}
index 4d432e97f62b2d540f9c78c2e503f3a007efe422..c697477bb65473d6df993ce0c74ed7e22922b473 100644 (file)
@@ -3,7 +3,7 @@
        concurrent-hashmap seqlock spsc-example spsc-queue-scfence \
        treiber-stack
 
-DIRS := ms-queue
+DIRS := ms-queue concurrent-hashmap
 
 .PHONY: $(DIRS)
 
index ac8427698f44318631cd1c3bebcc32b74ad0fc03..78ea6a644d60604145a0ac08811f29cbe33ab9e7 100644 (file)
@@ -1,6 +1,6 @@
 include ../benchmarks.mk
 
-TESTNAME = main testcase1
+TESTNAME = main testcase1 testcase2
 
 HEADERS = my_queue.h
 OBJECTS = main.o my_queue.o
@@ -13,6 +13,9 @@ main: $(HEADERS) $(OBJECTS)
 testcase1: $(HEADERS) my_queue.o testcase1.o 
        $(CC) -o $@ my_queue.o testcase1.o $(CFLAGS) $(LDFLAGS)
 
+testcase2: $(HEADERS) my_queue.o testcase2.o 
+       $(CC) -o $@ my_queue.o testcase2.o $(CFLAGS) $(LDFLAGS)
+
 %.o: %.c
        $(CC) -c -o $@ $< $(CFLAGS)
 
index 84b3300cb045b60e0a163f910601365d334ab660..08b8ee76b17f5032c36223f8dfd234b50ea9a009 100644 (file)
@@ -298,8 +298,8 @@ public class CodeGenerator {
 //
                File[] srcMSQueue = {
                                new File(homeDir + "/benchmark/ms-queue/my_queue.c"),
-                               new File(homeDir + "/benchmark/ms-queue/testcase.c"),
                                new File(homeDir + "/benchmark/ms-queue/testcase1.c"),
+                               new File(homeDir + "/benchmark/ms-queue/testcase2.c"),
                                new File(homeDir + "/benchmark/ms-queue/main.c"),
                                new File(homeDir + "/benchmark/ms-queue/my_queue.h") };
 
index 7e4ab29c446c74db5683957664c197fe86600aa7..b9ab022eaab70c4f913e230d959080855a7dbc83 100644 (file)
@@ -467,8 +467,13 @@ public class CodeVariables {
 
                // Define the __SPEC_CLEAN__ function for clean-up
                newCode.add(COMMENT("Cleanup routine of sequential variables"));
-               newCode.add("static void __SPEC_CLEANUP__() {");
-               addAllCodeWithIndent(newCode, construct.code.cleanupCode, "\t");
+               newCode.add("static bool __SPEC_CLEANUP__() {");
+               if (construct.code.cleanupCode.size() > 0) {
+                       addAllCodeWithIndent(newCode, construct.code.cleanupCode, "\t");        
+               } else {
+                       newCode.add("\treturn true;"); // If not specified return true
+               }
+               
                newCode.add("}");
                newCode.add("");
 
@@ -504,10 +509,10 @@ public class CodeVariables {
                newCode.add("\t" + STRUCT_NEW_DECLARE_DEFINE(ANNO_INIT, structName));
                newCode.add("\t"
                                + ASSIGN_TO_PTR(structName, "init_func",
-                                               "(void_func_t*) __SPEC_INIT__"));
+                                               "(void*) __SPEC_INIT__"));
                newCode.add("\t"
                                + ASSIGN_TO_PTR(structName, "cleanup_func",
-                                               "(void_func_t*) __SPEC_CLEANUP__"));
+                                               "(void*) __SPEC_CLEANUP__"));
                newCode.add("\t"
                                + ASSIGN_TO_PTR(structName, "func_table", "func_ptr_table"));
                newCode.add("\t"