Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4611136imm; Wed, 30 May 2018 08:41:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKlgxdQNsioRntsf3+RxCOcoGtdt73UeJq96BDBnM9b1wkl250tvEtQ+EWfuqoSl87MaoJH X-Received: by 2002:a17:902:14d:: with SMTP id 71-v6mr3294109plb.275.1527694871686; Wed, 30 May 2018 08:41:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527694871; cv=none; d=google.com; s=arc-20160816; b=jDkieK9dmPfnM1R279I1zoOW5n1muTRqXubEj0ehMD+T1/fw/Atj0OCb/kdlaQxMIX EjqAZPlUHEUI4I4pz7yJcerYfSJ0imrLOeWNFxGqt/iC6CojaGNtJeiCkHCN79KIvNmM k6uJ4by7+w0T47vm0cNpdGoCZxUeR2qfyE5zW5Ihag2RQae/gqdn90s3D5ziqErsK9BM VFl5Klhuj3L4mU5NSIzSeo2SDu2BgGVp8xJZ+X8RtR4ph7GL86h42tbylrxb6XH0/Rns 91Q4Dy/Cbm5rKUtPTufcQpG9x8V5lALN2xpBMrhn2mVpxlHl0Nw2oTifbALCRsgJQzvR LqRA== 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=83SF39gN8SLb60HWUO+0v3CUhEplNZcl8u4wJQYYmGQ=; b=JLQauT6eldPcs5dreId8bLCLQvms5Sw5lWI5oIIGVu85xi1CImNVu+QwuPuZMYxUe2 JfJfKYXj1bbbZRRxW7Hz7A3xBqivkcslBTCndbj/T0RNpAB5lpbqkfPo0M8IzAZ8xx4p WFGiKQcd5RwxS++iQNboTnsX7/lCNVDAsk1k0fFkLVFUuzMVdqQ0EsQt/uq+ogttgFxB jq2G788l0+1ieoSwi1cW8x+w/eGlAH5rU9XFOYScmKtNScJrWlkbJy52AQAFUeqPqJFm B8tG/sTfOFTkf6H00LUvWnQvoyypE6xQUpIhvvqkeYQCHPxxqbrWqZGtMhjoSruA5XUo QxQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bCo9hfqi; 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 m2-v6si27766690pgs.349.2018.05.30.08.40.56; Wed, 30 May 2018 08:41:11 -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=bCo9hfqi; 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 S1753327AbeE3PjR (ORCPT + 99 others); Wed, 30 May 2018 11:39:17 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:33611 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbeE3PjM (ORCPT ); Wed, 30 May 2018 11:39:12 -0400 Received: by mail-wr0-f194.google.com with SMTP id k16-v6so2766134wro.0 for ; Wed, 30 May 2018 08:39:12 -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=83SF39gN8SLb60HWUO+0v3CUhEplNZcl8u4wJQYYmGQ=; b=bCo9hfqiCiOau0IDzHCTXNNKNp8Jx1X/WETAWysXPF3Py4qmdqB+a5jcLjpaXFfd+E zLmV+uhkusFFUAti2AxWXRL1RTfvj+7VfPfM3wdHnEHwz3ndZBE16KOnb/bVYvOEV6vq y1HcHcMmaOOo/glLvfXHYEiJjo2otuMvLh34w= 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=83SF39gN8SLb60HWUO+0v3CUhEplNZcl8u4wJQYYmGQ=; b=TIyjx+urUEPzaOtPUTZ6EltY71OfUNCuRAhpybdYrMctAROWNx6DqPT8bKqsQV4pHT IkCcaq4NbxReUOqclYRYz0OVjjdsmTbTcUMgosLqCsotmCmhSNE5nGv8AnzCfTCzpKA5 wj/qzZCVJumW9Ap88y0Z0uWHAmtHFmHdoRLcgsIh4dH+q5mAKSDDUU012BUbTPcNVa3S FPTcKThwt0phq15UE53saiHlwgCR6a6Sl3X5TIGQ8PIXY/aGOQViGVkZdXhfcYlAZ5NC FaaYhDj4NEiUDcQBHqbW16g8QHqRsNXnyeMnwee/NRI8HmG/xUPElfr5FGB4C9Wf+LzR 5yBw== X-Gm-Message-State: ALKqPwf4FOcwlWyuhZUJaSVz6wXIXiPJXCPl4uwrncQCFD3ZAXiF8fl7 RHAWsYdjwgg2HobbHukfYOfwtw== X-Received: by 2002:adf:9246:: with SMTP id 64-v6mr2732375wrj.90.1527694751261; Wed, 30 May 2018 08:39:11 -0700 (PDT) Received: from leoy-ThinkPad-X240s ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id h81-v6sm34113458wmd.0.2018.05.30.08.39.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 08:39:09 -0700 (PDT) Date: Wed, 30 May 2018 23:39:00 +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: <20180530153900.GA10925@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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; } [...] Thanks, Leo Yan