From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.6 required=5.0 tests=DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id A87017D085 for ; Wed, 30 May 2018 15:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932113AbeE3Ptr (ORCPT ); Wed, 30 May 2018 11:49:47 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37219 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932110AbeE3Ptm (ORCPT ); Wed, 30 May 2018 11:49:42 -0400 Received: by mail-wr0-f193.google.com with SMTP id i12-v6so30065113wrc.4 for ; Wed, 30 May 2018 08:49:41 -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=BL9FDjS/lmGf0iw6TOwNx7sOazTEHLXdlKIjaLqtkg8=; b=ZsdcXLeIRKmjORiLwkQXhZ3cpVbtVuFumXWCiAU3mlMxMq1qT9ZSp703BNwKa3Qac3 eDanLdjTWBkuJBwe2AR1LSgmi8CUGSTXB3TpD3VTOm6C2lEf2/dx0BIhARXSmgZFBAv8 U0Qfn62XaVuW6Tn7KcYiNI7J5epv1fH0E8Cvc= 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=BL9FDjS/lmGf0iw6TOwNx7sOazTEHLXdlKIjaLqtkg8=; b=qUUdgumJ9RrxUtNxdgLY9XAb+DHd58wRpQOkw/lhczXI79Xardmk98n5IaeFP9Acf9 4EIhLLF1vtRkAY25Vbyj1k4pjva+zAlts1XnkbnFnjJuUACULM+2N9EuJOkE3xuXI52Y PnDJsBWoEtMuhVBKWXkc6DXB3VEDzq+OKD+NBPQp4YR4pICXAZl39aoIxoo5/vy+MS6+ TqDlm1ZHR21nLY7TVS9wj4XAJlczGR8E7wI+FDlUB/gD7lAs9/8mY699ThArKdoOOWWP GpL1T2zIunlh9Tr2HypcdIpC7O2RyF7Brz6qWFsXTI/+bv+rixJpYTa5YzW3Rx4GCVuf M/XA== X-Gm-Message-State: ALKqPweQOX4vTjXQyNwA/XnMlbY9NLxoFzYPAWnWqETo0nbj8YBntU+M MI1zOheGKLMjqmdgVNu5q7Rsuw== X-Google-Smtp-Source: ADUXVKKpTO71YlXZMQDs0Pkp54VZZaKzJjeKgpJYeQ94LPSo7O51KTqeau/DwpXJpfgrU6c1zKj/qQ== X-Received: by 2002:adf:9e8c:: with SMTP id a12-v6mr2349669wrf.170.1527695380815; Wed, 30 May 2018 08:49:40 -0700 (PDT) Received: from leoy-ThinkPad-X240s ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id e7-v6sm35160586wrn.88.2018.05.30.08.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 08:49:39 -0700 (PDT) Date: Wed, 30 May 2018 23:49:29 +0800 From: Leo Yan To: Mike Leach Cc: Robert Walker , Mathieu Poirier , Arnaldo Carvalho de Melo , Jonathan Corbet , Kim Phillips , Tor Jeremiassen , 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, coresight@lists.linaro.org Subject: Re: [RFT v3 1/4] perf cs-etm: Generate branch sample for missed packets Message-ID: <20180530154929.GB10925@leoy-ThinkPad-X240s> References: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> <1527497103-3593-2-git-send-email-leo.yan@linaro.org> <20180528221347.GA4109@xps15> <5efe804f-364b-6ae1-3fca-ec7f6d8a383d@arm.com> <20180530153900.GA10925@leoy-ThinkPad-X240s> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180530153900.GA10925@leoy-ThinkPad-X240s> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Wed, May 30, 2018 at 11:39:00PM +0800, Leo Yan wrote: > Hi Mike, > > On Wed, May 30, 2018 at 04:04:34PM +0100, Mike Leach wrote: > > [...] > > > >>> + /* Generate sample for exception packet */ > > >>> + if (etmq->prev_packet->exc == true) > > >>> + generate_sample = true; > > >> > > >> > > >> Please don't do that. Exception packets have a type of their own and can > > >> be > > >> added to the decoder packet queue the same way INST_RANGE and TRACE_ON > > >> packets > > >> are. Moreover exception packet containt an address that, if I'm reading > > >> the > > >> documenation properly, can be used to keep track of instructions that were > > >> executed between the last address of the previous range packet and the > > >> address > > >> executed just before the exception occurred. Mike and Rob will have to > > >> confirm > > >> this as the decoder may be doing all that hard work for us. > > >> > > > > clarification on the exception packets.... > > > > The Opencsd output exception packet gives you the exception number, > > and optionally the preferred return address. If this address is > > present does depend a lot on the underlying protocol - will normally > > be there with ETMv4. > > Exceptions are marked differently in the underlying protocol - the > > OCSD packets abstract away these differences. > > > > consider the code: > > > > 0x1000: > > 0x1100: BR 0x2000 > > .... > > 0x2000: > > 0x2020 BZ r4 > > > > Without an exception this would result in the packets > > > > OCSD_RANGE(0x1000,0x1104, Last instr type=Br, taken) // recall that > > range packets have start addr inclusive, end addr exclusive. > > OCSD_RANGE(0x2000,0x2024, Last instr type=Br, > depends on condition> > > > > Now consider an exception occurring before the BR 0x2000 > > > > this will result in:- > > OCSD_RANGE(0x1000, 0x1100, Last instr type=Other) > > OCSD_EXECEPTION(IRQ, ret-addr 0x1100) > > OCSD_RANGE(IRQ_START, IRQ_END+4, Last instr type = BR, taken) // > > this is more likely to have multiple ranges / branches before any > > return, but simplified here. > > OCSD_EXCEPTION_RETURN() // present if exception returns are > > explicitly marked in underlying trace - may not always be depending on > > circumstances. > > OCSD_RANGE(0x1100,0x1104, Last=BR, taken) // continue on with short > > range - just the branch > > OCSD_RANGE(0x2000,0x2024, Last instr type=Br, > depends on condition> > > > > Now consider the exception occurring after the BR, but before any > > other instructions are executed. > > > > OCSD_RANGE(0x1000,0x1104, Last instr type=Br, taken) // recall that > > range packets have start addr inclusive, end addr exclusive. > > OCSD_EXECEPTION(IRQ, ret-addr 0x2000) // here the preferred return > > address is actually the target of the branch. > > OCSD_RANGE(IRQ_START, IRQ_END+4, Last instr type = BR, taken) // > > this is more likely to have multiple ranges / branches before any > > return, but simplified here. > > OCSD_RANGE(0x2000,0x2024, Last instr type=Br, > depends on condition> > > > > So in general it is possible to arrive in the IRQ_START range with the > > previous packet having been either a taken branch, a not taken branch, > > or not a branch. > > Care must be taken - whether AutoFDO or normal trace disassembly not > > to assume that having the last range packet as a taken branch means > > that the next range packet is the target, if there is an intervening > > exception packet. > > Thanks a lot for detailed explaination. > > IIUC, AutoFDO will not have such issue due every range packet will be > handled for it. On the other hand, as you remind, the branch samples > (and its consumer trace disassembler) is very dependent on the flag > 'last_instr_taken_branch'. > > According to your explaination, I think we consider the branch is > taken for below situations: > > - The new coming packet is exception packet (both for exception entry > and exit packets); > - The previous packet is expcetion packet; > - The previous packet is normal range packet with > 'last_instr_taken_branch' = true; > > So I'd like to use below function to demonstrate my understanding for > exception packets handling. I also will send out one new patch for > support exception packet for reviewing. > > If you have concern or I miss anything, please let me know. > > static bool cs_etm__is_taken_branch(struct cs_etm_packet *prev_packet, > struct cs_etm_packet *packet,) > { > /* The branch is taken for normal range packet with taken branch flag */ > if (prev_packet->sample_type == CS_ETM_RANGE && > prev_packet->last_instr_taken_branch) > return true; > > /* The branch is taken if previous packet is exception packet */ > if (prev_packet->sample_type == CS_ETM_EXCEPTION || > prev_packet->sample_type == CS_ETM_EXCEPTION_RET) > return true; > > /* The branch is taken for an intervening exception packet */ > if (packet->sample_type == CS_ETM_EXCEPTION || > packet->sample_type == CS_ETM_EXCEPTION_RET) > return true; > > return false; > } Just clarify, I missed to mention I introduce two extra sample types: CS_ETM_EXCEPTION and CS_ETM_EXCEPTION_RET, one is for exception entry packet and another is for exception exit packet. If this is hard for understanding, you could hold on for reveiwing new patch. Thanks, Leo Yan -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html