mcctrl: move prepare waitqueue to per-process data

This commit is contained in:
Balazs Gerofi
2016-12-22 10:15:31 +09:00
parent e90eef8910
commit 972d14611a
3 changed files with 41 additions and 27 deletions

View File

@ -82,16 +82,17 @@ int (*mcctrl_sys_umount)(char *dir_name, int flags) = sys_umount;
#endif #endif
#endif #endif
//static DECLARE_WAIT_QUEUE_HEAD(wq_prepare);
//extern struct mcctrl_channel *channels; //extern struct mcctrl_channel *channels;
int mcctrl_ikc_set_recv_cpu(ihk_os_t os, int cpu); int mcctrl_ikc_set_recv_cpu(ihk_os_t os, int cpu);
static long mcexec_prepare_image(ihk_os_t os, static long mcexec_prepare_image(ihk_os_t os,
struct program_load_desc * __user udesc) struct program_load_desc * __user udesc)
{ {
struct program_load_desc *desc, *pdesc; struct program_load_desc *desc = NULL;
struct program_load_desc *pdesc = NULL;
struct ikc_scd_packet isp; struct ikc_scd_packet isp;
void *args, *envs; void *args = NULL;
void *envs = NULL;
long ret = 0; long ret = 0;
struct mcctrl_usrdata *usrdata = ihk_host_os_get_usrdata(os); struct mcctrl_usrdata *usrdata = ihk_host_os_get_usrdata(os);
struct mcctrl_per_proc_data *ppd = NULL; struct mcctrl_per_proc_data *ppd = NULL;
@ -108,42 +109,53 @@ static long mcexec_prepare_image(ihk_os_t os,
sizeof(struct program_load_desc))) { sizeof(struct program_load_desc))) {
printk("%s: error: copying program_load_desc\n", printk("%s: error: copying program_load_desc\n",
__FUNCTION__); __FUNCTION__);
kfree(desc); ret = -EFAULT;
return -EFAULT; goto free_out;
}
ppd = mcctrl_get_per_proc_data(usrdata, desc->pid);
if (!ppd) {
printk("%s: ERROR: no per process data for PID %d\n",
__FUNCTION__, desc->pid);
ret = -EINVAL;
goto free_out;
} }
num_sections = desc->num_sections; num_sections = desc->num_sections;
if (num_sections <= 0 || num_sections > 16) { if (num_sections <= 0 || num_sections > 16) {
printk("# of sections: %d\n", num_sections); printk("%s: ERROR: # of sections: %d\n",
return -EINVAL; __FUNCTION__, num_sections);
ret = -EINVAL;
goto free_out;
} }
pdesc = kmalloc(sizeof(struct program_load_desc) + pdesc = kmalloc(sizeof(struct program_load_desc) +
sizeof(struct program_image_section) sizeof(struct program_image_section)
* num_sections, GFP_KERNEL); * num_sections, GFP_KERNEL);
memcpy(pdesc, desc, sizeof(struct program_load_desc)); memcpy(pdesc, desc, sizeof(struct program_load_desc));
if (copy_from_user(pdesc->sections, udesc->sections, if (copy_from_user(pdesc->sections, udesc->sections,
sizeof(struct program_image_section) sizeof(struct program_image_section)
* num_sections)) { * num_sections)) {
kfree(desc); ret = -EFAULT;
kfree(pdesc); goto free_out;
return -EFAULT;
} }
kfree(desc); kfree(desc);
desc = NULL;
pdesc->pid = task_tgid_vnr(current); pdesc->pid = task_tgid_vnr(current);
if (reserve_user_space(usrdata, &pdesc->user_start, &pdesc->user_end)) { if (reserve_user_space(usrdata, &pdesc->user_start, &pdesc->user_end)) {
kfree(pdesc); ret = -ENOMEM;
return -ENOMEM; goto free_out;
} }
args = kmalloc(pdesc->args_len, GFP_KERNEL); args = kmalloc(pdesc->args_len, GFP_KERNEL);
if (copy_from_user(args, pdesc->args, pdesc->args_len)) { if (copy_from_user(args, pdesc->args, pdesc->args_len)) {
kfree(args); ret = -EFAULT;
kfree(pdesc); goto free_out;
return -EFAULT;
} }
envs = kmalloc(pdesc->envs_len, GFP_KERNEL); envs = kmalloc(pdesc->envs_len, GFP_KERNEL);
@ -169,20 +181,13 @@ static long mcexec_prepare_image(ihk_os_t os,
pdesc->status = 0; pdesc->status = 0;
mcctrl_ikc_send(os, pdesc->cpu, &isp); mcctrl_ikc_send(os, pdesc->cpu, &isp);
while (wait_event_interruptible(usrdata->wq_prepare, pdesc->status) != 0); while (wait_event_interruptible(ppd->wq_prepare, pdesc->status) != 0);
if (pdesc->err < 0) { if (pdesc->err < 0) {
ret = pdesc->err; ret = pdesc->err;
goto free_out; goto free_out;
} }
ppd = mcctrl_get_per_proc_data(usrdata, task_tgid_vnr(current));
if (!ppd) {
printk("ERROR: no per process data for PID %d\n", task_tgid_vnr(current));
ret = -EINVAL;
goto free_out;
}
/* Update rpgtable */ /* Update rpgtable */
ppd->rpgtable = pdesc->rpgtable; ppd->rpgtable = pdesc->rpgtable;
@ -201,6 +206,7 @@ free_out:
kfree(args); kfree(args);
kfree(pdesc); kfree(pdesc);
kfree(envs); kfree(envs);
kfree(desc);
return ret; return ret;
} }
@ -1178,6 +1184,7 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
INIT_LIST_HEAD(&ppd->wq_list); INIT_LIST_HEAD(&ppd->wq_list);
INIT_LIST_HEAD(&ppd->wq_req_list); INIT_LIST_HEAD(&ppd->wq_req_list);
INIT_LIST_HEAD(&ppd->wq_list_exact); INIT_LIST_HEAD(&ppd->wq_list_exact);
init_waitqueue_head(&ppd->wq_prepare);
spin_lock_init(&ppd->wq_list_lock); spin_lock_init(&ppd->wq_list_lock);
memset(&ppd->cpu_set, 0, sizeof(cpumask_t)); memset(&ppd->cpu_set, 0, sizeof(cpumask_t));
ppd->ikc_target_cpu = 0; ppd->ikc_target_cpu = 0;
@ -1530,10 +1537,18 @@ void mcexec_prepare_ack(ihk_os_t os, unsigned long arg, int err)
{ {
struct program_load_desc *desc = phys_to_virt(arg); struct program_load_desc *desc = phys_to_virt(arg);
struct mcctrl_usrdata *usrdata = ihk_host_os_get_usrdata(os); struct mcctrl_usrdata *usrdata = ihk_host_os_get_usrdata(os);
struct mcctrl_per_proc_data *ppd = NULL;
ppd = mcctrl_get_per_proc_data(usrdata, desc->pid);
if (!ppd) {
printk("%s: ERROR: no per process data for PID %d\n",
__FUNCTION__, desc->pid);
return;
}
desc->err = err; desc->err = err;
desc->status = 1; desc->status = 1;
wake_up_all(&usrdata->wq_prepare); wake_up_all(&ppd->wq_prepare);
} }

