Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4619829imm; Wed, 30 May 2018 08:50:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLxvufS/7B4Uz3M7L0U2Tvmls+q+mnBKz/dZLcoYRju+/j3vL8D1nrJ5khb0c1ZSZB8TkML X-Received: by 2002:a62:a054:: with SMTP id r81-v6mr3289652pfe.10.1527695445811; Wed, 30 May 2018 08:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527695445; cv=none; d=google.com; s=arc-20160816; b=Ox4AWcnBHTOR0+GxZdDYUHQNHk8HrJaKTLZkrazgZrQ71S1w0an9Wv+D8hkIPolVSz 3E7aJZdJ4D4clm7DuhMPW/nVlpY39bBk9mTZzudhyN6fvBo2sZT4INu9zxaSJulKSr9z 0zU1e1p0GVZBp3aRA82y6pmE4kU7j+Aidddb++WX2ZOo2aOwH8CuJkMThUwjeB7Ks1dM a4zuqPj7fXv3Jipn/zOiKN6svkUyZZh3PaAarg1BbgIG3FKMhj3iCtOj9ST0xTZwb0vD P7cAh7+1mxSaVsDu/ocVnb7LnAj23WBveV28YFQZxJh+lNwLaU+u/z7kCRyqTbSrsMGP EMPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=BL9FDjS/lmGf0iw6TOwNx7sOazTEHLXdlKIjaLqtkg8=; b=t5W1GC/A8Sdtt5Bpu4DjLQ1q3PdWOMi9jbJDRi/ye2P41+/tuaDvvkg30mHPZRyexe nQ/xplwSAYo5bJkpFqc/Hcm6Cycn9QMce6Si5C9aiGLctSWpbCvHAO5COplsrXSu4TVA 9YjEaTml2DjHM+r1AvEnyvONPMGULBswO4OtNwq8HOSz6zqt7Tm90Ypjy7sXu07O58J0 9QiCcJN7+R1fCQagiHR2WNHrC91BEQiqRFlPc335pdHCXzCDITQDy9hG+lQvzHhVr7vs sC1YTDJKOSz/AWf3b11ZMmzpqz+jE0DIMsKvKy9h0l+QmhHQxLqfsbsFhAFSBqVkXRrx jknw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZsdcXLeI; 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 g12-v6si34762924pla.194.2018.05.30.08.50.31; Wed, 30 May 2018 08:50:45 -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; dkim=pass header.i=@linaro.org header.s=google header.b=ZsdcXLeI; 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 S932131AbeE3Ptu (ORCPT + 99 others); Wed, 30 May 2018 11:49:50 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33666 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932109AbeE3Ptm (ORCPT ); Wed, 30 May 2018 11:49:42 -0400 Received: by mail-wr0-f195.google.com with SMTP id k16-v6so2800108wro.0 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=gVLlYRnLDWb0dp8E/zlyUZeFmP5K1VoXUsYk1tnMN3eifyNzU+58SWpjh4UluZR0+W k4hBTZdGHTuWDmnRMCAfpNOAq6wAwPle6c/zZEG9fW0HLzk/07UORdyeuFnsADi0nb5h 7/g8owT49r5ZENnTsiTm5dnISphmfeTEkqqaeftTAl/VeaZmMiG5A/fCDEP3bRsk7u0u ojBl+rIA2yEmW9FthFOGEe1kCKSMhnXnILBjlaGn2t3gybIrcPNbTdUgspXVtf4KTPyc JI6sDxTxzsv66S5QwIDbmhksM3wfg5Vz2ajrvf2Fv8IWdZmJCqOqJlDzXIL0/+bdw6mu Onag== X-Gm-Message-State: ALKqPwcDpfYA/ExnAcROXuXjfiZBBYzPfJYT0ppGRkXpWPSzOme3OhZK 2yBo7XTSpIva5E9O2P/eQtUlSA== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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