uti: futex call function in mcctrl

Previously, futex code of McKerenl was called by mccontrol,
but there ware some problems with this method.
(Mainly, location of McKernel image on memory)

Call futex code in mcctrl instead of the one in McKernel image,
giving the following benefits:
1. Not relying on shared kernel virtual address space with Linux any more
2. The cpu id store / retrieve is not needed and resulting in the code

Change-Id: Ic40929b64a655b270c435859fa287fedb713ee5c
refe: #1428
This commit is contained in:
Ken Sato
2020-09-18 14:42:26 +09:00
committed by Masamichi Takagi
parent 35296c8210
commit a9973e913d
62 changed files with 4320 additions and 1116 deletions

View File

@@ -83,26 +83,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(long delay_nsec, unsigned long* mem) {
if (delay_nsec < 0) {
printf("%s: delay_nsec<0\n", __FUNCTION__);
}
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void mydelay(long delay_nsec, long *mem) {
struct timespec start, end;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
@@ -154,11 +134,11 @@ void *progress_fn(void *_arg) {
break;
}
fwq(POLL_DELAY, &arg->mem);
fwq(POLL_DELAY);
/* Event found */
if (nevents > 0) {
fwq(COMPL_DELAY, &arg->mem); /* Simulate MPI protocol response */
fwq(COMPL_DELAY); /* Simulate MPI protocol response */
nevents = 0;
}
@@ -190,7 +170,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "CT09002 main running on McKernel INFO\n");
}
fwq_init(&mem);
fwq_init();
pthread_mutex_init(&ep_lock, NULL);
thr_args.bar_count = 0;
@@ -243,16 +223,16 @@ int main(int argc, char **argv) {
/* Acquire endpoint and send request-to-send packet */
pthread_mutex_lock(&ep_lock);
fwq(RTS_DELAY, &mem);
fwq(RTS_DELAY);
pthread_mutex_unlock(&ep_lock);
/* Start calculation */
/* Generate event on behaf of responder */
fwq(NIC_DELAY, &mem);
fwq(NIC_DELAY);
nevents++;
fwq(CALC_DELAY - NIC_DELAY, &mem); /* Overlap remainder */
fwq(CALC_DELAY - NIC_DELAY); /* Overlap remainder */
/* Wait until async thread consumes the event */
while (nevents > 0) {
@@ -260,7 +240,7 @@ int main(int argc, char **argv) {
}
} else {
/* No overlap case */
fwq(RTS_DELAY + CALC_DELAY + POLL_DELAY + COMPL_DELAY, &mem);
fwq(RTS_DELAY + CALC_DELAY + POLL_DELAY + COMPL_DELAY);
}
}
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);

View File

@@ -34,23 +34,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void *
util_thread(void *arg)
{
@@ -65,7 +48,7 @@ util_thread(void *arg)
}
errno = 0;
fwq(500 * 1000 * 1000UL, &mem); /* Sending debug messages through serial takes 0.05 sec */
fwq(500 * 1000 * 1000UL); /* Sending debug messages through serial takes 0.05 sec */
pthread_mutex_lock(&mutex);
if (owned) {
@@ -84,7 +67,7 @@ int main(int argc, char **argv) {
unsigned long mem;
pthread_mutex_init(&mutex, NULL);
fwq_init(&mem);
fwq_init();
fprintf(stderr, "CT14001 futex START\n");
@@ -110,7 +93,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "CT14004 lock first NG\n");
}
owned = 1;
fwq(2000 * 1000 * 1000UL, &mem); /* Need 2 sec to make child sleep */
fwq(2000 * 1000 * 1000UL); /* Need 2 sec to make child sleep */
pthread_mutex_unlock(&mutex);
pthread_join(thr, NULL);

View File

