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

@@ -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;
}