Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2140978imm; Thu, 9 Aug 2018 07:59:57 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzg8nRgRS23uZ/376M+b2J/3YUcLu1e4KbVSlL+B4Xu58Q1sXcIh6bLmGTWqWfwKKrANw8i X-Received: by 2002:a62:4a41:: with SMTP id x62-v6mr2777987pfa.45.1533826797056; Thu, 09 Aug 2018 07:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533826797; cv=none; d=google.com; s=arc-20160816; b=lH+hn8hFXUQcOIScrSo62EhS4Hr20gVfl9V7sCyT4KPH16biDzqcn1yiNBRhRymWRs 3/8pw0gKYe/prbA4TSQZAlMtlzlegfNS9tdGkD3u0BVhsQ666trvi+jbiO3aIUdBdNXa uuRlCfzOUdiGCBuQO+0/rvdao5N0rEZZfI4rMPQmHzCnm7dvwlvUhdzZqPSag0Xy/nYB R6spOpy9de0h9Mcel4/sF0E5QS8BvCl7ssp9Ml1ZKnbGaFrPOTKZjyraQ2Z+aD/GUS/h SVg4kktVwS1asa+8XCgxYNwjlKN6hYN0egtZNJBPNBSQpFFIDgmGTdY+uvr09486QI9C 4zjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=e7EcEspBYbVEaaWtJVJU0xBeb9dnnuOZEx1IDPpBajM=; b=ctsBZpUG07AFriuci571+YFjOnj/2ItIjlF4K9WIvlg1CgMqAVUU64fERAHdBqWBlT psYb2r803bIEu+0FwNrYjHTYvsGt/FyEYMbY5YnVhFVhJWO4pOc87mM+wHco9DLTG8Fc kBLRGXMp9eEVmnkDmb9lRuqzZ7DAJJU+6eOV4gDAARAf612Aq1Luj45PzpLCi/RQa0KK ox8HYTxi7wp0/vgKfeHN3EiJ0UQSz50W/moOYqz6z28+xepv0GOZhjwTkTD6lmZOmP3o MoB/sJ2JPePqtqbh2R0WJj33Wt9Jqq0C1oLfRy8c4Lq5FiEyzCo4gNEbbSqiLOmeZjr6 VHyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k20+d9Qi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11-v6si6010305plr.131.2018.08.09.07.59.42; Thu, 09 Aug 2018 07:59:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k20+d9Qi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732549AbeHIRYG (ORCPT + 99 others); Thu, 9 Aug 2018 13:24:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:35940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732388AbeHIRYF (ORCPT ); Thu, 9 Aug 2018 13:24:05 -0400 Received: from jouet.infradead.org (179-240-153-38.3g.claro.net.br [179.240.153.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 961BD2183D; Thu, 9 Aug 2018 14:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533826728; bh=18sgzCCYH0VRaNgDsUT6zGVUM0v24g6pXvqrIbbMhkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k20+d9Qixax+mAvx3NOit94bF6ibAKVJg6c8SasY5xfUId6EbjNEJcxZfourrs1Lp YqmFsRXgTosubOAp9dbX11TkNYCP7TrrAmv7lRauIf2Yyl8L8Ws0H4uWjRYugQAbR6 MNe4GgK6b2QNylCtDewwLu3HXP4oRAnfLRCdBWew= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 01/44] perf trace: Associate vfs_getname()'ed pathname with fd returned from 'openat' Date: Thu, 9 Aug 2018 11:57:39 -0300 Message-Id: <20180809145822.21391-2-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180809145822.21391-1-acme@kernel.org> References: <20180809145822.21391-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo When the vfs_getname() wannabe tracepoint is in place: # perf probe -l probe:vfs_getname (on getname_flags:73@acme/git/linux/fs/namei.c with pathname) # 'perf trace' will use it to get the pathname when it is copied from userspace to the kernel, right after syscalls:sys_enter_open, copied in the 'probe:vfs_getname', stash it somewhere and then, at syscalls:sys_exit_open time, if the 'open' return is not -1, i.e. a successfull open syscall, associate that pathname to this return, i.e. the fd. We were not doing this for the 'openat' syscall, which would cause 'perf trace' to fallback to using /proc to get the fd, change it so that we use what we got from probe:vfs_getname, reducing the 'openat' beautification process cost, ditching the syscalls performed to read procfs state and avoiding some possible races in the process. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-xnp44ao3bkb6ejeczxfnjwsh@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 88561eed7950..2a85f5198da0 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -121,7 +121,6 @@ struct trace { bool force; bool vfs_getname; int trace_pgfaults; - int open_id; }; struct tp_field { @@ -805,12 +804,17 @@ static struct syscall_fmt *syscall_fmt__find(const char *name) return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); } +/* + * is_exit: is this "exit" or "exit_group"? + * is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter. + */ struct syscall { struct event_format *tp_format; int nr_args; + bool is_exit; + bool is_open; struct format_field *args; const char *name; - bool is_exit; struct syscall_fmt *fmt; struct syscall_arg_fmt *arg_fmt; }; @@ -1299,6 +1303,7 @@ static int trace__read_syscall_info(struct trace *trace, int id) } sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); + sc->is_open = !strcmp(name, "open") || !strcmp(name, "openat"); return syscall__set_arg_fmts(sc); } @@ -1722,7 +1727,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, ret = perf_evsel__sc_tp_uint(evsel, ret, sample); - if (id == trace->open_id && ret >= 0 && ttrace->filename.pending_open) { + if (sc->is_open && ret >= 0 && ttrace->filename.pending_open) { trace__set_fd_pathname(thread, ret, ttrace->filename.name); ttrace->filename.pending_open = false; ++trace->stats.vfs_getname; @@ -3205,8 +3210,6 @@ int cmd_trace(int argc, const char **argv) } } - trace.open_id = syscalltbl__id(trace.sctbl, "open"); - err = target__validate(&trace.opts.target); if (err) { target__strerror(&trace.opts.target, err, bf, sizeof(bf)); -- 2.14.4