@@ -34,23 +34,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void *
util_thread(void *arg)
{
@@ -72,7 +55,7 @@ util_thread(void *arg)
fprintf(stderr, "CT14101 lock first NG\n");
}
owned = 1;
fwq(2000 * 1000 * 1000UL, &mem); /* Need 2 sec to make parent sleep */
fwq(2000 * 1000 * 1000UL); /* Need 2 sec to make parent sleep */
pthread_mutex_unlock(&mutex);
return NULL;
@@ -83,7 +66,7 @@ int main(int argc, char **argv) {
unsigned long mem;
pthread_mutex_init(&mutex, NULL);
fwq_init(&mem);
fwq_init();
fprintf(stderr, "CT14001 futex START\n");
@@ -102,7 +85,7 @@ int main(int argc, char **argv) {
}
fprintf(stderr, "CT14003 pthread_create OK\n");
fwq(500 * 1000 * 1000UL, &mem); /* Sending debug messages through serial takes 0.05 sec */
fwq(500 * 1000 * 1000UL); /* Sending debug messages through serial takes 0.05 sec */
pthread_mutex_lock(&mutex);
if (owned) {

View File

@@ -74,23 +74,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void mydelay(long delay_nsec, long *mem) {
struct timespec start, end;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
@@ -136,7 +119,7 @@ void *progress_fn(void *_arg) {
}
pthread_mutex_unlock(&ep_lock);
fwq(random() % 1000000000, &mem); /* 0 - 1 sec */
fwq(random() % 1000000000); /* 0 - 1 sec */
pthread_mutex_lock(&ep_lock);
}
return NULL;
@@ -156,7 +139,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "CT09002 main running on McKernel INFO\n");
}
fwq_init(&mem);
fwq_init();
pthread_mutex_init(&ep_lock, NULL);
for(i = 0; i < NTHR; i++) {
@@ -189,7 +172,7 @@ int main(int argc, char **argv) {
for (i = 0; i < 10; i++) {
pthread_mutex_lock(&ep_lock);
nevents++;
fwq(random() % 1000000000, &mem); /* 0 - 1 sec */
fwq(random() % 1000000000); /* 0 - 1 sec */
pthread_mutex_unlock(&ep_lock);
while (nevents > 0) {
FIXED_SIZE_WORK(&mem);

View File

@@ -74,23 +74,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void mydelay(long delay_nsec, long *mem) {
struct timespec start, end;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
@@ -126,7 +109,7 @@ void *progress_fn(void *_arg) {
for (i = 0; i < 100; i++) {
pthread_mutex_lock(&ep_lock);
nevents++;
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
pthread_mutex_unlock(&ep_lock);
while (nevents > 0) {
FIXED_SIZE_WORK(&mem);
@@ -150,7 +133,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "CT09002 main running on McKernel INFO\n");
}
fwq_init(&mem);
fwq_init();
pthread_mutex_init(&ep_lock, NULL);
for(i = 0; i < NTHR; i++) {
@@ -193,7 +176,7 @@ int main(int argc, char **argv) {
}
pthread_mutex_unlock(&ep_lock);
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
pthread_mutex_lock(&ep_lock);
}
pthread_mutex_unlock(&ep_lock);

View File

@@ -75,23 +75,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void mydelay(long delay_nsec, long *mem) {
struct timespec start, end;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
@@ -135,7 +118,7 @@ void *progress_fn(void *_arg) {
}
nevents = 0;
pthread_mutex_unlock(&ep_lock);
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
pthread_mutex_lock(&ep_lock);
}
pthread_mutex_unlock(&ep_lock);
@@ -156,7 +139,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "CT09002 main running on McKernel INFO\n");
}
fwq_init(&mem);
fwq_init();
pthread_cond_init(&ep_cond, NULL);
pthread_mutex_init(&ep_lock, NULL);
@@ -188,7 +171,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "CT09004 pthread_create OK\n");
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
for (i = 0; i < 100; i++) {
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
pthread_mutex_lock(&ep_lock);
nevents++;
pthread_cond_signal(&ep_cond);

View File

@@ -75,23 +75,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void mydelay(long delay_nsec, long *mem) {
struct timespec start, end;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
@@ -125,7 +108,7 @@ void *progress_fn(void *_arg) {
pthread_mutex_unlock(&arg->bar_lock);
for (i = 0; i < 100; i++) {
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
pthread_mutex_lock(&ep_lock);
nevents++;
pthread_cond_signal(&ep_cond);
@@ -152,7 +135,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "CT09002 main running on McKernel INFO\n");
}
fwq_init(&mem);
fwq_init();
pthread_mutex_init(&ep_lock, NULL);
for(i = 0; i < NTHR; i++) {
@@ -193,7 +176,7 @@ int main(int argc, char **argv) {
}
nevents = 0;
pthread_mutex_unlock(&ep_lock);
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
pthread_mutex_lock(&ep_lock);
}
pthread_mutex_unlock(&ep_lock);

View File

@@ -102,25 +102,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init() {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
bulk_fsw(N_INIT);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(long delay_nsec) {
if (delay_nsec < 0) {
printf("%s: delay_nsec<0\n", __FUNCTION__);
}
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
bulk_fsw(delay_nsec / nspw);
}
int progress_responder(struct thr_arg *thr_arg) {
int ret = 0;
int j;

View File

@@ -152,25 +152,6 @@ static int print_cpu_last_executed_on() {
goto fn_exit;
}
void fwq_init() {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
bulk_fsw(N_INIT);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(long delay_nsec) {
if (delay_nsec < 0) {
printf("%s: delay_nsec<0\n", __FUNCTION__);
}
bulk_fsw(delay_nsec / nspw);
}
void init_bar(struct thr_arg* thr_arg) {
pthread_mutex_lock(&thr_arg->bar_lock);
thr_arg->bar_count= 0;

View File

@@ -44,26 +44,6 @@ static inline void bulk_fsw(unsigned long n) {
#define N_INIT 1000000
void fwq_init() {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
bulk_fsw(N_INIT);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(long delay_nsec) {
if (delay_nsec < 0) {
printf("%s: delay_nsec<0\n", __FUNCTION__);
}
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
bulk_fsw(delay_nsec / nspw);
}
void *util_thread(void *arg) {
int rc;

View File

@@ -53,23 +53,6 @@ double nspw; /* nsec per work */
#define N_INIT 10000000
void fwq_init(unsigned long *mem) {
struct timespec start, end;
unsigned long nsec;
int i;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) - TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("[INFO] nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(unsigned long delay_nsec, unsigned long* mem) {
//printf("delay_nsec=%ld,count=%f\n", delay_nsec, delay_nsec / nspw);
BULK_FSW(delay_nsec / nspw, mem);
}
void fwq_omp(unsigned long delay_nsec, unsigned long* mem) {
#pragma omp parallel
{
@@ -110,7 +93,7 @@ void *util_fn(void *_arg) {
if (nevents > 0) {
nevents--;
fwq(random() % 100000000, &mem); /* 0 - 0.1 sec */
fwq(random() % 100000000); /* 0 - 0.1 sec */
}
pthread_mutex_unlock(&ep_lock);
}
@@ -127,7 +110,7 @@ int main(int argc, char **argv) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master is running on McKernel\n");
fwq_init(&mem);
fwq_init();
pthread_mutex_init(&ep_lock, NULL);
pthread_barrier_init(&bar, NULL, NTHR + 1);

View File

@@ -25,17 +25,20 @@ pthread_t thr;
long t_cond_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
long start, end;
print_cpu_last_executed_on("Utility thread");
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
@@ -50,7 +53,6 @@ void *util_fn(void *arg)
flag = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
fn_fail:
@@ -66,21 +68,24 @@ int main(int argc, char **argv)
{
int i;
int ret;
long start, end;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
while ((opt = getopt_long(argc, argv, "+b:", options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
@@ -103,11 +108,13 @@ int main(int argc, char **argv)
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_attr_init(&attr))) {
printf("%s: Error: pthread_attr_init failed (%d)\n", __FUNCTION__, ret);
@@ -128,11 +135,13 @@ int main(int argc, char **argv)
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
fprintf(stderr, "Error: sched_setscheduler failed (%d)\n", ret);
goto fn_fail;
fprintf(stderr, "Warning: sched_setscheduler: %s\n",
strerror(errno));
}
syscall(701, 1 | 2);
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
@@ -147,7 +156,9 @@ int main(int argc, char **argv)
end = rdtsc_light();
t_cond_wait += end - start;
}
syscall(701, 4 | 8);
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] waker: %ld cycles, waiter: %ld cycles, (waiter - waker) / nloop: %ld cycles\n", t_fwq, t_cond_wait, (t_cond_wait - t_fwq) / nloop);

View File

@@ -1,102 +0,0 @@
#!/usr/bin/bash
bn=`basename $0`
fn=`echo $bn | sed 's/.sh//'`
nloop=800
stop=0
reboot=0
go=0
mck=0
NNODES=1
NPROC=$((1 * NNODES))
LASTNODE=8200
use_hfi=0
while getopts srgmh:N:P:L: OPT
do
case ${OPT} in
s) stop=1
;;
r) reboot=1
;;
g) go=1
;;
m) mck=1
;;
h) use_hfi=1
;;
N) NNODES=$OPTARG
;;
P) NPROC=$OPTARG
;;
L) LASTNODE=$OPTARG
;;
*) echo "invalid option -${OPT}" >&2
exit 1
esac
done
MYHOME=/work/gg10/e29005
ABS_SRCDIR=${MYHOME}/project/os/mckernel/test/uti
MCK=${MYHOME}/project/os/install
NODES=`echo $(seq -s ",c" $(($LASTNODE + 1 - $NNODES)) $LASTNODE) | sed 's/^/c/'`
PPN=$((NPROC / NNODES))
echo NPROC=$NPROC NNODES=$NNODES PPN=$PPN NODES=$NODES
if [ ${mck} -eq 1 ]; then
MCEXEC="${MCK}/bin/mcexec"
mcexecopt="--enable-uti"
if [ ${use_hfi} -eq 1 ]; then
mcexecopt="--enable-hfi1 $mcexecopt"
fi
else
MCEXEC=
mcexecopt=
fi
if [ ${stop} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo mount /work
if [ ${mck} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
/sbin/pidof mcexec \| xargs -r kill -9
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo ${MCK}/sbin/mcstop+release.sh
else
:
fi
fi
if [ ${reboot} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo mount /work
if [ ${mck} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo ${MCK}/sbin/mcreboot.sh -c 2-17,70-85,138-153,206-221,20-35,88-103,156-171,224-239,36-51,104-119,172-187,240-255,52-67,120-135,188-203,256-271 -r 2-5,70-73,138-141,206-209:0+6-9,74-77,142-145,210-213:1+10-13,78-81,146-149,214-217:68+14-17,82-85,150-153,218-221:69+20-23,88-91,156-159,224-227:136+24-27,92-95,160-163,228-231:137+28-31,96-99,164-167,232-235:204+32-35,100-103,168-171,236-239:205+36-39,104-107,172-175,240-243:18+40-43,108-111,176-179,244-247:19+44-47,112-115,180-183,248-251:86+48-51,116-119,184-187,252-255:87+52-55,120-123,188-191,256-259:154+56-59,124-127,192-195,260-263:155+60-63,128-131,196-199,264-267:222+64-67,132-135,200-203,268-271:223 -m 32G@0,12G@1
else
:
fi
fi
if [ ${go} -eq 1 ]; then
cd $ABS_SRCDIR
make $fn
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
ulimit -u 16384;
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
ulimit -s unlimited
for((count=0;count<nloop;count++)); do
sudo $MCEXEC $mcexecopt ./$fn
echo =====
echo $count
echo =====
done
fi

View File

@@ -4,60 +4,57 @@
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <sys/mman.h>
#include <signal.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <uti.h>
#include "util.h"
#define WAITER_CPU 0
#define WAKER_CPU 1
int sem;
pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_futex_wait, t_fwq;
long t_cond_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
int testid = 32101;
long start, end;
print_cpu_last_executed_on("Utility thread");
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
fwq(blocktime);
end = rdtsc_light();
t_fwq += end - start;
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAKE, 1, NULL, NULL, 0)) == -1) {
printf("Error: futex wake: %s\n", strerror(errno));
}
//pthread_barrier_wait(&bar);
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
pthread_mutex_lock(&mutex); /* no futex */
while(!flag) {
pthread_cond_wait(&cond, &mutex); /* 1st futex */
}
flag = 0;
pthread_mutex_unlock(&mutex); /* 2nd futex */
end = rdtsc_light();
t_cond_wait += end - start;
}
ret = 0;
fn_fail:
return NULL;
}
@@ -71,21 +68,24 @@ int main(int argc, char **argv)
{
int i;
int ret;
long start, end;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
while ((opt = getopt_long(argc, argv, "+b:", options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
@@ -102,88 +102,66 @@ int main(int argc, char **argv)
fwq_init();
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_attr_init(&attr))) {
printf("Error: pthread_attr_init: %s\n", strerror(errno));
printf("%s: Error: pthread_attr_init failed (%d)\n", __FUNCTION__, ret);
goto fn_fail;
}
#if 0
uti_attr_t uti_attr;
ret = uti_attr_init(&uti_attr);
if (ret) {
printf("%s: Error: uti_attr_init failed (%d)\n", __FUNCTION__, ret);
exit(1);
}
/* Give a hint that it's beneficial to prioritize it in scheduling. */
ret = UTI_ATTR_HIGH_PRIORITY(&uti_attr);
if (ret) {
printf("%s: Error: UTI_ATTR_HIGH_PRIORITY failed (%d)\n", __FUNCTION__, ret);
exit(1);
}
if ((ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) {
printf("%s: Error: pthread_attr_setdetachstate failed (%d)\n", __FUNCTION__, ret);
exit(1);
}
if ((ret = uti_pthread_create(&thr, &attr, progress_function, NULL, &uti_attr))) {
printf("%s: Error: uti_pthread_create: %s\n", __FUNCTION__, strerror(errno));
exit(1);
}
if ((ret = uti_attr_destroy(&uti_attr))) {
printf("%s: Error: uti_attr_destroy failed (%d)\n", __FUNCTION__, ret);
exit(1);
}
#else
CPU_ZERO(&cpuset);
CPU_SET(WAKER_CPU, &cpuset);
if ((ret = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset))) {
printf("Error: pthread_attr_setaffinity_np: %s\n", strerror(errno));
printf("%s: Error: pthread_attr_setaffinity_np failed (%d)\n", __FUNCTION__, ret);
goto fn_fail;
}
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
fprintf(stderr, "Error: pthread_create failed (%d)\n", ret);
goto fn_fail;
}
#endif
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
printf("Error: sched_setscheduler: %s\n", strerror(errno));
ret = -errno;
goto fn_fail;
fprintf(stderr, "Warning: sched_setscheduler: %s\n",
strerror(errno));
}
syscall(701, 1 | 2);
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAIT, 0, NULL, NULL, 0))) {
printf("Error: futex wait failed (%s)\n", strerror(errno));
}
start = rdtsc_light();
//pthread_barrier_wait(&bar); /* 2nd futex */
fwq(blocktime);
end = rdtsc_light();
t_fwq += end - start;
pthread_mutex_lock(&mutex);
flag = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
if (!linux_run) {
syscall(701, 4 | 8);
}
end = rdtsc_light();
t_futex_wait += end - start;
syscall(701, 4 | 8);
pthread_join(thr, NULL);
printf("[INFO] waiter: %ld cycles, waker: %ld cycles, (waiter - waker) / nloop: %ld cycles\n", t_fwq, t_futex_wait, (t_futex_wait - t_fwq) / nloop);
printf("[INFO] waker: %ld cycles, waiter: %ld cycles, (waiter - waker) / nloop: %ld cycles\n", t_fwq, t_cond_wait, (t_cond_wait - t_fwq) / nloop);
ret = 0;
fn_fail:

View File

@@ -1,104 +0,0 @@
#!/usr/bin/bash
bn=`basename $0`
fn=`echo $bn | sed 's/.sh//'`
stop=0
reboot=0
go=0
mck=0
disable_uti=1
NNODES=1
NPROC=$((1 * NNODES))
LASTNODE=8200
use_hfi=0
while getopts srgmh:N:P:L:d: OPT
do
case ${OPT} in
s) stop=1
;;
r) reboot=1
;;
g) go=1
;;
m) mck=1
;;
h) use_hfi=1
;;
d) disable_uti=$OPTARG
;;
N) NNODES=$OPTARG
;;
P) NPROC=$OPTARG
;;
L) LASTNODE=$OPTARG
;;
*) echo "invalid option -${OPT}" >&2
exit 1
esac
done
MYHOME=/work/gg10/e29005
ABS_SRCDIR=${MYHOME}/project/os/mckernel/test/uti
MCK=${MYHOME}/project/os/install
NODES=`echo $(seq -s ",c" $(($LASTNODE + 1 - $NNODES)) $LASTNODE) | sed 's/^/c/'`
PPN=$((NPROC / NNODES))
echo NPROC=$NPROC NNODES=$NNODES PPN=$PPN NODES=$NODES
if [ $disable_uti -eq 1 ]; then
export DISABLE_UTI=1
else
unset DISABLE_UTI
fi
if [ ${mck} -eq 1 ]; then
MCEXEC="${MCK}/bin/mcexec"
mcexecopt="--enable-uti"
if [ ${use_hfi} -eq 1 ]; then
mcexecopt="--enable-hfi1 $mcexecopt"
fi
else
MCEXEC=
mcexecopt=
fi
if [ ${stop} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo mount /work
if [ ${mck} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
/sbin/pidof mcexec \| xargs -r kill -9
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo ${MCK}/sbin/mcstop+release.sh
else
:
fi
fi
if [ ${reboot} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo mount /work
if [ ${mck} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
sudo ${MCK}/sbin/mcreboot.sh -c 2-17,70-85,138-153,206-221,20-35,88-103,156-171,224-239,36-51,104-119,172-187,240-255,52-67,120-135,188-203,256-271 -r 2-5,70-73,138-141,206-209:0+6-9,74-77,142-145,210-213:1+10-13,78-81,146-149,214-217:68+14-17,82-85,150-153,218-221:69+20-23,88-91,156-159,224-227:136+24-27,92-95,160-163,228-231:137+28-31,96-99,164-167,232-235:204+32-35,100-103,168-171,236-239:205+36-39,104-107,172-175,240-243:18+40-43,108-111,176-179,244-247:19+44-47,112-115,180-183,248-251:86+48-51,116-119,184-187,252-255:87+52-55,120-123,188-191,256-259:154+56-59,124-127,192-195,260-263:155+60-63,128-131,196-199,264-267:222+64-67,132-135,200-203,268-271:223 -m 32G@0,12G@1
else
:
fi
fi
if [ ${go} -eq 1 ]; then
cd $ABS_SRCDIR
make $fn
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
ulimit -u 16384;
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $NODES \
ulimit -s unlimited
sudo $MCEXEC $mcexecopt ./$fn
fi

View File

@@ -22,54 +22,46 @@ int sem;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_fwq, t_futex_wake, t_futex_wait;
long t_fwq2;
long t_futex_wait, t_fwq;
long nloop;
long blocktime = 10 * 1000 * 1000L;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
long start2, end2;
long start, end;
int testid = 32101;
print_cpu_last_executed_on("Utility thread");
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
/* Measure fwq time */
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
fwq(blocktime);
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
end = rdtsc_light();
t_fwq2 += end - start;
/* Measure fwq + futex time */
syscall(701, 1 | 2 | 0x80000000);
pthread_barrier_wait(&bar);
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
start2 = rdtsc_light();
start = rdtsc_light();
fwq(blocktime);
end2 = rdtsc_light();
t_fwq += end2 - start2;
end = rdtsc_light();
t_fwq += end - start;
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAKE, 1, NULL, NULL, 0)) != 1) {
printf("Error: futex wake failed (%d,%s)\n", ret, strerror(errno));
sem = i + 1;
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAKE, 1,
NULL, NULL, 0)) != 1) {
printf("Error: futex wake: %d,%d\n", ret, errno);
}
//pthread_barrier_wait(&bar);
}
end = rdtsc_light();
t_futex_wake += end - start;
syscall(701, 4 | 8 | 0x80000000);
ret = 0;
fn_fail:
return NULL;
}
@@ -81,26 +73,29 @@ static struct option options[] = {
int main(int argc, char **argv)
{
int i, j;
int i;
int ret;
long start, end;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
while ((opt = getopt_long(argc, argv, "+b:", options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = 10 * 1000000000UL / blocktime;
nloop = (10 * 1000000000UL) / blocktime;
printf("[INFO] nloop=%ld,blocktime=%ld\n", nloop, blocktime);
@@ -117,14 +112,8 @@ int main(int argc, char **argv)
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
if ((ret = pthread_attr_init(&attr))) {
printf("Error: pthread_attr_init failed: %s\n", strerror(errno));
printf("Error: pthread_attr_init: %s\n", strerror(errno));
goto fn_fail;
}
@@ -136,32 +125,45 @@ int main(int argc, char **argv)
goto fn_fail;
}
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
goto fn_fail;
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
printf("Error: sched_setscheduler: %s\n", strerror(errno));
goto fn_fail;
printf("Warning: sched_setscheduler: %s\n", strerror(errno));
}
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAIT, 0, NULL, NULL, 0))) {
printf("Error: futex wait: %s\n", strerror(errno));
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAIT, i, NULL, NULL, 0))) {
printf("Error: futex wait failed (%s)\n", strerror(errno));
}
//pthread_barrier_wait(&bar);
//pthread_barrier_wait(&bar); /* 2nd futex */
}
end = rdtsc_light();
t_futex_wait += end - start;
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] compute: %ld, wake: %ld, wait: %ld, wake - compute: %ld, wait - compute: %ld (cycles)\n", t_fwq, t_futex_wake, t_futex_wait, (t_futex_wake - t_fwq) / nloop, (t_futex_wait - t_fwq) / nloop);
printf("[INFO] waiter: %ld cycles, waker: %ld cycles, (waiter - waker) / nloop: %ld cycles\n", t_futex_wait, t_fwq, (t_futex_wait - t_fwq) / nloop);
ret = 0;
fn_fail:
return ret;
}

