From patchwork Sat Oct 5 09:16:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175261 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1790707ill; Sat, 5 Oct 2019 02:16:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwVIXlj3fLg0pMmhYlj6J6i/Xz3QuYVwVZ4BueUtxZAL7cFI20CY0xDl7eLLMiAlqtw+iT X-Received: by 2002:a17:906:2cc8:: with SMTP id r8mr15990757ejr.197.1570267005865; Sat, 05 Oct 2019 02:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267005; cv=none; d=google.com; s=arc-20160816; b=xMZiZ0No+oQ/SX1bUw9N8EJBHEbQyiYDjOs2OTy/jTW/gG+EuD+lvIKRzGytrigLYG wT6koB+w3f9iaRZvHWf1fOHOGK86OicddXwe8KpXaDQTcK3XlXQ26r1Gr2EkU/aAqrym kbpuXvl1FXVJ+tEBBLiG6DtBlpD3fAU7CiLWq5Go5mCU+7D6EZwL7jdwmKrOytT6NyZ9 MqZbz3ziAyQDiMK90OiLfmy1b8CI9lyCU8u5KF7EfFClmh3iozO2mE30T0UpL8Oyakqr v4WSSRj5LibXSh28GAKyCE4mBGnb/W3MIV9YSlpIgTw+bXKxScBqMMHJ5VtxWFW8P29r ytzg== 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=5GP/KNw0NThi+xFyZyJwWXss0a8iqQMvGrS8dpQzhPU=; b=WiMMspqgWL7IWKTBJUv112n1/BO4Zm/yrAYC4b3oy9pVi3jzLeDbquHc+whnYkvLh4 4MS66PblB+eG7AKU/lmI5B6O6Jyn6vSld3F1fsYQrVs+wDGYp7RRMUrXrs2cAfHsbITt i5MC81A31ZwYehTKeK87vWxzk8kLcUvYE/Ntt8oi4I3Bmfyqqw57Er8IV10rzSkfUX74 MZmN43jnt2vF2veOPjT80FFEHb+ujHCogz2rTtdKIjDayMu38P+uLR3Vdp8ouXvMjnzL uQ20Mo4V7Tfi+dVog1qoMsVyl/i1oM4UVXPb0Z+8JAdI40m9WlvQtx6yx0yNUo8zYx+U W5TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SEchh8dj; 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 b30si5070907eda.200.2019.10.05.02.16.45; Sat, 05 Oct 2019 02:16:45 -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=SEchh8dj; 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 S1727597AbfJEJQm (ORCPT + 27 others); Sat, 5 Oct 2019 05:16:42 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:38819 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJQk (ORCPT ); Sat, 5 Oct 2019 05:16:40 -0400 Received: by mail-qt1-f196.google.com with SMTP id j31so12167934qta.5 for ; Sat, 05 Oct 2019 02:16:40 -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=5GP/KNw0NThi+xFyZyJwWXss0a8iqQMvGrS8dpQzhPU=; b=SEchh8dj4qcptxwJcOAo15ZrP0Q38g28a7exn9iyxXlFmNigonCzvKJmR+iRVs6LuZ pe8vklnaBfIYulObSewcnQQrqBuQJxJ/I2cyRFnh6KS/FnGui180xTOP+SyKzW1iYnlj b8+1/rcEni7xHn3+XNgwn8KKOMfaJMNhwG+nOI08nLatBTQSM5ZkymsT7UYadFZ2DsSN MvNrj0HDFMuVxFYIEnrKrucUC0Hh0WP5clNjK8Kgi1JpHRsbonXOoluIQqsOgn6FecLj rr+pjsUMIgoJfiL40lAgaeKoosOETz0+sdryR0vpnXdwZxjelYcPk80c9bX0jldErFH5 4+cw== 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=5GP/KNw0NThi+xFyZyJwWXss0a8iqQMvGrS8dpQzhPU=; b=qm9887M119pU+19NlEY3k2TOjpZgOB5g4BSE0WY0w9DRYKYIIY8/b10BAKgRFoKH1B Tk4LsxmebRohaEZzF2Joj99k+dhg0Ssz4buRghuhcStNwmjaYFL3wzEhJXUa7Fa7bHt7 /r/a6LaeBv+p1PQwETYGyEC+uBHCd2UkOL/qkTmBbUClf+ElImngAUGa4CuXFGtPji4Q Jquf9eVAdFDaZKqa8NT2X+dMaS0NxMxuJCpChaPLwLSzzeLkb7xnF0bdwi4jsZcEvmr6 amkn8uGGbokckFU9YUeyxINlBrlzVT8XjgqB+TsyVfhZB+jn4vjAl7egM39ZsBr3V9PR 3RSQ== X-Gm-Message-State: APjAAAXXR9sYoyF0kQZrM8mEysA0bIGV4cIimK+G3/obwTpHell+hi/W u0VwF89LgYxZQ6YhcUC6SRnDDQ== X-Received: by 2002:ac8:1701:: with SMTP id w1mr20870585qtj.24.1570266999647; Sat, 05 Oct 2019 02:16:39 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:16:39 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Cc: Leo Yan Subject: [PATCH v3 1/6] perf cs-etm: Fix unsigned variable comparison to zero Date: Sat, 5 Oct 2019 17:16:09 +0800 Message-Id: <20191005091614.11635-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-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 the u64 variable 'offset' is a negative integer, comparison it with bigger than zero is always going to be true because it is unsigned. Fix this by using s64 type for variable 'offset'. 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 4ba0f871f086..4bc2d9709d4f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -940,7 +940,7 @@ u64 cs_etm__last_executed_instr(const struct cs_etm_packet *packet) static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, u64 trace_chan_id, const struct cs_etm_packet *packet, - u64 offset) + s64 offset) { if (packet->isa == CS_ETM_ISA_T32) { u64 addr = packet->start_addr; @@ -1372,7 +1372,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, * sample is reported as though instruction has just been * executed, but PC has not advanced to next instruction) */ - u64 offset = (instrs_executed - instrs_over - 1); + s64 offset = (instrs_executed - instrs_over - 1); u64 addr = cs_etm__instr_addr(etmq, trace_chan_id, tidq->packet, offset); From patchwork Sat Oct 5 09:16:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175262 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1790809ill; Sat, 5 Oct 2019 02:16:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJvpSLeoOHg2X5StIby6qIsh/0KO3WP0IGFArJHf/Jk37wbs7K9URp89bqf4yghnHEnTW1 X-Received: by 2002:a17:906:234e:: with SMTP id m14mr15684709eja.118.1570267012968; Sat, 05 Oct 2019 02:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267012; cv=none; d=google.com; s=arc-20160816; b=lvC4L17NkFlnzc8guO0WLMGygT/Km6I8SnszVPA01cshdD7hfAZOCuhQYkAhDf1g2i nrK2a5yYisHGMd/Y0Bmfx06lulv2FmX6yqHJi/XE89acqCeg0lolIBu4kKW9tBy1or47 y8I2EcZ/IrShd3Qb12D4yBJZX49bsHmQKrmTJ4N1qBJVp0B4Au3YCozQFTE1EdHwgikS 3KtkHrJ/oWXTDtj8XVl21P+tW7H2vsnfMLkhba3S++twnJQ6J/UBOK4+lGjmV6ztIg28 Tp7U6maKSWki8l/4cckqpm/L05GVewhvwCNuvDLB7EdsQUtmlZe+V9uZoQ6hY+zuVEkC BEmg== 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=6oKadehOfuqvchi0MOdyWhMtht9hVnMfKkag850zFWI=; b=WWM1HZ2qnXHYq4X+lNo7FHSPLUb2yF12QIId+nbD8I5WrecBdBGP/NhT7C8JVmJ6Sm WrKbl76Crtp1in7P8Qf35HBnD84fNJUZ7D9B2KVm10sSy1K09LGtNl0xYuCYclUtWrdq f7fV7TwLTaDP3VeL9LGV4tglN3Vpnhy1h7srAcfcRDnLw3IojJ6Jaxc6NHz0PUcFNFoa vSvhA08Iw5jVSttk55KkjTIPfpTd/AsWsTDt9gPLBlJA3lXcL+x69VsV+3zLS6vG0Kjw lPsi3h6d42N89fT9ipJWeYLn5X371TUL97JqbAeYk0wzWgC5teff9OD8l1AUf68Zioxo 3uJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="TDZr/IHU"; 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 f23si4096121eji.266.2019.10.05.02.16.52; Sat, 05 Oct 2019 02:16:52 -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="TDZr/IHU"; 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 S1727703AbfJEJQt (ORCPT + 27 others); Sat, 5 Oct 2019 05:16:49 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:37381 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJQs (ORCPT ); Sat, 5 Oct 2019 05:16:48 -0400 Received: by mail-qt1-f196.google.com with SMTP id l3so12198876qtr.4 for ; Sat, 05 Oct 2019 02:16:46 -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=6oKadehOfuqvchi0MOdyWhMtht9hVnMfKkag850zFWI=; b=TDZr/IHUGHDNGMgaV72PWvAvVyveRW1J40XKwUGE+N8oYAHUd9mhkLlu09mVxBJI7s GqbPNcNj/bRMrczIfnEdBFl3ybYNtf4bIgaClwcgeUX4Rb+QHAk20D3cp9dfWcwRr4kG 9D29taw93N0VDo+9tf5dkmzL+dwoq9dvXJFxUN/t/1uJo2zsTO7+CPGv7WbG03vos9Tk diUjMGTSVNEgULTFALrHjMVgz4+eBpTrb5jDNoE4AmMxZ0Ib4MuqucEfuuz0VvOlIic8 PgBJApbTEMADIMHR4mf+dGQtoPkcNhb+uI20FhXYRF6+837HLdLIRfuxm4v6ybJ/39qh 0Kmw== 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=6oKadehOfuqvchi0MOdyWhMtht9hVnMfKkag850zFWI=; b=fzzIEeMLi+QUKyp+510Og0dyTo1pB/S1mHochaoNAIytT1OLSbEcm7Ycmg7jBqPdkF yENS8nwPDPgOcFxG5Fh+nnajjOGlufyUh5zeiYR10FuGTCX41CTKmloyQYfucDAZEABV aDF3IYFByj2PZStWOQUEwj47isEQffwVdXn4x+vBpaHEVCBRL7eitSjB23Hkk7kX7pil GwYGhZSOk83mjXMQR3VrkIitEOmhf/HHbLSlxfGKpcocQAqbeHQAFlMnalYY9nCHbJv+ LFJklTNRYVPtjbiXLghKHeyd7TFcAKu8Wc+vXZvvX1H7HdsPUM468/Xx08/Q2ycOlgne knbw== X-Gm-Message-State: APjAAAXC+6q0/8cGP01v9r55FYy4nQdYrp2vb49pKIPGIIhNBIszTRX/ /GgHTSDCRCcuxorZzcAg4/YHAA== X-Received: by 2002:aed:31c6:: with SMTP id 64mr20419643qth.67.1570267005805; Sat, 05 Oct 2019 02:16:45 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:16:45 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Cc: Leo Yan Subject: [PATCH v3 2/6] perf cs-etm: Refactor instruction size handling Date: Sat, 5 Oct 2019 17:16:10 +0800 Message-Id: <20191005091614.11635-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-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 4bc2d9709d4f..58ceba7b91d5 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -918,6 +918,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 */ @@ -942,19 +962,15 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, const struct cs_etm_packet *packet, s64 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, @@ -1094,16 +1110,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 Sat Oct 5 09:16:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175263 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1790881ill; Sat, 5 Oct 2019 02:16:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGD/Bl+Jbbw2wYJhfkkMTFPit5lxVxlKpn7+X7AOd2Absbmp0TufVDghUeIcZcWif/HvSy X-Received: by 2002:a50:9fe5:: with SMTP id c92mr19620419edf.280.1570267019400; Sat, 05 Oct 2019 02:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267019; cv=none; d=google.com; s=arc-20160816; b=HxZeWRnBIP6DdyhV3IjwU5Shrnj5RCQgno4mtK9thSA2ew2mdU/BBSvnk+KiuyiuFB IwXWNZsq08kfab4uLGANNNTFUcvR7TqWfcTK0RqwYX42qNcS0i+i59DXn9pFxZt+vYSU xo09BvFk4NpIHOO8kRb62zaEoyWUTDRri6m9GyY8S9mQm8f/t8wbNFnWrP2eV1E7kgbB Nf1kaIyGjd+yZCWlG5kgoD6p16NCMCwhQsf5d4DNcyWhFvr2e/J18Z6baesuIYNDMklS LFRGnUF5INU27EAg8HpcVEEi6Xbu/wu704Uk+tvgjeBEfuBKj4MDYe7mz4J3xRjTjTED TeuA== 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=Cvyd7SHkhsAyUTNzK4HPFdW4gJjTTlJOoIIwpnVpIng=; b=cxPik9jOS72TgZTLXVIM4DxXUscd4absq/wc5wuxTodm5NIwey2fVmROggiGPjQcxq UZk+48tVc1pUfa+h5OuajMCY+jqrGqGLuH6Uhhbomui8+iVqay2HW+sXXNuxT5D8dtgz A/BTpSO8Zb7kwBevoRFlZ0NYbCZ3BdqgYYO4iB2NqxnLSQZmn2wpHYZh9hPGv1xyP54p YsGw1mGq1xDvrZDjESFmbpQ63E92JbZnykTSV2lUmPHnf99XHs+HVDr8HObvu1UYsolx +anWyZ7CzkDKRL2CI0Y4q98cZiUENDLVsCTp9Qc42XIWNDZGYT+E5N7xIdaAPDDiOHOB nCPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z5vT+rgz; 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 h15si4543774ejx.211.2019.10.05.02.16.59; Sat, 05 Oct 2019 02:16:59 -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=z5vT+rgz; 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 S1727735AbfJEJQz (ORCPT + 27 others); Sat, 5 Oct 2019 05:16:55 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:34819 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJQx (ORCPT ); Sat, 5 Oct 2019 05:16:53 -0400 Received: by mail-qk1-f195.google.com with SMTP id w2so8180650qkf.2 for ; Sat, 05 Oct 2019 02:16:52 -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=Cvyd7SHkhsAyUTNzK4HPFdW4gJjTTlJOoIIwpnVpIng=; b=z5vT+rgzkZPqTKKCurUgvEv1ooynkUFR/AQMCq+v6/Osi48scL/33NZN1iGSeO2Dj3 Pn4NTON6EroCgzngDc0FbriOnT+uSNYaa4TspMk58PI+BwMXS/IlTmsMs9AVwlYlzOUS 7QNaXX953LvpWa6PJqJvz51Nkn4cedIaP/S46Ho9LEIe3D+udB47yY3yCdh2NvnWn8UL YbScIKTKICmyHa26J/VoJ/dVo4Bh3OlCsj7im2WOhQYw1isOR6/Oorsd55zCZfEoplsr ebEQ/sej2qOtSm9rzHqxoEUhNf1+vsQEPwlfFWi+tp4cR2tXID58ShYh2kMFyovTesBR eS5w== 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=Cvyd7SHkhsAyUTNzK4HPFdW4gJjTTlJOoIIwpnVpIng=; b=Km/58bd/ak05vVQf67BrpTOjfX/VOu8RYwuA0P752BDX+ixtTIRXnfFD3yIZHEMFtj rcEiVE9aJDzDZovQYzDwAeETQ21P6D9N35hWU7u8znQdPBzFXp0YFlVg08kNsq8Zj5r5 zYrpqvudROAPuWk+D/qpzFZf1O293/yCRiaOS0c25XR0Uej6iOJ8La8M/mKmx9D6AAsu kB4REnbxT+nZxoYKfqKb+FgpkBLmEkWghxYhxCKscQJ4ptvPK5jkXAJqrhv26bctbopR 9X/Tf3imAlkSB/YFJc1iT05wIKgSDhHMu51t2vaeCw409z0qcBHl0ag6aG1ltRVGbrB1 cGww== X-Gm-Message-State: APjAAAWpJylkUrpubE2jqnwpZBqQDPAe8PUYTcbLaWSdgeveZgEuiXh/ p1MEExPnjIizSibp4ezfcHE8VjZ0BpY= X-Received: by 2002:ae9:f215:: with SMTP id m21mr14508170qkg.47.1570267011921; Sat, 05 Oct 2019 02:16:51 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:16:51 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Cc: Leo Yan Subject: [PATCH v3 3/6] perf cs-etm: Support thread stack Date: Sat, 5 Oct 2019 17:16:11 +0800 Message-Id: <20191005091614.11635-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since Arm CoreSight doesn't support thread stack, the decoding cannot display symbols with indented spaces to reflect the stack depth. This patch adds support thread stack for Arm CoreSight, this allows 'perf script' to display properly for 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 58ceba7b91d5..780abbfd1833 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1117,6 +1117,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) @@ -1393,6 +1432,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; @@ -2593,6 +2635,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 Sat Oct 5 09:16:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175264 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1790904ill; Sat, 5 Oct 2019 02:17:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVuCcW+9Dc5iBRtVnIMmX8fMLMOp+tHPyw9NjK4ckK5ndMo09/4j65xHjFJA64aIvoWlAT X-Received: by 2002:a17:906:8319:: with SMTP id j25mr16417047ejx.122.1570267021312; Sat, 05 Oct 2019 02:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267021; cv=none; d=google.com; s=arc-20160816; b=X+Pr9ncXHwVP755v3lttPsfFSTewLRs7/KIA+/XAghfVGG+2XaDGoO03Tg+FkZ65jE I8Mt9V0T8YVF70G8DjuyRlKQq052+Q4ZgE0fm9ykjD5Xj5qY4SrOIVTzS0ihYjGX/J6x B7IyVb8m8ie5DV+BsEEwlsRKdThm9hjLNNUAcqBO04ZO2Xl19wTaZVQXhoAafF2LwILo tqE19cxmPhwVcgKUAWiYVednKM3ztiq7y+vJr+UOyg75zvoPqTO7jxUf54JsFoqrXiM2 Ky5xGrbp3Ih3ko0mDIIXAevX3W4URTPdLHIyvaSkb98YqSOS1KkmdQxfsArqXs8b8j3Y LBzQ== 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=eKAXVWwQgPpjvwNZSw/jMr+jLfq8J9kO6B2NrEvZfHo=; b=x1UxbR6kNhxK1/ri/d4wSGiA0SjKHBHloE/qMjFKcE5y8CklxirX12tBb6j0oq9kwB rY21D6kzeRoEGOThEF5ZyPsj6Pg75ODlPserbBDRo/JSTukoYETOInsyxGykCEsFCKhd +A5zJ+zygl7sjO0YBP2u3gKK7LJYNIerxfUGxpUqASMeN67u1RENABv4vcFS/hKqr65V XLXVchM/eNrc425H0ZOP9YKB1J32LyHwwwg1Yw13uCJ/m8X3eZ/tcK15N/FJbMOCntu8 llDmiYRbER105uptVj5M3Hrlh3beR3ptO7pYoIs1yaN4PNrKGHM44VXaWGAGI+5M4HAN rJ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iK2pdsCd; 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 h15si4543774ejx.211.2019.10.05.02.17.01; Sat, 05 Oct 2019 02:17:01 -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=iK2pdsCd; 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 S1727787AbfJEJRA (ORCPT + 27 others); Sat, 5 Oct 2019 05:17:00 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:42686 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJQ6 (ORCPT ); Sat, 5 Oct 2019 05:16:58 -0400 Received: by mail-qk1-f193.google.com with SMTP id f16so8147889qkl.9 for ; Sat, 05 Oct 2019 02:16:58 -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=eKAXVWwQgPpjvwNZSw/jMr+jLfq8J9kO6B2NrEvZfHo=; b=iK2pdsCdWaOc1I0g+2fPqCFgiDMtjeHznV8u0RGoNSxR8r/zz+UYDQ0+NvkRupaUGl 3m76XCA2lDeeOinMME+ErfKvXxK2G8UHBsyoH/Fvz6ZfGk4lwVSoamSf1KBuCIuCOD+Z q2MqqEpomwpsiLrsTLEfpRF1HcHjXw9avjBNhTyTm4FhdFjo29aQv4ofZtb2acJtYf6a GWXNFhxPMhBT4Fp8Mo42tYkrsYvjNNUG9H80iO1vYqEey9Kk9CLgr5/Z3ELokdaKIicn ylgrNGAUUpkum2dx/jbMU+BD/S7TjVHZVT3v3CQGJM7D2N26oyS0i+AlXh8ZBOtErEtv hB4g== 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=eKAXVWwQgPpjvwNZSw/jMr+jLfq8J9kO6B2NrEvZfHo=; b=Yee7/4hpnT9iZf+K/Tv8yETmBUiyDEpRRGLGKAJ/q5XH4zgVYPMaiOAH5avXfPwsJw +afc/KtbejOoSZVnNNuC61g5GGA8xLK8jUnf8oPFmkgZQi+fFofbr/aWPAUFvBkgxyMj VO4z1XoeK7J5m1eEl16dmh779JSc3dys7zdqic0/hYRkL0AVTosgqdz17QPQs8K7FYJG tF9+pjTCxd19pI/BIl2uOyVi+cUKGhpdXKsPXNVMmsbRmbA/o7yXJR1nwEvm9z1K/bP/ nRXFJ2ZN4E3VMqYpcc+WH2E7N0J4BVVXaxIVQvTc6/WLbEhPiN6BklqnDTtVfEYNYDYy CrMQ== X-Gm-Message-State: APjAAAU1tlCFhJxIuaipXhgWsP0FtPiO5iRdQ8EPTsYr5EOTihUeAxuV zSddnAPM4Qxln7Xo7gahPKxRRg== X-Received: by 2002:a37:a612:: with SMTP id p18mr13816710qke.56.1570267017479; Sat, 05 Oct 2019 02:16:57 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:16:56 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Cc: Leo Yan Subject: [PATCH v3 4/6] perf cs-etm: Support branch filter Date: Sat, 5 Oct 2019 17:16:12 +0800 Message-Id: <20191005091614.11635-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-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 option '-F,+callindent' or call chain related options, it means users only care about function calls and returns; for these cases, it's pointless to generate samples for the branches within function. But unlike other hardware trace handling (e.g. Intel's pt or bts), Arm CoreSight doesn't filter branch types for these options and generate samples for all branches, this causes Perf to output many spurious blanks if the branch is not a function call or return. To only output 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 avoid to output other unnecessary blanks. 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 780abbfd1833..4b42f9c9bd34 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -56,6 +56,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; @@ -1223,6 +1224,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; @@ -2639,6 +2644,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 Sat Oct 5 09:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175265 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1791020ill; Sat, 5 Oct 2019 02:17:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7ZBXnH6RdpuP1io3kedZB1XGbuA82vN403h0WwfWF4eW5R3/aczu8ONy/uWFP0VKMxneb X-Received: by 2002:a50:be87:: with SMTP id b7mr19877993edk.37.1570267029893; Sat, 05 Oct 2019 02:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267029; cv=none; d=google.com; s=arc-20160816; b=idI172/wnO5W9ZoFtW/10ezahaIOGZ0yR212mQk/g7wMPuuBd0BspRLGWwZ2A7Hz0x c/53px01YYU4xoQdI1Uyhwq0VUN/vamaHr0ccTRA61RitXkmSnGhH7L/GDfZWnSCgipL R7ihAkQANh6Fb3QBOW6QuJqKRipX/VzonaW9mPifIHbqRY0nsJ3K8LYkkOpWFAoZSP0U +yMP9vt7CxvX0vh8tbeENsn9gEpbBeTr0WavCGw6dL/kMND6zsCyL/KtEkMjC2qZKN5A sZyQS4RvJzdfklplX/pRTIs09nIJUGt5Vf4IMU+icJtRuw9SETGqqeTMMWqMb84kbTmz 2QEA== 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=vKe+RbONBbtsSEscZalEdBXt7OSCg1h7S1CJqx/C4I8=; b=j4i/0JIPTjSzUnBInH98GT+sar08X6j3kXzSUvrTwu0RBJTNsMSGg7KOwb4HYpV8pw W+pnK7sExllPvDbw++1SVoJU4hUHDi9r3eUzOwJqnqs2HnZrzVBeHMhXW4/48R2AjyDc cp7HDnoJiqTgj8urn2oahJcijt9yB/00p9RgL0etGgWxWhEoywYf6mBzvxpZ2EM0RYad Q81AvwOSRMQQaMVYOY3J4Bv8eHviCY3rMxHyVFDo8oW9a8URc5s10Ig0vQK5jPyQSBw/ QpIAh8y/9wu5HQo/go6gjkogEdP+L1uN7gQHaazpP0AxWBTAjbtBxsD+c2TST0A8q93B Vpqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lm4kUtl9; 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 y27si5431412edd.249.2019.10.05.02.17.09; Sat, 05 Oct 2019 02:17:09 -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=Lm4kUtl9; 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 S1727839AbfJEJRG (ORCPT + 27 others); Sat, 5 Oct 2019 05:17:06 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33610 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJRE (ORCPT ); Sat, 5 Oct 2019 05:17:04 -0400 Received: by mail-qt1-f193.google.com with SMTP id r5so12215568qtd.0 for ; Sat, 05 Oct 2019 02:17:03 -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=vKe+RbONBbtsSEscZalEdBXt7OSCg1h7S1CJqx/C4I8=; b=Lm4kUtl9jA8j3ivLXcwP7K8BKLshypBI7RUHI3Xnzp7uCFEVJ3bgfDM7PRxQ2xRR1A V7kogDQ8J4+eAxu7HQnZr/qR/ksOvQx1SbfHz/seX56uN8psAmwiUNzX1L37RZEcECWP f+Xgbx030dGDRJIlBHVcsUUOCQFp3wp7uL1JG4hvgHgCp/CcQ1O7DjLD6YjjYwsz52CM sl3ILW23Qzqv/9LygkMFvn2N98i7cfWmhCY9qfgA56jTK6qdReAn7tZai08jasMpKUqh zHYeB9WQJlMFiz7EGV8RybsYir+NRZlUH25ythvFOq5FltlsayVh7HetjDT4momcDcKI BTpQ== 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=vKe+RbONBbtsSEscZalEdBXt7OSCg1h7S1CJqx/C4I8=; b=a8/K/RFNJeDciFUbHvBM5j4epfvInCXvv/rEnma/h0u3vZGsVPAhLpkokhMBuYbRt9 qB+6U//R6mi8JKfc+KrzI1LRIeU2Sxfc3MS58TjtVMAZasDRO8u5t6Ahh5qpmFlJ/Cqh Q9USNasIxJ90P7Jc9/BHFoXzNW4MKIR0iTL8IYdcxyMjYJVMrUNgtyWRHvxelm0+68Tk GmnBAQTjvI8OeZCH3TRbsl+nUNYCoYuwPTRRUtwZ9NNpxdYokxWaCFffc7N0mjfFUSVZ AqdFRD1GvsDONAJYJ6iZMGoeW5nd50wgDAomM0b/pgPdvlnkzPQag0YebNAMTEAY50Pv s7rQ== X-Gm-Message-State: APjAAAU1z/Ng2doMyMcSuuyPU4EyRT+VLFMdJSqeUEgdLMO/F8QBRFgP 173UkotDwRKUGlq0uwsyJ/lQtA== X-Received: by 2002:aed:22cc:: with SMTP id q12mr20936122qtc.232.1570267023107; Sat, 05 Oct 2019 02:17:03 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:17:02 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Cc: Leo Yan Subject: [PATCH v3 5/6] perf cs-etm: Support callchain for instruction sample Date: Sat, 5 Oct 2019 17:16:13 +0800 Message-Id: <20191005091614.11635-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now CoreSight has supported the thread stack; based on the thread stack we can synthesize call chain for the instruction sample; the call chain can be injected by 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 4b42f9c9bd34..56e501cd2f5f 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" @@ -74,6 +75,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; @@ -251,6 +253,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); @@ -275,6 +287,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; } @@ -546,6 +559,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); /* @@ -1126,7 +1140,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); @@ -1182,6 +1196,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; @@ -1369,6 +1391,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; @@ -2639,7 +2663,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; } @@ -2651,6 +2674,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 Sat Oct 5 09:16:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175266 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1791068ill; Sat, 5 Oct 2019 02:17:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwARwCrzgW1mORuqRtdfFEn15ACYQPIKAcBzYqccce8+BuxjPyh0ge5ySerzgmU1p2E3SaS X-Received: by 2002:a05:6402:1426:: with SMTP id c6mr20249937edx.53.1570267032837; Sat, 05 Oct 2019 02:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267032; cv=none; d=google.com; s=arc-20160816; b=qM9pDDTNSPqC7Oblg8M4KkCqQBLuuGcC04ukhJjj9nBRdmw63Xv5jsQGZiat8brzpq NrNsSHo8S/1AMJSdgVyyUXnrGhxW7j9QhkkUfvIWv0S79q6EfYmFD/Lp+KwJ6bbJfBR+ gK/2q8+VkB8RYXS2evuQLNt80vsP/A0pZPHedS04e5dEr1TJeDXK7f//DbZGCt0LW2bk Yip7/+EqVPszK4V0zMy5enl81ywcT5PwuxwQZTDY4KBCq4vPiJwPrwdYXXLOzAo+UbeE tXlYyKCZ7XdhgmUvgX8wp2ZNqdZkNeOcFLWEaPRpc/oSxlU+dgpD5VDnr6/DfTwIIwO4 dMjg== 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=MASENXtjvjrGt9RAiM0XMBiZxBBH7YBJCk7GCr7TS68=; b=q6nWsELredZ5MtWIwxc7lBiwGy7Sa5CO62lLur/af1W2mNyILgQVevqDv2eWydWO+i 9Ot1KJMqVcD8oV7ICS5ezYWYLTfFnRunIkFRIKdVF9KqpMPze9kpC9/Z23NqZtAL99g5 VQEyJOud/3f1SW4J3TxT83llnWfImCiowiDX/ZgabXMHh7F6ZqcLbJLDOasDEbp+dcfQ vdFqwDw91xR4QIxI2yOenWSKddOytHNhgA11MpJhVydWQ7qmRH43BHqcq0FEdbXuFs8O VMYHR1wRQ8Ab74otu86RFN3Z9PSyDHClvm6XbNriBx/11/T0KVLHohrOhFVbaIWY+ifT GI1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BOZAQaCt; 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 y27si5431412edd.249.2019.10.05.02.17.12; Sat, 05 Oct 2019 02:17:12 -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=BOZAQaCt; 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 S1727881AbfJEJRL (ORCPT + 27 others); Sat, 5 Oct 2019 05:17:11 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43081 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJRJ (ORCPT ); Sat, 5 Oct 2019 05:17:09 -0400 Received: by mail-qk1-f194.google.com with SMTP id h126so8143467qke.10 for ; Sat, 05 Oct 2019 02:17:09 -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=MASENXtjvjrGt9RAiM0XMBiZxBBH7YBJCk7GCr7TS68=; b=BOZAQaCtY3VPwH+2WpEjt6kSfv/nQ8w6QKgJreO5w8ha6Xch0n3Gz1CSS4U+u65pnF qjwyPDVvQd5HttZYsi6omNZiaPcmbInsUs9rDSDwQeDwKbbBAM547VNDrnk+HRFifbRI k2idWM85mMwtcLNM/GiWrYbEstXYFyFTGBIp7IPWVnyz2ItuUZdsWfftzgAolt81wQiV /zJq4O79Y7ezXfnqwNAG0SHpsI3FvqEh65vnZkG9GRW3B+o2zgFyNJRMKZo7k3Oz1YmV KwCc55v63Likpj+nSVG2NPQJmbDLO1HRr1afjRQnfKieML/oAJXkHTjNZOgwuM+5snrV UYSg== 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=MASENXtjvjrGt9RAiM0XMBiZxBBH7YBJCk7GCr7TS68=; b=X95iZvpuoF3cx+Qdlg6JPGhlhNYWZe6aUeu+MHvbnogaxqYWs2WvVPdFEp7ReOFtwI y+6jF+P3SiIzJJtx+ri6KaksupOwNs0zIg8yHnpiDjyYBRoeLDbx9a88drfLhH3B/2ae RazyKgBUTFWL6w17WsGZIobwq1lzTJuF9yrTlVLN0DraETPVMRMzT0I7NEKfoec2mFQc AUvDJys9Bf+WQ2PF6Hs369wXe4OZ0/+A/q3ynwHHl9TgbyyceU4BXejKSVofk5d6wFYl 8Fal3dYX37dsl+Yg1fOhHEmwr6bnWI4eKzg+T6V0d3YF9yVKkVopR1fXwh0PdcPN3bD1 jyHg== X-Gm-Message-State: APjAAAVG4cRpjhl39lM0LZBQS1gwiFnIHPCIMIzjpZuk5utF4YfPUPVx wpOILeX1vET+l3mPRh2oRjKZug== X-Received: by 2002:a37:4e48:: with SMTP id c69mr14232654qkb.182.1570267028692; Sat, 05 Oct 2019 02:17:08 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:17:08 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Cc: Leo Yan Subject: [PATCH v3 6/6] perf cs-etm: Synchronize instruction sample with the thread stack Date: Sat, 5 Oct 2019 17:16:14 +0800 Message-Id: <20191005091614.11635-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-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; on the other hand, 'tidp->prev_packet' is used to generate the thread stack and the branch samples, this results in the instruction samples using one packet ahead than thread stack and branch samples ('tidp->prev_packet' vs 'tidq->packet'). 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. So the first two lines are: 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 the new packet and misses to pop stack if it is just 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 can be displayed correctly 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 56e501cd2f5f..fa969dcb45d2 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1419,7 +1419,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; @@ -1450,7 +1450,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, */ s64 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);