[CRIU] [PATCH] ptrace: Skip GETREGS on exits from syscalls when possible

Andrew Vagin avagin at parallels.com
Tue Sep 16 02:26:15 PDT 2014


On Tue, Sep 16, 2014 at 12:27:07AM +0400, Pavel Emelyanov wrote:
> From: Pavel Emelyanov <xemul at parallels.com>
> 
> The PTRACE_SYSCALL traps task twice -- first on enter into
> and then on exit from syscall. If we trace a single task (and
> we do it on dump two times per task) we may skip half of all
> getregs calls -- on exit we don't need them.

Acked-by: Andrew Vagin <avagin at parallels.com>

Can we use breakpoints to avoid step-by-step tracing?
> 
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
> ---
>  parasite-syscall.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/parasite-syscall.c b/parasite-syscall.c
> index 6f56617..266ef0b 100644
> --- a/parasite-syscall.c
> +++ b/parasite-syscall.c
> @@ -886,6 +886,10 @@ static int parasite_fini_seized(struct parasite_ctl *ctl)
>  	return 0;
>  }
>  
> +#define TRACE_ALL	1
> +#define TRACE_ENTER	2
> +#define TRACE_EXIT	3
> +
>  /*
>   * Trap tasks on the exit from the specified syscall
>   *
> @@ -897,6 +901,13 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr)
>  	user_regs_struct_t regs;
>  	int status, ret;
>  	pid_t pid;
> +	/*
> +	 * The PTRACE_SYSCALL will trap task twice -- on
> +	 * enter into and on exit from syscall. If we trace
> +	 * a single task, we may skip half of all getregs
> +	 * calls -- on exit we don't need them.
> +	 */
> +	int trace = (tasks == 1 ? TRACE_ENTER : TRACE_ALL);
>  
>  	/* Stop all threads on the enter point in sys_rt_sigreturn */
>  	while (tasks) {
> @@ -916,6 +927,15 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr)
>  			pr_err("%d\n", status);
>  			return -1;
>  		}
> +
> +		if (trace == TRACE_EXIT) {
> +			trace = TRACE_ENTER;
> +			pr_debug("`- Expecting exit\n");
> +			goto goon;
> +		}
> +		if (trace == TRACE_ENTER)
> +			trace = TRACE_EXIT;
> +
>  		ret = ptrace_get_regs(pid, &regs);
>  		if (ret) {
>  			pr_perror("ptrace");
> @@ -949,7 +969,7 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr)
>  			tasks--;
>  			continue;
>  		}
> -
> +goon:
>  		ret = ptrace(PTRACE_SYSCALL, pid, NULL, NULL);
>  		if (ret) {
>  			pr_perror("ptrace");
> -- 
> 1.8.4.2
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list