From 9390fe5d2c799960e8699ee0de84e710adcd1ca1 Mon Sep 17 00:00:00 2001 From: Tomoki Shirasawa Date: Mon, 12 Sep 2016 15:43:29 +0900 Subject: [PATCH] signal: send signal to thread using thread-id. not cpu-id --- arch/x86/kernel/syscall.c | 6 +++--- executer/user/mcexec.c | 20 +++++++++++--------- kernel/syscall.c | 7 ++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/syscall.c b/arch/x86/kernel/syscall.c index d6819a18..d1a00371 100644 --- a/arch/x86/kernel/syscall.c +++ b/arch/x86/kernel/syscall.c @@ -291,7 +291,7 @@ SYSCALL_DECLARE(rt_sigreturn) extern struct cpu_local_var *clv; extern unsigned long do_kill(struct thread *thread, int pid, int tid, int sig, struct siginfo *info, int ptracecont); -extern void interrupt_syscall(int all, int pid); +extern void interrupt_syscall(int pid, int tid); extern int num_processors; #define RFLAGS_MASK (RFLAGS_CF | RFLAGS_PF | RFLAGS_AF | RFLAGS_ZF | \ @@ -1287,7 +1287,7 @@ done: cpu_restore_interrupt(irqstate); if (doint && !(mask & tthread->sigmask.__val[0])) { - int cpuid = tthread->cpu_id; + int tid = tthread->tid; int pid = tproc->pid; int status = tthread->status; @@ -1298,7 +1298,7 @@ done: } if(!tthread->proc->nohost) - interrupt_syscall(pid, cpuid); + interrupt_syscall(pid, tid); if (status != PS_RUNNING) { if(sig == SIGKILL){ diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 32a1b8a5..52bdc84b 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -882,7 +882,7 @@ static void *main_loop_thread_func(void *arg) struct thread_data_s *td = (struct thread_data_s *)arg; td->tid = gettid(); - td->remote_tid = (int)td->tid; + td->remote_tid = -1; pthread_barrier_wait(&init_ready); td->ret = main_loop(td->fd, td->cpu, td->lock); @@ -1680,16 +1680,14 @@ do_generic_syscall( } static void -kill_thread(unsigned long cpu) +kill_thread(unsigned long tid) { - if(cpu >= 0 && cpu < n_threads){ - pthread_kill(thread_data[cpu].thread_id, LOCALSIG); - } - else{ - int i; + int i; - for (i = 0; i < n_threads; ++i) { + for (i = 0; i < n_threads; ++i) { + if(thread_data[i].remote_tid == tid){ pthread_kill(thread_data[i].thread_id, LOCALSIG); + break; } } } @@ -1848,6 +1846,8 @@ int main_loop(int fd, int cpu, pthread_mutex_t *lock) //pthread_mutex_lock(lock); + thread_data[cpu].remote_tid = w.sr.rtid; + switch (w.sr.number) { case __NR_open: ret = do_strncpy_from_user(fd, pathbuf, (void *)w.sr.args[0], PATH_MAX); @@ -2440,7 +2440,9 @@ return_execve2: break; } - + + thread_data[cpu].remote_tid = -1; + //pthread_mutex_unlock(lock); } __dprint("timed out.\n"); diff --git a/kernel/syscall.c b/kernel/syscall.c index 9e9cd2f3..8d05afa2 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -847,14 +847,15 @@ terminate_host(int pid) } void -interrupt_syscall(int pid, int cpuid) +interrupt_syscall(int pid, int tid) { - dkprintf("interrupt_syscall,target pid=%d,target cpuid=%d\n", pid, cpuid); + dkprintf("interrupt_syscall,target pid=%d,target tid=%d\n", pid, tid); ihk_mc_user_context_t ctx; long lerror; +kprintf("interrupt_syscall pid=%d tid=%d\n", pid, tid); ihk_mc_syscall_arg0(&ctx) = pid; - ihk_mc_syscall_arg1(&ctx) = cpuid; + ihk_mc_syscall_arg1(&ctx) = tid; lerror = syscall_generic_forwarding(__NR_kill, &ctx); if (lerror) {