#include <inttypes.h>
#include <sys/mman.h>
#include <stdbool.h>
+#include <pthread.h>
+#include <stdlib.h>
#ifndef SYS_prem_memguard_check
#define SYS_prem_memguard_check 793
#define MGRET_OVER_MEM_MASK 0x1lu
#define MGRET_OVER_TIM_MASK 0x1lu
+#define MAX_CORES 6
+
char memory[128*10204*1024];
+static pthread_barrier_t barrier;
+
struct mg_ret {
uint32_t time;
uint32_t mem;
mgret(retval); \
})
-int main(int argc, char *argv[])
+void *test_thread(void *ptr)
{
- cpu_set_t set;
- int cpu = 0;
-
- for (int i = 0; i < sizeof(memory); i += 64)
- memory[i] = 1;
-
- if (argc > 1)
- cpu = atoi(argv[1]);
-
+ cpu_set_t set;
+ int *cpu;
+ cpu = (int *) ptr;
+
/* Ensure that memory phase starts and ends on the same CPU */
CPU_ZERO(&set);
- CPU_SET(cpu, &set);
+ CPU_SET(*cpu, &set);
if (sched_setaffinity(getpid(), sizeof(set), &set) < 0)
err(1, "sched_setaffinity");
- printf("Pinned to CPU %d\n", cpu);
-
- struct mg_ret r;
+ printf("Pinned to CPU %d\n", *cpu);
+
+ pthread_barrier_wait(&barrier);
+
+ struct mg_ret r;
for (uint64_t flags = 0; flags < 4; flags++) {
compute_kernel(1); /* warm up */
printf("\n");
}
+
+ return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+ int cpu_mask = 0;
+
+ int cpu_count = 0;
+ pthread_t threads[MAX_CORES];
+ int cores[MAX_CORES];
+ int retvals[MAX_CORES];
+
+ /* TODO: currently shared memory */
+ for (int i = 0; i < sizeof(memory); i += 64)
+ memory[i] = 1;
+
+ if (argc > 1)
+ cpu_mask = strtol(argv[1], NULL, 16);
+
+ for(int i=0; i<MAX_CORES; i++){
+ if(cpu_mask & (1 << i)){
+ cpu_count++;
+ }
+ }
+
+ int s = pthread_barrier_init(&barrier, NULL, cpu_count);
+ if (s != 0)
+ err(1, "pthread_barrier_init");
+
+ for(int i=0; i<MAX_CORES; i++){
+ if(cpu_mask & (1 << i)){
+ cores[i] = i;
+ retvals[i] = pthread_create(&threads[i], NULL, test_thread, (void*) &cores[i]);
+ }
+ }
+
+ for(int i=0; i<MAX_CORES; i++){
+ if(cpu_mask & (1 << i)){
+ pthread_join(threads[i], NULL);
+ }
+ }
+
return 0;
}