#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #define NITER 100000000 #define perrorx(s) (perror(s), exit(1)) #define MAX_THREADS 512 #define CACHE_LINE_SIZE 128 #define __cache_aligned __attribute__((__aligned__(CACHE_LINE_SIZE))) static struct itimerval itv; /* this makes count a per thread variable */ static __thread unsigned volatile long count; pthread_t ptid[MAX_THREADS]; struct child_state_struct { int state; pid_t tid; long start_count; long end_count; double result; char filler[CACHE_LINE_SIZE - (sizeof(int)+sizeof(pid_t)+2*sizeof(long)+sizeof(double))]; }; struct child_state_struct child_state[MAX_THREADS] __cache_aligned; volatile int go __cache_aligned = 0; char filler[CACHE_LINE_SIZE - (sizeof(int))]; static void sigprof_handler(int signo, struct siginfo *sip, void *scp) { ++count; } void *func(void *arg) { int i, id = (int)(long)arg; double a = 0.1; pid_t tid; tid = syscall(__NR_gettid); child_state[id].tid = tid; child_state[id].state = 1; if (setitimer(ITIMER_PROF, &itv, 0) < 0) { fprintf(stderr, "Setitimer failed: %s\n", strerror(errno)); exit(1); } while(go<1); child_state[id].start_count = count; for (i=0;i