From: Chris Wilson Date: Thu, 24 Jul 2014 10:44:45 +0000 (+0100) Subject: igt_core: Refactor igt_stop_helper() to use igt_wait_helper() X-Git-Tag: intel-gpu-tools-1.8~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=745945546f7366a413a3a51a37f90caa3a227b1d;p=platform%2Fupstream%2Fintel-gpu-tools.git igt_core: Refactor igt_stop_helper() to use igt_wait_helper() Reduce code duplication as the igt_stop_helper can reuse igt_wait_helper() to replace its own waiting routine. Signed-off-by: Chris Wilson --- diff --git a/lib/igt_core.c b/lib/igt_core.c index 0a2ddad..1287ff6 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -843,56 +843,45 @@ bool __igt_fork_helper(struct igt_helper_process *proc) } /** - * igt_stop_helper: + * igt_wait_helper: * @proc: #igt_helper_process structure * - * Terminates a helper process. It is an error to call this on a helper process - * which hasn't been spawned yet. + * Joins a helper process. It is an error to call this on a helper process which + * hasn't been spawned yet. */ -void igt_stop_helper(struct igt_helper_process *proc) +int igt_wait_helper(struct igt_helper_process *proc) { - int status, ret; + int status = -1; assert(proc->running); - ret = kill(proc->pid, - proc->use_SIGKILL ? SIGKILL : SIGTERM); - assert(ret == 0); - - while (waitpid(proc->pid, &status, 0) == -1 && - errno == EINTR) - ; - igt_assert(WIFSIGNALED(status) && - WTERMSIG(status) == (proc->use_SIGKILL ? SIGKILL : SIGTERM)); + waitpid(proc->pid, &status, WNOHANG); proc->running = false; helper_process_pids[proc->id] = -1; helper_process_count--; + + return status; } /** - * igt_wait_helper: + * igt_stop_helper: * @proc: #igt_helper_process structure * - * Joins a helper process. It is an error to call this on a helper process which - * hasn't been spawned yet. + * Terminates a helper process. It is an error to call this on a helper process + * which hasn't been spawned yet. */ -void igt_wait_helper(struct igt_helper_process *proc) +void igt_stop_helper(struct igt_helper_process *proc) { int status; - assert(proc->running); - - while (waitpid(proc->pid, &status, 0) == -1 && - errno == EINTR) - ; - igt_assert(WIFEXITED(status) && WEXITSTATUS(status) == 0); - - proc->running = false; + /* failure here means the pid is already dead and so waiting is safe */ + kill(proc->pid, proc->use_SIGKILL ? SIGKILL : SIGTERM); - helper_process_pids[proc->id] = -1; - helper_process_count--; + status = igt_wait_helper(proc); + assert(WIFSIGNALED(status) && + WTERMSIG(status) == (proc->use_SIGKILL ? SIGKILL : SIGTERM)); } static void children_exit_handler(int sig) diff --git a/lib/igt_core.h b/lib/igt_core.h index 0e84e98..2838cb1 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -420,7 +420,7 @@ bool __igt_fork_helper(struct igt_helper_process *proc); */ #define igt_fork_helper(proc) \ for (; __igt_fork_helper(proc); exit(0)) -void igt_wait_helper(struct igt_helper_process *proc); +int igt_wait_helper(struct igt_helper_process *proc); void igt_stop_helper(struct igt_helper_process *proc); /* exit handler code */ diff --git a/tests/pm_rps.c b/tests/pm_rps.c index 96fec99..8593e36 100644 --- a/tests/pm_rps.c +++ b/tests/pm_rps.c @@ -253,8 +253,12 @@ static void load_helper_run(enum load load) static void load_helper_stop(void) { + int status; + kill(lh.igt_proc.pid, SIGUSR1); - igt_wait_helper(&lh.igt_proc); + status = igt_wait_helper(&lh.igt_proc); + + igt_assert(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR1); } static void load_helper_init(void)