Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3981834pxu; Mon, 21 Dec 2020 00:41:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxh+RzQ5smpY9EowHPZrYBbWoFsrkURLQM1PbOrLqYOpfgbCTrP4VhLaR/Alfun3dgGft2M X-Received: by 2002:a17:906:d62:: with SMTP id s2mr14380923ejh.61.1608540062742; Mon, 21 Dec 2020 00:41:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608540062; cv=none; d=google.com; s=arc-20160816; b=vCgA6+WyW5HYce6YOcD5tuU2LF3Bkt2B1pf+SVdxmtZLlPwS5QUMwfQsupTkVNcjz6 QcGmAwsHqVOx2rCaVtB6c6dSKWgBzP6jiuPKpuBAoOm9t5nx3WGHM4xGdSkmUVfgHjWk d9NTCsO/lGbAAsgEAFCY2kodBD7JaLTGiG9QB0xbNWrcCyxdudrj5ZliUJcVLRbN/6rr l78T7/Y0fxqXF9mJVQZl9u7qYozsh+Ue748TT1ApP1/p9U8w1PD+dwagBjxY/pLOtcNn 1GQ19yBjA1k7tzVfwJM4A3+OjkIdshIuM89Z8dck3jIfa3a5P5SSUSx2W4Fe10I1R8ef 1CyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=b41ba1W2ldSG8KVAp1Q9RnWVHFezJ/i7w5LipFnjCC4=; b=quFB9mw5lLmXvj8BxEQUmsKJXHkLw1vljlW1Ov3HJgnBZDi3Ur2bq2MHNpOblnE24p TfV//q1BXuIhSfaLllX+ZYLRpiJDHGSt503A20Bg6/aKMPQWhORfzfRVT0jFDfsFMYcb b1mL3NfmDg6ljywdMhir4rWEh5x0NM9pc7hJGGF/7hSfvpaNvXmqelDO/UZIcsQ41gDO aAZswqIzIH5wN+bXKg/zcY4KwNCpIrECXSvmncPUnOMYH4UJLA270RD69piAh6t0behg SeVat0yT59YLG2T+ouPwbU3Fy3kOuPPLunaLOR2M/KP9JW420Bnnb/ZGdYojy1OAW+ju DKJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tp7l5aUB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m3si8703628ejr.562.2020.12.21.00.40.40; Mon, 21 Dec 2020 00:41:02 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=tp7l5aUB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbgLUIiS (ORCPT + 99 others); Mon, 21 Dec 2020 03:38:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbgLUIiR (ORCPT ); Mon, 21 Dec 2020 03:38:17 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D547C0611CA for ; Mon, 21 Dec 2020 00:37:18 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id t6so5260608plq.1 for ; Mon, 21 Dec 2020 00:37:18 -0800 (PST) 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=b41ba1W2ldSG8KVAp1Q9RnWVHFezJ/i7w5LipFnjCC4=; b=tp7l5aUBba2mqatBtxBI1D8MVFq38CUJzZvJY8uMXHtt/XBBulxtQv3L4y3LZNXJIK E6XgRoDZNyEv6VAptUYRtfwYFsF7lW6n6DeH+7W0cTPdhkmxKkRCmED4PW4TodEhK3ZU d42Ycj+EP4rwtHWMuxe304024Be28cvX++GFOYq74mc2ubeaH8zWR1AmpYF1y765IEDh ql9wgR6N1jBQ45zdHDbyJAH3AwAMdjTv6W28dtR2v4kz39SzlGHdg5MA/cTIHIv9IB0R biZtL0WRhmNgkRRQ80HSgP+fNlZJ1c9aLFSrboOnU3+3x54JV/azJiaMEI/pTHbBy413 Kllw== 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=b41ba1W2ldSG8KVAp1Q9RnWVHFezJ/i7w5LipFnjCC4=; b=AL6iJ0geusC2dkvvWJtjKfNA/wqfyQIAgvS6lnw+iWhONJFQ5jmaQiA9NEEgpfw5dF uqKtrjxHbzGuuFGiteoM0l0vF0263sHeANdIsZLqdECmfgaM+9WYr151czBy92OYpOhd JtJRBk9V8bAd8biLRXpr+62RLxEMH8TVF0z057HSYiSLgmObKY+KqRRilzKF58JVDsC2 MU2ZWsbBAs2ZGqX71op5XMYHxLsZOu9Nu9m323wYm5gW3uWBOxLKjHEggd0AlC5gAl6S DruD1k8HnFIuV/r7Cs/+xwVLaGEL6SFr9PXYa6U7M/HnuVp5Mf+UYwUSrBCdfOYYjORm vBbA== X-Gm-Message-State: AOAM530QmyAI1Ne3Sj8o3zQHD8Lfaeh03MMof6F+dxo1xvHgYPkbL5a5 dR7Vkf37mFsB6vgR2Pi/Ylq42A== X-Received: by 2002:a17:902:8685:b029:dc:299c:a2c7 with SMTP id g5-20020a1709028685b02900dc299ca2c7mr15559270plo.33.1608539837724; Mon, 21 Dec 2020 00:37:17 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id x15sm15980340pfa.80.2020.12.21.00.37.16 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Dec 2020 00:37:17 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , John Garry , Will Deacon , Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Ian Rogers , James Clark , Dave Martin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 6/7] perf arm-spe: Bail out if the trace is later than perf event Date: Mon, 21 Dec 2020 16:35:56 +0800 Message-Id: <20201221083557.27642-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201221083557.27642-1-leo.yan@linaro.org> References: <20201221083557.27642-1-leo.yan@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's possible that record in Arm SPE trace is later than perf event and vice versa. This asks to correlate the perf events and Arm SPE synthesized events to be processed in the manner of correct timing. To achieve the time ordering, this patch reverses the flow, it firstly calls arm_spe_sample() and then calls arm_spe_decode(). By comparing the timestamp value and detect the perf event is coming earlier than Arm SPE trace data, it bails out from the decoding loop, the last record is pushed into auxtrace stack and is deferred to generate sample. To track the timestamp, everytime it updates timestamp for the latest record. Signed-off-by: Leo Yan --- tools/perf/util/arm-spe.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c index 2b008b973387..6bf2e4ff5342 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -353,12 +353,36 @@ static int arm_spe_sample(struct arm_spe_queue *speq) static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp) { struct arm_spe *spe = speq->spe; + struct arm_spe_record *record; int ret; if (!spe->kernel_start) spe->kernel_start = machine__kernel_start(spe->machine); while (1) { + /* + * The usual logic is firstly to decode the packets, and then + * based the record to synthesize sample; but here the flow is + * reversed: it calls arm_spe_sample() for synthesizing samples + * prior to arm_spe_decode(). + * + * Two reasons for this code logic: + * 1. Firstly, when setup queue in arm_spe__setup_queue(), it + * has decoded trace data and generated a record, but the record + * is left to generate sample until run to here, so it's correct + * to synthesize sample for the left record. + * 2. After decoding trace data, it needs to compare the record + * timestamp with the coming perf event, if the record timestamp + * is later than the perf event, it needs bail out and pushs the + * record into auxtrace heap, thus the record can be deferred to + * synthesize sample until run to here at the next time; so this + * can correlate samples between Arm SPE trace data and other + * perf events with correct time ordering. + */ + ret = arm_spe_sample(speq); + if (ret) + return ret; + ret = arm_spe_decode(speq->decoder); if (!ret) { pr_debug("No data or all data has been processed.\n"); @@ -372,10 +396,17 @@ static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp) if (ret < 0) continue; - ret = arm_spe_sample(speq); - if (ret) - return ret; + record = &speq->decoder->record; + /* Update timestamp for the last record */ + if (record->timestamp > speq->timestamp) + speq->timestamp = record->timestamp; + + /* + * If the timestamp of the queue is later than timestamp of the + * coming perf event, bail out so can allow the perf event to + * be processed ahead. + */ if (!spe->timeless_decoding && speq->timestamp >= *timestamp) { *timestamp = speq->timestamp; return 0; -- 2.17.1