View File

@ -283,7 +283,6 @@ int prepare_ikc_channels(ihk_os_t os)
} }
usrdata->os = os; usrdata->os = os;
init_waitqueue_head(&usrdata->wq_prepare);
ihk_host_os_set_usrdata(os, usrdata); ihk_host_os_set_usrdata(os, usrdata);
memcpy(&usrdata->listen_param, &listen_param, sizeof listen_param); memcpy(&usrdata->listen_param, &listen_param, sizeof listen_param);
ihk_ikc_listen_port(os, &usrdata->listen_param); ihk_ikc_listen_port(os, &usrdata->listen_param);

View File

@ -195,6 +195,7 @@ struct mcctrl_per_proc_data {
struct list_head wq_req_list; struct list_head wq_req_list;
struct list_head wq_list_exact; struct list_head wq_list_exact;
ihk_spinlock_t wq_list_lock; ihk_spinlock_t wq_list_lock;
wait_queue_head_t wq_prepare;
struct list_head per_thread_data_hash[MCCTRL_PER_THREAD_DATA_HASH_SIZE]; struct list_head per_thread_data_hash[MCCTRL_PER_THREAD_DATA_HASH_SIZE];
rwlock_t per_thread_data_hash_lock[MCCTRL_PER_THREAD_DATA_HASH_SIZE]; rwlock_t per_thread_data_hash_lock[MCCTRL_PER_THREAD_DATA_HASH_SIZE];
@ -280,7 +281,6 @@ struct mcctrl_usrdata {
int job_pos; int job_pos;
int mcctrl_dma_abort; int mcctrl_dma_abort;
unsigned long last_thread_exec; unsigned long last_thread_exec;
wait_queue_head_t wq_prepare;
struct list_head per_proc_data_hash[MCCTRL_PER_PROC_DATA_HASH_SIZE]; struct list_head per_proc_data_hash[MCCTRL_PER_PROC_DATA_HASH_SIZE];
rwlock_t per_proc_data_hash_lock[MCCTRL_PER_PROC_DATA_HASH_SIZE]; rwlock_t per_proc_data_hash_lock[MCCTRL_PER_PROC_DATA_HASH_SIZE];