Record pthread routine address in clone(), keep helper threads on caller CPU core (workaround for Fugaku)

Change-Id: I29d1589e430dc1396558cdf3df4d068c27173612
This commit is contained in:
Balazs Gerofi
2019-11-14 09:15:56 +09:00
committed by Masamichi Takagi
parent 97b107f61c
commit 3328ce03d9
5 changed files with 199 additions and 9 deletions

View File

@@ -500,6 +500,7 @@ static int process_msg_prepare_process(unsigned long rphys)
ihk_mc_unmap_memory(NULL, phys, sz);
return -ENOMEM;
}
sprintf(thread->pthread_routine, "%s", "[main]");
proc = thread->proc;
vm = thread->vm;

View File

@@ -608,6 +608,7 @@ struct thread {
// thread info
int cpu_id;
int tid;
char pthread_routine[PATH_MAX + 64];
int status; // PS_RUNNING -> PS_EXITED (-> ZOMBIE / ptrace)
// | ^ ^
// | | |
@@ -717,6 +718,7 @@ struct thread {
/* Syscall offload wait queue head */
struct waitq scd_wq;
unsigned long clone_pthread_start_routine;
int uti_state;
int mod_clone;
struct uti_attr *mod_clone_arg;

View File

@@ -2757,6 +2757,9 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
const struct ihk_mc_cpu_info *cpu_info = ihk_mc_get_cpu_info();
#endif
int err = 0;
unsigned long clone_pthread_start_routine = 0;
struct vm_range *range = NULL;
int helper_thread = 0;
dkprintf("%s,flags=%08x,newsp=%lx,ptidptr=%lx,"
"ctidptr=%lx,tls=%lx,curpc=%lx,cursp=%lx",
@@ -2766,6 +2769,18 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
dkprintf("do_fork(): stack_pointr passed in: 0x%lX, stack pointer of caller: 0x%lx\n",
newsp, cursp);
/* CLONE_VM and newsp == parent_tidptr impiles pthread start routine addr */
if ((clone_flags & CLONE_VM) && newsp == parent_tidptr) {
old->clone_pthread_start_routine = parent_tidptr;
dkprintf("%s: clone_pthread_start_routine: 0x%lx\n", __func__,
old->clone_pthread_start_routine);
return 0;
}
/* Clear pthread routine addr regardless if we succeed */
clone_pthread_start_routine = old->clone_pthread_start_routine;
old->clone_pthread_start_routine = 0;
parent_cpuid = old->cpu_id;
if (((clone_flags & CLONE_VM) && !(clone_flags & CLONE_THREAD)) ||
(!(clone_flags & CLONE_VM) && (clone_flags & CLONE_THREAD))) {
@@ -2821,10 +2836,34 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
}
}
cpuid = obtain_clone_cpuid(&old->cpu_set, old->mod_clone == SPAWN_TO_REMOTE && oldproc->uti_use_last_cpu);
if (cpuid == -1) {
kprintf("do_fork,core not available\n");
return -EAGAIN;
if (clone_pthread_start_routine) {
ihk_rwspinlock_read_lock_noirq(&old->vm->memory_range_lock);
range = lookup_process_memory_range(old->vm,
clone_pthread_start_routine,
clone_pthread_start_routine + 1);
ihk_rwspinlock_read_unlock_noirq(&old->vm->memory_range_lock);
if (range && range->memobj && range->memobj->path) {
if (!strstr(range->memobj->path, "omp.so")) {
helper_thread = 1;
}
dkprintf("clone(): %s thread from %s\n",
helper_thread ? "helper" : "compute",
range->memobj->path);
}
}
if (helper_thread) {
cpuid = ihk_mc_get_processor_id();
//cpuid = obtain_clone_cpuid(&oldproc->cpu_set, 1);
}
else {
cpuid = obtain_clone_cpuid(&oldproc->cpu_set,
(old->mod_clone == SPAWN_TO_REMOTE && oldproc->uti_use_last_cpu));
if (cpuid == -1) {
kprintf("do_fork,core not available\n");
return -EAGAIN;
}
}
new = clone_thread(old, curpc,
@@ -2835,6 +2874,17 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
goto release_cpuid;
}
if (clone_pthread_start_routine &&
range && range->memobj && range->memobj->path) {
sprintf(new->pthread_routine, "0x%lx @ %s",
clone_pthread_start_routine,
range->memobj->path);
}
else {
sprintf(new->pthread_routine, "%s", "[unknown]");
}
newproc = new->proc;
cpu_set(cpuid, &new->vm->address_space->cpu_set,