From nobody Mon Feb 9 10:24:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66816C77B73 for ; Wed, 24 May 2023 13:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234858AbjEXNUd (ORCPT ); Wed, 24 May 2023 09:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231854AbjEXNUU (ORCPT ); Wed, 24 May 2023 09:20:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C7281AA; Wed, 24 May 2023 06:20:18 -0700 (PDT) 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 99E691595; Wed, 24 May 2023 06:21:03 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F0F5F3F840; Wed, 24 May 2023 06:20:15 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, denik@chromium.org Cc: James Clark , Suzuki K Poulose , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , John Garry , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] perf cs-etm: Use previous thread for branch sample source IP Date: Wed, 24 May 2023 14:19:56 +0100 Message-Id: <20230524131958.2139331-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230524131958.2139331-1-james.clark@arm.com> References: <20230524131958.2139331-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Branch samples currently use the IP of the previous packet as the from IP, and the IP of the current packet as the to IP. But it incorrectly uses the current thread. In some cases like a jump into a different exception level this will attribute to the incorrect process. Fix it by tracking the previous thread in the same way the previous packet is tracked. Signed-off-by: James Clark Reviewed-by: Mike Leach --- tools/perf/util/cs-etm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ebffc9052561..a997fe79d458 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -86,6 +86,7 @@ struct cs_etm_traceid_queue { size_t last_branch_pos; union perf_event *event_buf; struct thread *thread; + struct thread *prev_thread; struct branch_stack *last_branch; struct branch_stack *last_branch_rb; struct cs_etm_packet *prev_packet; @@ -480,6 +481,7 @@ static int cs_etm__init_traceid_queue(struct cs_etm_que= ue *etmq, tidq->trace_chan_id =3D trace_chan_id; tidq->thread =3D machine__findnew_thread(&etm->session->machines.host, -1, queue->tid); + tidq->prev_thread =3D machine__idle_thread(&etm->session->machines.host); =20 tidq->packet =3D zalloc(sizeof(struct cs_etm_packet)); if (!tidq->packet) @@ -616,6 +618,8 @@ static void cs_etm__packet_swap(struct cs_etm_auxtrace = *etm, tmp =3D tidq->packet; tidq->packet =3D tidq->prev_packet; tidq->prev_packet =3D tmp; + thread__put(tidq->prev_thread); + tidq->prev_thread =3D thread__get(tidq->thread); } } =20 @@ -791,6 +795,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_q= ueue *etmq) /* Free this traceid_queue from the array */ tidq =3D etmq->traceid_queues[idx]; thread__zput(tidq->thread); + thread__zput(tidq->prev_thread); zfree(&tidq->event_buf); zfree(&tidq->last_branch); zfree(&tidq->last_branch_rb); @@ -1450,8 +1455,8 @@ static int cs_etm__synth_branch_sample(struct cs_etm_= queue *etmq, sample.time =3D cs_etm__resolve_sample_time(etmq, tidq); =20 sample.ip =3D ip; - sample.pid =3D tidq->thread->pid_; - sample.tid =3D tidq->thread->tid; + sample.pid =3D tidq->prev_thread->pid_; + sample.tid =3D tidq->prev_thread->tid; sample.addr =3D cs_etm__first_executed_instr(tidq->packet); sample.id =3D etmq->etm->branches_id; sample.stream_id =3D etmq->etm->branches_id; --=20 2.34.1