Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2175685ybm; Thu, 23 May 2019 12:36:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcdWZgEfw6R6MrvEjiXiF4YkNLOAFCyEubhVLHRkpA77EHh382FnNJdBwt70djS0EvhapP X-Received: by 2002:a62:5cc6:: with SMTP id q189mr75659207pfb.114.1558640168532; Thu, 23 May 2019 12:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640168; cv=none; d=google.com; s=arc-20160816; b=cd4mThjHmFCi9lHlxTWYeGkhuy1xSCDEr9l1nVPxF8uLfSn+QWtSoCLZ/gRoK7tAAX SSns1Cq0HLuHG0d0Ti5EM1mSb3xb7DObmeZhKAZT0eh9cguCBHDPnpzdTqkW7b/lwtoe uXOU+tHdvawpmcPhO4vsASAoB5oJfTRAVhCC6pLKGlEZurv+Bm8SjIbfqMQf1SxJLLvF eLjRqu9wfAfXD4NmRbo3/SKInBVnuhCIaiOB/lMIofeG2gDBUPQRI2xBHUoQVKPm3iWC WH9+maO3/8mwY1z8/oTFT0GjuLnSdnTbUFtdzqmMWFyPkODvqcXAPX8vu0V2sfY7/EJt TJVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/NHcTQG4bRkiGQpklDWa4IO10mjFOH9l+ov2T2QI6/g=; b=PT8J1oUjXSNJcWZDbOQox3ZEwaqpzYhXkdK695UL0P4j+t4vrfxtNbW2Y3zGvumvuy +DdRaq34xK/IiBxY6JkEa0XBLXzNrseQT+s7D3K0F+9nFX8pm2aL98sHU+QdgcPvVtAC WUaNejaYIPCo0QbZ++4yKd1KZmA23PdgQzaVtI6iHzLdmkHzD5rDmTH8UijGMz39d6yh 8Y+FdoVPyDuGAWnT/L+tXtxpfHnWS9eaNF1Oxc9dnfgNqSp4SUbzGYtBTa6+apzcRTky B0btZxi+ilmQgRq0PYXebv+Q0NAY3Z9ZAQaO3EDJ5LBkxHATVwmtDLfnm9izAs7sTIg4 HtFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nepY8IIa; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si282891pfh.286.2019.05.23.12.35.53; Thu, 23 May 2019 12:36:08 -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=@kernel.org header.s=default header.b=nepY8IIa; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392024AbfEWTaA (ORCPT + 99 others); Thu, 23 May 2019 15:30:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:43146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390192AbfEWT35 (ORCPT ); Thu, 23 May 2019 15:29:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D1B02133D; Thu, 23 May 2019 19:29:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639796; bh=+athbFoOd2Xxcsmu54xtO7qi37LKpNoQwFHL9MONUjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nepY8IIaAKyYKJ+RtchDwIiyTuaoUTnmzQ1TJZCnBdZOd+U4VaWxnn9No3hEQ9izN Z0VjntBIJi6yEa3dpWRcF7rbnSXBQzGkm3dipkzGjucNRtQ6pGilahmN9PDkjIrGYq w2pLFmsr67g9s5arGXHaVG06VlRAEnsSWhoR5Jzc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Jiri Olsa , Arnaldo Carvalho de Melo Subject: [PATCH 5.1 079/122] perf intel-pt: Fix instructions sampling rate Date: Thu, 23 May 2019 21:06:41 +0200 Message-Id: <20190523181715.203995084@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Adrian Hunter commit 7ba8fa20e26eb3c0c04d747f7fd2223694eac4d5 upstream. The timestamp used to determine if an instruction sample is made, is an estimate based on the number of instructions since the last known timestamp. A consequence is that it might go backwards, which results in extra samples. Change it so that a sample is only made when the timestamp goes forwards. Note this does not affect a sampling period of 0 or sampling periods specified as a count of instructions. Example: Before: $ perf script --itrace=i10us ls 13812 [003] 2167315.222583: 3270 instructions:u: 7fac71e2e494 __GI___tunables_init+0xf4 (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 30902 instructions:u: 7fac71e2da0f _dl_cache_libcmp+0x2f (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 10 instructions:u: 7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 8 instructions:u: 7fac71e2d9ea _dl_cache_libcmp+0xa (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 14 instructions:u: 7fac71e2d9ea _dl_cache_libcmp+0xa (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 6 instructions:u: 7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 14 instructions:u: 7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 4 instructions:u: 7fac71e2dab2 _dl_cache_libcmp+0xd2 (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222728: 16423 instructions:u: 7fac71e2477a _dl_map_object_deps+0x1ba (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222734: 12731 instructions:u: 7fac71e27938 _dl_name_match_p+0x68 (/lib/x86_64-linux-gnu/ld-2.28.so) ... After: $ perf script --itrace=i10us ls 13812 [003] 2167315.222583: 3270 instructions:u: 7fac71e2e494 __GI___tunables_init+0xf4 (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222667: 30902 instructions:u: 7fac71e2da0f _dl_cache_libcmp+0x2f (/lib/x86_64-linux-gnu/ld-2.28.so) ls 13812 [003] 2167315.222728: 16479 instructions:u: 7fac71e2477a _dl_map_object_deps+0x1ba (/lib/x86_64-linux-gnu/ld-2.28.so) ... Signed-off-by: Adrian Hunter Cc: Jiri Olsa Cc: stable@vger.kernel.org Fixes: f4aa081949e7b ("perf tools: Add Intel PT decoder") Link: http://lkml.kernel.org/r/20190510124143.27054-2-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -888,16 +888,20 @@ static uint64_t intel_pt_next_period(str timestamp = decoder->timestamp + decoder->timestamp_insn_cnt; masked_timestamp = timestamp & decoder->period_mask; if (decoder->continuous_period) { - if (masked_timestamp != decoder->last_masked_timestamp) + if (masked_timestamp > decoder->last_masked_timestamp) return 1; } else { timestamp += 1; masked_timestamp = timestamp & decoder->period_mask; - if (masked_timestamp != decoder->last_masked_timestamp) { + if (masked_timestamp > decoder->last_masked_timestamp) { decoder->last_masked_timestamp = masked_timestamp; decoder->continuous_period = true; } } + + if (masked_timestamp < decoder->last_masked_timestamp) + return decoder->period_ticks; + return decoder->period_ticks - (timestamp - masked_timestamp); } @@ -926,7 +930,10 @@ static void intel_pt_sample_insn(struct case INTEL_PT_PERIOD_TICKS: timestamp = decoder->timestamp + decoder->timestamp_insn_cnt; masked_timestamp = timestamp & decoder->period_mask; - decoder->last_masked_timestamp = masked_timestamp; + if (masked_timestamp > decoder->last_masked_timestamp) + decoder->last_masked_timestamp = masked_timestamp; + else + decoder->last_masked_timestamp += decoder->period_ticks; break; case INTEL_PT_PERIOD_NONE: case INTEL_PT_PERIOD_MTC: