mcexec: --mpol-threshold to control MPOL_BIND/MPOL_PREFERRED

This commit is contained in:
Balazs Gerofi
2017-02-08 21:49:25 +09:00
parent b4aecfd43c
commit 26b9484bae
8 changed files with 23 additions and 7 deletions

View File

@@ -125,6 +125,7 @@ struct program_load_desc {
struct rlimit rlimit[MCK_RLIM_MAX]; struct rlimit rlimit[MCK_RLIM_MAX];
unsigned long interp_align; unsigned long interp_align;
unsigned long mpol_flags; unsigned long mpol_flags;
unsigned long mpol_threshold;
char shell_path[SHELL_PATH_MAX_LEN]; char shell_path[SHELL_PATH_MAX_LEN];
__cpu_set_unit cpu_set[PLD_CPU_SET_SIZE]; __cpu_set_unit cpu_set[PLD_CPU_SET_SIZE];
struct program_image_section sections[0]; struct program_image_section sections[0];

View File

@@ -157,6 +157,7 @@ static int enable_vdso = 1;
static int mpol_no_heap = 0; static int mpol_no_heap = 0;
static int mpol_no_stack = 0; static int mpol_no_stack = 0;
static int mpol_no_bss = 0; static int mpol_no_bss = 0;
static unsigned long mpol_threshold = (1024*1024);
/* Partitioned execution (e.g., for MPI) */ /* Partitioned execution (e.g., for MPI) */
static int nr_processes = 0; static int nr_processes = 0;
@@ -1111,7 +1112,7 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[])
void print_usage(char **argv) void print_usage(char **argv)
{ {
fprintf(stderr, "Usage: %s [-c target_core] [-n nr_partitions] [<mcos-id>] (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] [<mcos-id>] (program) [args...]\n", argv[0]);
} }
void init_sigaction(void) void init_sigaction(void)
@@ -1300,6 +1301,12 @@ static struct option mcexec_options[] = {
.flag = &mpol_no_bss, .flag = &mpol_no_bss,
.val = 1, .val = 1,
}, },
{
.name = "mpol-threshold",
.has_arg = required_argument,
.flag = NULL,
.val = 'm',
},
/* end */ /* end */
{ NULL, 0, NULL, 0, }, { NULL, 0, NULL, 0, },
}; };
@@ -1355,7 +1362,7 @@ int main(int argc, char **argv)
} }
/* Parse options ("+" denotes stop at the first non-option) */ /* 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) { switch (opt) {
case 'c': case 'c':
target_core = atoi(optarg); target_core = atoi(optarg);
@@ -1369,6 +1376,10 @@ int main(int argc, char **argv)
nr_threads = atoi(optarg); nr_threads = atoi(optarg);
break; break;
case 'm':
mpol_threshold = atol(optarg);
break;
case 0: /* long opt */ case 0: /* long opt */
break; break;
@@ -1702,6 +1713,8 @@ int main(int argc, char **argv)
desc->mpol_flags |= MPOL_NO_BSS; desc->mpol_flags |= MPOL_NO_BSS;
} }
desc->mpol_threshold = mpol_threshold;
if (ioctl(fd, MCEXEC_UP_PREPARE_IMAGE, (unsigned long)desc) != 0) { if (ioctl(fd, MCEXEC_UP_PREPARE_IMAGE, (unsigned long)desc) != 0) {
perror("prepare"); perror("prepare");
close(fd); close(fd);

View File

@@ -129,7 +129,7 @@ int prepare_process_ranges_args_envs(struct thread *thread,
/* Non-TEXT sections that are large respect user allocation policy /* Non-TEXT sections that are large respect user allocation policy
* unless user explicitly requests otherwise */ * 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)) { !(pn->mpol_flags & MPOL_NO_BSS)) {
dkprintf("%s: section: %d size: %d pages -> IHK_MC_AP_USER\n", dkprintf("%s: section: %d size: %d pages -> IHK_MC_AP_USER\n",
__FUNCTION__, i, range_npages); __FUNCTION__, i, range_npages);
@@ -429,6 +429,7 @@ static int process_msg_prepare_process(unsigned long rphys)
proc->fsgid = pn->cred[7]; proc->fsgid = pn->cred[7];
proc->termsig = SIGCHLD; proc->termsig = SIGCHLD;
proc->mpol_flags = pn->mpol_flags; proc->mpol_flags = pn->mpol_flags;
proc->mpol_threshold = pn->mpol_threshold;
vm->region.user_start = pn->user_start; vm->region.user_start = pn->user_start;
vm->region.user_end = pn->user_end; vm->region.user_end = pn->user_end;

View File

@@ -555,6 +555,7 @@ struct process {
long maxrss_children; long maxrss_children;
/* Memory policy flags */ /* Memory policy flags */
unsigned long mpol_flags; unsigned long mpol_flags;
size_t mpol_threshold;
// perf_event // perf_event
int perf_status; int perf_status;

View File

@@ -193,6 +193,7 @@ struct program_load_desc {
struct rlimit rlimit[MCK_RLIM_MAX]; struct rlimit rlimit[MCK_RLIM_MAX];
unsigned long interp_align; unsigned long interp_align;
unsigned long mpol_flags; unsigned long mpol_flags;
unsigned long mpol_threshold;
char shell_path[SHELL_PATH_MAX_LEN]; char shell_path[SHELL_PATH_MAX_LEN];
__cpu_set_unit cpu_set[PLD_CPU_SET_SIZE]; __cpu_set_unit cpu_set[PLD_CPU_SET_SIZE];
struct program_image_section sections[0]; struct program_image_section sections[0];

View File

@@ -93,6 +93,7 @@ init_process(struct process *proc, struct process *parent)
proc->sgid = parent->sgid; proc->sgid = parent->sgid;
proc->fsgid = parent->fsgid; proc->fsgid = parent->fsgid;
proc->mpol_flags = parent->mpol_flags; proc->mpol_flags = parent->mpol_flags;
proc->mpol_threshold = parent->mpol_threshold;
memcpy(proc->rlimit, parent->rlimit, memcpy(proc->rlimit, parent->rlimit,
sizeof(struct rlimit) * MCK_RLIM_MAX); 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 */ /* Apply user allocation policy to stacks */
/* TODO: make threshold kernel or mcexec argument */ /* 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; !(proc->mpol_flags & MPOL_NO_STACK)) ? IHK_MC_AP_USER : 0;
dkprintf("%s: size: %lu %s\n", __FUNCTION__, size, dkprintf("%s: size: %lu %s\n", __FUNCTION__, size,
ap_flag ? "(IHK_MC_AP_USER)" : ""); ap_flag ? "(IHK_MC_AP_USER)" : "");

View File

@@ -1430,7 +1430,7 @@ do_mmap(const intptr_t addr0, const size_t len0, const int prot,
/* Small allocations mostly benefit from closest RAM, /* Small allocations mostly benefit from closest RAM,
* otherwise follow user requested policy */ * otherwise follow user requested policy */
unsigned long ap_flag = 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)) ? ((flags & MAP_STACK) && !(thread->proc->mpol_flags & MPOL_NO_STACK)) ?
IHK_MC_AP_USER : 0; IHK_MC_AP_USER : 0;

View File

@@ -54,8 +54,6 @@ typedef unsigned long ihk_mc_ap_flag;
#define IHK_MC_AP_BANDWIDTH 0x010000 #define IHK_MC_AP_BANDWIDTH 0x010000
#define IHK_MC_AP_LATENCY 0x020000 #define IHK_MC_AP_LATENCY 0x020000
#define AP_USER_THRESHOLD (2097152)
enum ihk_mc_pt_prepare_flag { enum ihk_mc_pt_prepare_flag {
IHK_MC_PT_FIRST_LEVEL, IHK_MC_PT_FIRST_LEVEL,
IHK_MC_PT_LAST_LEVEL, IHK_MC_PT_LAST_LEVEL,