add flag "corepin" for core pinning
authoryeom <yeom>
Thu, 18 Nov 2010 06:18:59 +0000 (06:18 +0000)
committeryeom <yeom>
Thu, 18 Nov 2010 06:18:59 +0000 (06:18 +0000)
Robust/src/Runtime/oooJava/trqueue.c
Robust/src/Runtime/workschedule.c

index c3f1734aeac7e79ded12f466cd2a18d0366b46fe..864e416285c963a683e99a28bcdc255ff1c405e0 100644 (file)
@@ -1,6 +1,8 @@
+#define _GNU_SOURCE
 #include "trqueue.h"
 #include "stdlib.h"
 #include "stdio.h"
+#include <sched.h>
 #include "mlp_lock.h"
 #include <pthread.h>
 #include "structdefs.h"
@@ -63,8 +65,16 @@ void createTR() {
     ptr->head=0;
     ptr->tail=0;
     ptr->id=myid;
+#if COREPIN
+    cpu_set_t cpuset;    
+    CPU_ZERO(&cpuset);
+    CPU_SET(myid, &cpuset);
+    pthread_attr_setaffinity_np(&nattr, sizeof(cpuset), &cpuset);    
+    printf("assign workerTR to core %d\n",myid);
+#endif
     ptr->allHashStructures=createAndFillMasterHashStructureArray();
-    int status=pthread_create( &thread, NULL, workerTR, (void *) ptr);
+    int status=pthread_create( &thread, &nattr, workerTR, (void *) ptr);
+    //    int status=pthread_create( &thread, NULL, workerTR, (void *) ptr);
     if (status!=0) {printf("ERROR\n");exit(-1);}
     pthread_attr_destroy(&nattr);
   }
index 94b3a17c288acd66980a58786d08aedd75ef2b46..01e0124deda6adfd7c1d1e30e5217c930de94aa3 100644 (file)
@@ -1,6 +1,9 @@
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
 #include <pthread.h>
+#include <sched.h>
+#include <sys/syscall.h>
 
 #include "mem.h"
 #include "workschedule.h"
@@ -18,6 +21,8 @@
 #endif
 
 
+
+
 //////////////////////////////////////////////////
 //
 //  for coordination with the garbage collector
@@ -317,6 +322,8 @@ void workScheduleInit( int numProcessors,
 #endif
     dqInit( &(deques[i]) );
   }
+
+#ifndef COREPIN
   
   pthread_attr_init( &attr );
   pthread_attr_setdetachstate( &attr, 
@@ -336,6 +343,37 @@ void workScheduleInit( int numProcessors,
 
     if( status != 0 ) { printf( "Error\n" ); exit( -1 ); }
   }
+#else
+  int numCore=24;
+  cpu_set_t cpuset;
+  pthread_attr_t thread_attr[numWorkSchedWorkers];
+  int idx;
+
+  workerDataArray[0].id = 0;
+  CPU_ZERO(&cpuset);
+  CPU_SET(0, &cpuset);
+  sched_setaffinity(syscall(SYS_gettid), sizeof(cpuset), &cpuset);  
+  
+  for(idx=1;idx<numWorkSchedWorkers;idx++){
+    int coreidx=idx%numCore;    
+    pthread_attr_t* attr = &thread_attr[idx];
+    pthread_attr_init(attr);
+    pthread_attr_setdetachstate(attr, PTHREAD_CREATE_JOINABLE);
+    CPU_ZERO(&cpuset);
+    CPU_SET(coreidx, &cpuset);
+    pthread_attr_setaffinity_np(attr, sizeof(cpuset), &cpuset);
+    
+    workerDataArray[idx].id = idx;
+    
+    status = pthread_create( &(workerDataArray[idx].workerThread), 
+                            attr,
+                            workerMain,
+                            (void*) &(workerDataArray[idx])
+                            );
+    printf("assign %d on %d",idx,coreidx);
+
+  }
+#endif
 }