check in changes for cpu affinity
authorbdemsky <bdemsky>
Sat, 14 Nov 2009 11:53:55 +0000 (11:53 +0000)
committerbdemsky <bdemsky>
Sat, 14 Nov 2009 11:53:55 +0000 (11:53 +0000)
Robust/src/Runtime/STM/inlinestm.h
Robust/src/Runtime/affinity.c [new file with mode: 0644]
Robust/src/Runtime/runtime.h
Robust/src/Runtime/thread.c
Robust/src/buildscript

index 050fbbcfe930b57e541c3df16947e523c3f82b16..7a6550e7a430a78c9ab596d12475ad1e6fdc5e7e 100644 (file)
@@ -109,7 +109,7 @@ static inline void FREELIST() {
   dchashlistnode_t *tmpptr=dc_c_list;
   while(tmpptr!=NULL) {
     dchashlistnode_t *next=tmpptr->lnext;
-    if (tmpptr>=ptr&&tmpptr<top) {
+    if (likely(tmpptr>=ptr)&&likely(tmpptr<top)) {
       /*zero in list   */
       tmpptr->key=NULL;
       tmpptr->next=NULL;
diff --git a/Robust/src/Runtime/affinity.c b/Robust/src/Runtime/affinity.c
new file mode 100644 (file)
index 0000000..8ea239d
--- /dev/null
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sched.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <runtime.h>
+
+static volatile unsigned int corecount=0;
+
+
+static inline int atomicinc(volatile unsigned int *lock) {
+  int retval=1;
+  __asm__ __volatile__("lock; xadd %0,%1"
+                       : "=r"(retval)
+                       : "m"(*lock), "0"(retval)
+                       : "memory");
+  return retval;
+}
+
+
+void set_affinity() {
+  int err;
+  cpu_set_t cpumask;
+
+  CPU_ZERO(&cpumask);
+
+  int ourcount=atomicinc(&corecount);
+  ourcount=ourcount&7;
+  int newvalue=ourcount>>1;
+  if (ourcount&1) {
+    newvalue=newvalue|4;
+  }
+
+  CPU_SET(newvalue, &cpumask);
+
+  err = sched_setaffinity(syscall(SYS_gettid), sizeof(cpu_set_t), &cpumask);
+
+  if (err == -1)
+    printf("set_affinity: %s\n", strerror(errno));
+}
index 138fbb5e42b40dd61baefdda60fdc4e5a6aa66a1..50cd81738383e850d2166b98af677a65d5ac1a09 100644 (file)
@@ -14,6 +14,10 @@ extern int failurecount;
 #endif
 #endif
 
+#ifdef AFFINITY
+void set_affinity();
+#endif
+
 #ifndef INTPTR
 #ifdef BIT64
 #define INTPTR long
index 02561d59bd7639ebe3e468ebb2d71ff161e9d8c2..b5e9a7895f6fd0c37be575b71183c7d81e425de1 100644 (file)
@@ -170,6 +170,9 @@ void initializethreads() {
 #endif
   processOptions();
   initializeexithandler();
+#ifdef AFFINITY
+  set_affinity();
+#endif
 
   //deprecated use of sighandler, but apparently still works
 #ifdef SANDBOX
@@ -253,6 +256,9 @@ void initializethreads() {
 
 #if defined(THREADS)||defined(STM)
 void initthread(struct ___Thread___ * ___this___) {
+#ifdef AFFINITY
+  set_affinity();
+#endif
 #ifdef SANDBOX
   struct sigaction sig;
   abortenabled=0;
index 1c2ff4495e7807213d4fef6ee95a2ad1126e555d..7526510feeeb198ba92c533292977d6fe17d17cf 100755 (executable)
@@ -13,6 +13,7 @@ echo -inlineatomic depth inline methods inside of transactions to specified dept
 echo "-stmarray partial array treatment"
 echo "-dualview dual view of arrays"
 echo "-hybrid use fission only when it looks like a good choice"
+echo "-numa numa aware"
 echo
 echo DSM options
 echo -dsm distributed shared memory
@@ -81,6 +82,7 @@ echo -help help
 }
 
 tmpbuilddirectory="tmpbuilddirectory"
+NUMA=false;
 SANDBOX=false;
 ABORTREADERS=false;
 ROBUSTROOT=~/research/Robust/src
@@ -155,6 +157,10 @@ then
 SANDBOX=true
 EXTRAOPTIONS="$EXTRAOPTIONS -DSANDBOX"
 JAVAOPTS="$JAVAOPTS -sandbox"
+elif [[ $1 = '-numa' ]]
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -DAFFINITY -D_GNU_SOURCE"
+NUMA=true
 elif [[ $1 = '-robustroot' ]]
 then
 ROBUSTROOT="$2"
@@ -718,6 +724,11 @@ $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
 $ROBUSTROOT/Runtime/math.c \
 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
 
+if $NUMA
+then
+FILES="$FILES $ROBUSTROOT/Runtime/affinity.c"
+fi
+
 if $FASTMEMCPY
 then
 FILES="$FILES $ROBUSTROOT/Runtime/memcpy32.o $ROBUSTROOT/Runtime/instrset32.o"