From patchwork Thu Oct 24 15:13:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11209993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E6FD913 for ; Thu, 24 Oct 2019 15:15:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D5E0D20679 for ; Thu, 24 Oct 2019 15:15:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="etmN95Og"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="P5Z9s7tQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5E0D20679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BSAjX+GYHTVdl21Z8a9cDfL7YYkhfk0pG1uiAh4JPD0=; b=etmN95Ogl6mBCtbcDK3dEavNqJ PzRz9SuVX72v+OGllT9yyYxawFxRrchkiyB2dzFGiMj2BjWpSSAfKRnBazUxLsqSxhVY8f5ioLUzT Mm3fGZUcinUJVYB1CIrT/Pc/5gOvhcVPgh95W2a6rZi37br+BhVQL1u6YG3ArdJBqG9kToy1byvoq Z7+JI6779/I8vrDHRUG+OM0bMild6qOWg7vJPYsMt3o8NE4lzmKljWk1B7yhMwNY7mpycGXMeufg/ LxjxbfpiI5t8TpE8rc5wyZ6fTp0C4MDVbMmzucu6ZQh4dZtCgjiI4hanMtxwZOaJ2c6o1ByF4KfQv 5nZ9ltCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNepe-0002pn-Dm; Thu, 24 Oct 2019 15:15:22 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNepS-0002Js-VE for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2019 15:15:12 +0000 Received: by mail-qk1-x742.google.com with SMTP id f18so23144434qkm.1 for ; Thu, 24 Oct 2019 08:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iAgomrDaaw+p9SyPDKe+DIwZEIKyPHeJdp6rMCsSqrc=; b=P5Z9s7tQX1G3oEdM4YkZvIy9JwZJm7c9n9mVSVcigEo+f08pPSB15O+iIGQQpa8iIM G3oOT++5AX46oumLuNw63gqOs1XcA+8gU94YEpASQyvBUu/+Vb1sPvW4JclYvp0wRC/Q YMSPhO+qnod1JwlDRe86ke+XVh6Pzokns3VnnCtu2LgOaBZWmk50vQILLjP1CdDojU6L wR4o17+y954XBO3kwDwXAPhXqd0Bb0kWtboPY48cuDnhNzrXBTyOH2SPpOXwC+g4rYLu 1L+1AljcwUuqwQQdJXineJMQK76V3ejsnirZjuwI0dMsBTPJ5nZG9MyDB9R1slKaECww JAfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iAgomrDaaw+p9SyPDKe+DIwZEIKyPHeJdp6rMCsSqrc=; b=OhIDK3Xi/4w+c3gBpquaChV1n85Oa4XmEc25sEE8w9pyR8vJQns8iGEtYvWYdUjOHR /edaLLZUqi+L7RC3+nR2IKS/tAjna5dGiqwAl+YmIFa291HHSFZnerYrQ/Y/WT0CvoGQ dUY9ccDmeCVKpy6VoAmlrkmyocUcFdvr0NCnmGASTlRRbyauUWTwaNFF4jqXq1uBBBDk V02MZhx1ORYeLP8NOfMBhUV5rIW0B4kPQtnnZovNIuio+ePCIBG+/xA4w//iwTJChjw8 1efwnTGWRqATcwR8Yl0FlAQJ6gQ5QtuZbEbwWkwrfWlPk86csPuj2tY5cX1FbVaRxEti ybZA== X-Gm-Message-State: APjAAAU7DGVU4HtGCOYx01pB31JHhNqC6BEYDAQngXLkAk/K8pLnocLb x8M2XBQxKA1f70ArTUU896qHDA== X-Google-Smtp-Source: APXvYqzlH3likrYVsNYXLQ5BlmwDmJjy4QCkXxBYjW7RbaO6cE+XDl6ZAOSajy7ViS/coV1V3YT1lQ== X-Received: by 2002:a37:f514:: with SMTP id l20mr1916565qkk.331.1571930109291; Thu, 24 Oct 2019 08:15:09 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id l5sm4346073qtj.52.2019.10.24.08.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 08:15:08 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML , Robert Walker Subject: [PATCH v1 1/4] perf cs-etm: Continuously record last branches Date: Thu, 24 Oct 2019 23:13:22 +0800 Message-Id: <20191024151325.28623-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024151325.28623-1-leo.yan@linaro.org> References: <20191024151325.28623-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191024_081511_058472_9E663B2A X-CRM114-Status: GOOD ( 15.60 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:742 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Every time synthesize instruction sample, the last branches recording will be reset. This would be fine if the instruction period is big enough, for example if we use the option '--itrace=i100000', the last branch array is reset for every instruction sample (10000 instructions per period); before generate the next instruction sample, there has the enough packets coming to fill last branch array. On the other hand, if set a very small period, the packets will be significantly reduced between two continuous instruction samples, thus if the last branch array is reset for the previous instruction sample, it's almost empty for the next instruction sample. To allow the last branches to work for any instruction periods, this patch avoids to reset the last branches for every instruction sample and only reset it when flush the trace data. The last branches will be reset only for two cases, one is for trace starting, another case is for discontinuous trace; thus it can continuously record last branches. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index f5f855fff412..8be6d010ae84 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1153,9 +1153,6 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, "CS ETM Trace: failed to deliver instruction event, error %d\n", ret); - if (etm->synth_opts.last_branch) - cs_etm__reset_last_branch_rb(tidq); - return ret; } @@ -1486,6 +1483,10 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, tidq->prev_packet = tmp; } + /* Reset last branches after flush the trace */ + if (etm->synth_opts.last_branch) + cs_etm__reset_last_branch_rb(tidq); + return err; } From patchwork Thu Oct 24 15:13:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11209995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7692F13BD for ; Thu, 24 Oct 2019 15:15:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5361621872 for ; Thu, 24 Oct 2019 15:15:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FhIoY2cq"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="v5d5gNh+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5361621872 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=O8kkLm8BDzRs7gm7/m7kBR1sJcyTtWsAscFAysJw6+M=; b=FhIoY2cqFz6cb+muK4uIaL9fVP 7Zm0H4Wz8XbcY+jjrXppaaKWiFhscftqWDmGXBhX0Eowhdn18GB81spAH4VCG6Na1mXKRUAnkwBy4 d4f7gR6P8eyhSB007oXAp/2pvGjvFYvxpid2i+R0Np/P5wViHuGXPfYaJ5irbRl4oeXOaQuiuXbw6 AGOBOyFn7bsHlmfXZKJBCQk22bNNOKu5zR9JOh7Y0U//cBL4B32IOZ5pAYxWj8f68vD1rv8I7gO0c AvjUa7wCK0boNUA7EwG85aN7143KDif4Z4R+I/UzU76NAaqX1tfOseB/u8UzZtH3da8BYotTzv9/o /BLnTPDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNepx-00033i-5b; Thu, 24 Oct 2019 15:15:41 +0000 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNepb-0002n3-2u for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2019 15:15:21 +0000 Received: by mail-qk1-x733.google.com with SMTP id 4so23745242qki.6 for ; Thu, 24 Oct 2019 08:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gsFY1KIx9iJYif7vQxfbD15FpxrJSPWH13lYc5zzTiA=; b=v5d5gNh+F59/fSvage2YJeu0cLoZxiwVNw1QuRHe4NO10ZLCCaNrLlBRYxnrKipV8O 9dsMfcQkiAkm/EGv0eX/+JbKLsQOmw/2i87u+R25IHXJ9Ndgu85G5rMMc/SkLkXY+E88 2nae7Dwl4iitpHvYkCNK93GVyA5+502RC86/ymFkr+rryLnLk9WMM6gWRGMWN/RmEMK+ tZ2hin6ad4yOBa3CcViHDy44CvTS8i8vXZMe1VGeKUpZuauwks8qrcBSLfgMDRdgofpf AxNr8rfjDerD1hEOwkLwvGhdNEEgWmHc9LWraLLGWBkk3sMx1kT1v0GHuZfXA2R/v19v NeaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gsFY1KIx9iJYif7vQxfbD15FpxrJSPWH13lYc5zzTiA=; b=EXuVCFA04/E1fGyU4yanjQxJ87bHwNpXXn2YuiRt4uSA0B9YMhOLiNtb3ilOXLrdZH 3NPdUQGn4rDurhIxruAqBLAS/I1ZX4Vwc4M8cF0Ztn6NcKkqaofN46O8Hl1ae4o+X8YD V+3vFmhEsK61P1fG4XueDSmbH2UemDVR+5TowwX8wTDkHGOxvzk5M6pO5vYPs1dJyMFo nGJEnzB8gaRXQ/2IAr9g6uVQ2C31MuA2pHNAcqKRIInQ7Qo23JpXT9VdhfyRpxRt/FaF CU24OBLoMIOC1mZYIKVsqBnrNUVw8UusafGOyYXUgfm5U8nd7CuaJppiUbBivCyo/JP1 SBuA== X-Gm-Message-State: APjAAAUQd50pmmZ4j2xvpH8j2FnkaOSFdAGJrhVpWDJBosOs/nXfdJB7 5mbVMk0laNWLCvA6+22aOM9GKQ== X-Google-Smtp-Source: APXvYqxDzu3MgqaB7/YwKp9MWBfvu+nHAZCMnwTh00EmBEMTyMuyRW969I338LrOuFJuxgxmdK1shA== X-Received: by 2002:ae9:dd05:: with SMTP id r5mr2054288qkf.252.1571930117698; Thu, 24 Oct 2019 08:15:17 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id l5sm4346073qtj.52.2019.10.24.08.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 08:15:17 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML , Robert Walker Subject: [PATCH v1 2/4] perf cs-etm: Correct synthesizing instruction samples Date: Thu, 24 Oct 2019 23:13:23 +0800 Message-Id: <20191024151325.28623-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024151325.28623-1-leo.yan@linaro.org> References: <20191024151325.28623-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191024_081519_172341_3C712994 X-CRM114-Status: GOOD ( 20.98 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:733 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When 'etm->instructions_sample_period' is less than 'tidq->period_instructions', the function cs_etm__sample() cannot handle this case properly with its logic. Let's see below flow as an example: - If we set itrace option '--itrace=i4', then function cs_etm__sample() has variables with initialized values: tidq->period_instructions = 0 etm->instructions_sample_period = 4 - When the first packet is coming: packet->instr_count = 10; the number of instructions executed in this packet is 10, thus update period_instructions as below: tidq->period_instructions = 0 + 10 = 10 instrs_over = 10 - 4 = 6 offset = 10 - 6 - 1 = 3 tidq->period_instructions = instrs_over = 6 - When the second packet is coming: packet->instr_count = 10; in the second pass, assume 10 instructions in the trace sample again: tidq->period_instructions = 6 + 10 = 16 instrs_over = 16 - 4 = 12 offset = 10 - 12 - 1 = -3 -> the negative value tidq->period_instructions = instrs_over = 12 So after handle these two packets, there have below issues: The first issue is that cs_etm__instr_addr() returns the address within the current trace sample of the instruction related to offset, so the offset is supposed to be always unsigned value. But in fact, function cs_etm__sample() might calculate a negative offset value (in handling the second packet, the offset is -3) and pass to cs_etm__instr_addr() with u64 type with a big positive integer. The second issue is it only synthesizes 2 samples for sample period = 4. In theory, every packet has 10 instructions so the two packets have total 20 instructions, 20 instructions should generate 5 samples (4 x 5 = 20). This is because cs_etm__sample() only calls once cs_etm__synth_instruction_sample() to generate instruction sample per range packet. This patch fixes the logic in function cs_etm__sample(); the basic idea is to divide into three parts for handling coming packet: - The first part is for synthesizing the first instruction sample, it combines the instructions from the tail of previous packet and the instructions from the head of the new packet; - The second part is to simply generate samples with sample period aligned; - The third part is the tail of new packet, the rest instructions will be left to next time handling with sequential packet. Suggested-by: Mike Leach Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 106 ++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 8be6d010ae84..8e9eb7583bcd 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1360,23 +1360,103 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, * TODO: allow period to be defined in cycles and clock time */ - /* Get number of instructions executed after the sample point */ - u64 instrs_over = tidq->period_instructions - - etm->instructions_sample_period; + /* + * Below diagram is used to demonstrate the instruction samples + * generation flows: + * + * Instrs Instrs Instrs Instrs + * Sample(n) Sample(n+1) Sample(n+2) Sample(n+3) + * | | | | + * V V V V + * -------------------------------------------------- + * ^ ^ + * | | + * Period Period + * instructions(Pi) instructions(Pi') + * + * | | + * \---------------- -----------------/ + * V + * instrs_executed + * + * When the new instruction packet is coming, period + * instructions (Pi) contains the the number of instructions + * executed after the sample point(n). So for the next sample + * point(n+1), it is combined the two parts instructions, one + * is the tail of the old packet and another is the head of + * the new coming packet. So we use 'head' variable to cauclate + * the instruction numbers in the new packet for sample(n+1). + * + * For sample(n+2) and sample(n+3), they consume the instruction + * for sample period, so we directly generate samples based on + * the sampe period. + * + * After sample(n+3), there still leave some instructions which + * will be used by later packet; so we use 'instrs_over' to + * track the rest instruction number and its final value + * presents the tail of the packet, it will be assigned to + * 'tidq->period_instructions' for next round calculation. + */ + u64 head, offset = 0; + u64 addr; /* - * Calculate the address of the sampled instruction (-1 as - * sample is reported as though instruction has just been - * executed, but PC has not advanced to next instruction) + * 'instrs_over' is the number of instructions executed after + * sample points, initialise it to 'instrs_executed' and will + * decrease it for consumed instructions in every synthesized + * instruction sample. */ - u64 offset = (instrs_executed - instrs_over - 1); - u64 addr = cs_etm__instr_addr(etmq, trace_chan_id, - tidq->packet, offset); + u64 instrs_over = instrs_executed; - ret = cs_etm__synth_instruction_sample( - etmq, tidq, addr, etm->instructions_sample_period); - if (ret) - return ret; + /* + * 'head' is the instructions number of the head in the new + * packet, it combines with the tail of previous packet to + * generate a sample. So 'head' uses the sample period to + * decrease the instruction number introduced by the previous + * packet. + */ + head = etm->instructions_sample_period - + (tidq->period_instructions - instrs_executed); + + if (head) { + offset = head; + + /* + * Calculate the address of the sampled instruction (-1 + * as sample is reported as though instruction has just + * been executed, but PC has not advanced to next + * instruction) + */ + addr = cs_etm__instr_addr(etmq, trace_chan_id, + tidq->packet, offset - 1); + ret = cs_etm__synth_instruction_sample( + etmq, tidq, addr, + etm->instructions_sample_period); + if (ret) + return ret; + + instrs_over -= head; + } + + while (instrs_over >= etm->instructions_sample_period) { + offset += etm->instructions_sample_period; + + /* + * Calculate the address of the sampled instruction (-1 + * as sample is reported as though instruction has just + * been executed, but PC has not advanced to next + * instruction) + */ + addr = cs_etm__instr_addr(etmq, trace_chan_id, + tidq->packet, offset - 1); + ret = cs_etm__synth_instruction_sample( + etmq, tidq, addr, + etm->instructions_sample_period); + if (ret) + return ret; + + instrs_over -= etm->instructions_sample_period; + } /* Carry remaining instructions into next sample period */ tidq->period_instructions = instrs_over; From patchwork Thu Oct 24 15:13:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11209997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B26E313BD for ; Thu, 24 Oct 2019 15:15:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 865C720679 for ; Thu, 24 Oct 2019 15:15:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="t7At4HHX"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PSwpr/P5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 865C720679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zRFJCHVyOXnEqwoyFevhDFyjk/l/aR1p9Etw6pNMi3I=; b=t7At4HHX+yiSZo7eKNp45ebbAt rdHc3/YjaUC6NLF23LQt7YIRp79qvsMkJ9Cd39LWVqgkkL9/QnX6DY3ZAZskGmFDGz8H/iNZJl0Zz lzAF81+rHB8G72yNBZ9whT7nssVk537MEUvIVpJ4QqEW8GqUEZAH/wCbEIkrpCx22GJOO0rwK2/PG 6xUODBUJfxbHZ+LFtQTQgqo6/cmhVaRNpYZpiMmtsFkHxs6M9HSwY1YyrhLdNnMXScJnjUFWvtHCi 7Bq6Yvo44JNEF94SZxIgbmdDE0PN7Re1RB1UDsE7nLhNUXHmJ4/O5rosXKMqOFZ9e47iUx7jv5bJR 4jCxu6cQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNeqA-0003IG-Hj; Thu, 24 Oct 2019 15:15:54 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNepk-0002u4-8Y for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2019 15:15:29 +0000 Received: by mail-qt1-x841.google.com with SMTP id c17so35373740qtn.8 for ; Thu, 24 Oct 2019 08:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2+8OeCtlRuFQGQZkXW2FoUzBMjUDZlZhy5R5fOMQGeQ=; b=PSwpr/P52oXDPu2DuTOP4dcsZcERIOhjHhdwDQRNfFRrpF9TIL5cZxYpBlX/M4zdD9 jccri2mOi3BLErYUJevgdsA74Ah0X2U1frueLyhrrZabUK9phjly8F7t+pIjD8qcJmGF r/8MuRsNVFxl1KfFSZI0HltGPoDsxO5xYzBk86XXz1xKEM/Qtg5Wm+sfGO0/f2ZsbfND D6YmUNYR9E2kolYMEcOddXAhqesSb0Fej+dqgdPaR/7ytC2+bjyTM6PAfaxaRbtOqnaP VeXJ7ztGmGd3lVaIMe58/MGoiQqJtukk+kgriL/7A8vhUVkkM75AAg7ZB6WGcaV4MKjP nZrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2+8OeCtlRuFQGQZkXW2FoUzBMjUDZlZhy5R5fOMQGeQ=; b=Wv5heSVsCMiotqUB3jl5VMhqZh2XFvQVtp6Dob6z1IofD6ZtbcQ9wdWZj4CKCVXxSt b5HROTA3dtnERCYc1aJEG0Z3Cjx35iE1RcuRDZyuyL+kMukpC1bhm6h33c5lSAVw4Xxv UmESqsULcRbXC0TmhOz/eGFGjvc2RhOOAv1DZJ8U7G5OlijBxglSwY/YTiu5POZryGV1 QrUp9xkjc2BU37tHAbiP0kQArJlYnyhocaL8whUnF+IVnRP5/XILn8P8SfPrCWHlMO19 yLjFxsJezw11JFnt0BaBoS0C2xdjp/hNUG5DrQbEma9zKoHXzrxSOZnDsMmn1/O7Ts7N xoUw== X-Gm-Message-State: APjAAAXpjgw8YUnoLWQY1UgMU4sZK2Kup+ChGC0qyYHBctzrj7mPYMGF WWWEsp+OUAVSSlIdNmrpKw8Z9Q== X-Google-Smtp-Source: APXvYqwQ6KBz4sS0PRZ22lkCUee3uDjw8e66CKmbsWmea6h8xYNFQE8bF2jhT1Ce/ZksIWxqDZgHrA== X-Received: by 2002:ac8:5343:: with SMTP id d3mr4659044qto.157.1571930126807; Thu, 24 Oct 2019 08:15:26 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id l5sm4346073qtj.52.2019.10.24.08.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 08:15:26 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML , Robert Walker Subject: [PATCH v1 3/4] perf cs-etm: Optimize copying last branches Date: Thu, 24 Oct 2019 23:13:24 +0800 Message-Id: <20191024151325.28623-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024151325.28623-1-leo.yan@linaro.org> References: <20191024151325.28623-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191024_081528_336936_97065E15 X-CRM114-Status: GOOD ( 14.57 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:841 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If an instruction range packet can generate multiple instruction samples, these samples share the same last branches; it's not necessary to copy the same last branches repeatedly for these samples within the same packet. This patch moves out the last branches copying from function cs_etm__synth_instruction_sample(), and execute it once prior to generating instruction samples. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 8e9eb7583bcd..d9a857abaca8 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1134,10 +1134,8 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample); - if (etm->synth_opts.last_branch) { - cs_etm__copy_last_branch_rb(etmq, tidq); + if (etm->synth_opts.last_branch) sample.branch_stack = tidq->last_branch; - } if (etm->synth_opts.inject) { ret = cs_etm__inject_event(event, &sample, @@ -1408,6 +1406,10 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, */ u64 instrs_over = instrs_executed; + /* Prepare last branches for instruction sample */ + if (etm->synth_opts.last_branch) + cs_etm__copy_last_branch_rb(etmq, tidq); + /* * 'head' is the instructions number of the head in the new * packet, it combines with the tail of previous packet to @@ -1526,6 +1528,11 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, if (etmq->etm->synth_opts.last_branch && tidq->prev_packet->sample_type == CS_ETM_RANGE) { + u64 addr; + + /* Prepare last branches for instruction sample */ + cs_etm__copy_last_branch_rb(etmq, tidq); + /* * Generate a last branch event for the branches left in the * circular buffer at the end of the trace. @@ -1533,7 +1540,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, * Use the address of the end of the last reported execution * range */ - u64 addr = cs_etm__last_executed_instr(tidq->prev_packet); + addr = cs_etm__last_executed_instr(tidq->prev_packet); err = cs_etm__synth_instruction_sample( etmq, tidq, addr, @@ -1586,11 +1593,16 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq, */ if (etmq->etm->synth_opts.last_branch && tidq->prev_packet->sample_type == CS_ETM_RANGE) { + u64 addr; + + /* Prepare last branches for instruction sample */ + cs_etm__copy_last_branch_rb(etmq, tidq); + /* * Use the address of the end of the last reported execution * range. */ - u64 addr = cs_etm__last_executed_instr(tidq->prev_packet); + addr = cs_etm__last_executed_instr(tidq->prev_packet); err = cs_etm__synth_instruction_sample( etmq, tidq, addr, From patchwork Thu Oct 24 15:13:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11209999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6992E913 for ; Thu, 24 Oct 2019 15:16:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25F5A2166E for ; Thu, 24 Oct 2019 15:16:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VBol6otD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KhtIu0dC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25F5A2166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0QvaWjQxnvQAEWBXLMwZHEyTww12v6iUzgzmxnjc0/8=; b=VBol6otD9kPpVjjoO881KH0V9y uweeh6yVW/LyQcE9+AgRYDs3biSxIJr9w4p93q0AI411bb102IeOEX6oEidX5GB55OnOkOVU6Ug1R hxgigPBU0kh+c54n0uqbYH3JB4U6uTtWCrz4hejv2HRa1uTzWdNsrfLIgALEA9Ce2mS1Lvc3eeBjs cQRr3vKAMTSJ9630a+gCbJprNnQ1SyLNNF+cYZUMRZIY0hzDCtRxv5ktcHEEdb8b5po3amQCmeOO+ WfOp9foIudJtnCDvdN8lZYLNSIeZSfCII38aGarELVVmj6MhDIeXk8pZVZYHUISztgYtajQlsR6SE fB9lrjEQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNeqT-0003cb-3R; Thu, 24 Oct 2019 15:16:13 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNepw-00033b-1c for linux-arm-kernel@lists.infradead.org; Thu, 24 Oct 2019 15:15:42 +0000 Received: by mail-qk1-x741.google.com with SMTP id f18so23146089qkm.1 for ; Thu, 24 Oct 2019 08:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+iIRtubR+3wcJynWU+Kes2QJp/E/y+xxgrhDiusBOkw=; b=KhtIu0dCBCIld0cRA5SUcUS0KOYjEc4cfXPg8KYjHxlBNZegNKIW0LE1dFWTzdCJXh XUQXG5Zc6ePCGNVe7v+Y7NRdYoXFxV8EinQmz7Z4e3MQPPmeDGTHMpOLD8gDxqYKn22I 8hMZF9W4N4Dz6VQ48+unWncjtlnk+ljhv817Cs5eAP/8XOa7uUc3iPIyKfQ6XIfcnK/g HbBn+S0oxLTyyEsLnnmGIkyOom6kq3bS9L/dzVAZ3LvkNtMAa4fJzxcyKT+LZzu5o33I c6w4nBBsi08CAsqiaATFlWr5WDDf7fTODch3cCyRefSwjhMB6Onh+6g9Q1mDeqQVl+mK vbCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+iIRtubR+3wcJynWU+Kes2QJp/E/y+xxgrhDiusBOkw=; b=GFefBBZ7+HwasWKnIDP5hMpS2EIarDsLYaCCqLBNJWqtZ2FM8dGxcSKu85pJOXz+gt S/5ThK1vHF9UWIxRy8D+Ge+nmvqDYslzZWnj7qUT/tXyJQls2uS7p9gWjNsW7uJ0AQTx s3wYPDfIhkVo2QAkxYRlpRvYc4AStLA+IiA2Au6l1lV9PJoMY9GCNBunj5gtfgNIAI7s JKLrm8ZtZr4wgZkxrHeKUC9unQLxG8HCch+dm9wuVsM24LJcsGHij70Dxgq5NGcM/ljU MwGqkkkbCWzESP8lGvkGKTspC+M/iBC3zQA/WOyQVAoLr2TQEUQYH7eAgQkdg2EOualp zjIw== X-Gm-Message-State: APjAAAXHTTMWBj9Pe+yzqhFqu1hUskN04tiD+arRXM2Ty+22vsuHZdCc 7T6TctbEl/KNVgEV1xyrPLFgiQ== X-Google-Smtp-Source: APXvYqy18zf3XosU8y4peGneBh50FW2Gynb+ZaBTGHs+TmE6Px6rp0nwka0P0vb4Yv2oZ65stPVprg== X-Received: by 2002:a37:e50f:: with SMTP id e15mr14378854qkg.192.1571930138163; Thu, 24 Oct 2019 08:15:38 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id l5sm4346073qtj.52.2019.10.24.08.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 08:15:37 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML , Robert Walker Subject: [PATCH v1 4/4] perf cs-etm: Fix unsigned variable comparison to zero Date: Thu, 24 Oct 2019 23:13:25 +0800 Message-Id: <20191024151325.28623-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024151325.28623-1-leo.yan@linaro.org> References: <20191024151325.28623-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191024_081540_247128_CC83A6DA X-CRM114-Status: GOOD ( 13.28 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:741 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The variable 'offset' in function cs_etm__sample() is u64 type, it's not appropriate to check it with 'while (offset > 0)'; this patch changes to 'while (offset)'. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index d9a857abaca8..52fe7d6d4f29 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -945,7 +945,7 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, if (packet->isa == CS_ETM_ISA_T32) { u64 addr = packet->start_addr; - while (offset > 0) { + while (offset) { addr += cs_etm__t32_instr_size(etmq, trace_chan_id, addr); offset--;