From patchwork Fri Nov 1 02:07:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 178239 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp200559ill; Thu, 31 Oct 2019 19:08:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyV3a2AVAauGKl5Dv/9R9jPy7qihHw2kPwAGumUbS5wNG3Pvgw/kKVIYjXphoKnIRBeuWQX X-Received: by 2002:a17:906:4dd5:: with SMTP id f21mr7212289ejw.203.1572574097596; Thu, 31 Oct 2019 19:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572574097; cv=none; d=google.com; s=arc-20160816; b=zrXcNUuJfmT+rI3iXGAxMt7QvZDR4x/iin5bya/QFZZOHKJeHFbSsSSYTVN9fKuJAT q387rGbyymYeTAByy3sChZ0q8csjzD+iCmiTlFTbGtkSgByJu/Y5VaMVLPflGGeRhNkR JCYZ5JyrgbFj3jCnTXftyZySwhusm7MoQQL8euldB2OkTpg0VCbTE/BG+L8mfwQgolpp 1RLIKMO79QkPRJqIonjTrYEHOWk1cuoVKZsZg1C+n+DttbHVNNUo8q9LeKWmBBc839vr 2wHYP0UUBmysTQEtZgfErTbl71KXptEK3xFzbgNu2PYetwyVKTzkVWd95llFESBUA55n bJOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=iAgomrDaaw+p9SyPDKe+DIwZEIKyPHeJdp6rMCsSqrc=; b=KF1ba6qqVrbFoK1O/OVTIb4+yGn93cpvJWOTLb2kqSUnIjQYUJh/4MYRHz3apmXBFW GITpukObCTGgqkAIrWyBD1nXtyMOPGR2VGaVYV3RNR/lgaiQmcgXGYJ2uM368sLN2kl7 F/4upuuUXuUgtLDYHh77ZFZOSWngvESP6QBU7YicjyPlA/LVKEZRNcJuEPJcxqgG/yCw 8UvuvDOyKlByJxjs08sLBHrz2WRzfyOP5aO2Mzf/fCuoqDxoxEzl/WBNrXSpGolLLpxn 5gmGDvi1h4cl2vwtMvDB/vbk/TOcnzIHkp6oBg4wvAZI2CHxB+aEoZhIOuVjmfSzTURz S/Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KBf2RlKG; 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 nt21si4458647ejb.119.2019.10.31.19.08.17; Thu, 31 Oct 2019 19:08:17 -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=KBf2RlKG; 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 S1728882AbfKACIL (ORCPT + 26 others); Thu, 31 Oct 2019 22:08:11 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:46611 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbfKACIL (ORCPT ); Thu, 31 Oct 2019 22:08:11 -0400 Received: by mail-yw1-f66.google.com with SMTP id i2so2958491ywg.13 for ; Thu, 31 Oct 2019 19:08: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=KBf2RlKG/HVF+HdZkZwipGGFDc87+W3TEb3cKUL72YSFO06gGeEQCdgEwVcGArbIEC 0hSgawpERrPxShlj96U8j0EgDlDAsSoXTlAfDF2GR344/R8BofFgqibEFBlB+mtGqpuN yFMWgZDIShlUYgLFAy6VDY/j17XU0RC2KQPP9Zcp0/Fq/zv2fYl5Gzg2C+K9spCxNznK QykUXf43faePtkV1/a+P/HuHQYCopqaTgTTJtmlrkvjthjf5XRXXi8vGr5ds8Y7RcjoL KbYzAlzMi2De7OyKSieTdE1sGOTS6Q/7qt25zBlxC+3NjFCaXNOZpXMQxfg/hFGQtbec FXmA== 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=KGKj1h/YmuZ6t6FDgjyA5QAqtZ0FjuZB+CQKsNuwdOGl+aXgAqnJYtTBw69xEYZe3t koYMeqMvj7ffkCr3qEwcqEmB9TRHKkgrEJJ8LtHMr7hBSM4pl7dDyusvy2ac2+0xJThI r0L5Cxi3cIrxFoNP7P86q9h8RXtiIDh2dJJhynzqb2K+NXMfqHtSqRotkAFB6pqfBFgf o2mCdc3F3IXw8VNTztEDrIQ3ndk7MXs6yp2m4B0NQEr1wAOARfaI7xi8o5iOvrg2NtAO yxX6thGBjL+rLY3jTPxDrK6uSBMdTZ/R9avVaEX1m1zTNac2EXWBK913f2PIl3BwRgxf tcIg== X-Gm-Message-State: APjAAAWyM6tFOlC3uASKqNbrtgDDZ70VyDXjHHzRt7+erWmzduD7370a E+tEdZDCIpyoShtMBrYgOMzdmw== X-Received: by 2002:a81:8501:: with SMTP id v1mr6501020ywf.406.1572574090230; Thu, 31 Oct 2019 19:08:10 -0700 (PDT) Received: from localhost.localdomain (li1038-30.members.linode.com. [45.33.96.30]) by smtp.gmail.com with ESMTPSA id m5sm3762076ywj.27.2019.10.31.19.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 19:08:09 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel , Linux Kernel Mailing List , Coresight ML , Robert Walker Cc: Leo Yan Subject: [PATCH v2 1/4] perf cs-etm: Continuously record last branches Date: Fri, 1 Nov 2019 10:07:47 +0800 Message-Id: <20191101020750.29063-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191101020750.29063-1-leo.yan@linaro.org> References: <20191101020750.29063-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) -- 2.17.1 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 Fri Nov 1 02:07:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 178240 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp200715ill; Thu, 31 Oct 2019 19:08:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxstSLQ2c7BoqJoT0LP6zKGrkcsQw0QWBrZKahHDCNVmuLlH1G/XPUEeofe8mfUFGg5z8jP X-Received: by 2002:aa7:c691:: with SMTP id n17mr10198863edq.100.1572574108161; Thu, 31 Oct 2019 19:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572574108; cv=none; d=google.com; s=arc-20160816; b=ilzPSCGkY30AE3IBUzB4rTFRcpBQ+VcdDbegx+3Kgc+P9p4cX6Nlnk0iVo+Luq+NTq MCkHPTsLqC9CN2mtN3x8f5g4SP0SY0rsYVF5dinM4j818nX84SukBrIyoJoABrsPCT93 9Me3L3R57ZgU0y4rwdGNBsyIDG6UlJAzfvkFEPgFv09bqvzkoM4MUOtX9HNR5q0cnJKg WJJPu0e3TY792xxzTQeHFcaUGwlJfSfNBx96+ToYwexHSDBmciY5mkO9rhKoLaaLU8qR mfK2L70A9j5jm8fprVkRpVeDv4lZz8p+MC/v+WTW3YIl2eP7DeU1ZEg4ZbWtJKFk6Hq5 d/nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=gsFY1KIx9iJYif7vQxfbD15FpxrJSPWH13lYc5zzTiA=; b=wj+3Nj5LoXV7PERrGBJxF0p5FrieGwE4gerxBwdC6tOVfm9I+96z9c49q2hiRpZIgM g/r2QPzt0dIfuLl3M3LIvMEZPbpJ+WhifaRe2p4A+hcnDQzYKhPXUvG4Fc24P1MgJKax AxvTJ/X33ed3MZyJyKxbB8ZBAHyBcb+Hsq9JgPcpuREcXAzI56L73th8J7cBdrztZKQ5 rsZlFHjfpimvP9XifrKQxl51QeLhODzAn30r55OIA/SgGadKla15Vtna7VHCcqEHADjZ Ffc04d4rdbXlOZb+ysPUqw4NSpjGAlT6CsgsbAdhh1JsRexI/VQA2EdjhtJdKLPrPc+/ XzEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nnIBH/N8"; 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 i2si4824440ejh.311.2019.10.31.19.08.27; Thu, 31 Oct 2019 19:08:28 -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="nnIBH/N8"; 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 S1728998AbfKACIS (ORCPT + 26 others); Thu, 31 Oct 2019 22:08:18 -0400 Received: from mail-yb1-f170.google.com ([209.85.219.170]:39949 "EHLO mail-yb1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbfKACIR (ORCPT ); Thu, 31 Oct 2019 22:08:17 -0400 Received: by mail-yb1-f170.google.com with SMTP id d12so3309946ybn.7 for ; Thu, 31 Oct 2019 19:08:16 -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=nnIBH/N8r0bXFneNBS/XdONbwd5cpWNaSL+I/9jdd5Fmz60RYTHgZRqaUPxlkLfJF/ fT6GoUIjbcZhvKEtfb1T5N8NEwHU+IiYHQ3C82VVD/k4ASdseeN5QRLFhb9CmK7yaztb l8Ox6EfAwEAeytcg+F2Eva4DhkSi98nCukrrUg3mYlwAEh1lRsw4xa2lar2+1mxpb52c W/Dm2m44xqX8rNbaKrzSkpjoauSA9/olWoWgM/M1PlrW3gt0vFsy0lTDtBMVcQxSGoko kl4I1jePNxSuX/D0RlPxYlv9XF/duXDAKtVGCoMRrUg9FKfem1SRsGMYr0PEcOLiw0eY jcHQ== 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=tywmPe8ZrijwFtEII6Q/V4lwjjHzZk/VznBIJSOe7wbx8i2+N685O0jMfKQB0mXwIa zIDXkLW/uf/o4WVzeee8qYIYM9NB7MZImLVa8rnxr+TVZJ8fHGEFkMpryaclQySAJnvG VHbS416FA/HHSsH5/Qxee80qlK7JsCPzIAXbuRYpXJgVGdvZzYyWDWx4tp66pwhX7yho p1+JEgeCLzBJ9H9PHQmm94Tv3prk5V7luI+6nJtjqMx5AFftf98QxVd7iIprdfX204jm KWHFeQdOmqFrply902Pf9Moz/4kUvU3l77eABPEzYBtA2LsHU2lJ0v7kkYMYDpvSstDV 5hWA== X-Gm-Message-State: APjAAAXBcnxo1WvgdB0UqEQUyBNCBUT/VIsY14yNxuG1SVh3H+SvUZ19 U4109Kzk4WpKOu2vC3W0WTWgOQ== X-Received: by 2002:a25:ba01:: with SMTP id t1mr6972869ybg.309.1572574095898; Thu, 31 Oct 2019 19:08:15 -0700 (PDT) Received: from localhost.localdomain (li1038-30.members.linode.com. [45.33.96.30]) by smtp.gmail.com with ESMTPSA id m5sm3762076ywj.27.2019.10.31.19.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 19:08:15 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel , Linux Kernel Mailing List , Coresight ML , Robert Walker Cc: Leo Yan Subject: [PATCH v2 2/4] perf cs-etm: Correct synthesizing instruction samples Date: Fri, 1 Nov 2019 10:07:48 +0800 Message-Id: <20191101020750.29063-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191101020750.29063-1-leo.yan@linaro.org> References: <20191101020750.29063-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) -- 2.17.1 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 Fri Nov 1 02:07:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 178241 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp200721ill; Thu, 31 Oct 2019 19:08:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxh8Czstr2/Li0SIx0eVZqPH6Wi4Z25PUzSLkqMLVyHOZGDVVsa5aP0l5VRFxmkWzO4DbS2 X-Received: by 2002:aa7:db46:: with SMTP id n6mr10017541edt.46.1572574108638; Thu, 31 Oct 2019 19:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572574108; cv=none; d=google.com; s=arc-20160816; b=gfftsa0+DXZOVz1XBW3dMrXgO9MclQThFAg3rOSk04S9GTZ/yE/PhadlMRutcD0Gjp ijCT32IqgipxpcE+Mtz4oG99Pya8PXlgMNmiMXe3b51TC1WVdU+BWGmFw0auwrXyf/Yd 8M4TRhXglUn8YYS29QydNzvgi1H0EC8Xkoi4oqAXVOnJTDctG6Ce2vkcYxAma5aW15OM dvcTCjgHkPwjDG8MvGOUTcc6/UKHLfuRTCrZBvI0pOylp6rnYmkVHLdpEQng6ZQbRWF+ hkqgFtMX1s2O6Df3ZzWW5LNsQLNaR0klWX3KH2mfMYQvKZgvz2YCsYaQnzxKIxZaZOoO HGsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=2+8OeCtlRuFQGQZkXW2FoUzBMjUDZlZhy5R5fOMQGeQ=; b=FvXCCCLkneSgoKEm9DkW/sICmkhfjaqC74UCe4ep2F29TQ9NJvDqSD131/VKFHo8Pq T0H0+u1dCazu8/QrFnhVg8Xp0elkupk5JC2TX2NKwsUs3Q9yh/8ZSVw4y0qzUqbAXpmT /WFb+K8HHfUmqgtOu2Eb0xOO2z95ioU++OVwFTJdm1XKZwumKDfIaBMpSUwAWUkKoGoQ cq+1ECZSuGRQfxXLz25n3n9DmozkynwqgpY5VGG9gBXkLMRL16f1arT5EEfsnKKTgYTA W+ngz6tPh8B+BRFQXsQ4sai8PFul1lz0eQ5/0DsI7l/lBd5mOu275kwin90ATuJNHLax 6jqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJOHhfl0; 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 i2si4824440ejh.311.2019.10.31.19.08.28; Thu, 31 Oct 2019 19:08:28 -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=AJOHhfl0; 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 S1729117AbfKACIX (ORCPT + 26 others); Thu, 31 Oct 2019 22:08:23 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:33232 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbfKACIW (ORCPT ); Thu, 31 Oct 2019 22:08:22 -0400 Received: by mail-yw1-f66.google.com with SMTP id v5so2991538ywd.0 for ; Thu, 31 Oct 2019 19:08:21 -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=AJOHhfl0StRhcUpCA5zJeo0P2IEvqTeNDulLlCaBFPK+ZAP8dVuthBje7eWoyabpjm SSyOsc4/telusudRFg7SxtO18Dx15vBSSGVrf6wWnueNcje2xiGzfdgYnz8IwJHU5j47 WVOhVQTaO0dD7N7OPls4kqy73Ru6D+gidplMIDTPqGoy78UtifHtMaRjWPu3wrarGqLF SnBaDUA9Nr7OZ63yooGcuv+E82R3dJ0OA1b3vYMGOQ5NQqwrQsbCm4AyVqGTn1P/17K+ DirLYY63HQxTeO4NBeBIEIAj48p2Obx9uqX1AKDjI3OBSTlx+D5m39Od+M2l8Jshf1wH gikA== 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=PP8JKo8MsLrsj7MO2j+Bx8XYfZRfpFLTPf4dfv6XI7/oQDYh9cEJzTQw7Axl5jMZsE rfNGAzknXYXMcIkptpxaMFUaYSYdmywgpa+zKi6RnUkUEbG9Ss6nbuzdgj2tomQ/McSB ZAnumslUFSK4ksm4HUvGpW0V+cBa2cY2F6dA45cpGbLJS0FTAW86zkH1JeiwV4OynNDE kHRQ2tuaHM5J96MsihPNq/3YNilV8DFMn8DkgZ/3U6qnriHa6CReBYwplKOzoC4v3eG3 PnG/KKt93XRlCWAEvDU99Y/IcTtzIh/YJGcaSHzTE2wk8XkrQ3R8Ft/WFat8lymooZOp M5UA== X-Gm-Message-State: APjAAAUnhYc5v6to6zh3bqw7iEHSsjtd0LKvPbycDJmdaEQYO59gHZTG 6s4KId0Maf3dGsZAAUFRsCd6EsV9dXUVrg== X-Received: by 2002:a0d:f1c2:: with SMTP id a185mr6531087ywf.298.1572574101361; Thu, 31 Oct 2019 19:08:21 -0700 (PDT) Received: from localhost.localdomain (li1038-30.members.linode.com. [45.33.96.30]) by smtp.gmail.com with ESMTPSA id m5sm3762076ywj.27.2019.10.31.19.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 19:08:20 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel , Linux Kernel Mailing List , Coresight ML , Robert Walker Cc: Leo Yan Subject: [PATCH v2 3/4] perf cs-etm: Optimize copying last branches Date: Fri, 1 Nov 2019 10:07:49 +0800 Message-Id: <20191101020750.29063-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191101020750.29063-1-leo.yan@linaro.org> References: <20191101020750.29063-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) -- 2.17.1 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 Fri Nov 1 02:07:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 178242 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp200801ill; Thu, 31 Oct 2019 19:08:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3va0BWfqvk/dcJV0CerNkb/7mZchYa4sptlzyotcc1GmYxl79E5TxMUq171qYBXTf7Nba X-Received: by 2002:a05:6402:154e:: with SMTP id p14mr10117698edx.145.1572574115067; Thu, 31 Oct 2019 19:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572574115; cv=none; d=google.com; s=arc-20160816; b=TjL4raKCZQvE8bYsY4isckKNzGf/DCFqy1+/TjGGIrijXkD1LMCTb+qZ+MDkLvoa/L D6jl2BJ737vMY4xXDMitTXZO4He7ze8AhO0L4clsxa9Az+UgN0Jw6iBFQwTbG5bKlvv0 +qzrpzlQKozouNde1/4DOqKPS/vzY9QeqvpqoIYISjcmyxDCo/uxvWZSeDZygwVqiowg eQF5Hx/g3UfPb1jS2bREqHx8RrivozfWiyLmMRrcAxwGZCWhYatc70G6+R+RmajYeV2/ 8xNFKJn638mrLrtiPw1xe+tcKVaWjm5xAbuP32j1rv3LjdQkDSWq9Kk4JNHO5z00sEgU Qljg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=+iIRtubR+3wcJynWU+Kes2QJp/E/y+xxgrhDiusBOkw=; b=UFTxvrpHenSWDbXgc5eO9RjrP0Q6Q79c6DCy1dRUjK0SEwIGU54Fq5JVEug9DB0SlH 2RhGqYfSQR1qfa+G1YUFIFTrwMptSth+vA2ER665JwdJNDoh0RNQcDxdeSXIosELBGGr M7tqK9WaDfjUYWC3104oZqQLxfGDUbWrRzqwSEdmcSaohRz56d7qzR0oIqVjYkpPO0fD vGpA5FPqeIcOKPuSZ4GFQ3/M+YGUW0HYEf6xWMAzsw1yeeAV5jV0+Di5OVTujFgFkYkq kxZP8Nm3HEnqrBphOSDeaChV77cvqZQSG4TKeKIezzDah9NssdTTT6+s2rroxvwhmmm5 zXnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NC1q5M8j; 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 4si5593527ejc.382.2019.10.31.19.08.34; Thu, 31 Oct 2019 19:08:35 -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=NC1q5M8j; 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 S1729182AbfKACI3 (ORCPT + 26 others); Thu, 31 Oct 2019 22:08:29 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:38376 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbfKACI1 (ORCPT ); Thu, 31 Oct 2019 22:08:27 -0400 Received: by mail-yb1-f195.google.com with SMTP id w6so1736643ybj.5 for ; Thu, 31 Oct 2019 19:08: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=+iIRtubR+3wcJynWU+Kes2QJp/E/y+xxgrhDiusBOkw=; b=NC1q5M8jluovAv+CJVmfUvLK4FahIG39LJ6l6gjbCZNa0UpX/mFDwNFqHQiy1rePxC /lbNlkIbyZL58s39+0Wb2t5W1VYQ6Y0GCUYYdttaWTpE8t46toe9NpguBwwHVVOSaw01 +fvDyEdd3LOlUWQsIxhWRiNIxniYiHEyi04hLDNX7S/Rma6Ub8dSPdWBA3vKjwhZ2Nse PqomKFz8PSBasrKVgjJNsSp+eHqcpecI8MOiLr2G1mHF1PIPxkCgFkSilH+tM1D7QREx iAtGvPl+1b1RtFLTVvsNP+F19SDMMjmPa50SD3+5SFhh2FlphPLBnDYHBI5bc/oJ67eF gd1Q== 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=fFPJIMqIBnqKj7sR5UUKLvJoP6b6pRhI2T+5JU+DWtOyguCRgXF8FuouePw09HPply IYlIY013YZMjFcUMG5nKyZJXPJEvmaR0cq6xbT/wIsa+U0OT9FOLkyfcoWwZGKYzv2EL uNT3lGjhrnX175M9FB87IyA98Y2s6/XU+S1u+W9oNbmlmecsW8s4+J4EkfuhvE78KMIm +IGpoRRP2jY8uO27Al5YE6OmC4C66U5UivNZ+rhDl3JJTk44qFs06wErPyr6V1FIAE0w SsHAhv/aTPSisT2qJCSteZyMRw5xpyEUTlmoq25/NCWVl9I1JT4yJ5wykhA3mmpVTZIc 3lTw== X-Gm-Message-State: APjAAAUIw3ANKwqyO7XiZ9gWxZhz8iC9GIZRWyC0r1Q0rqdpI/30RvfY FrxIT0eCLobGL6V6dEQAZV1HWg== X-Received: by 2002:a25:c008:: with SMTP id c8mr7402086ybf.318.1572574106466; Thu, 31 Oct 2019 19:08:26 -0700 (PDT) Received: from localhost.localdomain (li1038-30.members.linode.com. [45.33.96.30]) by smtp.gmail.com with ESMTPSA id m5sm3762076ywj.27.2019.10.31.19.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 19:08:25 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel , Linux Kernel Mailing List , Coresight ML , Robert Walker Cc: Leo Yan Subject: [PATCH v2 4/4] perf cs-etm: Fix unsigned variable comparison to zero Date: Fri, 1 Nov 2019 10:07:50 +0800 Message-Id: <20191101020750.29063-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191101020750.29063-1-leo.yan@linaro.org> References: <20191101020750.29063-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) -- 2.17.1 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--;