From patchwork Wed Apr 14 14:39:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 12203007 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.8 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_PASS,USER_AGENT_GIT autolearn=unavailable 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 1D51DC43462 for ; Wed, 14 Apr 2021 14:41:59 +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 0D69F61029 for ; Wed, 14 Apr 2021 14:41:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D69F61029 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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=8ojo7kV20zNvPooTUD5fNR4/OQhKqKg+lUHY8/lCzh0=; b=S5j1SkvU9275LxaSCGRDj62ge KmcCq5DyEtAlKodEVSmLZmFZCzN8VzrsygSEAPpMxCrn99rrKqviiZuHQss3OFhKW0kHku9oedPWH rbFxXtwgI5d8CddhZNrRaKTnTUgHVszz96QirUbuyKekEx8RgasC3kJrGYZd9UGILf+R9UheN9e7A knGgirOeus76ZlaaP+7h1Q6gt28Koxszj+hk8Fz3agimg7JA8ZgoyBiEkP9sKI0NX+weTkbrG7uwS 9cw94V9KoWw63UUTldfYCW4sAF0/ro/tlvRYW4W0UqTodUy0NMyOmX32O+wcLEWgMN5RtEgCuJL8k OO1eQIdxw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lWgga-00CueL-JE; Wed, 14 Apr 2021 14:40:09 +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 1lWggK-00CudQ-0k for linux-arm-kernel@desiato.infradead.org; Wed, 14 Apr 2021 14:39:52 +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=uLQVQZEnQskSg1N36kSjZzXD10KW6a2xLIC8ehdBIHE=; b=4c0DzmJZvziHinXVAp/NtehHDF +yv/h0wTNoGbHX9NESD3K6pye4bnWwY9A8/Lib2/ygSIBC6EUvtwJ927Vu48a1VInM4yWaP3guqmU ZFlnrEy+vTmjVq0dDyx2rrRA8izUDSH7yxLvovl3esVYwupUphkfi66cFR4kj4qNAYHMQ6AWit1Ut 30u9riv8L1A6u/jOeOZnhQ99vGC6o2DMKmIr+gOu/FPypxyCLRMok3tlILA375kJPtVXBlR6XPvdM 3o99NB5DMMk/Nq7L9e0vnouNq3UAnUj2bhL8bAU4G9hD7lM7zbH2SLappyXoQEkQ/uhruA+uW8tOD hgLRbdNQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lWggH-007pjr-7Y for linux-arm-kernel@lists.infradead.org; Wed, 14 Apr 2021 14:39:50 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1875A11D4; Wed, 14 Apr 2021 07:39:43 -0700 (PDT) Received: from e121896.arm.com (unknown [10.57.47.202]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 875223F694; Wed, 14 Apr 2021 07:39:40 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org Cc: al.grant@arm.com, branislav.rankov@arm.com, denik@chromium.org, suzuki.poulose@arm.com, James Clark , Mike Leach , Leo Yan , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mathieu Poirier , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] perf cs-etm: Set time on synthesised samples to preserve ordering Date: Wed, 14 Apr 2021 17:39:19 +0300 Message-Id: <20210414143919.12605-2-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210414143919.12605-1-james.clark@arm.com> References: <20210414143919.12605-1-james.clark@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210414_073949_387690_822175E8 X-CRM114-Status: GOOD ( 15.35 ) 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 The following attribute is set when synthesising samples in timed decoding mode: attr.sample_type |= PERF_SAMPLE_TIME; This results in new samples that appear to have timestamps but because we don't assign any timestamps to the samples, when the resulting inject file is opened again, the synthesised samples will be on the wrong side of the MMAP or COMM events. For example this results in the samples being associated with the perf binary, rather than the target of the record: perf record -e cs_etm/@tmc_etr0/u top perf inject -i perf.data -o perf.inject --itrace=i100il perf report -i perf.inject Where 'Command' == perf should show as 'top': # Overhead Command Source Shared Object Source Symbol Target Symbol Basic Block Cycles # ........ ....... .................... ...................... ...................... .................. # 31.08% perf [unknown] [.] 0x000000000040c3f8 [.] 0x000000000040c3e8 - If the perf.data file is opened directly with perf, without the inject step, then this already works correctly because the events are synthesised after the COMM and MMAP events and no second sorting happens. Re-sorting only happens when opening the perf.inject file for the second time so timestamps are needed. Using the timestamp from the AUX record mirrors the current behaviour when opening directly with perf, because the events are generated on the call to cs_etm__process_queues(). Signed-off-by: James Clark Co-developed-by: Al Grant Signed-off-by: Al Grant Acked-by: Suzuki K Poulos Reviewed-by: Leo Yan Reviewed-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index c25da2ffa8f3..d0fa9dce47f1 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -54,6 +54,7 @@ struct cs_etm_auxtrace { u8 sample_instructions; int num_cpu; + u64 latest_kernel_timestamp; u32 auxtrace_type; u64 branches_sample_type; u64 branches_id; @@ -1192,6 +1193,8 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, event->sample.header.misc = cs_etm__cpu_mode(etmq, addr); event->sample.header.size = sizeof(struct perf_event_header); + if (!etm->timeless_decoding) + sample.time = etm->latest_kernel_timestamp; sample.ip = addr; sample.pid = tidq->pid; sample.tid = tidq->tid; @@ -1248,6 +1251,8 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, event->sample.header.misc = cs_etm__cpu_mode(etmq, ip); event->sample.header.size = sizeof(struct perf_event_header); + if (!etm->timeless_decoding) + sample.time = etm->latest_kernel_timestamp; sample.ip = ip; sample.pid = tidq->pid; sample.tid = tidq->tid; @@ -2412,9 +2417,10 @@ static int cs_etm__process_event(struct perf_session *session, else if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) return cs_etm__process_switch_cpu_wide(etm, event); - if (!etm->timeless_decoding && - event->header.type == PERF_RECORD_AUX) + if (!etm->timeless_decoding && event->header.type == PERF_RECORD_AUX) { + etm->latest_kernel_timestamp = sample_kernel_timestamp; return cs_etm__process_queues(etm); + } return 0; }