Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp66639pxy; Fri, 30 Apr 2021 00:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXHeSEPwYxbPXAiRs1UA/JsmnKG4yG/0SO78HZZv1+g9MrrI0uV1sXJAcDlw6hTeZrURzk X-Received: by 2002:a17:90a:6a0f:: with SMTP id t15mr3984229pjj.64.1619766282514; Fri, 30 Apr 2021 00:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619766282; cv=none; d=google.com; s=arc-20160816; b=x8wtCtY2KS/QfXuv8014oNL5hTr3tXJ7IPSQfh7HXmpKzy0Ym7aO1GEfPMwthvDR/6 L4Ixqd+P9owYXiWUGIgN248BMHTgK+WRd3EwqMhoyeXkiCkCksbnBz3XeX874dNVSOjJ 1EnV4AfUSKyk5Rl/YcNKJRzRQNzs62LQEdLcAh7aTnbMvwuj02B6idzSoBFQxw/2bSdY hEFATmrDVbNELonNsvY6G60/vbamSWPaiSlbnLqtFVWm6BcYd1KBU1mPD6OkA8vHc3St UwjexUULOHvCGvR50IwuTbKo38wFpAJFI7ZgbkGbtwBkwiIaRZvawzz1SwSYo9YLCO1V DyqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:references:in-reply-to:message-id :date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=IdGXu7CqYMnpZqgJqMzfh7a3xM2EZ8baj0YgZDl+Mvg=; b=PC5XiIa+irX9iV/AKumXRTkrbZYbJmFugB2tGOgJ8SDlkgxT+WzSXlW7klCYhLkht4 R0LU+qwefuMeG/6tH5SVt+K5sxZiuV0cFL9yFeZsbrljLtlVuWLcktTa6OfQP/LAjLQI o/EFGPYxBvRZXoGrqvQzb6394EzrhV8OwBG8fhBN/6OM4s9s5L+yu4oh93msNjWa/G50 tFEKjBxtp2R0jo7x8NgnQNVNiLsQWVXrxubkDFVPlRDFmWYIZIcXlvdg0fxKCoJ0s2SF pKPZejI3tgyclxvYt4b3Cwy6xr9l2D9cIc3sjTRbeeXkEpP+0ocfMQOjw4ZJq12ZrTU9 eFnw== 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 i12si2461401pgp.587.2021.04.30.00.04.16; Fri, 30 Apr 2021 00:04:42 -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 S231179AbhD3HD6 (ORCPT + 99 others); Fri, 30 Apr 2021 03:03:58 -0400 Received: from mga09.intel.com ([134.134.136.24]:34054 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230518AbhD3HDw (ORCPT ); Fri, 30 Apr 2021 03:03:52 -0400 IronPort-SDR: usk3Hv2EOrtCUSaxOBw/EMJ6eWOmiX65j3l5TWQ/4Qr2pBKjPDcjVA9GVIQ9SprCR/Ld3beYsd Fh5zBzUx+8Bw== X-IronPort-AV: E=McAfee;i="6200,9189,9969"; a="197312435" X-IronPort-AV: E=Sophos;i="5.82,260,1613462400"; d="scan'208";a="197312435" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2021 00:03:04 -0700 IronPort-SDR: 6XwRF/QPPZBUC4tp70B7EV9gQPhBtKt2usn7P6tFl7gSHPRWulcaM6KHT2RiBISJcAXkMh1drz UP/2Zla8+rAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,260,1613462400"; d="scan'208";a="404492314" Received: from ahunter-desktop.fi.intel.com ([10.237.72.174]) by orsmga002.jf.intel.com with ESMTP; 30 Apr 2021 00:03:02 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo , Jiri Olsa , Andi Kleen Cc: linux-kernel@vger.kernel.org Subject: [PATCH V2 07/12] perf intel-pt: Let overlap detection handle VM timestamps Date: Fri, 30 Apr 2021 10:03:04 +0300 Message-Id: <20210430070309.17624-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210430070309.17624-1-adrian.hunter@intel.com> References: <20210430070309.17624-1-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Intel PT timestamps are affected by virtualization. While TSC packets can still be considered to be unique, the TSC values need not be in order any more. Adjust the algorithm accordingly. Signed-off-by: Adrian Hunter --- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 ++++++++---- tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 3 ++- tools/perf/util/intel-pt.c | 10 +++++++++- 3 files changed, 19 insertions(+), 6 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 8c59677bee13..8f916f90205e 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c @@ -3227,6 +3227,7 @@ static unsigned char *adj_for_padding(unsigned char *buf_b, * @len_b: size of second buffer * @consecutive: returns true if there is data in buf_b that is consecutive * to buf_a + * @ooo_tsc: out-of-order TSC due to VM TSC offset / scaling * * If the trace contains TSC we can look at the last TSC of @buf_a and the * first TSC of @buf_b in order to determine if the buffers overlap, and then @@ -3239,7 +3240,8 @@ static unsigned char *adj_for_padding(unsigned char *buf_b, static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a, size_t len_a, unsigned char *buf_b, - size_t len_b, bool *consecutive) + size_t len_b, bool *consecutive, + bool ooo_tsc) { uint64_t tsc_a, tsc_b; unsigned char *p; @@ -3274,7 +3276,7 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a, start = buf_b + len_b - (rem_b - rem_a); return adj_for_padding(start, buf_a, len_a); } - if (cmp < 0) + if (cmp < 0 && !ooo_tsc) return buf_b; /* tsc_a < tsc_b => no overlap */ } @@ -3292,6 +3294,7 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a, * @have_tsc: can use TSC packets to detect overlap * @consecutive: returns true if there is data in buf_b that is consecutive * to buf_a + * @ooo_tsc: out-of-order TSC due to VM TSC offset / scaling * * When trace samples or snapshots are recorded there is the possibility that * the data overlaps. Note that, for the purposes of decoding, data is only @@ -3302,7 +3305,8 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a, */ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a, unsigned char *buf_b, size_t len_b, - bool have_tsc, bool *consecutive) + bool have_tsc, bool *consecutive, + bool ooo_tsc) { unsigned char *found; @@ -3315,7 +3319,7 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a, if (have_tsc) { found = intel_pt_find_overlap_tsc(buf_a, len_a, buf_b, len_b, - consecutive); + consecutive, ooo_tsc); if (found) return found; } diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h index d9e62a7f6f0e..bebdb7d37b39 100644 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h @@ -269,7 +269,8 @@ int intel_pt_fast_forward(struct intel_pt_decoder *decoder, uint64_t timestamp); unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a, unsigned char *buf_b, size_t len_b, - bool have_tsc, bool *consecutive); + bool have_tsc, bool *consecutive, + bool ooo_tsc); int intel_pt__strerror(int code, char *buf, size_t buflen); diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 7bee969eb335..a494d47aa1ad 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -278,9 +278,17 @@ static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer * void *start; start = intel_pt_find_overlap(a->data, a->size, b->data, b->size, - pt->have_tsc, &consecutive); + pt->have_tsc, &consecutive, + pt->synth_opts.vm_time_correlation); if (!start) return -EINVAL; + /* + * In the case of vm_time_correlation, the overlap might contain TSC + * packets that will not be fixed, and that will then no longer work for + * overlap detection. Avoid that by zeroing out the overlap. + */ + if (pt->synth_opts.vm_time_correlation) + memset(b->data, 0, start - b->data); b->use_size = b->data + b->size - start; b->use_data = start; if (b->use_size && consecutive) -- 2.25.1