Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp358510ybv; Thu, 13 Feb 2020 01:43:20 -0800 (PST) X-Google-Smtp-Source: APXvYqyXPLNuBFDP0ZKFH5JZpkNwAXmd8lEGVA8x/1wc6K2RedBBqSUXVdD95FFdkuxkeIifnDqB X-Received: by 2002:aca:5303:: with SMTP id h3mr2195768oib.109.1581587000464; Thu, 13 Feb 2020 01:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581587000; cv=none; d=google.com; s=arc-20160816; b=Yo1CAwAQh92jih2DfB3i1EYj2sXLUVZIWVFOiFi2p9pfLXAQeKoEwo62kg5gqFg9Ww tz6Ro8vnLpjqem4bN9X6ry+6XtvI+s2tsoFdWbpbyR6sDGoqgmGtvd8w27mi2Fdbe5EZ FxoQi7ZOcI71NL0gRSyd3zAarQ/mTR0zmAbmM8ZTNamcaNtuYn5sha0zT0ajHn/Pcnm0 rUq341BKy5zKduSqiQ44WpbhyaI1cKoeTH3XnFkIDCJeQxlvFZJR5KbX041wFvAYPmjJ gnezWhSzxHpqEVVqv1Rtej/KpgWAgJFoRPQjekAiGm6h1rvb9gppEHhi7IcGCuyjKL9Y XZzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=G6IPm5U0/N32JfuJRrXFpT4+8WxS2iUn3t7D8Wj9RWY=; b=Cg4GYljHgSkgHMDffxo7JPMrA1OHM88lqrTJjEoZFnrh5G9GdoN6aPnLs1MlU1uehS 0wbaC7alAeq2Z/5RReTiHjz+92G1/JD8kN9q8hgM1IMr4FmGQxHDwlEKgC55qrlfQA8q GN2Qh5EojUPrad976C/u44fL45sxjBi8zWuVCZk7bPzVWhsIF2Szs/D5WWdhehHWr+ZV szzyUlJbIqJaxVvA2+3nVAqfzxdjpJ3sfz/46W1O1zu17t9G9uX3iIFd3yra8PF0e0oM l2/ZzkdifXz8OBILYqwVcu6+q/VroICJDifi1NT10NacAMkdHk6aWzxhQyjYXb36BIL9 2kgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vrNgUqWP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s22si960147otq.100.2020.02.13.01.43.07; Thu, 13 Feb 2020 01:43:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vrNgUqWP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729742AbgBMJmn (ORCPT + 99 others); Thu, 13 Feb 2020 04:42:43 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:55258 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729440AbgBMJmm (ORCPT ); Thu, 13 Feb 2020 04:42:42 -0500 Received: by mail-pj1-f65.google.com with SMTP id dw13so2140949pjb.4 for ; Thu, 13 Feb 2020 01:42:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=G6IPm5U0/N32JfuJRrXFpT4+8WxS2iUn3t7D8Wj9RWY=; b=vrNgUqWPxNjcbcprI69cNxpFGDoNlqSdIUfnpnFCC1Z+cnY1e70ej8SOS8MyZU1iUu Foyb6kugSrVv9KNVBrdGT+IR49tDjT63OdH1PVsbdb8eaJZzpwdVvO2LUkxHjjMEWfYg ZfC0+UdGGiaKJwebfefg71mPJ2whj5CFNxWU0Zx7NEh6kAwNrVsvvhky53G9uGNGvHYl yh4g1tiGbTFJnbzGFg1DsE9xEfqMzWCN2BFgXkbH0Yla2SkezfnvY4mggLN4uEjtMlJU deL11fXjY/a4OVGq1zdDrramCjTp7bNYT6tV4N68F7XmWRRCkOSPxyqeGVApT3TYZGSE IdiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G6IPm5U0/N32JfuJRrXFpT4+8WxS2iUn3t7D8Wj9RWY=; b=Pl+HGLkO/QG2Zrm0N6lU9RxAnpclggOuDzoIOS0IEgcBQaA5Doh4oHty4Ivbax4U+E Eq2Ym9JmhyQVsH+IAoH0mmQSNlQFpXz3UHfhSXy4L/nr+m8J4VYit4YX2mqkBC414qbf FM5wEkhS4xZLW8xxA464jY1g+eBXyCkVwhXkbmqJ3X2vHaB2nfNYLoIasLkRA4MX9uyU phD6ozTY4mpale/qMyoTTO7rcMrZc11vrguKKsfsLr8UkFIgaY734jco2qQYp777ZcWQ vjHrVQ1kuBIGrK4xycNe4SxtsSUhsMHqHNJkq+Y66CzPV0Pxr9SyLhatptLr76bQc6Nq L1qQ== X-Gm-Message-State: APjAAAUFd65bVstAvFsrtIPILYBfgjp14ru1uPSIDT+YYjlun2Ga3C8p kyzaQ43FiSj0PTKA5QZO5HkAVg== X-Received: by 2002:a17:902:2e:: with SMTP id 43mr12872821pla.326.1581586961690; Thu, 13 Feb 2020 01:42:41 -0800 (PST) Received: from localhost.localdomain (li1441-214.members.linode.com. [45.118.134.214]) by smtp.gmail.com with ESMTPSA id 3sm2310277pfi.13.2020.02.13.01.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 01:42:41 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Robert Walker , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan Subject: [PATCH v4 1/5] perf cs-etm: Swap packets for instruction samples Date: Thu, 13 Feb 2020 17:42:00 +0800 Message-Id: <20200213094204.2568-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200213094204.2568-1-leo.yan@linaro.org> References: <20200213094204.2568-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Mike Leach --- 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 5471045ebf5c..84f30c2de185 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.17.1