View File

@@ -1,93 +0,0 @@
#!/usr/bin/bash
bn=`basename $0`
fn=`echo $bn | sed 's/.sh//'`
stop=0
reboot=0
go=0
mck=0
NNODES=1
NPROC=$((1 * NNODES))
LASTNODE=8200
use_hfi=0
while getopts srgmh:N:P:L: OPT
do
case ${OPT} in
s) stop=1
;;
r) reboot=1
;;
g) go=1
;;
m) mck=1
;;
h) use_hfi=1
;;
N) NNODES=$OPTARG
;;
P) NPROC=$OPTARG
;;
L) LASTNODE=$OPTARG
;;
*) echo "invalid option -${OPT}" >&2
exit 1
esac
done
MYHOME=/work/gg10/e29005
ABS_SRCDIR=${MYHOME}/project/os/mckernel/test/uti
MCK=${MYHOME}/project/os/install
nodes=`echo $(seq -s ",c" $(($LASTNODE + 1 - $NNODES)) $LASTNODE) | sed 's/^/c/'`
PPN=$((NPROC / NNODES))
echo NPROC=$NPROC NNODES=$NNODES PPN=$PPN nodes=$nodes
if [ "`cat /etc/mtab | while read line; do cut -d" " -f 2; done | grep /work`" == "" ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $nodes sudo mount /work
fi
if [ ${mck} -eq 1 ]; then
MCEXEC="${MCK}/bin/mcexec"
mcexecopt="--enable-uti"
if [ ${use_hfi} -eq 1 ]; then
mcexecopt="--enable-hfi1 $mcexecopt"
fi
else
MCEXEC=
mcexecopt=
fi
if [ ${stop} -eq 1 ]; then
if [ ${mck} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $nodes \
/sbin/pidof mcexec \| xargs -r kill -9
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $nodes \
sudo ${MCK}/sbin/mcstop+release.sh
else
:
fi
fi
if [ ${reboot} -eq 1 ]; then
if [ ${mck} -eq 1 ]; then
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $nodes \
sudo ${MCK}/sbin/mcreboot.sh -c 2-17,70-85,138-153,206-221,20-35,88-103,156-171,224-239,36-51,104-119,172-187,240-255,52-67,120-135,188-203,256-271 -r 2-5,70-73,138-141,206-209:0+6-9,74-77,142-145,210-213:1+10-13,78-81,146-149,214-217:68+14-17,82-85,150-153,218-221:69+20-23,88-91,156-159,224-227:136+24-27,92-95,160-163,228-231:137+28-31,96-99,164-167,232-235:204+32-35,100-103,168-171,236-239:205+36-39,104-107,172-175,240-243:18+40-43,108-111,176-179,244-247:19+44-47,112-115,180-183,248-251:86+48-51,116-119,184-187,252-255:87+52-55,120-123,188-191,256-259:154+56-59,124-127,192-195,260-263:155+60-63,128-131,196-199,264-267:222+64-67,132-135,200-203,268-271:223 -m 32G@0,12G@1
else
:
fi
fi
if [ ${go} -eq 1 ]; then
cd $ABS_SRCDIR
make $fn
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $nodes \
ulimit -u 16384;
PDSH_SSH_ARGS_APPEND="-tt -q" pdsh -t 2 -w $nodes \
ulimit -s unlimited
sudo $MCEXEC $mcexecopt ./$fn
fi

View File

@@ -1,62 +1,168 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <sched.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include "util.h"
#define WAITER_CPU 0
#define WAKER_CPU 1
int sem;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_futex_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
long start, end;
int testid = 32101;
print_cpu_last_executed_on("Utility thread");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAIT, i, NULL, NULL, 0))) {
printf("Error: futex wait failed (%s)\n", strerror(errno));
}
//pthread_barrier_wait(&bar); /* 2nd futex */
}
end = rdtsc_light();
t_futex_wait += end - start;
ret = 0;
fn_fail:
return NULL;
}
int my_thread_create()
static struct option options[] = {
/* end */
{ NULL, 0, NULL, 0, }
};
int main(int argc, char **argv)
{
pthread_t thr;
int ret = 0;
int i;
int ret;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret == 0, "util_indicate_clone,ret=%d,errno=%d\n", ret, errno);
if ((ret = pthread_create(&thr, NULL, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
printf("[INFO] nloop=%ld,blocktime=%ld\n", nloop, blocktime);
if ((ret = pthread_join(thr, NULL))) {
printf("Error: pthread_join: %s\n", strerror(errno));
CPU_ZERO(&cpuset);
CPU_SET(WAKER_CPU, &cpuset);
if ((ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset))) {
printf("Error: sched_setaffinity: %s\n", strerror(errno));
goto fn_fail;
}
print_cpu_last_executed_on("Master thread");
fwq_init();
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
if ((ret = pthread_attr_init(&attr))) {
printf("Error: pthread_attr_init: %s\n", strerror(errno));
goto fn_fail;
}
fn_exit:
return ret;
CPU_ZERO(&cpuset);
CPU_SET(WAITER_CPU, &cpuset);
fn_fail:
ret = -1;
goto fn_exit;
}
int
main(int argc, char **argv)
{
int ret = 0;
if ((ret = my_thread_create())) {
printf("Error: my_thread_create,ret=%d\n", ret);
if ((ret = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset))) {
printf("Error: pthread_attr_setaffinity_np: %s\n", strerror(errno));
goto fn_fail;
}
fn_exit:
return ret;
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
goto fn_fail;
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
printf("Warning: sched_setscheduler: %s\n", strerror(errno));
}
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
fwq(blocktime);
end = rdtsc_light();
t_fwq += end - start;
sem = i + 1;
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAKE, 1,
NULL, NULL, 0)) != 1) {
printf("Error: futex wake: %d, %d\n", ret, errno);
}
//pthread_barrier_wait(&bar);
}
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] waiter: %ld cycles, waker: %ld cycles, (waiter - waker) / nloop: %ld cycles\n", t_futex_wait, t_fwq, (t_futex_wait - t_fwq) / nloop);
ret = 0;
fn_fail:
ret = -1;
goto fn_exit;
return ret;
}

