From patchwork Fri Aug 30 06:24:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11123015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E7FF14E5 for ; Fri, 30 Aug 2019 06:25:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A4632186A for ; Fri, 30 Aug 2019 06:25:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hgQrREsZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YHEXZXd6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A4632186A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=H4vl9PAXCV2WPzPJ1Y8XO1Yle+v2bBLzuxUPR0JSbro=; b=hgQrREsZL76sGutRnTB0rGRf9E moot5n8Qsbz81ekiUMkAWnyyjgJYSCCuK+3vri0XL8/Qf9vvVfM83CKSCDGm9S2P/xO1/VvsB9tAF Z7GKB+bNSju8My+0KDv8d6SfRVL0+QZbAkdvvnR+wL5ChTVrcDVtA51asWZCSKR1x3XK5SnGHZPOI IRpTPENPUuNMNYcUoe6BuuHF4b1vFNQS6vYH9EWadbiG8fz/s91FT8FWOJQkPFuIxsqzFNWRkEPo1 8HqlnRIvnr0V2GSGwPa7JVKtBZ3CNAMrtDZ2ouqizHV7a8obJ7ABVLfMKjmZYq0A7WaoTK7JKdr/G cxsf4c3w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i3aLM-0000ZR-9W; Fri, 30 Aug 2019 06:25:08 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i3aL3-0008QF-Lh for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2019 06:24:51 +0000 Received: by mail-yw1-xc43.google.com with SMTP id e65so2041346ywh.0 for ; Thu, 29 Aug 2019 23:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OXG5Krp0+0YHinlseDtdKmGPRzdmcPPxpIaorK0Sd/U=; b=YHEXZXd6sRfhS4BLjTBmyXis4Z3lNVzZFsvLaN6IeIVjVYDTmD4veeHZo7dGHtMe83 pPMJfxluP/5bGXyNRyXc8H1hGniUvoDg3qZ4wSycHg6O4NplPwDCUfsLg/ZdyIOUEXfE GhmISYvHcc+pqp7h2e6WfUpV8hclsnlEeFlmQ0fGdiozLihG6lPt64bRmO3k+89jaW+Z pEbLeoR7wiM0U1IojVKnaQ3kZo6w3vnphGTEhHN8xT/QKOq6MxIfQyWtufypvpLBzgG/ 4UwrAcFrA6umJeFVNY1hqqdyJ1cfnKLPo3StT75wvOuXb4QnnWgfBe67FNwv4+Mp4gEY 9wug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OXG5Krp0+0YHinlseDtdKmGPRzdmcPPxpIaorK0Sd/U=; b=CMeHVy6TneeHTzZu+WTk3ljCH68ufz7tTIavRTgLfBsCXOcmVfJK2bjRRLg4H9fYEZ rVJ1BGpaxY49WYpVM+WzqdHtkwxi+2Ij1hS8/GD5T6BFJzZ+HEaDurpEMqzMz3CxGp4E R0sfdLpL/zBNtyBGDZnOsWjRyLABG/FgXBGdRedBWY9t7ARpUvPLDOY6Q1nMdio75Ywm b5GyU5KGcG2NjsFlEugSjOEWvdYD33yRv+LGI/SdCIEwBiWbac7sx2I4W/6VSU8uBncA 9fX5kGsl0Bst2kj1E0evAz2w5lN381l2lk/5vvtHv3lnhI6QVXlBf29vDgMe92VHKUbx P/IQ== X-Gm-Message-State: APjAAAXjfSBPY0JBInkXiYBwiuxvPxhA9uWnvYG56X23rBbJIAmfcKPT D0SvrMbDjzdCuNRZ3vfSOt6WfA== X-Google-Smtp-Source: APXvYqz67vqqy5rGYmWF/4BuddczksgMWXcyQXd0kAabISPC5eC7+OWMjXoeCtH6cBGH5sHTou3oCA== X-Received: by 2002:a0d:dd51:: with SMTP id g78mr9844096ywe.102.1567146288582; Thu, 29 Aug 2019 23:24:48 -0700 (PDT) Received: from localhost.localdomain (li1320-244.members.linode.com. [45.79.221.244]) by smtp.gmail.com with ESMTPSA id r193sm976784ywe.8.2019.08.29.23.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 23:24:48 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Adrian Hunter Subject: [PATCH v1 1/3] perf cs-etm: Refactor instruction size handling Date: Fri, 30 Aug 2019 14:24:19 +0800 Message-Id: <20190830062421.31275-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190830062421.31275-1-leo.yan@linaro.org> References: <20190830062421.31275-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190829_232449_727474_A8C2781D X-CRM114-Status: GOOD ( 14.43 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:c43 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org There has several code pieces need to know the instruction size, but now every place calculates the instruction size separately. This patch refactors to create a new function cs_etm__instr_size() as a central place to analyze the instruction length based on ISA type and instruction value. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 44 +++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index b3a5daaf1a8f..882a0718033d 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -914,6 +914,26 @@ static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq, return ((instrBytes[1] & 0xF8) >= 0xE8) ? 4 : 2; } +static inline int cs_etm__instr_size(struct cs_etm_queue *etmq, + u8 trace_chan_id, + enum cs_etm_isa isa, + u64 addr) +{ + int insn_len; + + /* + * T32 instruction size might be 32-bit or 16-bit, decide by calling + * cs_etm__t32_instr_size(). + */ + if (isa == CS_ETM_ISA_T32) + insn_len = cs_etm__t32_instr_size(etmq, trace_chan_id, addr); + /* Otherwise, A64 and A32 instruction size are always 32-bit. */ + else + insn_len = 4; + + return insn_len; +} + static inline u64 cs_etm__first_executed_instr(struct cs_etm_packet *packet) { /* Returns 0 for the CS_ETM_DISCONTINUITY packet */ @@ -938,19 +958,23 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, const struct cs_etm_packet *packet, u64 offset) { + int insn_len; + if (packet->isa == CS_ETM_ISA_T32) { u64 addr = packet->start_addr; while (offset > 0) { - addr += cs_etm__t32_instr_size(etmq, - trace_chan_id, addr); + addr += cs_etm__instr_size(etmq, trace_chan_id, + packet->isa, addr); offset--; } return addr; } - /* Assume a 4 byte instruction size (A32/A64) */ - return packet->start_addr + offset * 4; + /* Return instruction size for A32/A64 */ + insn_len = cs_etm__instr_size(etmq, trace_chan_id, + packet->isa, packet->start_addr); + return packet->start_addr + offset * insn_len; } static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq, @@ -1090,16 +1114,8 @@ static void cs_etm__copy_insn(struct cs_etm_queue *etmq, return; } - /* - * T32 instruction size might be 32-bit or 16-bit, decide by calling - * cs_etm__t32_instr_size(). - */ - if (packet->isa == CS_ETM_ISA_T32) - sample->insn_len = cs_etm__t32_instr_size(etmq, trace_chan_id, - sample->ip); - /* Otherwise, A64 and A32 instruction size are always 32-bit. */ - else - sample->insn_len = 4; + sample->insn_len = cs_etm__instr_size(etmq, trace_chan_id, + packet->isa, sample->ip); cs_etm__mem_access(etmq, trace_chan_id, sample->ip, sample->insn_len, (void *)sample->insn); From patchwork Fri Aug 30 06:24:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11123017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E174014D5 for ; Fri, 30 Aug 2019 06:25:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDFE821721 for ; Fri, 30 Aug 2019 06:25:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DOu+cccC"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wPf/U6vB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDFE821721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=RiZnt1yUmb0YJIlzAVUBVCI2XP66oHy+tKQPz7WyoFY=; b=DOu+cccCDMX/IBaqJILMMkhoSg 7h9dkl4PcEhUwEefUBN8b5VkfyHCIp59PwinLY4bWYpyM5idl4FSEydtGEJKZf9RpCs4WjS8qYX6q R0Gw1VXLU/s1vzUTLcZgbe2b6Sy59Zae78WTT7dujt0pNoUitO7mvViGXbTRpG9RTUatbaCOuxmlZ cnXrwsFF5IXCkMvUo5GqeV4Qfn7qj0dHHJobsnkwuIRJQXnkYaZeIuNYtKFHyQ3NYecUHjvHdIA1e dw7RmhSI1jalvFmxItBfGVtHaImce88k9uDq3FmJaUmavBoVFSyMAWMFrl2PqyyiTFioNRIycyLxI s3b+ZbgQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i3aLj-0001al-5d; Fri, 30 Aug 2019 06:25:31 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i3aL9-0008VE-Oo for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2019 06:24:57 +0000 Received: by mail-yb1-xb42.google.com with SMTP id m9so2092063ybm.3 for ; Thu, 29 Aug 2019 23:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ELhnXlXvAFpwCV+V+b16yA2Nld0gK9Jz+4VNmTdBWdw=; b=wPf/U6vBDNIDDjJdEeBOmvaat9NvWYI/03e7p7HMz2TC2ZjEYLn5tveASdi7BR+AvA uibnvuSe/esgef7sw1I5vAnsW00Xt5qexP5PVQEKjG+YBy/bipVr9GF+qOmUXjwWvIH4 +NQOJiJcjkNj/PGY9m38pWmhGpi5pg1gNh0m5GcDsHpyQBAc/eWhNB99u1fyWR3uCGax Q4oEXrIKdlL+17FlRKeL/DyTkK7kIEYOmkNZzLjmp7FW7fxRziJmV6SxPOfzMw7i5+ts mrnyKG47YnoVjyQ0ZKwjJNOOLU0rgdzouLzcJTO0m2hh6YR2L8qWgiV9vBsC5BRKr4O/ 7XDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ELhnXlXvAFpwCV+V+b16yA2Nld0gK9Jz+4VNmTdBWdw=; b=aLV/m5X2jnTNYETabKYosjSx4vJ33e30ZiSwPp4UtzGeY044+rjbfmhM6PpqN8bd8c I0LkjfxLcCYWncXRLZ/dk4lcAz8lel0u7DrSdjGR/dEHTkLoD6+CaSq4WFPaDZaKSqtJ yb0EZXX6hzd58YB5CE1JN+hQEJO7/mLAp+HBoK73ZT1JkO6DlauisXTKqPvWcuaiKtEE yvNtE1zGFgaw3hTjmoZy/B6IiXpJIo/A076li6Yo9I74Is8cd4vVAQDa3P3SVsnEnAHK 1n491h1ojaVOUEfd8h7y3xEcYS8hBgo3rP1V/6M20VGbkdGaBIrSyvSJ9bZ1NReOvm5A TCxA== X-Gm-Message-State: APjAAAWFdjHODfUdvlRlhRGUyuanHubKBEEaJ4JhKaSi1gbgwFYsL/ti J1//GlcGnSiFOumqrTSaagwxVkb8dAgbGQ== X-Google-Smtp-Source: APXvYqyvU5/TZFIK+mjFwUTLF+eCFaZYTSR08qcHNcKCNl2yqbNOf3yvoTXvqjr/RXrksLmAjMn8LQ== X-Received: by 2002:a25:bb83:: with SMTP id y3mr9736959ybg.345.1567146294119; Thu, 29 Aug 2019 23:24:54 -0700 (PDT) Received: from localhost.localdomain (li1320-244.members.linode.com. [45.79.221.244]) by smtp.gmail.com with ESMTPSA id r193sm976784ywe.8.2019.08.29.23.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 23:24:53 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Adrian Hunter Subject: [PATCH v1 2/3] perf cs-etm: Add callchain to instruction sample Date: Fri, 30 Aug 2019 14:24:20 +0800 Message-Id: <20190830062421.31275-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190830062421.31275-1-leo.yan@linaro.org> References: <20190830062421.31275-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190829_232456_029342_A48BBCA7 X-CRM114-Status: GOOD ( 17.02 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b42 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Firstly, this patch adds support for the thread stack; when every branch packet is coming we will push or pop the stack based on the sample flags. Secondly, based on the thread stack we can synthesize call chain for the instruction sample, this can be used by itrace option '--itrace=g'. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 74 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 882a0718033d..ad573d3bd305 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -17,6 +17,7 @@ #include #include "auxtrace.h" +#include "callchain.h" #include "color.h" #include "cs-etm.h" #include "cs-etm-decoder/cs-etm-decoder.h" @@ -69,6 +70,7 @@ struct cs_etm_traceid_queue { size_t last_branch_pos; union perf_event *event_buf; struct thread *thread; + struct ip_callchain *chain; struct branch_stack *last_branch; struct branch_stack *last_branch_rb; struct cs_etm_packet *prev_packet; @@ -246,6 +248,16 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, if (!tidq->prev_packet) goto out_free; + if (etm->synth_opts.callchain) { + size_t sz = sizeof(struct ip_callchain); + + /* Add 1 to callchain_sz for callchain context */ + sz += (etm->synth_opts.callchain_sz + 1) * sizeof(u64); + tidq->chain = zalloc(sz); + if (!tidq->chain) + goto out_free; + } + if (etm->synth_opts.last_branch) { size_t sz = sizeof(struct branch_stack); @@ -270,6 +282,7 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, zfree(&tidq->last_branch); zfree(&tidq->prev_packet); zfree(&tidq->packet); + zfree(&tidq->chain); out: return rc; } @@ -541,6 +554,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq) zfree(&tidq->last_branch_rb); zfree(&tidq->prev_packet); zfree(&tidq->packet); + zfree(&tidq->chain); zfree(&tidq); /* @@ -1121,6 +1135,41 @@ static void cs_etm__copy_insn(struct cs_etm_queue *etmq, sample->insn_len, (void *)sample->insn); } +static void cs_etm__add_stack_event(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) +{ + struct cs_etm_auxtrace *etm = etmq->etm; + u8 trace_chan_id = tidq->trace_chan_id; + int insn_len; + u64 from_ip, to_ip; + + if (etm->synth_opts.callchain || etm->synth_opts.thread_stack) { + + from_ip = cs_etm__last_executed_instr(tidq->prev_packet); + to_ip = cs_etm__first_executed_instr(tidq->packet); + + /* + * T32 instruction size might be 32-bit or 16-bit, decide by + * calling cs_etm__t32_instr_size(). + */ + if (tidq->prev_packet->isa == CS_ETM_ISA_T32) + insn_len = cs_etm__t32_instr_size(etmq, trace_chan_id, + from_ip); + /* Otherwise, A64 and A32 instruction size are always 32-bit. */ + else + insn_len = 4; + + thread_stack__event(tidq->thread, tidq->prev_packet->cpu, + tidq->prev_packet->flags, + from_ip, to_ip, insn_len, + etmq->buffer->buffer_nr); + } else { + thread_stack__set_trace_nr(tidq->thread, + tidq->prev_packet->cpu, + etmq->buffer->buffer_nr); + } +} + static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 addr, u64 period) @@ -1146,6 +1195,14 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample); + if (etm->synth_opts.callchain) { + thread_stack__sample(tidq->thread, tidq->packet->cpu, + tidq->chain, + etm->synth_opts.callchain_sz + 1, + sample.ip, etm->kernel_start); + sample.callchain = tidq->chain; + } + if (etm->synth_opts.last_branch) { cs_etm__copy_last_branch_rb(etmq, tidq); sample.branch_stack = tidq->last_branch; @@ -1329,6 +1386,8 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR; } + if (etm->synth_opts.callchain) + attr.sample_type |= PERF_SAMPLE_CALLCHAIN; if (etm->synth_opts.last_branch) attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; @@ -1397,6 +1456,9 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, tidq->period_instructions = instrs_over; } + if (tidq->prev_packet->last_instr_taken_branch) + cs_etm__add_stack_event(etmq, tidq); + if (etm->sample_branches) { bool generate_sample = false; @@ -2596,7 +2658,17 @@ int cs_etm__process_auxtrace_info(union perf_event *event, } else { itrace_synth_opts__set_default(&etm->synth_opts, session->itrace_synth_opts->default_no_sample); - etm->synth_opts.callchain = false; + + etm->synth_opts.thread_stack = + session->itrace_synth_opts->thread_stack; + } + + if (etm->synth_opts.callchain && !symbol_conf.use_callchain) { + symbol_conf.use_callchain = true; + if (callchain_register_param(&callchain_param) < 0) { + symbol_conf.use_callchain = false; + etm->synth_opts.callchain = false; + } } err = cs_etm__synth_events(etm, session); From patchwork Fri Aug 30 06:24:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11123019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 035C814E5 for ; Fri, 30 Aug 2019 06:26:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D3D7521721 for ; Fri, 30 Aug 2019 06:25:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Xd9p4DX7"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="anOoup8N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3D7521721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VxsT+bdurTdBuEE20KKA2J7dAiMR+f/qbEgvVembJ7I=; b=Xd9p4DX7xuI10vlzd3X4iRGLIq jclpKyklRpaS1QszcVZj87CJM/OAaLGHnES7sCLbFx+Y6S5WBPoclqNv0Qb3n/R+G5X44gMOgpf9b 3AptM01LcLdfLRydmDUR/VAIVTrM/a8jdtftfM7iaNhn/QCgZaUwTXBR4bZ27dkl9mN3TLQyS3rPB 5eGx8weRILt7+XObekPcEPgSr6BX2FyB7fHho6bMBIuGt4xiG9inTCo16HpxVzN+tIFiaYzz9IuHm +sdJs073OEuSsC0x93A+2sNf4sbot7Qz/wqCyapWhWBJRwuReEPmyrWjL67neN7CGCWjzzAR6jsvw o551fDYg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i3aM5-0001uG-Rw; Fri, 30 Aug 2019 06:25:53 +0000 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i3aLE-00007q-3P for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2019 06:25:01 +0000 Received: by mail-yb1-xb43.google.com with SMTP id m9so2092121ybm.3 for ; Thu, 29 Aug 2019 23:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LW/cyVok2Jx1Gl00HhV8gtiT8RMfRuMvrAfcIARqkHQ=; b=anOoup8NEzR708g9QLZe0LlLW1dHoyJlaY4aiva0hYfwdnh/25lhlp6WWCRuVqfDDK dJrpirug7Wvl1oNUStKASkVBltOaFvN/8PjGmFx3GMU9ptP/VgRaS673M+3oQyKJZ9g/ XiG5ZQYvUkV4JsYMChF0y+xq0opTxWZI7lTtP7A8X0jXlG7ymholngnzlPFOc/WIm4D4 0O63FdN51BBL4rrEewu4y0ErkJ7aSiT/YCl0a68k2bDep7HyagVbrQbPJ7ANfulPycqR 1fANyvSx1HcIUW4qUqrJrCLufB1EXHolBJ04sAfeSq/+baTPSIxL+C1JlPkZevF1lXkh N1ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LW/cyVok2Jx1Gl00HhV8gtiT8RMfRuMvrAfcIARqkHQ=; b=WbyiRd2zfH41l5Z/DHTMp49jxB0dRam7juZW0f/8I0yG8ibvvNjMiUWHBIiDcVO3u6 EeJPE3qncuoZoouphvY4AV1cBohEkW13EAMwHyq5+TlPY5ZeiWsJN4/qcDJk96hD6DWX CDGO/yFTAodnmVOlsOcbYixUeeX4Xv8cqA7Ubj8lgck7gFogq0s1+2tcifNP5dX0+zB1 HkBbA04uQLjDuvxjxE3ghy0kZYe1ord8tZRW2MgfbJDXkxfLJRz9AJwzQspoAJNZetKp 73LgmleynTGOmyyawtIgp+AbyNNrO4YJgOnxUz4fOKp68nmYF5+J/5JB2t1QS4fz+L74 ZJow== X-Gm-Message-State: APjAAAX5BKwaUr+xkzB286lGZWJ8PialAraSA2oT9xtlTtNGQel8T5nr yk34JQFs7/jh65SPtkYpGig4rA== X-Google-Smtp-Source: APXvYqzXKOQ8vLvXYqgVCKUbIIGXmIs/9n9gYZH3CWl6SicBE7b7FoFlpIMNY4eBB8SbvaOW52BQhg== X-Received: by 2002:a25:2f85:: with SMTP id v127mr9400791ybv.95.1567146299428; Thu, 29 Aug 2019 23:24:59 -0700 (PDT) Received: from localhost.localdomain (li1320-244.members.linode.com. [45.79.221.244]) by smtp.gmail.com with ESMTPSA id r193sm976784ywe.8.2019.08.29.23.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 23:24:58 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Adrian Hunter Subject: [PATCH v1 3/3] perf cs-etm: Correct the packet usage for instruction sample Date: Fri, 30 Aug 2019 14:24:21 +0800 Message-Id: <20190830062421.31275-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190830062421.31275-1-leo.yan@linaro.org> References: <20190830062421.31275-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190829_232500_357802_19A77A52 X-CRM114-Status: GOOD ( 12.98 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b43 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org It uses 'tidq->packet' rather than 'tidq->prev_packet' to generate instruction sample, comparing against the thread stack and the branch samples which are using the 'tidp->prev_packet', thus this leads the instruction sample to use one ahead packet than thread stack and branch samples. As result, the instruction's call chain can be wrongly displayed as below: main 1579 100 instructions: ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) ffff000010214850 perf_event_update_userpage+0x48 ([kernel.kallsyms]) ffff000010219360 perf_swevent_add+0x88 ([kernel.kallsyms]) ffff0000102135f4 event_sched_in.isra.57+0xbc ([kernel.kallsyms]) ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) In this log, the continuous two lines includes two functions, the up line contains the child function info and the bottom line contains its parent function, and so forth. But if review the first two lines: perf_event_update_userpage+0x4c => the sampled instruction perf_event_update_userpage+0x48 => the parent function's calling The child function and parent function is the same function perf_event_update_userpage(), but perf_event_update_userpage() isn't a recursive function, thus this calling sequence shouldn't never happen. This is caused by the instruction sample using the 'tidq->packet', but this packet is not handled yet by thread stack, the thread stack is delayed to handle one return packet for stack popping. To fix this issue, we can simply to use 'tidq->prev_packet' to generate the instruction sample, this allows the thread stack to push/pop properly for instruction sample. Finally, we can get below result: main 1579 100 instructions: ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) ffff000010219360 perf_swevent_add+0x88 ([kernel.kallsyms]) ffff0000102135f4 event_sched_in.isra.57+0xbc ([kernel.kallsyms]) ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ad573d3bd305..0bd2b3c48394 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1414,7 +1414,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, struct cs_etm_packet *tmp; int ret; u8 trace_chan_id = tidq->trace_chan_id; - u64 instrs_executed = tidq->packet->instr_count; + u64 instrs_executed = tidq->prev_packet->instr_count; tidq->period_instructions += instrs_executed; @@ -1445,7 +1445,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, */ u64 offset = (instrs_executed - instrs_over - 1); u64 addr = cs_etm__instr_addr(etmq, trace_chan_id, - tidq->packet, offset); + tidq->prev_packet, offset); ret = cs_etm__synth_instruction_sample( etmq, tidq, addr, etm->instructions_sample_period);