From patchwork Mon Sep 23 16:07:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 174218 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2992128ill; Mon, 23 Sep 2019 09:08:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAnDAW+SkCxkzfVSeqXAaT3MqsP6KHFAlOeoJR3oli6iIFApaa8jpXi9WCvDBodpU7mofq X-Received: by 2002:a17:907:2042:: with SMTP id pg2mr571731ejb.97.1569254899453; Mon, 23 Sep 2019 09:08:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569254899; cv=none; d=google.com; s=arc-20160816; b=vPPjHNOsfR7aJMyxzmN100cxQwNjiae6Fibcu/gvS9Hnsts/jjBrWbdSxhvcgKTMh7 n3o3x3gPRRWkAK+4r/ZTS3NdZs/zLW+cETUDRak7N7OuKhAGizVkmKQ/aXeyV/epB26w pDdL0bD302LbOLfPZAKHhsvy9c1Nab3UoNiGPkOqyb5QvO7kZxxICZn1z0r5alQvmC79 JSy/ci7I4YZe49Xr0wexDNurN6two+9HnKkyvvPchJqRQRMSgeq3hMj5g9BTAUITItrs bYc6f5MKhi7Q/WS0hOtvYGDr9bmaBwRMdZdFHjr7h7JXos0NDP6bMQKLkmM36KzcNgb4 tS8g== 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; bh=PTSvUaUcz4xj5MLSxSCaFDMyStE9w7Ne+2lkvbOJnZc=; b=XcS9ykfhkoc+tVVRRDgy+Hu28aM+REC3uquEK9ZvXlmnUThQNmgdJYoFcxWPicBtYS 2nR/+dpoZUQcxFYMyC051v+6yO1/h9x3GzETWWv/nxJlI6EwLKoVwq6C/uSmO3rca59a XUvw9RhQ8QPnOwnFdCG0u0pw7jTMj8TC+ARuyXj+kFxvhIoHJUQBpifGHdLNvLPdNaHm gFtotmKWivCmGwbCy3O5EqmBDZWUlPepeil/wzrl1I83m4NYj+Ah66i7XcJw9mlWIKJB LsVMyMY6rTAHHXqEKeSAkvQ1jEshlfp82YgtuCcpgO6gL9nZ0Nu3rPoe+EsYsfzDedpm f/Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iuoaK4s3; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si5225095ejr.246.2019.09.23.09.08.19; Mon, 23 Sep 2019 09:08:19 -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=@linaro.org header.s=google header.b=iuoaK4s3; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387912AbfIWQIP (ORCPT + 26 others); Mon, 23 Sep 2019 12:08:15 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46137 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387819AbfIWQIN (ORCPT ); Mon, 23 Sep 2019 12:08:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id a3so8224772pgm.13 for ; Mon, 23 Sep 2019 09:08:12 -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=PTSvUaUcz4xj5MLSxSCaFDMyStE9w7Ne+2lkvbOJnZc=; b=iuoaK4s3jA9qx5hTsEJ8UFFw44uPYfMk/d78HxnJHP/HCH8BHehsUezXIaOoWyuLGD m1LjGTOKOcFyhs640Cx3260rEuQwrXfsUPxak7Q+SX1xCWIn4YvI2gaWdt/svmbiqEbI 1Lo2bwde76R1s6P2jv7SFBrSsKwHjWFcz6qfEP7tPj2u42shRsYTFePN1bYIJMPrwHzI QuVCEABL/4di0uIuJlLvgnfXp/69OMqj0de4ztKYR6YODPOo/zKzPiYGe7qBNLlT1Mqn qNim+dVhvYu+lY5vwg4XKRIduCHPedYyaeGu+I7Z2hHwHFxh8ZH7ZXsCkVF83hgSiwGa 1Fcw== 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=PTSvUaUcz4xj5MLSxSCaFDMyStE9w7Ne+2lkvbOJnZc=; b=s4QhyUPy4yKfU0PD1ZhV8MxDEA3Hz4cOfUsAmyLWavjyOk4D2gqde+4vpDg02JHWic kJP67GIIPMZ8qayxioflBceJpNyVhdQUSu/XQKGiI+ysA+yxCY2r9Ob0SHN/SfQpNFii nMno+81Otk8qs7upzhbNeO83hsNUWPEoVlFBO5pDcS88l7p0PNgFMNjzIQhREp4W1U5R nUqYu84sa8eg/b9XXHmhwdtCoIjXmwStO74rUK5ePPZ+0+ag6TLwANjQ3wqprqixU7Q9 gZmMszEB5scQCsqXkh+slVvv96YpMbMde/rtO//yqnyLV/PRAAWjMG59bCpA7iB39ze5 ztLw== X-Gm-Message-State: APjAAAVpidSHuBUPaEgNlis70L9zc7u190TFl1Vv4ytbSvmO+X2D3IfO iamDUbMhUb346QeYnzIthAMdRA== X-Received: by 2002:a62:1cd2:: with SMTP id c201mr335248pfc.51.1569254892370; Mon, 23 Sep 2019 09:08:12 -0700 (PDT) Received: from localhost.localdomain ([12.206.46.62]) by smtp.gmail.com with ESMTPSA id r1sm9880006pgv.70.2019.09.23.09.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 09:08:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML Cc: Leo Yan Subject: [PATCH v2 1/5] perf cs-etm: Refactor instruction size handling Date: Tue, 24 Sep 2019 00:07:55 +0800 Message-Id: <20190923160759.14866-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923160759.14866-1-leo.yan@linaro.org> References: <20190923160759.14866-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In cs-etm.c there have several functions need to know instruction size based on address, e.g. cs_etm__instr_addr() and cs_etm__copy_insn() these two functions both calculate the instruction size separately. Furthermore, if we consider to add new features later which also might require to calculate instruction size. For this reason, this patch refactors the code to introduce a new function cs_etm__instr_size(), it will be a central place to calculate the instruction size based on ISA type and instruction address. For a neat implementation, cs_etm__instr_addr() will always execute the loop without checking ISA type, this allows cs_etm__instr_size() and cs_etm__instr_addr() have no any duplicate code with each other and both functions can be changed independently later without breaking anything. As a side effect, cs_etm__instr_addr() will do a few more iterations for A32/A64 instructions, this would be fine if consider perf tool runs in the user space. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index f87b9c1c9f9a..1de3f9361193 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -917,6 +917,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 */ @@ -941,19 +961,15 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, const struct cs_etm_packet *packet, u64 offset) { - if (packet->isa == CS_ETM_ISA_T32) { - u64 addr = packet->start_addr; + u64 addr = packet->start_addr; - while (offset > 0) { - addr += cs_etm__t32_instr_size(etmq, - trace_chan_id, addr); - offset--; - } - return addr; + while (offset > 0) { + addr += cs_etm__instr_size(etmq, trace_chan_id, + packet->isa, addr); + offset--; } - /* Assume a 4 byte instruction size (A32/A64) */ - return packet->start_addr + offset * 4; + return addr; } static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq, @@ -1093,16 +1109,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 Mon Sep 23 16:07:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 174219 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2992140ill; Mon, 23 Sep 2019 09:08:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAnAK4BYv9esSVpe/glf9Pw0a156XQz+RuRqnnaVfHk7szZqrkzEoD7ddzjamcqYtqNfr9 X-Received: by 2002:a50:908c:: with SMTP id c12mr901410eda.45.1569254900092; Mon, 23 Sep 2019 09:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569254900; cv=none; d=google.com; s=arc-20160816; b=ir+dod2pWiGQHzBgbaUlY4zs1HIClsEHE0/08aRFfX9fxdQJKZuDH8vlLdVAB60Au7 iRB2yTvBJagt1BFh8N1t2a/5Aq8TPvVbjBsmJafjppSLnWFyaIAqHMq3hAq3UUgC7D8F ezuyzbcfm3tyMjIpGKsJbGNoRckw027FO/ebA/7GB/LVlOgnF1SB3wRUlg3PRqvJf1nc NcMLQc9x7xeI21adPKPnYeQoxEeaEY+I55MUIX9/4tmfZc7LpT5mZFccL+PfNN3c2PuV fW9UiGMjuYjg0PT2I8yC6vrd0+Yag0XrXJNN+shzbJHWilyxJ+C+MBBwgAXYGVaMzcyg ZKRg== 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; bh=2BxhOdJYXJi532SmentxbXVQYJErTKd5nVs++YvZFCU=; b=VitZ/hpDoc8phhChiNmNV0c4Tss3WnbBEdV6qZdogCgJZWJNQIc+ggJJxGIrhn934Q qz0R0v/Zu1RCTmD7HpY00dVWMtQmEAunKZr1IOkewddcegtBf+QqgxWCzqPXUj+LywWx xLUWmbN5HZbXZ5lbfyXTtzQWZve/1EN5JYPo1dXonLYRnjxhWv4FWHlGQqQJ4Kcg8uFW /CJm3GHUHgOMFWJCG/2xpZieUraCJrw+9VbP6LKL1peNNXuERQPF8Deq3glnUYW9KCDP i5bm6TswzRVBt1BTe39/RWD3DJr4Ey+jjwNw1Og5BTsRvPSNfBesrVauUbzAb54C/aar 7qMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FuJY65Uc; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si5225095ejr.246.2019.09.23.09.08.19; Mon, 23 Sep 2019 09:08:20 -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=@linaro.org header.s=google header.b=FuJY65Uc; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387986AbfIWQIR (ORCPT + 26 others); Mon, 23 Sep 2019 12:08:17 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36450 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387969AbfIWQIP (ORCPT ); Mon, 23 Sep 2019 12:08:15 -0400 Received: by mail-pf1-f193.google.com with SMTP id y22so9409554pfr.3 for ; Mon, 23 Sep 2019 09:08:15 -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=2BxhOdJYXJi532SmentxbXVQYJErTKd5nVs++YvZFCU=; b=FuJY65Uccx36X3yZKLYnu5YgoLkoKPHdaCgcxI4S3TLOblQObylYTyM2jj+nF8rT0/ wKwhN0mJ0QORonekDL+A+pYZXSlNOkrbFoETnBLYUZyi4+4YqHR0H/JyPGKIFmZ7b/6Z nyeYgnu9EVky+iLmTg6GeRPSw4Ae7h36sN/IwIrqlxo0MgqJvpQOjHKuyb6Xqdk90hLd qcSiDIRuvQ5VCzh4PBcdrNCFPZATaeszoier7rCXg1QcPnyExYfodq1GSToljEwJ9vZg q0YTKL3e/eTPv1ZMvAhgWVHC9NaoNFKYsivR48KdZiNbGMbznV2txAnDg6FxMYZIin4T T/PA== 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=2BxhOdJYXJi532SmentxbXVQYJErTKd5nVs++YvZFCU=; b=DKjPSNxxseJTT26q0pTVcGNe3Yk2/Gdw9M6sAWSeKhPRbX3gqg4ws7Onf+CJ2kE6kg /WladwCiHJ45sVPQMm8stOZeUUH9QIhghI373mfMtoSqQwpiPte8dzYblAciSqIShA3q 87Rh2CbHyQ3HNmC+g7ItpRwSyh8ofLVZETx24vkTBde5dzeR7V/GIexTBLUOAsZ9EZhz PHY//mNGUXJHO+i6lhBP8N4hIAUGcOyQbcXSdo//1KkytgsMiryAYJAvkmZDguE08qlT A47j05KRTgZFs1frHuiMmB5HzanbPyNjJR/Hxc+cWWh4aJKGaWuYQsbMFcTrYJ8Yb+jQ p6rQ== X-Gm-Message-State: APjAAAVBxHpAjr6jcNsIHvg/LqdnYZUxjkXrccdPzdgfXIAyItgC2W/8 ksMAUGcZPA8WwsNe1oPL30LKDA== X-Received: by 2002:a63:1d02:: with SMTP id d2mr708391pgd.190.1569254893704; Mon, 23 Sep 2019 09:08:13 -0700 (PDT) Received: from localhost.localdomain ([12.206.46.62]) by smtp.gmail.com with ESMTPSA id r1sm9880006pgv.70.2019.09.23.09.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 09:08:13 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML Cc: Leo Yan Subject: [PATCH v2 2/5] perf cs-etm: Support thread stack Date: Tue, 24 Sep 2019 00:07:56 +0800 Message-Id: <20190923160759.14866-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923160759.14866-1-leo.yan@linaro.org> References: <20190923160759.14866-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Arm CoreSight doesn't support thread stack, thus the decoding cannot display the symbol with indented spaces to reflect the stack depth. This patch adds support thread stack, this allows 'perf script' to support option '-F,+callindent'. Before: # perf script -F,+callindent main 2808 1 branches: coresight_test1 ffff8634f5c8 coresight_test1+0x3c (/root/coresight_test/libcstest.so) main 2808 1 branches: printf@plt aaaaba8d37ec main+0x28 (/root/coresight_test/main) main 2808 1 branches: printf@plt aaaaba8d36bc printf@plt+0xc (/root/coresight_test/main) main 2808 1 branches: _init aaaaba8d3650 _init+0x30 (/root/coresight_test/main) main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) [...] After: # perf script -F,+callindent main 2808 1 branches: coresight_test1 ffff8634f5c8 coresight_test1+0x3c (/root/coresight_test/libcstest.so) main 2808 1 branches: printf@plt aaaaba8d37ec main+0x28 (/root/coresight_test/main) main 2808 1 branches: printf@plt aaaaba8d36bc printf@plt+0xc (/root/coresight_test/main) main 2808 1 branches: _init aaaaba8d3650 _init+0x30 (/root/coresight_test/main) main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) [...] Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 1de3f9361193..6bdc9cd8293c 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1116,6 +1116,45 @@ 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.thread_stack) { + from_ip = cs_etm__last_executed_instr(tidq->prev_packet); + to_ip = cs_etm__first_executed_instr(tidq->packet); + + insn_len = cs_etm__instr_size(etmq, trace_chan_id, + tidq->prev_packet->isa, from_ip); + + /* + * Create thread stacks by keeping track of calls and returns; + * any call pushes thread stack, return pops the stack, and + * flush stack when the trace is discontinuous. + */ + thread_stack__event(tidq->thread, tidq->prev_packet->cpu, + tidq->prev_packet->flags, + from_ip, to_ip, insn_len, + etmq->buffer->buffer_nr); + } else { + /* + * The thread stack can be output via thread_stack__process(); + * thus the detailed information about paired calls and returns + * will be facilitated by Python script for the db-export. + * + * Need to set trace buffer number and flush thread stack if the + * trace buffer number has been alternate. + */ + 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) @@ -1392,6 +1431,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; @@ -2592,6 +2634,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, 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; } err = cs_etm__synth_events(etm, session); From patchwork Mon Sep 23 16:07:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 174222 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2992356ill; Mon, 23 Sep 2019 09:08:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqygMOGfy83PMpS3dk5J2oWJ4DHwCY6NNbaq3LdEVeGtz/P6VE0Lpq0/2EWDfAV+aQVWcUht X-Received: by 2002:a50:9e65:: with SMTP id z92mr879487ede.49.1569254912415; Mon, 23 Sep 2019 09:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569254912; cv=none; d=google.com; s=arc-20160816; b=V1LYlSzTrc+bC1tv6sMEEYxuqiCjUEJ5rdMFxLT9PNr2VeFlYTqHKKsKAdAeCKrwFH 2av6KwAZY2NN7S1NEX+AzDEB24rrctlHQ8fu5RPRBEhYlGcUW9jWTQik3XEhpumEzJim nNSJRdDzJdmsH920Q3NIzWc+1SdQ6BrXN3ge7DQtHQMGuVqPHbxdDBp6+AKhZyvG8Dbo Iq9HiW9wXy6LwlHrIq7zA8bWolvNoETufp2bJYfhHjp0aPdW7LawJVjnMs8hO2BbFe5x fjo+IQfQnj2EBD3b+RIMrjN4UNMLNrFF+nuzJ/WZbJ2Oel3qhKKuiOi8FvSjQaGz4ei6 j/+w== 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; bh=hEw6NY5M2Jhu1QjE48KzJEVuyxHVkatyT3269XxLGmY=; b=vzYj+4zkwX2lCxPxuuEZoDcgRyDEtWicO1h0qQsyuOzGEYzNpeTpP25/QqNcHhEXd8 jP1rLG5Rqz7r8vN7ZeEVg0Ew7r4CI+64tKJSxDhXYNhnuCFB0SuTC0Rat44oALkOKAB+ oQ9zXGD2YSIKqelfTpiCE15ad7VeFfg5cr7mVQK3yT9j+DS7lR633Bl4UbJjJySQEzbt EJTzfoxO0wYEA3xIzuOxPJScFa+axlKrtH9XPnaqKHPot1PlBOKnU8N64+pIbZXVA+0B YWUCVvqiDbYOAy43hCj8KUAk5xKItYenC+ozEMbcpYyDYRo1Eac+uBYpbeHRJDCyFleL qoJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TQqgxpQ7; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h23si7307707edh.248.2019.09.23.09.08.32; Mon, 23 Sep 2019 09:08:32 -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=@linaro.org header.s=google header.b=TQqgxpQ7; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388217AbfIWQI2 (ORCPT + 26 others); Mon, 23 Sep 2019 12:08:28 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39296 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387819AbfIWQIQ (ORCPT ); Mon, 23 Sep 2019 12:08:16 -0400 Received: by mail-pl1-f195.google.com with SMTP id s17so5224278plp.6 for ; Mon, 23 Sep 2019 09:08:15 -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=hEw6NY5M2Jhu1QjE48KzJEVuyxHVkatyT3269XxLGmY=; b=TQqgxpQ7HQmVgDVqV7HrYin2y0u7zy7VtKMraO8LlIyWmnlJIRl3J90jSsm/6tboTi 1tT6qLIC2RAcNeBwM56cD6sO3sRxN1O8gjgaE8ToFmbsSqCKQnqemRgEN1j9pEFd9Kkr Bbbm6ZBVJ2oFTXralq+Lx56we80H8zTzrtpV2r7e+zxBETseLoJT3u4JEvkXFaSFG+ng 0pGju6cldDNrZtSQcZVX3YqjyFJpFGu5QRAaA45cAybKCKIbLv905Wadg64AIaqx1+eA R9xYF2Mccqj/fEqvnT7jSBR6nVQqSDWGNiXAJYwkbc2BfBgoQKveTieg89Ee7zVt0gSu 6nCw== 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=hEw6NY5M2Jhu1QjE48KzJEVuyxHVkatyT3269XxLGmY=; b=qmzsZe97KDMX0KjYbMf+nLOGPwbQrWH8guhFqlT9ElGCYk99Lf1M4ErudXGIaiKKKW y67oEcwWVurNmtfV7TwNbilpqMfOnc62GUBH+W3P/iRy5JZrL8q32z5AmStjdaPiqlrX MXgvy1RoG2NDs/mDace3tQj3rHDWYzYylDOzljRUibrhZEpkdmp/W6MRyknzL3j0vwC5 4cybnxxnhwo8ywIid+xdxvPoVvbs9m9MUbCwbHIImkBrUJtcwaVepq3iKZcrdGkxP6Fn qeXebBjZnRQLCOfZeaQjQ4woz/YlGo8CsR6g4HeLWIiNvjArAPKHJSwhTG3lKqI2/RjL Zq9w== X-Gm-Message-State: APjAAAU6KyC9lSkzE/FtCWbdZ7ETaIjSUnpHSs+IAhuF13VCKtU9gQb4 5p5LYiOGYZ5ma1lENuAcuLsUcw== X-Received: by 2002:a17:902:b086:: with SMTP id p6mr455657plr.315.1569254895147; Mon, 23 Sep 2019 09:08:15 -0700 (PDT) Received: from localhost.localdomain ([12.206.46.62]) by smtp.gmail.com with ESMTPSA id r1sm9880006pgv.70.2019.09.23.09.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 09:08:14 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML Cc: Leo Yan Subject: [PATCH v2 3/5] perf cs-etm: Support branch filter Date: Tue, 24 Sep 2019 00:07:57 +0800 Message-Id: <20190923160759.14866-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923160759.14866-1-leo.yan@linaro.org> References: <20190923160759.14866-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If user specifies options -F,+callindent or call chain related options, it means the user only cares about functions calls and returns; thus in this case it's pointless to generate samples for other types of branches. To output only pairs of calls and returns, this patch introduces branch filter and the filter is set according to synthetic options. Finally, perf can output only for calls and returns and without redundant branches. Before: # perf script -F,+callindent main 2808 1 branches: coresight_test1@plt aaaaba8d37d8 main+0x14 (/root/coresight_test/main) main 2808 1 branches: coresight_test1@plt aaaaba8d367c coresight_test1@plt+0xc (/root/coresight_test/main) main 2808 1 branches: _init aaaaba8d3650 _init+0x30 (/root/coresight_test/main) main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s [...] After: # perf script -F,+callindent main 2808 1 branches: coresight_test1@plt aaaaba8d37d8 main+0x14 (/root/coresight_test/main) main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: do_lookup_x ffff8636a49c _dl_lookup_symbol_x+0x104 (/lib/aarch64-linux-gnu/ld-2.28. main 2808 1 branches: check_match ffff86369bf0 do_lookup_x+0x238 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: strcmp ffff86369888 check_match+0x70 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: printf@plt aaaaba8d37ec main+0x28 (/root/coresight_test/main) main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: do_lookup_x ffff8636a49c _dl_lookup_symbol_x+0x104 (/lib/aarch64-linux-gnu/ld-2.28. main 2808 1 branches: _dl_name_match_p ffff86369af0 do_lookup_x+0x138 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: strcmp ffff8636f7f0 _dl_name_match_p+0x18 (/lib/aarch64-linux-gnu/ld-2.28.so) [...] Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 6bdc9cd8293c..018c7e682ded 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -55,6 +55,7 @@ struct cs_etm_auxtrace { int num_cpu; u32 auxtrace_type; + u32 branches_filter; u64 branches_sample_type; u64 branches_id; u64 instructions_sample_type; @@ -1222,6 +1223,10 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, } dummy_bs; u64 ip; + if (etm->branches_filter && + !(etm->branches_filter & tidq->prev_packet->flags)) + return 0; + ip = cs_etm__last_executed_instr(tidq->prev_packet); event->sample.header.type = PERF_RECORD_SAMPLE; @@ -2638,6 +2643,13 @@ int cs_etm__process_auxtrace_info(union perf_event *event, session->itrace_synth_opts->thread_stack; } + if (etm->synth_opts.calls) + etm->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | + PERF_IP_FLAG_TRACE_END; + if (etm->synth_opts.returns) + etm->branches_filter |= PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_TRACE_BEGIN; + err = cs_etm__synth_events(etm, session); if (err) goto err_delete_thread; From patchwork Mon Sep 23 16:07:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 174220 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2992166ill; Mon, 23 Sep 2019 09:08:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtmrYDhRG0dlUv1tZsPlH4mh7HTsnEqkQEkKV540KcyjwW70t1lbONMAa1cHu6Sif+DTW8 X-Received: by 2002:a50:d0d5:: with SMTP id g21mr910657edf.204.1569254901576; Mon, 23 Sep 2019 09:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569254901; cv=none; d=google.com; s=arc-20160816; b=M+Wbo6BunmKF9T2YpQE5MHuqYhTBFsE8F1qEAO9+vMgM2PxfSljwu662QtI/1+HVvg +B7XCK2zwAMfdllyRG6TYnRp8h8eoe2egj1TQVjLxJNVhDAHygxfZuzGjun+NgsLNvSM ZH2m7ocgOOuRIvUe7JfbRzWql7JU4wIOiCcadaCMIvtT2aJmvPlrmoEpdxleTvHqJ4Sq IdaL9/Go+vLLu0xdODB8ToHY1yJs8+j6mKf4iv2uuWUs3MwCybmDdO6z5+zvIAIBLdRp /+s7rhSzdhn1PJTPHEdzJIuhlZKG8rew2ThwnokMYC8AYL0aDoMXnCyUqJgGqan3Rnzj 2bEw== 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; bh=ETR3TzZ5ptxgZyXVIEMbUVt7wSrL6NEDEKof5BmO9Pc=; b=MUC3Wm/XRfbpOPhmjtV6UUGZMuAIhEZBO72g4woxKIceMSxb617dieMXV0iC7Qcb4j rx5sVEyEWV/iPJGYU9kzmcXEbmpmogcEeDR61ZQ6T9boQ0LnGrId6e4FAUin/xA3dTA3 QXw/LsEeDKzB3erVnWSg/Pvoc4xx024FtAr27HiMSJDzXsAkMbCOplKbvTEWuDoUk1gk lJBQo86xaaH4HhuBNg0nJmspNf2i2l1+8JlP3R6HA/BEyDCPCtTWxhR8m7eJ5CFVhVQk u62Z81uqTaayc3iybZTO0aP65t0Cj1jYjnNKlKJiXAQh6jqTh0sGnieZ8X6dQ50mxrfi p2wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dBIwpdcL; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si5225095ejr.246.2019.09.23.09.08.21; Mon, 23 Sep 2019 09:08:21 -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=@linaro.org header.s=google header.b=dBIwpdcL; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388012AbfIWQIU (ORCPT + 26 others); Mon, 23 Sep 2019 12:08:20 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34510 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387969AbfIWQIS (ORCPT ); Mon, 23 Sep 2019 12:08:18 -0400 Received: by mail-pf1-f194.google.com with SMTP id b128so9415511pfa.1 for ; Mon, 23 Sep 2019 09:08:17 -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=ETR3TzZ5ptxgZyXVIEMbUVt7wSrL6NEDEKof5BmO9Pc=; b=dBIwpdcLFGtVRpg1U8Z6A1m4LJ6TPyQtUZIPjP0m2JG5ph/MeYzA06C3QUqx/J/Oz0 Nha+yE04DSTymZFcdc5tXQxPtbM1rsWA6f87YptLUpNpPUozJhycUMDE0Lkebfq8wk66 4D/wKTKCPlV41H9n0evAjSTIZJAPycEurI+doNmcTwXOv/09PW4SgEvI/BE3RO94AP5L mmK5rjsvbHqztuVn55Gkx6fR0aIwjXyEC129IoQINbL2gNld9cL0+MH0QULxK6bHuLX0 bdHc2E7/Zjphfly3enKC5U91ddmgPs9lRUPQFQSMOrPMmlR6ypbBPerX7Ig/Q1DxvAGW 5Mqw== 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=ETR3TzZ5ptxgZyXVIEMbUVt7wSrL6NEDEKof5BmO9Pc=; b=gb3nIdqlK2VTeKkN9r0MhVeuNGzJvlmkUxJk8yy/d4HCrx9lhMPQ7I2YURt+oYmm+k mvNkFWNkQzErWAzSB6/wAecB50KJr66HoQ4XOJ0yaSAkIJoAo8n/n2HctQFIwVnfoMy6 0srdvcZkchHOOQ+r70NWuyBhHm458eBeEmJZh1lS9YbsFYM/jCS4+GqNoo1tH15D3J6K gSUAz9G/L9P8NNeH29Yp9hBFu/mHOETOyzPZzt6aahdPxSK1cqCqKzkKLqI2XuLFHgCF rCEbN4sQZS2ELyOHjwS3dWKwDQN7RTke9ya7WgQjesW33PPmMA7SR8b43qtRZoFYo1A0 ehVA== X-Gm-Message-State: APjAAAXGwMuknQaGpVV4T4k370GfFiHhkUjQVg8rUT966eqzs3hr43zU 9gyg/L04QhkwIIdRAVyKb4ZbDA== X-Received: by 2002:a17:90a:b302:: with SMTP id d2mr245796pjr.3.1569254897444; Mon, 23 Sep 2019 09:08:17 -0700 (PDT) Received: from localhost.localdomain ([12.206.46.62]) by smtp.gmail.com with ESMTPSA id r1sm9880006pgv.70.2019.09.23.09.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 09:08:16 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML Cc: Leo Yan Subject: [PATCH v2 4/5] perf cs-etm: Support callchain for instruction sample Date: Tue, 24 Sep 2019 00:07:58 +0800 Message-Id: <20190923160759.14866-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923160759.14866-1-leo.yan@linaro.org> References: <20190923160759.14866-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CoreSight has supported the thread stack; so based on the thread stack we can synthesize call chain for the instruction sample; the call chain can be used by itrace option '--itrace=g'. Before: # perf script --itrace=g16l64i100 main 1579 100 instructions: ffff0000102137f0 group_sched_in+0xb0 ([kernel.kallsyms]) main 1579 100 instructions: ffff000010213b78 flexible_sched_in+0xf0 ([kernel.kallsyms]) main 1579 100 instructions: ffff0000102135ac event_sched_in.isra.57+0x74 ([kernel.kallsyms]) main 1579 100 instructions: ffff000010219344 perf_swevent_add+0x6c ([kernel.kallsyms]) main 1579 100 instructions: ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) [...] After: # perf script --itrace=g16l64i100 main 1579 100 instructions: ffff000010213b78 flexible_sched_in+0xf0 ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) main 1579 100 instructions: ffff0000102135ac event_sched_in.isra.57+0x74 ([kernel.kallsyms]) ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) main 1579 100 instructions: ffff000010219344 perf_swevent_add+0x6c ([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 | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 018c7e682ded..bd09254a7208 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" @@ -73,6 +74,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; @@ -250,6 +252,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); @@ -274,6 +286,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; } @@ -545,6 +558,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); /* @@ -1125,7 +1139,7 @@ static void cs_etm__add_stack_event(struct cs_etm_queue *etmq, int insn_len; u64 from_ip, to_ip; - if (etm->synth_opts.thread_stack) { + 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); @@ -1181,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; @@ -1368,6 +1390,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; @@ -2638,7 +2662,6 @@ 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; } @@ -2650,6 +2673,14 @@ int cs_etm__process_auxtrace_info(union perf_event *event, etm->branches_filter |= PERF_IP_FLAG_RETURN | PERF_IP_FLAG_TRACE_BEGIN; + 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); if (err) goto err_delete_thread; From patchwork Mon Sep 23 16:07:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 174221 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2992227ill; Mon, 23 Sep 2019 09:08:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+9zCq189Tf9pgmW3qDvsQ/pZni3pIZPaxj1cjTC5McmdShd130SsYsyBod15EroX7Ohkj X-Received: by 2002:a05:6402:1212:: with SMTP id c18mr183431edw.259.1569254904470; Mon, 23 Sep 2019 09:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569254904; cv=none; d=google.com; s=arc-20160816; b=iBP0kgq4Mml4CH4vR9AoMu/7SCjUVA9KEh1y5G/9NFlqM+xcTlNTTTlGsakthfRsOW 28EIc4QqmWZhFHL4b9Qm++Tn0lCdvP0BWTruRG6aaUErjXap8bC9jeDu5L8eu+rGyRoW rFvPXwLNEmUprZny8AWc/hbb7U6TPIikqXYboRUqcUBV1g0CbFH5VI3tIioRAm7/U1mz lkMLd1cFSO7ota6UfeSjW0rBxMuUCOAj4kMfnq3H7bPdfh84F9KQEF3+xzXhhS6v5XHy lEvHl1eV6CwyVgHdK9YiaMsoVuDe3/YUCK3TXX+JiCi9bKR6x5cIrI588Hp3wYPi1Riu u+UA== 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; bh=qbgL52JbC3nZvOpwtMEyx7CsWNJZAh5SrAdnx2jzAo8=; b=goJNQuKqqZ7mhxEboG1RVvUbZa/XaNE9J2caU4kPBTRU9pQzcyeErlLZBJsyZMOGlO 5IJhnlb7Bfb//+Kr4j5FawSuV9qoARRweu0JmRBpo5/koDV20ElyzwZ1mGDbqoxtNZNJ p25hSX14BZ/exSKRoiXAGJYZB+YQVA1jLcCmHc4CnjxiwG6GjtNoZAFGe5lYaEaGMQsM LU4VM+AgcqxGEVZFDG5xOHeDPMi2gUJ2vj6ILVer1BhPThDC0r4geE4nAyaiQq9di43p G7GnXuUNNkH2fAGnNX7qtcQDfqmSrjj18fwkqE1VsqOgWCJ2jyfNxWBeF5hh/EQWoCmN TB2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FSOY9rC3; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si5225095ejr.246.2019.09.23.09.08.24; Mon, 23 Sep 2019 09:08:24 -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=@linaro.org header.s=google header.b=FSOY9rC3; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388084AbfIWQIX (ORCPT + 26 others); Mon, 23 Sep 2019 12:08:23 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34513 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387969AbfIWQIV (ORCPT ); Mon, 23 Sep 2019 12:08:21 -0400 Received: by mail-pf1-f195.google.com with SMTP id b128so9415564pfa.1 for ; Mon, 23 Sep 2019 09:08:19 -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=qbgL52JbC3nZvOpwtMEyx7CsWNJZAh5SrAdnx2jzAo8=; b=FSOY9rC3vU5FztGsRFEwH7V4vSC9FJwLCLLrXOgsTUDaEwnAmpuq8BbixzXG2ShMOL 6lLd0syInfmXdqh3Al2QF+TUN79k3rBRUqlhtoX+TSudrnCbPz/q5/W2p5ygqb5kOQhl CnUXmSZFkMcg+WAj3b1AFeDWZ6VA5jzu6MW/OwI58N93JXE4xidealql1q8NAYKm6H38 tUwoNg8zLOr1KT09n5HsSneDQYjLwHoKbwCeHrDbG+J2ibdHNqDaDUTkFSoJWBfWD16c +yZQ1VB6Y0h7yY85Pe7mLUYfXy/Q370DvImDh7J1Vb9oh0oN1B8jdJO+sngnP1GgpSbC RyMg== 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=qbgL52JbC3nZvOpwtMEyx7CsWNJZAh5SrAdnx2jzAo8=; b=lk+ychHVC/KG5qXTOZ4MhbKilCBwpL/uWQiChkFjnP6sEBFATIi95hR/qbLiPwVws7 xbEEErFmAjxbttBDkgpzU5ZdBqbhIvOmsoyyYdAxbJjU3v4+tT/uFbM75bOynM6KwCSG g/w7HcHbXT69vXLwhT2pNnpvDjqMT+6OJZvqDBpXTIxXn2Tl/HBZu/SuYnDbJZIMa+0B Q/+ZCuIABAua9V66DuZb7OrXekZZpr0Ri4GEOsPh4DrUFF0pkbIOEEzTDFTAJuapZYt8 2NE2Bp8Zr7nO6ldFJGckP68ZlZMAOu6oBvYcATdqw0uxUd+jav5m3akyDB25AbPHEIBv LBwQ== X-Gm-Message-State: APjAAAVMUx9RytSkptYEOIFiQWK1xBAKgfcx+Lf11Ot1RoKotLTCHJpE aBtlV/4Meo+S1PdM0zCsMQWaqg== X-Received: by 2002:a62:4e09:: with SMTP id c9mr373088pfb.152.1569254899217; Mon, 23 Sep 2019 09:08:19 -0700 (PDT) Received: from localhost.localdomain ([12.206.46.62]) by smtp.gmail.com with ESMTPSA id r1sm9880006pgv.70.2019.09.23.09.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 09:08:18 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML Cc: Leo Yan Subject: [PATCH v2 5/5] perf cs-etm: Correct callchain for instruction sample Date: Tue, 24 Sep 2019 00:07:59 +0800 Message-Id: <20190923160759.14866-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923160759.14866-1-leo.yan@linaro.org> References: <20190923160759.14866-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The synthesized flow use 'tidq->packet' for instruction samples, comparing against the thread stack and the branch samples which are uses the 'tidp->prev_packet', thus the instruction samples result in using an packet ahead than thread stack and branch samples. This leads to an instruction's callchain error as shows in below example: 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 the callchain log, for the two continuous lines the up line contains one child function info and the followed line contains the caller function info, and so forth. But 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 both are the same function perf_event_update_userpage(), but this isn't a recursive function, thus the sequence for perf_event_update_userpage() calling itself shouldn't never happen. This callchain error is caused by the instruction sample using an ahead packet than the thread stack, the thread stack is deferred to process this packet and missed to pop stack if this is a return packet. To fix this issue, we can simply change to use 'tidq->prev_packet' to generate the instruction samples, this allows the thread stack to push and pop synchronously with instruction sample. Finally, the callchain is displayed as below: 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(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index bd09254a7208..3f7edfd15124 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1418,7 +1418,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; @@ -1449,7 +1449,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);