Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp184525imm; Mon, 21 May 2018 04:29:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqQ6clH4tFTTtgjzoxMuJdebDLcNugw0jHOyaCQyL/NOpW24vXjodfYcpD4BzeJuOTvZAg4 X-Received: by 2002:a62:7682:: with SMTP id r124-v6mr19598802pfc.80.1526902146219; Mon, 21 May 2018 04:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526902146; cv=none; d=google.com; s=arc-20160816; b=SjJRxA2y1u/6pSmmKxnGD7wuul1TtTGGHDcTY3lSsQp5Lm4HuXTCDYXke9XmseOcrj ZPum0gz4z/4MNAirrPnSeQk1oZNVO4DTr+B/ETbpp8m9lVSxyqo1pWqVQNykP0bzDXCY l4QE59afwQ2CpTlFF6ZjByc0QlD8Gjo7IYGgBjhbbTaU4ARqtj0YtRV6aj8cg0cI7QLP W8j19p1jSCenUNTRztYQw7bw3+nQNuB3/19uo+t7NSe5T34ctMX0lRRvQczTuMz1K3IF dz2y6/XgWpxee74CDHWC2upg1kNZSsyTDTYslvI6ENJ/cPN7tqnPVXEElWPe3gusKYFu dUvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=IP1UbwjPOi/qCLkO5QetGsT10bDwB8i6w9FhhC84hxw=; b=Js7wOjffVQAoTkW+DbNMqvRo13icW1x5BO1yUkSOJCQj2Z0fLaH99ikcbQs+KlgWT/ JAN6mVHu5np+97MEPZqVqOwaR1O5dozw9hsyIf+PQ9AlLSUPo0CtFhuKplp9fIciMA9O aMPdwMDMsojiGL30Au9xvVX2T/B+xm+9MoYlLUc0jfcdODTV68DgtkWiW/pzyYdwXmO5 6OuY+uAFaC6XLJe7jGZtesbfvBXUl7WPGjT1qVgRBmI7ozrA3FmVKYCdDLY42M0LFppP EsLiQW5G6hIIqScBA/u4Oc/b9muxBslVqFtomRtk1pSGMOL9fN9EYJp2Tt2BIlykxnib S+PQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1-v6si11077264pgo.637.2018.05.21.04.28.51; Mon, 21 May 2018 04:29:06 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751166AbeEUL2S (ORCPT + 99 others); Mon, 21 May 2018 07:28:18 -0400 Received: from foss.arm.com ([217.140.101.70]:47390 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753147AbeEUL2L (ORCPT ); Mon, 21 May 2018 07:28:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 400CF1435; Mon, 21 May 2018 04:28:11 -0700 (PDT) Received: from [10.33.0.150] (e111474-lin.blackburn.arm.com [10.33.0.150]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DBCF53F25D; Mon, 21 May 2018 04:28:07 -0700 (PDT) Subject: Re: [RFT v2 1/4] perf cs-etm: Generate sample for missed packets To: Leo Yan , Arnaldo Carvalho de Melo , Mathieu Poirier , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Tor Jeremiassen , mike.leach@linaro.org, kim.phillips@arm.com, coresight@lists.linaro.org Cc: Mike Leach References: <1526892748-326-1-git-send-email-leo.yan@linaro.org> <1526892748-326-2-git-send-email-leo.yan@linaro.org> From: Robert Walker Message-ID: Date: Mon, 21 May 2018 12:27:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1526892748-326-2-git-send-email-leo.yan@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Leo, On 21/05/18 09:52, Leo Yan wrote: > Commit e573e978fb12 ("perf cs-etm: Inject capabilitity for CoreSight > traces") reworks the samples generation flow from CoreSight trace to > match the correct format so Perf report tool can display the samples > properly. But the change has side effect for packet handling, it only > generate samples when 'prev_packet->last_instr_taken_branch' is true, > this results in the start tracing packet and exception packets are > dropped. > > This patch checks extra two conditions for complete samples: > > - If 'prev_packet->sample_type' is zero we can use this condition to > get to know this is the start tracing packet; for this case, the start > packet's end_addr is zero as well so we need to handle it in the > function cs_etm__last_executed_instr(); > I think you also need to add something in to handle discontinuities in trace - for example it is possible to configure the ETM to only trace execution in specific code regions or to trace a few cycles every so often. In these cases, prev_packet->sample_type will not be zero, but whatever the previous packet was. You will get a CS_ETM_TRACE_ON packet in such cases, generated by an I_TRACE_ON element in the trace stream. You also get this on exception return. However, you should also keep the test for prev_packet->sample_type == 0 as you may not see a CS_ETM_TRACE_ON when decoding a buffer that has wrapped. Regards Rob > - If 'prev_packet->exc' is true, we can know the previous packet is > exception handling packet so need to generate sample for exception > flow. > > Fixes: e573e978fb12 ("perf cs-etm: Inject capabilitity for CoreSight traces") > Cc: Mike Leach > Cc: Robert Walker > Cc: Mathieu Poirier > Signed-off-by: Leo Yan > --- > tools/perf/util/cs-etm.c | 35 ++++++++++++++++++++++++++++------- > 1 file changed, 28 insertions(+), 7 deletions(-) > > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c > index 822ba91..378953b 100644 > --- a/tools/perf/util/cs-etm.c > +++ b/tools/perf/util/cs-etm.c > @@ -495,6 +495,13 @@ static inline void cs_etm__reset_last_branch_rb(struct cs_etm_queue *etmq) > static inline u64 cs_etm__last_executed_instr(struct cs_etm_packet *packet) > { > /* > + * The packet is the start tracing packet if the end_addr is zero, > + * returns 0 for this case. > + */ > + if (!packet->end_addr) > + return 0; > + > + /* > * The packet records the execution range with an exclusive end address > * > * A64 instructions are constant size, so the last executed > @@ -897,13 +904,27 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) > etmq->period_instructions = instrs_over; > } > > - if (etm->sample_branches && > - etmq->prev_packet && > - etmq->prev_packet->sample_type == CS_ETM_RANGE && > - etmq->prev_packet->last_instr_taken_branch) { > - ret = cs_etm__synth_branch_sample(etmq); > - if (ret) > - return ret; > + if (etm->sample_branches && etmq->prev_packet) { > + bool generate_sample = false; > + > + /* Generate sample for start tracing packet */ > + if (etmq->prev_packet->sample_type == 0) > + generate_sample = true; > + > + /* Generate sample for exception packet */ > + if (etmq->prev_packet->exc == true) > + generate_sample = true; > + > + /* Generate sample for normal branch packet */ > + if (etmq->prev_packet->sample_type == CS_ETM_RANGE && > + etmq->prev_packet->last_instr_taken_branch) > + generate_sample = true; > + > + if (generate_sample) { > + ret = cs_etm__synth_branch_sample(etmq); > + if (ret) > + return ret; > + } > } > > if (etm->sample_branches || etm->synth_opts.last_branch) { >