mcexec: --disable-sched-yield: avoid kernel/user switch

This commit is contained in:
Balazs Gerofi
2017-03-05 14:36:56 +09:00
parent a256280118
commit e554f4e2f9
6 changed files with 89 additions and 5 deletions

View File

@@ -1,9 +1,10 @@
CC=@CC@
BINDIR=@BINDIR@
LIBDIR=@LIBDIR@
KDIR ?= @KDIR@
CFLAGS=-Wall -O -I.
VPATH=@abs_srcdir@
TARGET=mcexec
TARGET=mcexec libsched_yield
@uncomment_if_ENABLE_MEMDUMP@TARGET+=eclair
LIBS=@LIBS@
IHKDIR ?= $(VPATH)/../../../ihk/linux/include/
@@ -16,6 +17,9 @@ mcexec: mcexec.c
eclair: eclair.c
$(CC) $(CFLAGS) -I${IHKDIR} -o $@ $^ $(LIBS)
libsched_yield: libsched_yield.c
$(CC) -shared -fPIC -Wl,-soname,sched_yield.so.1 -o libsched_yield.so.1.0.0 $^ -lc -ldl
clean:
$(RM) $(TARGET) *.o
@@ -24,5 +28,7 @@ clean:
install:
mkdir -p -m 755 $(BINDIR)
install -m 755 mcexec $(BINDIR)
mkdir -p -m 755 $(LIBDIR)
install -m 755 libsched_yield.so.1.0.0 $(LIBDIR)
@uncomment_if_ENABLE_MEMDUMP@install -m 755 eclair $(BINDIR)

View File

@@ -0,0 +1,27 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <sys/time.h>
#include <sched.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#undef sched_yield
typedef int (*int_void_fn)(void);
static int_void_fn orig_sched_yield = 0;
int sched_yield(void)
{
#if 0
if (!orig_sched_yield) {
orig_sched_yield = (int_void_fn)dlsym(RTLD_NEXT, "sched_yield");
}
printf("sched_yield() called\n");
#endif
return 0;
}

View File

@@ -152,6 +152,7 @@ static int fd;
static char *exec_path = NULL;
static char *altroot;
static const char rlimit_stack_envname[] = "MCKERNEL_RLIMIT_STACK";
static const char ld_preload_envname[] = "MCKERNEL_LD_PRELOAD";
static int ischild;
static int enable_vdso = 1;
static int mpol_no_heap = 0;
@@ -160,6 +161,7 @@ static int mpol_no_bss = 0;
static int no_bind_ikc_map = 0;
static unsigned long mpol_threshold = 0;
static int profile = 0;
static int disable_sched_yield = 0;
/* Partitioned execution (e.g., for MPI) */
static int nr_processes = 0;
@@ -1321,6 +1323,12 @@ static struct option mcexec_options[] = {
.flag = NULL,
.val = 'm',
},
{
.name = "disable-sched-yield",
.has_arg = no_argument,
.flag = &disable_sched_yield,
.val = 1,
},
/* end */
{ NULL, 0, NULL, 0, },
};
@@ -1361,10 +1369,6 @@ int main(int argc, char **argv)
altroot = "/usr/linux-k1om-4.7/linux-k1om";
}
/* Collect environment variables */
envs_len = flatten_strings(-1, NULL, environ, &envs);
envs = envs;
rlim_stack.rlim_cur = MCEXEC_DEF_CUR_STACK_SIZE;
rlim_stack.rlim_max = MCEXEC_DEF_MAX_STACK_SIZE;
@@ -1436,6 +1440,29 @@ int main(int argc, char **argv)
return 1;
}
if (disable_sched_yield) {
char sched_yield_lib_path[PATH_MAX];
sprintf(sched_yield_lib_path, "%s/libsched_yield.so.1.0.0",
MCKERNEL_LIBDIR);
__dprintf("%s: %s\n", __FUNCTION__, sched_yield_lib_path);
if (setenv("LD_PRELOAD", sched_yield_lib_path, 1) < 0) {
printf("%s: warning: failed to set LD_PRELOAD for sched_yield\n",
__FUNCTION__);
}
}
/* Set LD_PRELOAD to McKernel specific value */
else if (getenv(ld_preload_envname)) {
if (setenv("LD_PRELOAD", getenv(ld_preload_envname), 1) < 0) {
printf("%s: warning: failed to set LD_PRELOAD environment variable\n",
__FUNCTION__);
}
unsetenv(ld_preload_envname);
}
/* Collect environment variables */
envs_len = flatten_strings(-1, NULL, environ, &envs);
envs = envs;
#ifdef ENABLE_MCOVERLAYFS
__dprintf("mcoverlay enable\n");
char mcos_procdir[PATH_MAX];