From patchwork Mon Apr 12 09:10:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12197323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09C0BC43462 for ; Mon, 12 Apr 2021 09:13:08 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F52A61207 for ; Mon, 12 Apr 2021 09:13:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F52A61207 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WhMSulzgR8/1xEt28p8PVnc4T2P3XB2vZ4cXwJ3nZEk=; b=FtshUkyCVAn46OFasW0QN7vpx RNhR1fIk2svX12l2oPRri13s8MsoUZszohnGPBzFIdlIDF6cWN2PycZ8IZ6jzVkOH03p8rxAvFW5s de+pr6pw1tbkMrdqjUX/6PXeKUNvBKTwjEBWA9VeB6ku6He3v9E3TSaTz9vhhkCNZWGUP6yREGKj0 xhsR5RwWi3ySJBXL0aZp6yMJQM2zVZWhPPt7ocTxngRKfqS9Dw8NBZi3Z2bewJU+8KvfBVbrEuSB4 Gt/g1ucNx3WoCEVNhdHcU3MEFSGBf7VGYt5zznxYgwh3HJZd2V/78rTT+W/WpPD0Vy7NLSr1olOVT nAqeVi1pA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lVsbT-006Dnv-Ay; Mon, 12 Apr 2021 09:11:31 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVsae-006DdL-0N for linux-arm-kernel@desiato.infradead.org; Mon, 12 Apr 2021 09:10:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=DDdEqeCFnwU5ANrpdIiJovBy2YEnraj0jTTiTw73jWA=; b=LxLcHRL9KdjBdZuYgbTIw1L+Cw tLr4/NXEf+MivcGKLwUdN5VuAC7cO4nLdHhS4PilG172uY6/+yQRDBpwS/LjVAe+J6wuRi85qRSTX 8bFj/siJhRx/G2Y6CFIGpt4zNaLEhM0bdGGGDssmyXf+JtpRVoTqg0jkPv+BnKQ53Op4Yf7XubRFN KJ1a91Dhg5i/zcduFch2mNKYw1dRh5hmIKyl6fAp5lLPyE30trO1CUNRHTuTfbTnNxGnEANyFJIwN 7zthHcPD+JuSC/MRpahsfWuWN0M8AztuFxamuO6Yedz+UYcLUqIdJZgzUkhA34Qlomvx5GQAeUwe2 GOG3Augw==; Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVsab-0061y8-Cg for linux-arm-kernel@lists.infradead.org; Mon, 12 Apr 2021 09:10:38 +0000 Received: by mail-pg1-x533.google.com with SMTP id w10so8884341pgh.5 for ; Mon, 12 Apr 2021 02:10:37 -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 :mime-version:content-transfer-encoding; bh=DDdEqeCFnwU5ANrpdIiJovBy2YEnraj0jTTiTw73jWA=; b=gg91CZixyITMefJ1sJhgx2hdXm1ZE+PRY67Lka7AurxoPGvAFDu78OuIbjd8ih6vVl I/oeaaFX5uePc5UX5CIMzuWc+mL5n9XSyjzWMB2j/bBUrdkFDXntmO+017RX/UX+zhIB fe8yPcIuPIbrw93HkbAYlapl5xsTSrLQrtqksd+y4ON7P06weocFwd634h675ZQJcH6A NgQQLS6gLGlwTMC16kMGtVhGJOx8nUo197GKeu9pgp4JhoQ9+0PMqdxdXuewhtuw+qn/ qr8k2NWxTuUrTAnNIGK55rwzJ+4WAuSppVdo6O3aV2nL5zfyGPYiNXvWDOJUz7mVDtLm MKtA== 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:mime-version:content-transfer-encoding; bh=DDdEqeCFnwU5ANrpdIiJovBy2YEnraj0jTTiTw73jWA=; b=TuVLVdI9KXhmXCzaANWraEOdPp6RHN3EowLsjQYK1+10wlg1xR2RZy+saaCqizP9tI ytNeYVl6jB9pqZuL4cwnza9xvauYGRh3KPR/aC9rfgZdsGN2S2mrKbsoTjEOm6KT7QFj UZt8wJ5mrJCM8wJ3BZvaOexJzEWCdQH4V4sT24ZAR9dIteNzRs7vna7jAIWH6cUfycp6 gK6Kj7wnidnzbyRSwTGNWkxeUgrYLMpUNdgzOPLi37iOZp9uBYU3mRqkr5qxTCJJCBb7 1MYv8ayjXMtNOwcuT11r2hnKlmPAB+/1/e16thnQ2Bi7cZ5zoNQKWtwK+lCRZvjt0Czi SdSA== X-Gm-Message-State: AOAM532yDnh5IbkklCG57EQanLQXMWwitEeXW/Cscug/5N7Cyt5eo4Ab Y+nEfRJn8SSD/C3mQVOptM3ZoTgsT5p2lTbF X-Google-Smtp-Source: ABdhPJz7fgOGppChz65URuEp0R1SWnjO2GdVuEfsC8NuxoeKAA2p/4KKgvB+VV+20LJHEFGOL/1BLw== X-Received: by 2002:a05:6a00:8c2:b029:23d:60e9:ecb7 with SMTP id s2-20020a056a0008c2b029023d60e9ecb7mr24072334pfu.57.1618218636576; Mon, 12 Apr 2021 02:10:36 -0700 (PDT) Received: from localhost ([116.206.101.232]) by smtp.gmail.com with ESMTPSA id lt11sm1503371pjb.23.2021.04.12.02.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 02:10:36 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Al Grant , John Garry , Will Deacon , Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Dave Martin , James Clark , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v4 5/6] perf arm-spe: Bail out if the trace is later than perf event Date: Mon, 12 Apr 2021 17:10:05 +0800 Message-Id: <20210412091006.468557-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210412091006.468557-1-leo.yan@linaro.org> References: <20210412091006.468557-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210412_021037_451295_23ECC4DC X-CRM114-Status: GOOD ( 21.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 c13a89f06ab8..b37d1cacebe9 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -434,12 +434,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"); @@ -453,10 +477,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;