62
test/uti/CT35.c Normal file
View File

@@ -0,0 +1,62 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <sched.h>
#include "util.h"
void *util_fn(void *arg)
{
int ret;
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
fn_fail:
return NULL;
}
int my_thread_create()
{
pthread_t thr;
int ret = 0;
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret == 0, "util_indicate_clone,ret=%d,errno=%d\n", ret, errno);
if ((ret = pthread_create(&thr, NULL, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
}
if ((ret = pthread_join(thr, NULL))) {
printf("Error: pthread_join: %s\n", strerror(errno));
}
fn_exit:
return ret;
fn_fail:
ret = -1;
goto fn_exit;
}
int
main(int argc, char **argv)
{
int ret = 0;
if ((ret = my_thread_create())) {
printf("Error: my_thread_create,ret=%d\n", ret);
}
fn_exit:
return ret;
fn_fail:
ret = -1;
goto fn_exit;
}

View File

@@ -1,13 +1,14 @@
.SUFFIXES: # Disable implicit rules
SYSCALLL_INTERCEPT_DIR=$(HOME)/usr
UTI_DIR=$(HOME)/project/uti/install
SYSCALLL_INTERCEPT_DIR=$(MCK_DIR)
include $(HOME)/.mck_test_config.mk
CC = gcc
CPPFLAGS = -I$(UTI_DIR)/include
CCFLAGS = -g -O0
LDFLAGS = -L$(UTI_DIR)/lib -Wl,-rpath,$(UTI_DIR)/lib -luti -lpthread -lrt
LDFLAGS = -L$(UTI_DIR)/lib -Wl,-rpath,$(UTI_DIR)/lib -luti -lpthread -lrt
LDFLAGS2 = -lpthread -lrt
SRCS = $(shell ls CT*.c)
EXES = $(SRCS:.c=)
@@ -27,9 +28,21 @@ file::
CT30.o:: CT30.c
icc $(CCFLAGS) -qopenmp $(CPPFLAGS) -c $<
CT30: CT30.o
CT30: CT30.o util.o
icc -o $@ $^ $(LDFLAGS) -qopenmp
CT31: CT31.o util.o
$(CC) -o $@ $^ $(LDFLAGS2) $(CPPFLAGS)
CT32: CT32.o util.o
$(CC) -o $@ $^ $(LDFLAGS2) $(CPPFLAGS)
CT33: CT33.o util.o
$(CC) -o $@ $^ $(LDFLAGS2) $(CPPFLAGS)
CT34: CT34.o util.o
$(CC) -o $@ $^ $(LDFLAGS2) $(CPPFLAGS)
%.o:: %.c
$(CC) $(CCFLAGS) $(CPPFLAGS) -c $<

View File

@@ -338,14 +338,46 @@ CT29 no reverse offload
CT30 CT21にopenmpスレッドを追加したテスト
CT31 pthread_cond_waitオーバーヘッド測定
* waiterとwakerのCPUは、それぞれ、WAITER_CPU、WAKER_CPUで設定
* Linuxがwaker、McKernelがwaiter
CT32 futex waitオーバーヘッド測定
* waiterとwakerのCPUは、それぞれ、WAITER_CPU、WAKER_CPUで設定
CT32 pthread_cond_waitオーバーヘッド測定
* Linuxがwaiter、McKernelがwaker
CT33 futex wakeオーバーヘッド測定
* waiterとwakerのCPUは、それぞれ、WAITER_CPU、WAKER_CPUで設定
CT33 Main threadでfutex_wait, UTI threadでfutex_wakeをした場合のオーバーヘッド測定
* Linuxがwaker、McKernelがwaiter
CT34 繰り返しpthread_create
CT34 UTI threadでfutex_wait, Main threadでfutex_wakeをした場合のオーバーヘッド測定
* Linuxがwaiter、McKernelがwaker
CT35 LD_PRELOADでsyscall_interceptを用いたsoをつけた場合のテスト
CT35 繰り返しpthread_create
CT36 LD_PRELOADでsyscall_interceptを用いたsoをつけた場合のテスト
==========
How to run
==========
Prepare $HOME/.mck_test_config. Example:
# Config file for McKernel tests
MCK_DIR=/home/m-takagi/project/os/install
BIN=/home/m-takagi/project/os/install/bin
SBIN=/home/m-takagi/project/os/install/sbin
: ${OSTEST:=/home/m-takagi/project/src/ostest}
: ${LTP:=/home/m-takagi/project/src/ltp/install}
BOOTPARAM="-k 0 -f LOG_LOCAL6 -c 1-7,9-15,17-23,25-31 -m 10G@0,10G@1 -r 1-7:0+9-15:8+17-23:16+25-31:24 -O"
: ${MCKERNEL_VERSION:=1.5.0}
Prepare $HOME/.mck_test_config.mk. Example:
# Config file for McKernel tests
BIN ?= /home/m-takagi/project/os/install/bin
SBIN ?= /home/m-takagi/project/os/install/sbin
OSTEST ?=
LTP ?=
BOOTPARAM ?= -c 1-7,9-15,17-23,25-31 -m 10G@0,10G@1 -r 1-7:0+9-15:8+17-23:16+25-31:24
MCK_DIR ?= /home/m-takagi/project/os/install
ARCH ?= x86_64
TARGET ?= smp-x86
UTI_DIR ?= /home/m-takagi/project/uti/install_mckernel

171
test/uti/arm64/CT31.c Normal file
View File

@@ -0,0 +1,171 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <signal.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "util.h"
#define WAITER_CPU 0
#define WAKER_CPU 1
pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_cond_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
unsigned long mem;
print_cpu_last_executed_on("Utility thread");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
fwq(blocktime, &mem);
end = rdtsc_light();
t_fwq += end - start;
pthread_mutex_lock(&mutex);
flag = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
fn_fail:
return NULL;
}
static struct option options[] = {
/* end */
{ NULL, 0, NULL, 0, }
};
int main(int argc, char **argv)
{
int i;
int ret;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
unsigned long mem;
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
printf("[INFO] nloop=%ld,blocktime=%ld\n", nloop, blocktime);
CPU_ZERO(&cpuset);
CPU_SET(WAITER_CPU, &cpuset);
if ((ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset))) {
printf("Error: sched_setaffinity: %s\n", strerror(errno));
goto fn_fail;
}
print_cpu_last_executed_on("Master thread");
fwq_init(&mem);
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_attr_init(&attr))) {
printf("%s: Error: pthread_attr_init failed (%d)\n", __FUNCTION__, ret);
goto fn_fail;
}
CPU_ZERO(&cpuset);
CPU_SET(WAKER_CPU, &cpuset);
if ((ret = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset))) {
printf("%s: Error: pthread_attr_setaffinity_np failed (%d)\n", __FUNCTION__, ret);
goto fn_fail;
}
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
fprintf(stderr, "Error: pthread_create failed (%d)\n", ret);
goto fn_fail;
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
fprintf(stderr, "Warning: sched_setscheduler: %s\n",
strerror(errno));
}
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
pthread_mutex_lock(&mutex); /* no futex */
while(!flag) {
pthread_cond_wait(&cond, &mutex); /* 1st futex */
}
flag = 0;
pthread_mutex_unlock(&mutex); /* 2nd futex */
end = rdtsc_light();
t_cond_wait += end - start;
}
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] waker: %ld nsec, waiter: %ld nsec, (waiter - waker) / nloop: %ld nsec\n", t_fwq * 10, t_cond_wait * 10, (t_cond_wait - t_fwq) * 10 / nloop);
ret = 0;
fn_fail:
return ret;
}

