From patchwork Tue May 22 08:39:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10417629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C870360224 for ; Tue, 22 May 2018 08:40:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD23328B74 for ; Tue, 22 May 2018 08:40:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DDD728B7A; Tue, 22 May 2018 08:40:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CAB0228B74 for ; Tue, 22 May 2018 08:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/lqOjoO/h124JmdWr7N+ZnLH/7pvl7ilQ/MME+Yx8EU=; b=XGLq4vGK/iyNO5 FrXqlf0JHiFG+TJ5m7GLC4LOVeX5SgfpgLsig9RZhBCEHf/2HbAbl/zf4F/m6OcBI8MrXaZMDkppz Mg2GYLiItLu32yLflqjJnk+5lG/ZXacXSFzge7I3GkP1/sL1FvpAaLd9F5EIb95mAaJRcgejv7bR0 YLZQcaED0c98YxjVqdA84qNAsMX+k6fRF9+68fvz66OQJpt2VN0ciVVtQ/ci/uUZFGj8+gLFsNdBo v3QArPq7L9qi2rc9qa861bcdLPLA65mlt+mbBGGll1o6wqytDsQCahkUBbVuecN2HaY1fB/VwiN0X eMpd8rpZ3ohZZGa5WJog==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fL2ph-0007S1-SB; Tue, 22 May 2018 08:39:49 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fL2pd-0007Fk-NM for linux-arm-kernel@lists.infradead.org; Tue, 22 May 2018 08:39:47 +0000 Received: by mail-pg0-x243.google.com with SMTP id p8-v6so7548363pgq.10 for ; Tue, 22 May 2018 01:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=kAUwDb0EkBkcp4j9Xj3XkPMa1zxX5DcL2CzrAbGqey4=; b=LN0R4UOouE46Vmjh5QI556F27x+k2InaQfA4yqayDiDhPOdmCxxqyZUjWlVkGVV/lG 3efPP3qNQaaQwdirbo8kLkiNLDkCTgoI/6Nu40E9Cm6Vwi+IwnYRVBIxqcELndz2YxNo X/EO1TFQztA7JrV0qx+bvRJNDR8BzGat8N1fM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kAUwDb0EkBkcp4j9Xj3XkPMa1zxX5DcL2CzrAbGqey4=; b=Mux2wuhXRZod8nn11tYyIbJfJwFY2GNvYQdph+q5EsULqO0rOvMQNwTiK4tDFHC8O5 3mK+dov4uKdKdRgd9pkfNeyUsbR2x8ALDS3+sUNRi1V/9t2PM9iJENopJPuhuJitQCDo quNyqeIy6Hw9DkYTBao+cClqbLPLGWhBKtJpsW5hmYrb2ZFncreN1oVuzvrSY4O3omc6 QJKSU6IdnURYVBmIjZFUpy3fiE8Opd8K3Bem0ovp6lG3DRVmDMkaG6W7QMbualYcbgpR 8tfpOyPrQ4kCdBo9NaDiW2040bLuEmfUob9TC/nCohi8GR5nW2a7ubArDPvmCynHD3AQ 4uGQ== X-Gm-Message-State: ALKqPweoVR+0bwwxGfFTeq+EqW2Nj+fNodoCjtoKsgg+9KH/YHnVj1sH 3vy+3gE9XgNnp2c05g9uVEbMxA== X-Google-Smtp-Source: AB8JxZoYB00SGFI2rmRSc6LaaMXz1v6k29UBgqtcc340aEOQoBGdJICxmZH6FBFzFZ95uerlj97TBA== X-Received: by 2002:a65:4502:: with SMTP id n2-v6mr17875951pgq.95.1526978373815; Tue, 22 May 2018 01:39:33 -0700 (PDT) Received: from leoy-ThinkPad-X240s (li1170-132.members.linode.com. [45.79.71.132]) by smtp.gmail.com with ESMTPSA id z25-v6sm32018142pfi.171.2018.05.22.01.39.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 01:39:32 -0700 (PDT) Date: Tue, 22 May 2018 16:39:20 +0800 From: Leo Yan To: Robert Walker Subject: Re: [RFT v2 1/4] perf cs-etm: Generate sample for missed packets Message-ID: <20180522083920.GD31075@leoy-ThinkPad-X240s> References: <1526892748-326-1-git-send-email-leo.yan@linaro.org> <1526892748-326-2-git-send-email-leo.yan@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180522_013945_779545_3207138E X-CRM114-Status: GOOD ( 35.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kim.phillips@arm.com, Mathieu Poirier , Jonathan Corbet , Peter Zijlstra , coresight@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Tor Jeremiassen , Alexander Shishkin , Ingo Molnar , Mike Leach , Namhyung Kim , Jiri Olsa , linux-arm-kernel@lists.infradead.org, mike.leach@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Rob, On Mon, May 21, 2018 at 12:27:42PM +0100, Robert Walker wrote: > 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. Thanks for reviewing. Let's dig more detailed into this issue, especially for handling packet CS_ETM_TRACE_ON, I'd like divide into two sub cases. - The first case is for using python script: I use python script to analyze packets with below command: ./perf script --itrace=ril128 -s arm-cs-trace-disasm.py -F cpu,event,ip,addr,sym -- -v -d objdump -k ./vmlinux What I observe is after we pass python script with parameter '-s arm-cs-trace-disasm.py', then instruction tracing options '--itrace=ril128' isn't really used; the perf tool creates another new process for launch python script and re-enter cmd_script() function, but at the second time when invoke cmd_script() for python script execution the option '--itrace=ril128' is dropped and all parameters are only valid defined by the python script. As result, I can the variable 'etmq->etm->synth_opts.last_branch' is always FALSE for running python script. So all CS_ETM_TRACE_ON packets will be ignored in the function cs_etm__flush(). Even the CS_ETM_TRACE_ON packets are missed to handle, the program flow still can work well. The reason is without the interference by CS_ETM_TRACE_ON, the CS_ETM_RANGE packets can smoothly create instruction range by ignore the middle CS_ETM_TRACE_ON packet. Please see below example, in this example there have 3 packets, the first one packet is CS_ETM_RANGE packet which is labelled with 'PACKET_1', the first one packet can properly generate branch sample data with previous packet as expected; the second packet is PACKET_2 which is CS_ETM_TRACE_ON, but 'etmq->etm->synth_opts.last_branch' is false so function cs_etm__flush() doesn't handle it and skip the swap operation "etmq->prev_packet = tmp"; the third packet is PACKET_3, which is CS_ETM_RANGE packet and we can see it's smoontly to create continous instruction range between PACKET_1 and PACKET_3. cs_etm__sample: prev_packet: sample_type=1 exc=0 exc_ret=0 cpu=1 start_addr=0xffff000008a5f79c end_addr=0xffff000008a5f7bc last_instr_taken_branch=1 PACKET_1: cs_etm__sample: packet: sample_type=1 exc=0 exc_ret=0 cpu=1 start_addr=0xffff000008a5f858 end_addr=0xffff000008a5f864 last_instr_taken_branch=1 cs_etm__synth_branch_sample: ip=0xffff000008a5f7b8 addr=0xffff000008a5f858 pid=2290 tid=2290 id=1000000021 stream_id=1000000021 period=1 cpu=1 flags=0 cpumode=2 cs_etm__flush: prev_packet: sample_type=1 exc=0 exc_ret=0 cpu=1 start_addr=0xffff000008a5f858 end_addr=0xffff000008a5f864 last_instr_taken_branch=1 PACKET_2: cs_etm__flush: packet: sample_type=2 exc=0 exc_ret=0 cpu=2 start_addr=0xdeadbeefdeadbeef end_addr=0xdeadbeefdeadbeef last_instr_taken_branch=1 cs_etm__sample: prev_packet: sample_type=1 exc=0 exc_ret=0 cpu=1 start_addr=0xffff000008a5f858 end_addr=0xffff000008a5f864 last_instr_taken_branch=1 PACKET_3: cs_etm__sample: packet: sample_type=1 exc=0 exc_ret=0 cpu=2 start_addr=0xffff000008be7528 end_addr=0xffff000008be7538 last_instr_taken_branch=1 cs_etm__synth_branch_sample: ip=0xffff000008a5f860 addr=0xffff000008be7528 pid=2290 tid=2290 id=1000000021 stream_id=1000000021 period=1 cpu=2 flags=0 cpumode=2 So seems to me, the CS_ETM_TRACE_ON packet doesn't introduce trouble for the program flow analysis if we can handle all CS_ETM_RANGE packets and without handling CS_ETM_TRACE_ON packet for branch samples. - The second case is for --itrace option without python script: ./perf script --itrace=ril -F cpu,event,ip,addr,sym -k ./vmlinux In this case, the flag 'etmq->etm->synth_opts.last_branch' is true so CS_ETM_TRACE_ON packet will be handled; but I can observe the CS_ETM_RANGE packet in etmq->prev_packet isn't handled in the function cs_etm__flush() for branch sample, so actually we miss some branch sample for this case. So I think we also need handle CS_ETM_RANGE packet in function cs_etm__flush() to generate branch samples. But this has side effect, we introduce the extra track for CS_ETM_TRACE_ON packet for branch samples, so we will see one branch range like: [ 0xdeadbeefdeadbeef .. 0xdeadbeefdeadbeef ]. Please reivew below change is okay for you? Thanks a lot for suggestions. Reviewed-by: Robert Walker diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 822ba91..37d3722 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,28 @@ 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 || + etmq->prev_packet->sample_type == CS_ETM_TRACE_ON) + 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) { @@ -921,12 +943,17 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) static int cs_etm__flush(struct cs_etm_queue *etmq) { + struct cs_etm_auxtrace *etm = etmq->etm; int err = 0; struct cs_etm_packet *tmp; - if (etmq->etm->synth_opts.last_branch && - etmq->prev_packet && - etmq->prev_packet->sample_type == CS_ETM_RANGE) { + if (!etmq->prev_packet) + return 0; + + if (etmq->prev_packet->sample_type != CS_ETM_RANGE) + return 0; + + if (etmq->etm->synth_opts.last_branch) { /* * Generate a last branch event for the branches left in the * circular buffer at the end of the trace. @@ -939,18 +966,25 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) err = cs_etm__synth_instruction_sample( etmq, addr, etmq->period_instructions); + if (err) + return err; etmq->period_instructions = 0; + } - /* - * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for - * the next incoming packet. - */ - tmp = etmq->packet; - etmq->packet = etmq->prev_packet; - etmq->prev_packet = tmp; + if (etm->sample_branches) { + err = cs_etm__synth_branch_sample(etmq); + if (err) + return err; } - return err; + /* + * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for + * the next incoming packet. + */ + tmp = etmq->packet; + etmq->packet = etmq->prev_packet; + etmq->prev_packet = tmp; + return 0; } static int cs_etm__run_decoder(struct cs_etm_queue *etmq)