Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp879511pxk; Thu, 17 Sep 2020 20:09:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8ryq0WM1heFHT/F2R88Bz2V878zJu2I1qVgoUH7FI9IFlYhuXrqgHE71WItg3Nk40xky9 X-Received: by 2002:a17:906:7d0d:: with SMTP id u13mr35363646ejo.448.1600398577128; Thu, 17 Sep 2020 20:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398577; cv=none; d=google.com; s=arc-20160816; b=LYw5ILngoBmHG36+YipyeRehTQ29HWuI16Nf29GYuOnQJWl4UQH9LfHjLhpCBNN0R8 QMwaBfdR3IHDjVBPXDhCvvGYKflmei5xpCqfaIv7Vs0VXbye7KHUg0/DpO+7HeoQLtD/ d1af7Jv3duUuV1eV5lNcnYarkyr2cJpXY7nKUl/vC3ePmNS6xvzBqfaLBoRm+WyBp1ZN kiem8tprj73mursAjCXSicLNDYYRWtybbljAfeyaJSaw3AAq4bBx0L4TIbpu23CRVNmb reD3mnVN/z2OJsbrjuP+6eWhfStf8zdcB7JhjYbzj0zv8Qw7EZdc96+ADpkCfSeCxV4B Ceag== 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 :dkim-signature; bh=t5TeiF2ktecftq34UYgqhED+Um/S68qS4lOR+qGL788=; b=dSuzxH68miZFq36haOATaYz9mJlHju7Y1Wm5KegA/VQmZhaohb8p/znpftWOdTUWhV X6TGnOn10so/mSOFY9S2YuB6jiRwultTGI0gzv/F7IO+EqHv5C1sU/wUVrW5lGeUssKa 5z4Ecxj5+hypuKTUbNxcwlV90n49JypEPCA/eXeE2r0AZNUROm3uO1L7z84//4EN+ZRP FXbQ1AH3BDD+LU2OcA11v5o/s6cqchW5qu6Ex8lnBRnFoFfMh8Yyin0ea6HRynNYSXEp ot8dUduVSPuA3nZ3rTd6/dh0RKfljCpnriQHkCvrPM9DGdRKzZ/zizkuzQKsHcpILXe9 PaGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="03/H2OTf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i3si1255692ejd.424.2020.09.17.20.09.13; Thu, 17 Sep 2020 20:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="03/H2OTf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729447AbgIRDFG (ORCPT + 99 others); Thu, 17 Sep 2020 23:05:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:52048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbgIRCEd (ORCPT ); Thu, 17 Sep 2020 22:04:33 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 24E0A235F8; Fri, 18 Sep 2020 02:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394672; bh=BiouPKCrG2nElZXDM6x8aHBIiaJckJhpU6dfa35QRNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=03/H2OTfzhyMN9ykgT9fuhbphW4WWtb48HXyeEzCdzhTc+8jZMPt2tclQJ7CMHjAy JtqzlRZJlg3H8sIqqRtmITzJhlaVOMEHIsx/P9YZJmtQJL4rDrLfGaDazoanadsJ9I s0JWUVCjwMMTLKq9Uv62qYez8ZxYHdlIpNbMc6cg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Leo Yan , Mathieu Poirier , Mike Leach , Alexander Shishkin , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , Robert Walker , Suzuki Poulouse , coresight ml , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.4 164/330] perf cs-etm: Swap packets for instruction samples Date: Thu, 17 Sep 2020 21:58:24 -0400 Message-Id: <20200918020110.2063155-164-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan [ Upstream commit d01751563caf0dec7be36f81de77cc0197b77e59 ] If use option '--itrace=iNNN' with Arm CoreSight trace data, perf tool fails inject instruction samples; the root cause is the packets are only swapped for branch samples and last branches but not for instruction samples, so the new coming packets cannot be properly handled for only synthesizing instruction samples. To fix this issue, this patch refactors the code with a new function cs_etm__packet_swap() which is used to swap packets and adds the condition for instruction samples. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier Reviewed-by: Mike Leach Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Robert Walker Cc: Suzuki Poulouse Cc: coresight ml Cc: linux-arm-kernel@lists.infradead.org Link: http://lore.kernel.org/lkml/20200219021811.20067-2-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/cs-etm.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index f5f855fff412e..38298cbb07524 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -363,6 +363,23 @@ struct cs_etm_packet_queue return NULL; } +static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm, + struct cs_etm_traceid_queue *tidq) +{ + struct cs_etm_packet *tmp; + + if (etm->sample_branches || etm->synth_opts.last_branch || + etm->sample_instructions) { + /* + * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for + * the next incoming packet. + */ + tmp = tidq->packet; + tidq->packet = tidq->prev_packet; + tidq->prev_packet = tmp; + } +} + static void cs_etm__packet_dump(const char *pkt_string) { const char *color = PERF_COLOR_BLUE; @@ -1340,7 +1357,6 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq) { struct cs_etm_auxtrace *etm = etmq->etm; - struct cs_etm_packet *tmp; int ret; u8 trace_chan_id = tidq->trace_chan_id; u64 instrs_executed = tidq->packet->instr_count; @@ -1404,15 +1420,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, } } - if (etm->sample_branches || etm->synth_opts.last_branch) { - /* - * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for - * the next incoming packet. - */ - tmp = tidq->packet; - tidq->packet = tidq->prev_packet; - tidq->prev_packet = tmp; - } + cs_etm__packet_swap(etm, tidq); return 0; } @@ -1441,7 +1449,6 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, { int err = 0; struct cs_etm_auxtrace *etm = etmq->etm; - struct cs_etm_packet *tmp; /* Handle start tracing packet */ if (tidq->prev_packet->sample_type == CS_ETM_EMPTY) @@ -1476,15 +1483,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq, } swap_packet: - if (etm->sample_branches || etm->synth_opts.last_branch) { - /* - * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for - * the next incoming packet. - */ - tmp = tidq->packet; - tidq->packet = tidq->prev_packet; - tidq->prev_packet = tmp; - } + cs_etm__packet_swap(etm, tidq); return err; } -- 2.25.1