171
test/uti/arm64/CT32.c Normal file
View File

@@ -0,0 +1,171 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <signal.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "util.h"
#define WAITER_CPU 0
#define WAKER_CPU 1
pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_cond_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
unsigned long mem;
print_cpu_last_executed_on("Utility thread");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
pthread_mutex_lock(&mutex); /* no futex */
while(!flag) {
pthread_cond_wait(&cond, &mutex); /* 1st futex */
}
flag = 0;
pthread_mutex_unlock(&mutex); /* 2nd futex */
end = rdtsc_light();
t_cond_wait += end - start;
}
fn_fail:
return NULL;
}
static struct option options[] = {
/* end */
{ NULL, 0, NULL, 0, }
};
int main(int argc, char **argv)
{
int i;
int ret;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
unsigned long mem;
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
printf("[INFO] nloop=%ld,blocktime=%ld\n", nloop, blocktime);
CPU_ZERO(&cpuset);
CPU_SET(WAITER_CPU, &cpuset);
if ((ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset))) {
printf("Error: sched_setaffinity: %s\n", strerror(errno));
goto fn_fail;
}
print_cpu_last_executed_on("Master thread");
fwq_init(&mem);
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_attr_init(&attr))) {
printf("%s: Error: pthread_attr_init failed (%d)\n", __FUNCTION__, ret);
goto fn_fail;
}
CPU_ZERO(&cpuset);
CPU_SET(WAKER_CPU, &cpuset);
if ((ret = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset))) {
printf("%s: Error: pthread_attr_setaffinity_np failed (%d)\n", __FUNCTION__, ret);
goto fn_fail;
}
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
fprintf(stderr, "Error: pthread_create failed (%d)\n", ret);
goto fn_fail;
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
fprintf(stderr, "Warning: sched_setscheduler: %s\n",
strerror(errno));
}
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
fwq(blocktime, &mem);
end = rdtsc_light();
t_fwq += end - start;
pthread_mutex_lock(&mutex);
flag = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] waker: %ld nsec, waiter: %ld nsec, (waiter - waker) / nloop: %ld nsec\n", t_fwq * 10, t_cond_wait * 10, (t_cond_wait - t_fwq) * 10 / nloop);
ret = 0;
fn_fail:
return ret;
}

