Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp791514rwd; Thu, 25 May 2023 04:08:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7G8JxXbOs8Tr4TSOldH+hlYdk3jC3ZOVls91T7lWmRvTg2VkCW1eEUUWYC0KmqiinqITdJ X-Received: by 2002:a05:6a00:1344:b0:643:85a0:57fe with SMTP id k4-20020a056a00134400b0064385a057femr9221915pfu.2.1685012916428; Thu, 25 May 2023 04:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685012916; cv=none; d=google.com; s=arc-20160816; b=T8lZJkVf92a8HTFw2DZTBR69oPTimk2Wu86R7HQ8LlVFYB33u5DlDUD42/rcAgp2qE HoCefaFNVClZoqdWrf78t4F6Eo9sVzzcdfpTtkD6R1QOtTskD98OojX9vMkMAq2DNGd/ gktwFDa5ltDsQQeEUtuPwUKiCIzpLttbBiuOG6/ZDxnD82WZ6Rb55xYzO5jRPEVHdhdh hg0lsdnRIEm1pNED+VJI5yeJXlSx5Tj06TxNOlmL8/KYg/Lwly1e9xIR/CLj1u7Ynq0O wNwba+EY3vwlgp/7PO/RcHXYWUnZZI+AlLZHMABUBnbDulEu7/8BE0FHcETONRQB8zkF wQAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=H3s3eZRI7QHvVIXMBnOcIVhi2D8A5weHZjK0BaSR+nk=; b=T80nQ6EBZsj0LuZo2Ufo6TJjnOLnF4IMJ8O3T5E5D8aRDbKxtU48sFqZHQALXRX4T3 X/CBWlvuL1oT9x6FY2+2G5lYQeTkQhoVHjXyeuNnH1g+x7b8j+n/En/FIRiO8th233Av 7oPGRu79A0h2spIHBocWW+8j6sbyAUeccFNYPrAXlBQSRjdZFLxPj+le+Pc+o1FCKaGf KlhzI5zeDnSVgvcOFNaO8Jpd3pLxQSXQpUDg07Wabo3tkaz8H00jXnqMXSP+Y2JF+Bwx UsD0tVb6+purBjoLNRTfpYPLnjzkzOPFCsh1oCfwJwRQ+OgbFiyHPD6Me3jP5Lahsm6x e82Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cucLmxav; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a633c0b000000b0053476becd25si322955pga.285.2023.05.25.04.08.20; Thu, 25 May 2023 04:08:36 -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; dkim=pass header.i=@linaro.org header.s=google header.b=cucLmxav; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240015AbjEYLB0 (ORCPT + 99 others); Thu, 25 May 2023 07:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240885AbjEYLBP (ORCPT ); Thu, 25 May 2023 07:01:15 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC5410B for ; Thu, 25 May 2023 04:01:13 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2537909d28cso938502a91.0 for ; Thu, 25 May 2023 04:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685012473; x=1687604473; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=H3s3eZRI7QHvVIXMBnOcIVhi2D8A5weHZjK0BaSR+nk=; b=cucLmxavBifaLssd4xQNhM2B/lvEYyfF8EURLo5UTEQ0Dgfz3ZkvQr2WA78X7IVGmk Rvflg4ubyvL7x96Tc7vzIh/xb3B0V3C617ZBJnnN3gTsYa6LqZ+hE1yEzdAaznO3VYbf YMKr3Vicip/93XHpe7Lt5xOYelBREDwvfSj0Uhh08941gUeCI+kNUFtDwdc6rRtTB8H4 eXm1tX/g/vVJ5bSJWyEz0gzg4tSQUT9w6bmwOV1AzloqLkUDhWyXyNv2rBcHTUhZFf2J EdTSerQWRpbV9okH8OWuiSD5LVs025+NTGZjh2BIKOjPktA/BAKiSZKj2RIyTsOs9T2h SUeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685012473; x=1687604473; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H3s3eZRI7QHvVIXMBnOcIVhi2D8A5weHZjK0BaSR+nk=; b=aIKJ7orBfUjpthOlxMR/0PTIwFypnZXnYR65AgFfidjfC8yrGHejOeadKG8lKvN4kQ dnoHgtvcN/4jH82fYFR7Wf+R2ALnt8sVauDP1xWfKHIEfULXlqVupzmts1u+lgxLvBn3 O2xAH7nnjdjx31Mg5ZZUsSWrwKWh0u0J4MvMi9l+gXDvKi/FgjaDc/pzpwkmrAFUFb/n GEzXOzYI+jMxfhIXZy7B9IDTBN9DNTI2bgkYH1+EN3BdlABC0Gp0EaElhYK4xr3t+1p1 FqZTXyKco8qn23g7oPusjMldrE51WoDGcWcfdSxmgzupevm6e0G7kDPOEUDyNQM7cjwg g5VA== X-Gm-Message-State: AC+VfDyntWdIs6X4SQrv4KlBypJ6Bqz+Ak7KTYtHPBx21LhTxok3K7WK 0b4x1njecagjj4RqUUWYHHJSkBzSNsBmnMzyv86omA== X-Received: by 2002:a17:90a:f691:b0:23a:ad68:25a7 with SMTP id cl17-20020a17090af69100b0023aad6825a7mr1381642pjb.2.1685012472914; Thu, 25 May 2023 04:01:12 -0700 (PDT) MIME-Version: 1.0 References: <20230524131958.2139331-1-james.clark@arm.com> <20230524131958.2139331-3-james.clark@arm.com> In-Reply-To: <20230524131958.2139331-3-james.clark@arm.com> From: Mike Leach Date: Thu, 25 May 2023 12:01:01 +0100 Message-ID: Subject: Re: [PATCH 2/4] perf cs-etm: Use previous thread for branch sample source IP To: James Clark Cc: coresight@lists.linaro.org, denik@chromium.org, 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 On Wed, 24 May 2023 at 14:20, James Clark wrote: > > 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 > --- > 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 > Reviewed-by: Mike Leach -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK