Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp622005ybt; Fri, 10 Jul 2020 08:17:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbEDiJJJ6ne6SpIB//nOHWr+7EhTz6qsDPTdRrwMzghsH8ytS/WPS6p5+8MJH3Pqm3il1e X-Received: by 2002:a17:906:f1d5:: with SMTP id gx21mr60391806ejb.121.1594394233815; Fri, 10 Jul 2020 08:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594394233; cv=none; d=google.com; s=arc-20160816; b=Ds8EWXJB0uMZch+QESUkU/vV4pC4Rs847kkn5e0OuI3LN4lUUlMXw5YzIO2MYiTTZE QC6Ntlf0sh8nJ3fSNhqiaonfjDSFCrn5eySNKCP9C8mZhGLZYVJSfSmmzyLdmvRF9yOU zyU2U5/vxmP6O3Ms+ijdHlCmZBPwA9I/BFtHTpht4RGR0JAYouMNkwnIUghpgHXuJtiI eIj1aarzrcJRV8vXtVd4ExBd0lWUEVnYhol28LQ53s9UErIaEck15km1QBL//F4Pj18R LaB6IH16HjXUo5RHLmaRTFKe1U9TD50C4IAQ6mpUUdet1gOHOzTkFICq24OGOJP4M5GS Vx8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=R81sS95q5pPkrmTwRqytIcyV61bzGQFR+PIDre6H57I=; b=dzgGU6QjCzdzeOIMYRK4zgwXh37slZElYhfFXU555X/DYLK2YAldPvvxAih8ocz3Uo 2LAMyZT2eiAQILewTbBJ3mNitYXhk9JC/p7bNzCQQBIZd8I+v5+8AojfaCRjLDxZoNd5 eWL/tlNS1g9tilT/Bk53JW5gg7K8hhRTx+E5R/D3kbHQccKPSC3YD4iAup2Y7sI7HCEq 2j4Rs2pwEWwUYv5RtBXoRHG0/JahaCk30upiIGS0PuKYzhzhU7MM9geA/5UY755ujgPm 9ql9g4oPdpvRBE13gaIxHEtoA83L5ghjY24avbet+W9OKc+uO6FQpyKqjgeDcKyFCyQH UCZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q28si4144589edw.196.2020.07.10.08.16.50; Fri, 10 Jul 2020 08:17:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727998AbgGJPNb (ORCPT + 99 others); Fri, 10 Jul 2020 11:13:31 -0400 Received: from mga09.intel.com ([134.134.136.24]:38270 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726965AbgGJPLx (ORCPT ); Fri, 10 Jul 2020 11:11:53 -0400 IronPort-SDR: Cp6LbjhzQlpOllXg7hkmao7g6daeJMweY1IPdsErem6Bf05Y+uFV7RjV0uB4j3iZ6yTryz3cR4 Ew+SmysBCtfQ== X-IronPort-AV: E=McAfee;i="6000,8403,9678"; a="149686211" X-IronPort-AV: E=Sophos;i="5.75,336,1589266800"; d="scan'208";a="149686211" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2020 08:11:51 -0700 IronPort-SDR: wx/p/6Y9F70FCM9u+GtIwF3UEbtRwgc61zMQZTq5rfuccrFA9iFnVcOZa+Q22Vh7mv3P97d/WB LotmiQIxsSlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,336,1589266800"; d="scan'208";a="484675462" Received: from ahunter-desktop.fi.intel.com ([10.237.72.73]) by fmsmga005.fm.intel.com with ESMTP; 10 Jul 2020 08:11:49 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Andi Kleen , linux-kernel@vger.kernel.org Subject: [PATCH V2 02/12] perf intel-pt: Fix duplicate branch after CBR Date: Fri, 10 Jul 2020 18:10:54 +0300 Message-Id: <20200710151104.15137-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200710151104.15137-1-adrian.hunter@intel.com> References: <20200710151104.15137-1-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CBR events can result in a duplicate branch event, because the state type defaults to a branch. Fix by clearing the state type. Example: trace 'sleep' and hope for a frequency change Before: $ perf record -e intel_pt//u sleep 0.1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.034 MB perf.data ] $ perf script --itrace=bpe > before.txt After: $ perf script --itrace=bpe > after.txt $ diff -u before.txt after.txt --- before.txt 2020-07-07 14:42:18.191508098 +0300 +++ after.txt 2020-07-07 14:42:36.587891753 +0300 @@ -29673,7 +29673,6 @@ sleep 93431 [007] 15411.619905: 1 branches:u: 0 [unknown] ([unknown]) => 7f0818abb2e0 clock_nanosleep@@GLIBC_2.17+0x0 (/usr/lib/x86_64-linux-gnu/libc-2.31.so) sleep 93431 [007] 15411.619905: 1 branches:u: 7f0818abb30c clock_nanosleep@@GLIBC_2.17+0x2c (/usr/lib/x86_64-linux-gnu/libc-2.31.so) => 0 [unknown] ([unknown]) sleep 93431 [007] 15411.720069: cbr: cbr: 15 freq: 1507 MHz ( 56%) 7f0818abb30c clock_nanosleep@@GLIBC_2.17+0x2c (/usr/lib/x86_64-linux-gnu/libc-2.31.so) - sleep 93431 [007] 15411.720069: 1 branches:u: 7f0818abb30c clock_nanosleep@@GLIBC_2.17+0x2c (/usr/lib/x86_64-linux-gnu/libc-2.31.so) => 0 [unknown] ([unknown]) sleep 93431 [007] 15411.720076: 1 branches:u: 0 [unknown] ([unknown]) => 7f0818abb30e clock_nanosleep@@GLIBC_2.17+0x2e (/usr/lib/x86_64-linux-gnu/libc-2.31.so) sleep 93431 [007] 15411.720077: 1 branches:u: 7f0818abb323 clock_nanosleep@@GLIBC_2.17+0x43 (/usr/lib/x86_64-linux-gnu/libc-2.31.so) => 7f0818ac0eb7 __nanosleep+0x17 (/usr/lib/x86_64-linux-gnu/libc-2.31.so) sleep 93431 [007] 15411.720077: 1 branches:u: 7f0818ac0ebf __nanosleep+0x1f (/usr/lib/x86_64-linux-gnu/libc-2.31.so) => 55cb7e4c2827 rpl_nanosleep+0x97 (/usr/bin/sleep) Signed-off-by: Adrian Hunter Fixes: 91de8684f1cff ("perf intel-pt: Cater for CBR change in PSB+") Fixes: abe5a1d3e4bee ("perf intel-pt: Decoder to output CBR changes immediately") Cc: stable@vger.kernel.org --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c index 75c4bd74d521..7ffcbd6fcd1a 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -1977,8 +1977,10 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder) * possibility of another CBR change that gets caught up * in the PSB+. */ - if (decoder->cbr != decoder->cbr_seen) + if (decoder->cbr != decoder->cbr_seen) { + decoder->state.type = 0; return 0; + } break; case INTEL_PT_PIP: @@ -2019,8 +2021,10 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder) case INTEL_PT_CBR: intel_pt_calc_cbr(decoder); - if (decoder->cbr != decoder->cbr_seen) + if (decoder->cbr != decoder->cbr_seen) { + decoder->state.type = 0; return 0; + } break; case INTEL_PT_MODE_EXEC: -- 2.17.1