diff --git a/arch/x86/kernel/syscall.c b/arch/x86/kernel/syscall.c index e3e3ce78..d194533f 100644 --- a/arch/x86/kernel/syscall.c +++ b/arch/x86/kernel/syscall.c @@ -295,6 +295,15 @@ do_kill(int pid, int tid, int sig) if(pid == proc->pid || pid == 0){ tproc = proc; } + else{ + for(i = 0; i < num_processors; i++){ + if(get_cpu_local_var(i)->current && + get_cpu_local_var(i)->current->pid == pid){ + tproc = get_cpu_local_var(i)->current; + break; + } + } + } } else if(pid == -1){ for(i = 0; i < num_processors; i++) @@ -358,6 +367,9 @@ do_kill(int pid, int tid, int sig) else{ ihk_mc_spinlock_unlock(&tproc->sigpendinglock, irqstate); } + if(proc != tproc){ + ihk_mc_interrupt_cpu(get_x86_cpu_local_variable(tproc->cpu_id)->apic_id, 0xd0); + } interrupt_syscall(1); return rc; } diff --git a/executer/include/uprotocol.h b/executer/include/uprotocol.h index b0d7500c..47540578 100644 --- a/executer/include/uprotocol.h +++ b/executer/include/uprotocol.h @@ -134,9 +134,17 @@ struct prepare_dma_desc { unsigned long size; unsigned long pa; }; + struct free_dma_desc { unsigned long pa; unsigned long size; }; +struct signal_desc { + int cpu; + int pid; + int tid; + int sig; +}; + #endif diff --git a/executer/kernel/control.c b/executer/kernel/control.c index ff632bc7..4b0c837d 100644 --- a/executer/kernel/control.c +++ b/executer/kernel/control.c @@ -268,16 +268,21 @@ static long mcexec_start_image(ihk_os_t os, return 0; } -static long mcexec_send_signal(ihk_os_t os, unsigned long sigparam) +static long mcexec_send_signal(ihk_os_t os, struct signal_desc *sigparam) { struct ikc_scd_packet isp; struct mcctrl_channel *c; struct mcctrl_usrdata *usrdata = ihk_host_os_get_usrdata(os); + struct signal_desc sig; + if (copy_from_user(&sig, sigparam, sizeof(struct signal_desc))) { + return -EFAULT; + } c = usrdata->channels; isp.msg = SCD_MSG_SEND_SIGNAL; - isp.ref = 0; - isp.arg = sigparam; + isp.ref = sig.cpu; + isp.pid = sig.pid; + isp.arg = (long)sig.tid << 32 | (sig.sig & 0x00000000ffffffffL); mcctrl_ikc_send(os, 0, &isp); @@ -758,7 +763,7 @@ long __mcctrl_control(ihk_os_t os, unsigned int req, unsigned long arg) return mcexec_load_syscall(os, (struct syscall_load_desc *)arg); case MCEXEC_UP_SEND_SIGNAL: - return mcexec_send_signal(os, arg); + return mcexec_send_signal(os, (struct signal_desc *)arg); case MCEXEC_UP_GET_CPU: return mcexec_get_cpu(os); diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 3e1a05d8..04d57a34 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -574,23 +574,44 @@ static void *main_loop_thread_func(void *arg) void sendsig(int sig, siginfo_t *siginfo, void *context) { - unsigned long param; + pid_t pid = getpid(); pid_t tid = gettid(); int i; + int cpu; + struct signal_desc sigdesc; - if(tid != master_tid){ - for(i = 0; i < ncpu; i++) + + if(siginfo->si_pid == pid && + siginfo->si_signo == SIGINT) + return; + if(tid == thread_data[0].tid){ + cpu = thread_data[0].cpu; + tid = master_tid; + } + else if(tid != master_tid){ + for(i = 1; i < ncpu; i++) if(thread_data[i].tid == tid){ if(thread_data[i].terminate) return; break; } - if(i == ncpu) - return; + if(i != ncpu) + cpu = thread_data[i].cpu; + else{ + cpu = 0; + tid = -1; + } + } + else{ + cpu = 0; + tid = -1; } - param = ((unsigned long)sig) << 32 | ((unsigned long)getpid()); - if (ioctl(fd, MCEXEC_UP_SEND_SIGNAL, param) != 0) { + sigdesc.cpu = cpu; + sigdesc.pid = (int)pid; + sigdesc.tid = (int)tid; + sigdesc.sig = sig; + if (ioctl(fd, MCEXEC_UP_SEND_SIGNAL, &sigdesc) != 0) { perror("send_signal"); close(fd); exit(1); @@ -702,7 +723,6 @@ int main(int argc, char **argv) int envs_len; char *envs; char *args; - char **a; char *p; int i; int error; @@ -976,14 +996,12 @@ static void kill_thread(unsigned long cpu) { if(cpu >= 0 && cpu < ncpu){ - thread_data[cpu].terminate = 1; pthread_kill(thread_data[cpu].thread_id, SIGINT); } else{ int i; for (i = 0; i < ncpu; ++i) { - thread_data[i].terminate = 1; pthread_kill(thread_data[i].thread_id, SIGINT); } } diff --git a/kernel/host.c b/kernel/host.c index 1a14e194..7f469fa1 100644 --- a/kernel/host.c +++ b/kernel/host.c @@ -535,7 +535,7 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c, //cpu_local_var(next) = (struct process *)packet->arg; return 0; case SCD_MSG_SEND_SIGNAL: - rc = do_kill((int)packet->arg, -1, (int)(packet->arg >> 32)); + rc = do_kill((int)packet->pid, (int)(packet->arg >> 32), packet->arg & 0x00000000ffffffffL); kprintf("SCD_MSG_SEND_SIGNAL: %lx, rc=%d\n", packet->arg, rc); return 0; } diff --git a/kernel/syscall.c b/kernel/syscall.c index 8535a222..94924394 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -94,6 +94,7 @@ static char *syscall_name[] MCKERNEL_UNUSED = { void check_signal(unsigned long rc, void *regs); void do_signal(long rc, void *regs, struct process *proc, struct sig_pending *pending); +extern unsigned long do_kill(int pid, int tid, int sig); int copy_from_user(struct process *, void *, const void *, size_t); int copy_to_user(struct process *, void *, const void *, size_t); @@ -415,7 +416,10 @@ terminate(int rc, int sig, ihk_mc_user_context_t *ctx) /* Signal parent if still attached */ ihk_mc_spinlock_lock_noirq(&ftn->parent->lock); if (ftn->parent->owner) { + do_kill(ftn->parent->owner->pid, -1, SIGCHLD); +/* sigchld_parent(ftn->parent->owner, 0); +*/ } ihk_mc_spinlock_unlock_noirq(&ftn->parent->lock); @@ -1335,8 +1339,6 @@ SYSCALL_DECLARE(set_tid_address) return cpu_local_var(current)->pid; } -extern unsigned long do_kill(int pid, int tid, int sig); - SYSCALL_DECLARE(kill) { int pid = ihk_mc_syscall_arg0(ctx);