From 54d9fb4b0f0e1fd58911356bf9bbec9bba1da236 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Sat, 14 Nov 2009 11:53:55 +0000 Subject: [PATCH] check in changes for cpu affinity --- Robust/src/Runtime/STM/inlinestm.h | 2 +- Robust/src/Runtime/affinity.c | 43 ++++++++++++++++++++++++++++++ Robust/src/Runtime/runtime.h | 4 +++ Robust/src/Runtime/thread.c | 6 +++++ Robust/src/buildscript | 11 ++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Robust/src/Runtime/affinity.c diff --git a/Robust/src/Runtime/STM/inlinestm.h b/Robust/src/Runtime/STM/inlinestm.h index 050fbbcf..7a6550e7 100644 --- a/Robust/src/Runtime/STM/inlinestm.h +++ b/Robust/src/Runtime/STM/inlinestm.h @@ -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=ptr)&&likely(tmpptrkey=NULL; tmpptr->next=NULL; diff --git a/Robust/src/Runtime/affinity.c b/Robust/src/Runtime/affinity.c new file mode 100644 index 00000000..8ea239d3 --- /dev/null +++ b/Robust/src/Runtime/affinity.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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)); +} diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 138fbb5e..50cd8173 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -14,6 +14,10 @@ extern int failurecount; #endif #endif +#ifdef AFFINITY +void set_affinity(); +#endif + #ifndef INTPTR #ifdef BIT64 #define INTPTR long diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index 02561d59..b5e9a789 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -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; diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 1c2ff449..7526510f 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -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" -- 2.34.1