171
test/uti/arm64/CT33.c Normal file
View File

@@ -0,0 +1,171 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include "util.h"
#define WAITER_CPU 0
#define WAKER_CPU 1
int sem;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_futex_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
int testid = 32101;
unsigned long mem;
print_cpu_last_executed_on("Utility thread");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
fwq(blocktime, &mem);
end = rdtsc_light();
t_fwq += end - start;
sem = i + 1;
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAKE, 1,
NULL, NULL, 0)) != 1) {
printf("Error: futex wake: %d,%d\n", ret, errno);
}
//pthread_barrier_wait(&bar);
}
ret = 0;
fn_fail:
return NULL;
}
static struct option options[] = {
/* end */
{ NULL, 0, NULL, 0, }
};
int main(int argc, char **argv)
{
int i;
int ret;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
unsigned long mem;
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
printf("[INFO] nloop=%ld,blocktime=%ld\n", nloop, blocktime);
CPU_ZERO(&cpuset);
CPU_SET(WAITER_CPU, &cpuset);
if ((ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset))) {
printf("Error: sched_setaffinity: %s\n", strerror(errno));
goto fn_fail;
}
print_cpu_last_executed_on("Master thread");
fwq_init(&mem);
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
if ((ret = pthread_attr_init(&attr))) {
printf("Error: pthread_attr_init: %s\n", strerror(errno));
goto fn_fail;
}
CPU_ZERO(&cpuset);
CPU_SET(WAKER_CPU, &cpuset);
if ((ret = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset))) {
printf("Error: pthread_attr_setaffinity_np: %s\n", strerror(errno));
goto fn_fail;
}
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
goto fn_fail;
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
printf("Warning: sched_setscheduler: %s\n", strerror(errno));
}
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAIT, i, NULL, NULL, 0))) {
printf("Error: futex wait failed (%s)\n", strerror(errno));
}
//pthread_barrier_wait(&bar); /* 2nd futex */
}
end = rdtsc_light();
t_futex_wait += end - start;
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] waiter: %ld nsec, waker: %ld nsec, (waiter - waker) / nloop: %ld nsec\n", t_futex_wait * 10, t_fwq * 10, (t_futex_wait - t_fwq) * 10 / nloop);
ret = 0;
fn_fail:
return ret;
}

