From: adash Date: Tue, 10 Jul 2007 01:39:15 +0000 (+0000) Subject: Shared data structure to process prefetch requests X-Git-Tag: preEdgeChange~533 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=912e8e470f260989ef04a138a7a2320f6c6d33cf;p=IRC.git Shared data structure to process prefetch requests --- diff --git a/Robust/src/Runtime/DSTM/interface/Makefile b/Robust/src/Runtime/DSTM/interface/Makefile index f01dcef9..7f38b40b 100644 --- a/Robust/src/Runtime/DSTM/interface/Makefile +++ b/Robust/src/Runtime/DSTM/interface/Makefile @@ -1,22 +1,22 @@ d-3: - gcc -dr -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c + gcc -dr -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c demsky: - gcc -DDEBUG -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c + gcc -DDEBUG -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c queue.c d-4: - gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c + gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c all: - gcc -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c - gcc -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c - gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c + gcc -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c + gcc -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c queue.c + gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c mac: - gcc -DMAC -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c - gcc -DMAC -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c - gcc -DMAC -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c + gcc -DMAC -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c + gcc -DMAC -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c queue.c + gcc -DMAC -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c clean: rm -rf d-3 d-4 demsky diff --git a/Robust/src/Runtime/DSTM/interface/queue.c b/Robust/src/Runtime/DSTM/interface/queue.c new file mode 100644 index 00000000..fc12eaab --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/queue.c @@ -0,0 +1,83 @@ +#include "queue.h" + +prefetchthreadqueue_t queue; //Global shared prefetch queue + +void queueInsert(int *array) { + pthread_mutex_lock(&queue.qlock); + queue.rear = queue.rear % ARRAY_SIZE; + if(queue.front == queue.rear && queue.buffer[queue.front] != NULL) { + printf("The Circular Queue is Full : OVERFLOW\n"); + pthread_mutex_unlock(&queue.qlock); + return; + } else { + queue.buffer[queue.rear] = array; + queue.rear++; + } + pthread_mutex_unlock(&queue.qlock); +} + +int *queueDelete() { + int *i; + i = NULL; + pthread_mutex_lock(&queue.qlock); + if(queue.front == queue.rear && queue.buffer[queue.front] == NULL) { + printf("The Circular Queue is Empty : UNDERFLOW\n"); + pthread_mutex_unlock(&queue.qlock); + return NULL; + } else { + i = queue.buffer[queue.front]; + queue.buffer[queue.front] = NULL; + queue.front++; + queue.front = queue.front % ARRAY_SIZE; + pthread_mutex_unlock(&queue.qlock); + return i; + } +} + +void queueInit() { + int i; + queue.front = 0; + queue.rear = 0; + for(i = 0; i< ARRAY_SIZE; i++) + queue.buffer[i] = NULL; + /* Initialize the pthread_mutex variable */ + pthread_mutex_init(&queue.qlock, NULL); +} + +/* For testing purposes */ +#if 0 +main() { + int *d; + queueIsEmpty(); + int a[] = {5, 2, 8, -1}; + int b[] = {11, 8, 4, 19, -1}; + int c[] = {16, 8, 4, -1}; + printf("Front = %d, Rear = %d\n",queue.front, queue.rear); + d = queueDelete(); + printf("Front = %d, Rear = %d\n",queue.front, queue.rear); + queueInsert(a); + printf("Enqueued ptr is %x\n", a); + printf("1st Insert Front = %d, Rear = %d\n",queue.front, queue.rear); + queueInsert(b); + printf("Enqueued ptr is %x\n", b); + printf("2nd Insert Front = %d, Rear = %d\n",queue.front, queue.rear); + queueInsert(c); + printf("3rd Insert Front = %d, Rear = %d\n",queue.front, queue.rear); + d = queueDelete(); + printf("Dequeued ptr is %x\n", d); + printf("After 1st del Front = %d, Rear = %d\n",queue.front, queue.rear); + queueInsert(c); + printf("Enqueued ptr is %x\n", c); + printf("After 4th insert Front = %d, Rear = %d\n",queue.front, queue.rear); + d = queueDelete(); + printf("Dequeued ptr is %x\n", d); + printf("After 2nd del Front = %d, Rear = %d\n",queue.front, queue.rear); + d = queueDelete(); + printf("Dequeued ptr is %x\n", d); + printf("After 3rd del Front = %d, Rear = %d\n",queue.front, queue.rear); + d = queueDelete(); + printf("Dequeued ptr is %x\n", d); + printf("After 4th del Front = %d, Rear = %d\n",queue.front, queue.rear); +} + +#endif diff --git a/Robust/src/Runtime/DSTM/interface/queue.h b/Robust/src/Runtime/DSTM/interface/queue.h new file mode 100644 index 00000000..9ad5df45 --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/queue.h @@ -0,0 +1,22 @@ +#ifndef _QUEUE_H_ +#define _QUEUE_H_ + +#include +#include +#include + +#define ARRAY_SIZE 20 + +// DS that contains information to be shared between threads. +typedef struct prefetchthreadqueue { + int *buffer[ARRAY_SIZE]; + int front; + int rear; + pthread_mutex_t qlock; +} prefetchthreadqueue_t; + +void queueInsert(int *); +int *queueDelete(); +void queueInit(); //Initializes the queue and qlock mutex + +#endif