Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3216206ybl; Sun, 2 Feb 2020 17:54:42 -0800 (PST) X-Google-Smtp-Source: APXvYqyCYnCYx+hJLJmUqfhIrQrcj50Btg95J4XUk1Zf7PHQ4Bu+5C4wVlTA++wYRY7YNJPTbI3b X-Received: by 2002:a05:6830:1251:: with SMTP id s17mr16138498otp.108.1580694882512; Sun, 02 Feb 2020 17:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580694882; cv=none; d=google.com; s=arc-20160816; b=Wn1y7Qf7uiCwv1PePAYYp5bTQLr+A+wDx//mFStycPCaM2LvrdY/ZUVWU2efzPIJRP kKYYh5a0YXtHLvDaQYVmw+7lU50v+TEv1iFjqPYs2I12qDo/GeEzs0m43AU10i5RXnxq V+9ZZ+okPCkWZeac2D/dYT14OvESYmmj0GdcOLMXTeVPpM58VA0ug8kEJMOw2M7LA1IW ftKbb5qaHhB7gWBdeBzI9Y0qZqJ3jTFE4Hy6v6zHYtHCrp/LSnExh18+o2t0gHSFoBDM ov1w7vQtzGOdYnYMhmwqdN03Gxz0pCxDH+IhcJim7Zi7acrZmyh0v0E0ajzQDYjW60fw 3Sdg== 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=ovSiMu6eDg8baSn4QabjoCI5Td3xLx7krHbZCycw6hU=; b=zH7OABh72KVswXna+0Ap1uXibd76wSNGTmuIJr/fwmJMVzJThrvcKWijnHYS1E0GsY BvFeZicED5zfa++cUlr55Y62wWG7NHGR08TIF1Z69Z2vOMIKZch9mVNfNLo1lo1AP5Vn pIq9LXqGjEXBphlgBMsRsBg7yQLYv0upQhJf9cczdLOt2787MWd4IXhciCTdVR8n4TQ/ W24TymWYDrJiGLLZ2CmmKqiGIChh2oUMlwFU5wAuMv1NA3GJJB6O4Z11jT2t2/Jt39Du Ih9G2+sQXBpTY10dVwab7Mek6ZbF8pkGBkeRbvdaZPHpgf00+3WSJwK7X03yx25nnar8 9AFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eO3E7ihU; 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 l5si8598652otf.37.2020.02.02.17.54.31; Sun, 02 Feb 2020 17:54:42 -0800 (PST) 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=eO3E7ihU; 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 S1727202AbgBCBxF (ORCPT + 99 others); Sun, 2 Feb 2020 20:53:05 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46503 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbgBCBxF (ORCPT ); Sun, 2 Feb 2020 20:53:05 -0500 Received: by mail-pg1-f193.google.com with SMTP id z124so6917226pgb.13 for ; Sun, 02 Feb 2020 17:53:04 -0800 (PST) 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=ovSiMu6eDg8baSn4QabjoCI5Td3xLx7krHbZCycw6hU=; b=eO3E7ihUXPiMjX8jGUakX3FEHjLd2ZMiVPSuyOuH5f9C5BIMM76Prjrie2GEQAeQzr zfWwdrs8YnD4mEdB9cDpPd3bwTDSmwm6lZjin8ULJ94omHChZLlFTdFOWqYlmebYpdHz vG768/8ONU5r1nsx01y3DfoStJ5nrpL+2fK4hEpWITgM0lCIygkPh65bcTMkRhaSnYkY cH8FtUcSyTQzCoE1CZkPhDQvnWMk0F3uSEI1Q7S6HK/sq5C2zRfqO/0BpLI8CSak73Nl kqMjxtdvzzr5HTbttXtdNrUJ3bAkeb+u2jnmnxH9KkmSTVU4+V69aejkzAjMhFAlDqdt CIsw== 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=ovSiMu6eDg8baSn4QabjoCI5Td3xLx7krHbZCycw6hU=; b=RKKBCpb+YqPmqHM6rkLbHB7pgZAyBEhx/IdooiKClzpMH6rVzkQslXmPdkttiJcAI2 Int3K2ppz4REalf/MCPKflvzhxq02fEirkw8NFwkZR136X0rUBAG9ZMP6th10znq+g5s k+WuaBoTi605PU8HZUkx7T9Yz7dIXD6xWeHAavQqfff9153cVRThqhsh7TyubleHziTG 2FtTi6diq4YwYBK6AsmcbyJydGCTVJkY4tVPjrlA8pLwrKxpyEgBQIk0lgQEf0gMx3GR 8eSirNrJDVrxP21vF8WZ81Gsj87Znm+dsgY3zotFENltBgGuMP0mw7mq2f4lKbOXa5uQ m08w== X-Gm-Message-State: APjAAAUac18qc+UGfp+YWPr+LftlK2Gqt+NCLWBsnTm7lX/3HN1n3RRZ v0BFC5VpuJrW8WaByNwn0QDSfg== X-Received: by 2002:a63:fe43:: with SMTP id x3mr23657136pgj.119.1580694784305; Sun, 02 Feb 2020 17:53:04 -0800 (PST) Received: from localhost.localdomain (li1441-214.members.linode.com. [45.118.134.214]) by smtp.gmail.com with ESMTPSA id y38sm17348308pgk.33.2020.02.02.17.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2020 17:53:03 -0800 (PST) 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 , Robert Walker , Coresight ML Cc: Leo Yan Subject: [PATCH v3 4/5] perf cs-etm: Optimize copying last branches Date: Mon, 3 Feb 2020 09:52:02 +0800 Message-Id: <20200203015203.27882-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200203015203.27882-1-leo.yan@linaro.org> References: <20200203015203.27882-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 an instruction range packet can generate multiple instruction samples, these samples share the same last branches; it's not necessary to copy the same last branches repeatedly for these samples within the same packet. This patch moves out the last branches copying from function cs_etm__synth_instruction_sample(), and execute it prior to generating instruction samples. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index c5a05f728eac..dbddf1eec2be 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1134,10 +1134,8 @@ 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.last_branch) { - cs_etm__copy_last_branch_rb(etmq, tidq); + if (etm->synth_opts.last_branch) sample.branch_stack = tidq->last_branch; - } if (etm->synth_opts.inject) { ret = cs_etm__inject_event(event, &sample, @@ -1407,6 +1405,10 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, */ u64 instrs_over = instrs_executed; + /* Prepare last branches for instruction sample */ + if (etm->synth_opts.last_branch) + cs_etm__copy_last_branch_rb(etmq, tidq); + /* * 'head' is the instructions number of the head in the new * packet, it combines with the tail of previous packet to @@ -1526,6 +1528,11 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, if (etmq->etm->synth_opts.last_branch && tidq->prev_packet->sample_type == CS_ETM_RANGE) { + u64 addr; + + /* Prepare last branches for instruction sample */ + cs_etm__copy_last_branch_rb(etmq, tidq); + /* * Generate a last branch event for the branches left in the * circular buffer at the end of the trace. @@ -1533,7 +1540,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, * Use the address of the end of the last reported execution * range */ - u64 addr = cs_etm__last_executed_instr(tidq->prev_packet); + addr = cs_etm__last_executed_instr(tidq->prev_packet); err = cs_etm__synth_instruction_sample( etmq, tidq, addr, @@ -1587,11 +1594,16 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq, */ if (etmq->etm->synth_opts.last_branch && tidq->prev_packet->sample_type == CS_ETM_RANGE) { + u64 addr; + + /* Prepare last branches for instruction sample */ + cs_etm__copy_last_branch_rb(etmq, tidq); + /* * Use the address of the end of the last reported execution * range. */ - u64 addr = cs_etm__last_executed_instr(tidq->prev_packet); + addr = cs_etm__last_executed_instr(tidq->prev_packet); err = cs_etm__synth_instruction_sample( etmq, tidq, addr, -- 2.17.1