170
test/uti/arm64/CT34.c Normal file
View File

@@ -0,0 +1,170 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include "util.h"
#define WAITER_CPU 0
#define WAKER_CPU 1
int sem;
pthread_barrier_t bar;
int flag;
pthread_t thr;
long t_futex_wait, t_fwq;
long nloop;
long blocktime = 10L * 1000 * 1000;
int linux_run;
void *util_fn(void *arg)
{
int i;
int ret;
long start, end;
int testid = 32101;
unsigned long mem;
print_cpu_last_executed_on("Utility thread");
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret == -1, "Utility thread is running on Linux\n");
}
pthread_barrier_wait(&bar);
start = rdtsc_light();
for (i = 0; i < nloop; i++) {
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAIT, i, NULL, NULL, 0))) {
printf("Error: futex wait failed (%s)\n", strerror(errno));
}
//pthread_barrier_wait(&bar); /* 2nd futex */
}
end = rdtsc_light();
t_futex_wait += end - start;
ret = 0;
fn_fail:
return NULL;
}
static struct option options[] = {
/* end */
{ NULL, 0, NULL, 0, }
};
int main(int argc, char **argv)
{
int i;
int ret;
long start, end;
cpu_set_t cpuset;
pthread_attr_t attr;
pthread_barrierattr_t bar_attr;
struct sched_param param = { .sched_priority = 99 };
int opt;
unsigned long mem;
while ((opt = getopt_long(argc, argv, "+b:l", options, NULL)) != -1) {
switch (opt) {
case 'b':
blocktime = atoi(optarg);
break;
case 'l':
linux_run = 1;
break;
default: /* '?' */
printf("unknown option %c\n", optopt);
exit(1);
}
}
nloop = (10 * 1000000000UL) / blocktime;
printf("[INFO] nloop=%ld,blocktime=%ld\n", nloop, blocktime);
CPU_ZERO(&cpuset);
CPU_SET(WAKER_CPU, &cpuset);
if ((ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset))) {
printf("Error: sched_setaffinity: %s\n", strerror(errno));
goto fn_fail;
}
print_cpu_last_executed_on("Master thread");
fwq_init(&mem);
pthread_barrierattr_init(&bar_attr);
pthread_barrier_init(&bar, &bar_attr, 2);
if ((ret = pthread_attr_init(&attr))) {
printf("Error: pthread_attr_init: %s\n", strerror(errno));
goto fn_fail;
}
CPU_ZERO(&cpuset);
CPU_SET(WAITER_CPU, &cpuset);
if ((ret = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset))) {
printf("Error: pthread_attr_setaffinity_np: %s\n", strerror(errno));
goto fn_fail;
}
if (!linux_run) {
ret = syscall(732);
OKNGNOJUMP(ret != -1, "Master thread is running on McKernel\n");
ret = syscall(731, 1, NULL);
OKNGNOJUMP(ret != -1, "util_indicate_clone\n");
}
if ((ret = pthread_create(&thr, &attr, util_fn, NULL))) {
printf("Error: pthread_create: %s\n", strerror(errno));
goto fn_fail;
}
if ((ret = sched_setscheduler(0, SCHED_FIFO, &param))) {
printf("Warning: sched_setscheduler: %s\n", strerror(errno));
}
if (!linux_run) {
syscall(701, 1 | 2);
}
pthread_barrier_wait(&bar);
for (i = 0; i < nloop; i++) {
start = rdtsc_light();
fwq(blocktime, &mem);
end = rdtsc_light();
t_fwq += end - start;
sem = i + 1;
if ((ret = syscall(__NR_futex, &sem, FUTEX_WAKE, 1,
NULL, NULL, 0)) != 1) {
printf("Error: futex wake: %d, %d\n", ret, errno);
}
//pthread_barrier_wait(&bar);
}
if (!linux_run) {
syscall(701, 4 | 8);
}
pthread_join(thr, NULL);
printf("[INFO] waiter: %ld nsec, waker: %ld nsec, (waiter - waker) / nloop: %ld nsec\n", t_futex_wait * 10, t_fwq * 10, (t_futex_wait - t_fwq) * 10 / nloop);
ret = 0;
fn_fail:
return ret;
}

