From 375b8b02ae398aceddb920e0e7e94287e33f231e Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Wed, 14 Jan 2015 18:09:15 -0800 Subject: [PATCH] changes --- benchmark/ms-queue/my_queue.h | 4 +- benchmark/ms-queue/testcase.c | 4 +- benchmark/ms-queue/testcase1.c | 103 ++++++++++++++++++ .../codeGenerator/CodeGenerator.java | 1 + 4 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 benchmark/ms-queue/testcase1.c diff --git a/benchmark/ms-queue/my_queue.h b/benchmark/ms-queue/my_queue.h index 90f5775..0768428 100644 --- a/benchmark/ms-queue/my_queue.h +++ b/benchmark/ms-queue/my_queue.h @@ -95,7 +95,7 @@ void init_queue(queue_t *q, int num_threads); # interface call tag_elem_t *elem = new_tag_elem(__ID__, val); push_back(__queue, elem); - model_print("Enqueue: input=%d\n", val); + //model_print("Enqueue: input=%d\n", val); @End */ void enqueue(queue_t *q, unsigned int val); @@ -111,7 +111,7 @@ void enqueue(queue_t *q, unsigned int val); _Old_Val = get_data(front(__queue)); pop_front(__queue); } - model_print("Dequeue: __RET__=%d, retVal=%d, Old_Val=%d\n", __RET__, *retVal, _Old_Val); + // model_print("Dequeue: __RET__=%d, retVal=%d, Old_Val=%d\n", __RET__, *retVal, _Old_Val); @Post_check: _Old_Val == 0 ? !__RET__ : _Old_Val == *retVal @End diff --git a/benchmark/ms-queue/testcase.c b/benchmark/ms-queue/testcase.c index c896d7e..9deb686 100644 --- a/benchmark/ms-queue/testcase.c +++ b/benchmark/ms-queue/testcase.c @@ -33,14 +33,14 @@ static void main_task(void *param) int pid = *((int *)param); if (pid % 3 == 0) { output1 = 1; - bool succ1 = dequeue(queue, &output1); + succ1 = dequeue(queue, &output1); if (succ1) printf("Thrd 2: Dequeue %d.\n", output1); else printf("Thrd 2: Dequeue NULL.\n"); } else if (pid % 3 == 1) { output2 = 2; - bool succ2 = dequeue(queue, &output2); + succ2 = dequeue(queue, &output2); if (succ2) printf("Thrd 3: Dequeue %d.\n", output2); else diff --git a/benchmark/ms-queue/testcase1.c b/benchmark/ms-queue/testcase1.c new file mode 100644 index 0000000..c7c7b9c --- /dev/null +++ b/benchmark/ms-queue/testcase1.c @@ -0,0 +1,103 @@ +#include +#include +#include + +#include "my_queue.h" +#include "model-assert.h" + +static int procs = 4; +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 2: Dequeue %d.\n", output1); + else + printf("Thrd 2: Dequeue NULL.\n"); + } else if (pid % 4 == 1) { + output2 = 2; + succ2 = dequeue(queue, &output2); + if (succ2) + printf("Thrd 3: Dequeue %d.\n", output2); + else + printf("Thrd 3: Dequeue NULL.\n"); + } else if (pid % 4 == 2) { + int input = 47; + enqueue(queue, input); + printf("Thrd 4 Enqueue %d.\n", input); + } else { + int input = 27; + enqueue(queue, input); + printf("Thrd 5 Enqueue %d.\n", input); + } +} + +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, ¶m[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; +} diff --git a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java index e95ff5f..4a1c2a7 100644 --- a/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java +++ b/src/edu/uci/eecs/specCompiler/codeGenerator/CodeGenerator.java @@ -299,6 +299,7 @@ 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/main.c"), new File(homeDir + "/benchmark/ms-queue/my_queue.h") }; -- 2.34.1