Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp533027rwd; Thu, 8 Jun 2023 04:30:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DBpLOfR0lPq97Q8LJ/pg+GcwlPQ1RwITBWNAPTMCVuJWs+fhUz8eygF9b4bPvhPjQgAm8 X-Received: by 2002:a05:6a21:2d8f:b0:102:472b:424c with SMTP id ty15-20020a056a212d8f00b00102472b424cmr4122567pzb.22.1686223854277; Thu, 08 Jun 2023 04:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686223854; cv=none; d=google.com; s=arc-20160816; b=IMuJ9C9ikjmhOHHA9TBJ38co/hwhFiWUc0CbpApiOcRE98rjAx/8DjSxzGkH22zT60 Yo/YeZpWwA1faygSESEBEUk5iNNIF+2Iavzle8CzMneiiMUTOEvTwGS5IP3dIdEhnzzp 8bAYaKYKg+/eVq3SbHpAesPAkM4J8sMwqpanPoael0u6J6SNSQkZBU5zl7dWx/bD1Yem adFIDTWC8mUzl3adCXpJf77M/fHsNWpl8FewczSpQ3w7yLlW0PSR0/WeFUM9dIBS/ev5 NqAUrq1zlURWj5R9ta8DQhSiMcUsh+piUKfUyOSyUhdoswHGAX5vdF1fifF+WeLqzn2t MGjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=x3dItVPf7l95At1P7F1/airOu8gvPyKGdyLpR4Say9o=; b=HUBhOTtyuTXZkkkNfR9IVKK2K435E7uo65Kse2Yqs1n0E5MKIcaQXICu/BwePnp/o5 Szzyjfk7Ne4iJLhK2UIIh1ymSu+bUx+etB3VMhR7lTzA2jPqqd6ATGBCESoLPRrg4bgf XI8gFBPWTiYe3Dgc8VOKtoZ0Rh35fcyxQ/ADyxdNL8vSdaYq+pz922LLAfBZgGWY0PPN NqDmJJXmxFG5KHuv3Zj8hONOwmyxqSH2oI8WUdzpeRlxI48G8kexCsOiNbvbhhqSQqRE fOW3YYnw65P3xNvE5wRMd8jDBt8whrMFrywZAdyhFeucJvzAUeRMi6GvfnXDPM83Y/Nl nSYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020aa79582000000b0064f6a52105csi654679pfj.378.2023.06.08.04.30.41; Thu, 08 Jun 2023 04:30:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234210AbjFHLAR (ORCPT + 99 others); Thu, 8 Jun 2023 07:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235776AbjFHLAA (ORCPT ); Thu, 8 Jun 2023 07:00:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9256911A; Thu, 8 Jun 2023 03:59:59 -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 C0E8DAB6; Thu, 8 Jun 2023 04:00:44 -0700 (PDT) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C94D93F71E; Thu, 8 Jun 2023 03:59:56 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org Cc: James Clark , Mike Leach , Suzuki K Poulose , 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 v2 2/5] perf cs-etm: Use previous thread for branch sample source IP Date: Thu, 8 Jun 2023 11:59:26 +0100 Message-Id: <20230608105930.1389276-3-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230608105930.1389276-1-james.clark@arm.com> References: <20230608105930.1389276-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reviewed-by: Mike Leach Signed-off-by: James Clark --- 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_queue *etmq, tidq->trace_chan_id = trace_chan_id; tidq->thread = machine__findnew_thread(&etm->session->machines.host, -1, queue->tid); + tidq->prev_thread = machine__idle_thread(&etm->session->machines.host); tidq->packet = 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 = tidq->packet; tidq->packet = tidq->prev_packet; tidq->prev_packet = tmp; + thread__put(tidq->prev_thread); + tidq->prev_thread = thread__get(tidq->thread); } } @@ -791,6 +795,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq) /* Free this traceid_queue from the array */ tidq = 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 = cs_etm__resolve_sample_time(etmq, tidq); sample.ip = ip; - sample.pid = tidq->thread->pid_; - sample.tid = tidq->thread->tid; + sample.pid = tidq->prev_thread->pid_; + sample.tid = tidq->prev_thread->tid; sample.addr = cs_etm__first_executed_instr(tidq->packet); sample.id = etmq->etm->branches_id; sample.stream_id = etmq->etm->branches_id; -- 2.34.1