View File

@@ -1,6 +1,9 @@
# Makefile COPYRIGHT FUJITSU LIMITED 2019
CC = gcc
LDFLAGS = -Wall -lpthread
LDFLAGS = -Wall -lpthread
CCFLAGS = -g -O0
CPPFLAGS =
SRCS = $(shell ls CT*.c)
TARGET = $(SRCS:.c=)
@@ -10,5 +13,23 @@ all: $(TARGET)
test: all
./run.sh
%.o:: %.c
$(CC) $(CCFLAGS) $(CPPFLAGS) -c $<
util.o:: util.c
$(CC) $(CCFLAGS) $(CPPFLAGS) -c $<
CT31: CT31.o util.o
$(CC) -o $@ $^ $(LDFLAGS) $(CPPFLAGS)
CT32: CT32.o util.o
$(CC) -o $@ $^ $(LDFLAGS) $(CPPFLAGS)
CT33: CT33.o util.o
$(CC) -o $@ $^ $(LDFLAGS) $(CPPFLAGS)
CT34: CT34.o util.o
$(CC) -o $@ $^ $(LDFLAGS) $(CPPFLAGS)
clean:
rm -f $(TARGET)
rm -f $(TARGET) *.o

122
test/uti/arm64/util.c Normal file
View File

@@ -0,0 +1,122 @@
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <unistd.h>
#include <sys/syscall.h> /* For SYS_xxx definitions */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sched.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include "util.h"
#define TS2NS(sec, nsec) \
((unsigned long)(sec) * 1000000000ULL + \
(unsigned long)(nsec))
#define N_INIT 10000000
static inline void FIXED_SIZE_WORK(unsigned long *ptr)
{
asm volatile("mov %x0, x20\n"
"add x20, x20, #1\n"
"mov x20, %x0\n"
: "+rm" (*ptr)
:
: "x20", "cc", "memory");
}
static inline void BULK_FSW(unsigned long n,
unsigned long *ptr)
{
int j;
for (j = 0; j < (n); j++) {
FIXED_SIZE_WORK(ptr);
}
}
double nspw; /* nsec per work */
unsigned long nsec;
void fwq_init(unsigned long *mem)
{
struct timespec start, end;
unsigned long nsec;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start);
BULK_FSW(N_INIT, mem);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
nsec = (TS2NS(end.tv_sec, end.tv_nsec) -
TS2NS(start.tv_sec, start.tv_nsec));
nspw = nsec / (double)N_INIT;
printf("nsec=%ld, nspw=%f\n", nsec, nspw);
}
void fwq(long delay_nsec, unsigned long *mem)
{
BULK_FSW(delay_nsec / nspw, mem);
}
int print_cpu_last_executed_on(const char *name) {
char fn[256];
char* result;
pid_t tid = syscall(SYS_gettid);
int fd;
int offset;
int mpi_errno = 0;
sprintf(fn, "/proc/%d/task/%d/stat", getpid(), (int)tid);
//printf("fn=%s\n", fn);
fd = open(fn, O_RDONLY);
if(fd == -1) {
printf("open() failed\n");
goto fn_fail;
}
result = malloc(65536);
if(result == NULL) {
printf("malloc() failed");
goto fn_fail;
}
int amount = 0;
offset = 0;
while(1) {
amount = read(fd, result + offset, 65536);
// printf("amount=%d\n", amount);
if(amount == -1) {
printf("read() failed");
goto fn_fail;
}
if(amount == 0) {
goto eof;
}
offset += amount;
}
eof:;
//printf("result:%s\n", result);
char* next_delim = result;
char* field;
int i;
for(i = 0; i < 39; i++) {
field = strsep(&next_delim, " ");
}
int cpu = sched_getcpu();
if(cpu == -1) {
printf("getcpu() failed\n");
goto fn_fail;
}
printf("[INFO] %s (tid: %d) is running on %02d,%02d\n", name, tid, atoi(field), cpu);
fn_exit:
free(result);
return mpi_errno;
fn_fail:
mpi_errno = -1;
goto fn_exit;
}

70
test/uti/arm64/util.h Normal file
View File

@@ -0,0 +1,70 @@
#ifndef __UTIL_H_INCLUDED__
#define __UTIL_H_INCLUDED__
#include <stdint.h>
#define isb() asm volatile("isb" : : : "memory")
#define DEBUG
#ifdef DEBUG
#define dprintf(...) do { \
char msg[1024]; \
sprintf(msg, __VA_ARGS__); \
fprintf(stderr, "%s,%s", __func__, msg); \
} while (0)
#else
#define dprintf(...) do { } while (0)
#endif
#define eprintf(...) do { \
char msg[1024]; \
sprintf(msg, __VA_ARGS__); \
fprintf(stderr, "%s,%s", __func__, msg); \
} while (0)
#define CHKANDJUMP(cond, err, ...) do { \
if (cond) { \
eprintf(__VA_ARGS__); \
ret = err; \
goto fn_fail; \
} \
} while (0)
#define _OKNG(verb, jump, cond, fmt, args...) do { \
if (cond) { \
if (verb) \
printf("[ OK ] " fmt, ##args); \
} else { \
printf("[ NG ] " fmt, ##args); \
if (jump) \
goto fn_fail; \
} \
} while (0)
#define OKNG(args...) _OKNG(1, 1, ##args)
#define NG(args...) _OKNG(0, 1, ##args)
#define OKNGNOJUMP(args...) _OKNG(1, 0, ##args)
#define DIFFNSEC(end, start) ((end.tv_sec - start.tv_sec) * 1000000000UL + (end.tv_nsec - start.tv_nsec))
#define TIMER_KIND CLOCK_MONOTONIC_RAW /* CLOCK_THREAD_CPUTIME_ID */
static inline uint64_t rdtsc_light(void )
{
unsigned long cval;
isb();
asm volatile("mrs %0, cntvct_el0" : "=r" (cval));
return cval;
}
extern double nspw; /* nsec per work */
extern unsigned long nsec;
void fwq_init(unsigned long *mem);
void fwq(long delay_nsec, unsigned long *mem);
int print_cpu_last_executed_on(const char *name);
#endif