Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp359016ybv; Thu, 13 Feb 2020 01:44:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyLnJ9T3HrUgBAiwPfpYDp2EuKJH9vot38FSue891mjAhu+FAPU89TG8LdphITJRUk/rVjF X-Received: by 2002:a9d:6d1a:: with SMTP id o26mr12192983otp.141.1581587046110; Thu, 13 Feb 2020 01:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581587046; cv=none; d=google.com; s=arc-20160816; b=i2fay3dQJ1VFac7NjeisB0zB4uRBl3WR2C803a55PtnoVk9xJADJYKb88fB39Yv+Kk waU0crUo573GZ+NcF6gRPaYBD0TfYgWczjiNKEy+y6TJvdJ143CD2paenusMornqE0DX 7FTHvZgHPxRLrcbhdgDeBo/5T2Xw1ectCSYn6z+YWTyDB/x3SYV5kUBs/gMZcppAtLLf NJsYQXyVsmA5iXI0Vf6TzOj4rTRuPnctRNZ+aHlxppwwgIkLmfgY6wR/eXITsfuPbkWw CDIRyyy+7UjCWAdJXih2crLi2uT14pd9dpgMaq813A+8Rr/9mE6fqy2hu6Iu6dVb4hea 9K1Q== 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=OCgHNqEUlfiCJzRowkU7/269i7iDkpUPlf4f9JcwX54=; b=fCxnacGD0AadQnO8Pgoc4QRd8qIlHYZxfO7e5yFmugMgZKrc2AJnmcCeQTUfufS7tz TVvZjIY1/FgCql/FyfIVPe+qwUw7ZqY656CUN+xFthK80dRuMZlL/miPfwEJAufhLkAk JqT2WYvKCC85p4vvCuuIFn/kgx+jiylFVBLUVQS9fktzIjKVFwd1de7GbwNjFzp6ml1b UBcH+shVUm3Zr/W/oiOPdQ1tgzshQC6gmfjDdc267Bm4+rLNJbk7udgX5AL08RvEq0P6 HoYO53GzVyEbACJlLZbbHZ/C3iPVQiKwhKMLKOvkw+tRFR1FfdPHvAERmXgU5eBnq7EK Rh4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kkzyE0jY; 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 z18si920850oti.219.2020.02.13.01.43.53; Thu, 13 Feb 2020 01:44:06 -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=kkzyE0jY; 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 S1729841AbgBMJnS (ORCPT + 99 others); Thu, 13 Feb 2020 04:43:18 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40337 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbgBMJnS (ORCPT ); Thu, 13 Feb 2020 04:43:18 -0500 Received: by mail-pl1-f195.google.com with SMTP id y1so2128232plp.7 for ; Thu, 13 Feb 2020 01:43:18 -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=OCgHNqEUlfiCJzRowkU7/269i7iDkpUPlf4f9JcwX54=; b=kkzyE0jY2khCQPlvgDr0BgfcRujUSFX5dZAjHWoqtnTf9tfmslHRD5+kx3P4lpHdWh 9fwqsBbM3K+5y5HDae6Jy51sKEujHwtg2xm4CAMWS5IZ78Z45RuKrV1B1MRQ6FqoSItf mCfj5b+XGm1FILjyvmo3A27/eRmji2hPDkOwoodBTX3tmnLDNexmL9/pWVNrgXwtLYqr dBe19jEFJ0WLUb2lqOndNZ0wQ/xQvZl+SN0IeH64jFjzBy2vr6NIOb0ZCdkUskpylLCd 4NYWTKYwc5SuOsDTmyviRsazg3r5n/mdpVz9ratijaWBvc8HdeXw4Ymbo2jMwCt1FSdC cJpg== 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=OCgHNqEUlfiCJzRowkU7/269i7iDkpUPlf4f9JcwX54=; b=jXNncfGBZSaFF0gvOHTtJYcCXK0qv/WHJe/9bWUhq7DzhM1kzUav23ctmRg+ZsfgsU dBIikaEK0GildbiBEqT4+ksmwY/hzKZIAK0GIeC1tgNxEKXnGfmmg+FRKI2SAgPsiVCT lngCIU/5kjniWHVpjloUmoXeCjEhXGNeNlJWxQu+DPcPPxwCmRvr0+mlL44cMVPN/Nbc spYx2QT1u8+TqzSO7QFpK4pTEfJ2K6ek8dgyYDH43XTpOCTvOALJOXw3yfcM5XDEPwVN I7UOwMyGx96qSWbcN7NJzki1FxZgguKya59/qTqA6n0I850/mgBAUa6CoQABrqzwEXzd PS2Q== X-Gm-Message-State: APjAAAW4+JYukFNWEWawT0Y0dcVehwtR8sjksV5X/O6tRG/d2e5TVXCL Gpjif/Eb9SOqIBXNBh+Q6+8U9A== X-Received: by 2002:a17:902:bd88:: with SMTP id q8mr26284888pls.13.1581586997887; Thu, 13 Feb 2020 01:43:17 -0800 (PST) Received: from localhost.localdomain (li1441-214.members.linode.com. [45.118.134.214]) by smtp.gmail.com with ESMTPSA id 3sm2310277pfi.13.2020.02.13.01.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 01:43:17 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Robert Walker , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan Subject: [PATCH v4 4/5] perf cs-etm: Optimize copying last branches Date: Thu, 13 Feb 2020 17:42:03 +0800 Message-Id: <20200213094204.2568-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200213094204.2568-1-leo.yan@linaro.org> References: <20200213094204.2568-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 Reviewed-by: Mike Leach --- 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 4b7d6c36ce3c..aa4b6d060ebb 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1151,10 +1151,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, @@ -1429,6 +1427,10 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, u64 offset = etm->instructions_sample_period - instrs_prev; u64 addr; + /* Prepare last branches for instruction sample */ + if (etm->synth_opts.last_branch) + cs_etm__copy_last_branch_rb(etmq, tidq); + while (tidq->period_instructions >= etm->instructions_sample_period) { /* @@ -1506,6 +1508,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. @@ -1513,7 +1520,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, @@ -1558,11 +1565,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