diff --git a/executer/include/uprotocol.h b/executer/include/uprotocol.h index 77d81988..844fb55e 100644 --- a/executer/include/uprotocol.h +++ b/executer/include/uprotocol.h @@ -125,6 +125,7 @@ struct program_load_desc { struct rlimit rlimit[MCK_RLIM_MAX]; unsigned long interp_align; unsigned long mpol_flags; + unsigned long mpol_threshold; char shell_path[SHELL_PATH_MAX_LEN]; __cpu_set_unit cpu_set[PLD_CPU_SET_SIZE]; struct program_image_section sections[0]; diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 0bf1522e..3b32759d 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -157,6 +157,7 @@ static int enable_vdso = 1; static int mpol_no_heap = 0; static int mpol_no_stack = 0; static int mpol_no_bss = 0; +static unsigned long mpol_threshold = (1024*1024); /* Partitioned execution (e.g., for MPI) */ static int nr_processes = 0; @@ -1111,7 +1112,7 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[]) void print_usage(char **argv) { - fprintf(stderr, "Usage: %s [-c target_core] [-n nr_partitions] [] (program) [args...]\n", argv[0]); + fprintf(stderr, "usage: %s [-c target_core] [-n nr_partitions] [--mpol-threshold=N] [--mpol-no-heap] [--mpol-no-bss] [--mpol-no-stack] [] (program) [args...]\n", argv[0]); } void init_sigaction(void) @@ -1300,6 +1301,12 @@ static struct option mcexec_options[] = { .flag = &mpol_no_bss, .val = 1, }, + { + .name = "mpol-threshold", + .has_arg = required_argument, + .flag = NULL, + .val = 'm', + }, /* end */ { NULL, 0, NULL, 0, }, }; @@ -1355,7 +1362,7 @@ int main(int argc, char **argv) } /* Parse options ("+" denotes stop at the first non-option) */ - while ((opt = getopt_long(argc, argv, "+c:n:t:", mcexec_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "+c:n:t:m:", mcexec_options, NULL)) != -1) { switch (opt) { case 'c': target_core = atoi(optarg); @@ -1369,6 +1376,10 @@ int main(int argc, char **argv) nr_threads = atoi(optarg); break; + case 'm': + mpol_threshold = atol(optarg); + break; + case 0: /* long opt */ break; @@ -1702,6 +1713,8 @@ int main(int argc, char **argv) desc->mpol_flags |= MPOL_NO_BSS; } + desc->mpol_threshold = mpol_threshold; + if (ioctl(fd, MCEXEC_UP_PREPARE_IMAGE, (unsigned long)desc) != 0) { perror("prepare"); close(fd); diff --git a/kernel/host.c b/kernel/host.c index 5e758d72..d3f16137 100644 --- a/kernel/host.c +++ b/kernel/host.c @@ -129,7 +129,7 @@ int prepare_process_ranges_args_envs(struct thread *thread, /* Non-TEXT sections that are large respect user allocation policy * unless user explicitly requests otherwise */ - if (i >= 1 && pn->sections[i].len >= AP_USER_THRESHOLD && + if (i >= 1 && pn->sections[i].len >= pn->mpol_threshold && !(pn->mpol_flags & MPOL_NO_BSS)) { dkprintf("%s: section: %d size: %d pages -> IHK_MC_AP_USER\n", __FUNCTION__, i, range_npages); @@ -429,6 +429,7 @@ static int process_msg_prepare_process(unsigned long rphys) proc->fsgid = pn->cred[7]; proc->termsig = SIGCHLD; proc->mpol_flags = pn->mpol_flags; + proc->mpol_threshold = pn->mpol_threshold; vm->region.user_start = pn->user_start; vm->region.user_end = pn->user_end; diff --git a/kernel/include/process.h b/kernel/include/process.h index 92c1b50c..9d220785 100644 --- a/kernel/include/process.h +++ b/kernel/include/process.h @@ -555,6 +555,7 @@ struct process { long maxrss_children; /* Memory policy flags */ unsigned long mpol_flags; + size_t mpol_threshold; // perf_event int perf_status; diff --git a/kernel/include/syscall.h b/kernel/include/syscall.h index b998dc18..91edbc49 100644 --- a/kernel/include/syscall.h +++ b/kernel/include/syscall.h @@ -193,6 +193,7 @@ struct program_load_desc { struct rlimit rlimit[MCK_RLIM_MAX]; unsigned long interp_align; unsigned long mpol_flags; + unsigned long mpol_threshold; char shell_path[SHELL_PATH_MAX_LEN]; __cpu_set_unit cpu_set[PLD_CPU_SET_SIZE]; struct program_image_section sections[0]; diff --git a/kernel/process.c b/kernel/process.c index be2bbdd1..49db5664 100644 --- a/kernel/process.c +++ b/kernel/process.c @@ -93,6 +93,7 @@ init_process(struct process *proc, struct process *parent) proc->sgid = parent->sgid; proc->fsgid = parent->fsgid; proc->mpol_flags = parent->mpol_flags; + proc->mpol_threshold = parent->mpol_threshold; memcpy(proc->rlimit, parent->rlimit, sizeof(struct rlimit) * MCK_RLIM_MAX); } @@ -1928,7 +1929,7 @@ int init_process_stack(struct thread *thread, struct program_load_desc *pn, /* Apply user allocation policy to stacks */ /* TODO: make threshold kernel or mcexec argument */ - ap_flag = (size >= AP_USER_THRESHOLD && + ap_flag = (size >= proc->mpol_threshold && !(proc->mpol_flags & MPOL_NO_STACK)) ? IHK_MC_AP_USER : 0; dkprintf("%s: size: %lu %s\n", __FUNCTION__, size, ap_flag ? "(IHK_MC_AP_USER)" : ""); diff --git a/kernel/syscall.c b/kernel/syscall.c index 25773d11..e7b908f8 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -1430,7 +1430,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot, /* Small allocations mostly benefit from closest RAM, * otherwise follow user requested policy */ unsigned long ap_flag = - (!(flags & MAP_STACK) && len >= AP_USER_THRESHOLD) || + (!(flags & MAP_STACK) && len >= thread->proc->mpol_threshold) || ((flags & MAP_STACK) && !(thread->proc->mpol_flags & MPOL_NO_STACK)) ? IHK_MC_AP_USER : 0; diff --git a/lib/include/ihk/mm.h b/lib/include/ihk/mm.h index 3c9a9475..8c58a420 100644 --- a/lib/include/ihk/mm.h +++ b/lib/include/ihk/mm.h @@ -54,8 +54,6 @@ typedef unsigned long ihk_mc_ap_flag; #define IHK_MC_AP_BANDWIDTH 0x010000 #define IHK_MC_AP_LATENCY 0x020000 -#define AP_USER_THRESHOLD (2097152) - enum ihk_mc_pt_prepare_flag { IHK_MC_PT_FIRST_LEVEL, IHK_MC_PT_LAST_LEVEL,