From patchwork Mon Dec 10 08:52:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 153244 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3327249ljp; Mon, 10 Dec 2018 00:53:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/UoQHz//G6SsrW7Ue16UxaJaqt6hE+CeFZJhPFWUivHMIpIcE+9EZMEKzRT/bHyPlteHVDc X-Received: by 2002:a65:5c4b:: with SMTP id v11mr10074314pgr.333.1544432008167; Mon, 10 Dec 2018 00:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544432008; cv=none; d=google.com; s=arc-20160816; b=FZWmK8pqGw8FjQIDWcCoZZuX2A3/pLkFIa7dwbUOR8Naj1f0RJuBkPbPErmhrhbbAt eaGEsR66YZGFXgKUXiwEFogs7mANXrwvg/XGLh79PFWexFahCDukpe5WSp2ahcQbKH57 pXrHEilSvMbmAxK9vh5NowVjMlneKk4oA5vxqfiqsRCrSBV+eT9JTJPw5Do+W/Hon+zB SNRyPOd+l2B61ETVvP7e5haq+y1lQs1O22Hy14KixnIZys/YYYDlQRteywoLkPSpByAg uDKklB1Fr6BcvmUEUFxNyAQVbq6nNxNwhLYABO3x0OrH9DOTu6tEduyzAUC4gK1S9Dd1 ZhWw== 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=39wBlDXGyPZlvdOM4v0qZ1Ghil7xJLHLF05MaMBQC4c=; b=qZQhY6FvN55euBpu/1SrulwI+8f0be3yOtHiHH7W9oMkj36jTAwikwXUi1gq7VQmrd d4cpGYuOziAO+nXH071qfJddipKeIUZK4gPjjIh/rCLobXK3Rb3OYisq7yhbOwsYbsj4 hIxSHi9IrS7xBCyjUk1EkrA+6fErGKxQmkoLjlsbCKsFxJCWFvnMhX+SMIDBaS3gQ0MN rdyyS4oiIEdTnZeIar6MrcSGIoJmTdKH7n4Z2Syshuk/vgiHq2ic+xy73IpmuBxNZ0k4 yr4KAO/8ITW/Xod5gbtJ4VuPy+7UtqBze/3uwAB29IN5Cilw7mxqSWe93mAkZrDLwo7I HXCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bxt7r7e1; 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 m7si9279073pgi.547.2018.12.10.00.53.27; Mon, 10 Dec 2018 00:53:28 -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=bxt7r7e1; 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 S1726691AbeLJIxZ (ORCPT + 31 others); Mon, 10 Dec 2018 03:53:25 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41710 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726572AbeLJIxY (ORCPT ); Mon, 10 Dec 2018 03:53:24 -0500 Received: by mail-wr1-f68.google.com with SMTP id x10so9538678wrs.8 for ; Mon, 10 Dec 2018 00:53:23 -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=39wBlDXGyPZlvdOM4v0qZ1Ghil7xJLHLF05MaMBQC4c=; b=bxt7r7e1AGI4295LFa3jazbFqPFJ32MDDhQyDn4+GuLOA0SEIMz9uk5rORpI2g3oZN qDMO3WpYTVfLKNe8SNjhp0YhRcwg2b6cjABzskwJK1WY2p+BK0xRMR3B0NehJEMpd2LE HL5EBnL+r1UUHKvB2FEbsUt2ojc/XuzWq95W4= 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=39wBlDXGyPZlvdOM4v0qZ1Ghil7xJLHLF05MaMBQC4c=; b=X9+eTCgBe049Soovy1WhuDz2QgmL3RS/sXPqSJxuzI6FG8RZdfoVoUppfxZH0ocoAx wJwuCWPmrJbijsa1Mz3tndIbaUn85/H42Zmiu/NScZyRzz6rXXDEOkX/4PDBhnkZqF9P 1dmip+IaRl6PZnZw+3TK+E0hLQfuPx89MYiE6Z24k5GIu0myP8hIGv9i1z67pDbPcW6m m+NsycQVuVvDYyYvsfwCFMMYJj5pFNYvl2aD5o9PoG7erbFc7l8R29TjOtUbsFP/XIAW 3t0D/AE0W1hrTpJb5lzC3ZK0IFiHwvcVmKthEgrQuKo4z6rIz5eU7+/H3bfGS2fcPItM UXqA== X-Gm-Message-State: AA+aEWaZlDf39rbP7WOk/nRJJlkn2lN2v81flFEAvC+CE7+flvcZjscV Am5b6e2VqqJv1zCDss8BJ2mq0w== X-Received: by 2002:adf:be0f:: with SMTP id n15mr9403212wrh.267.1544432002659; Mon, 10 Dec 2018 00:53:22 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id m4sm9097351wml.2.2018.12.10.00.53.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Dec 2018 00:53:21 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan , Mike Leach , Robert Walker Subject: [PATCH v2 1/6] perf cs-etm: Correct packets swapping in cs_etm__flush() Date: Mon, 10 Dec 2018 16:52:56 +0800 Message-Id: <1544431981-24144-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> References: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The structure cs_etm_queue uses 'prev_packet' to point to previous packet, this can be used to combine with new coming packet to generate samples. In function cs_etm__flush() it swaps packets only when the flag 'etm->synth_opts.last_branch' is true, this means that it will not swap packets if without option '--itrace=il' to generate last branch entries; thus for this case the 'prev_packet' doesn't point to the correct previous packet and the stale packet still will be used to generate sequential sample. Thus if dump trace with 'perf script' command we can see the incorrect flow with the stale packet's address info. This patch corrects packets swapping in cs_etm__flush(); except using the flag 'etm->synth_opts.last_branch' it also checks the another flag 'etm->sample_branches', if any flag is true then it swaps packets so can save correct content to 'prev_packet'. Finally this can fix the wrong program flow dumping issue. The patch has a minor refactoring to use 'etm->synth_opts.last_branch' instead of 'etmq->etm->synth_opts.last_branch' for condition checking, this is consistent with that is done in cs_etm__sample(). Reviewed-by: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 23159c33..789707b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1042,7 +1042,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) } swap_packet: - if (etmq->etm->synth_opts.last_branch) { + if (etm->sample_branches || etm->synth_opts.last_branch) { /* * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for * the next incoming packet. From patchwork Mon Dec 10 08:52:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 153245 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3327288ljp; Mon, 10 Dec 2018 00:53:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/UL2BpUTr61VYF0kq7T3Zcb+U8DsS4+io0JK/jdsKH+CjiVbIzEXVaE3Qe+BnvkNikGQ5we X-Received: by 2002:a63:7e5b:: with SMTP id o27mr10069704pgn.214.1544432013355; Mon, 10 Dec 2018 00:53:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544432013; cv=none; d=google.com; s=arc-20160816; b=o+I3U/1UhNDlDjdtgqjh7NXiouretT2qunIs6pgVsoaTFOGV+9hbpHxEDRC/eAFwGO CvH5ymMF+ZgNK/8A6WMko/VdVBOh2yyuN/aI7AkBRPNebHa6dANjNP+mKxzOls1Dik7y 7kcVKxWLStqos9PjmdvhwW38ydcqgwkwoFlYuVJWnGw6yZZnEfbJq+2PNuqBtYFTU5yh z6rI7lDDMi3FlA6U905/rsauBvLPtYhl3hV+8O9fzKC5+pUUpY8zWhkOB2pFwL687Cdr 9ZDU9MZkytWefuqCMOYN+rzQbs1z8YwKRBU+NHMictHL08GhcXCc12MFVJ/f7mm4qSDT vYwA== 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=/Mqm5NLjImIYS16X8WHi66jKS9/dDWkoWlmg3vq+u2w=; b=V5P75McGW6/dy13raP7+8agvVLnY4GBJgWKeJA2VuCCczR7Pde8maQek5xUocXdDfy hOWUXActqc73Rb5ppfsWJTvfBYT+IhrQbcv01bqKGRFgVZhn+V9ryYDUOM10hhu3hJlG aTqWvJyda4DMLH9t7+0Lxq/Ml6Jku/jyRaFR5A/L04mNukh1+hwqtYXcDoM31H5jGohE CnL1JFc0Z+d8g1D8GjGTh5UukAttauDzlYZZ7+t+VOssyTbox5nwSo4IZTyt1Mo4lgHX YZuQGgqcXNdP1a7fzrjl2DDdIvfszeS5Bi8LKox4NHg0a5YCcGN9IAd8fP5RvKKZRXvG J+IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E+7cjU7r; 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 a19si8822889pgj.429.2018.12.10.00.53.32; Mon, 10 Dec 2018 00:53:33 -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=E+7cjU7r; 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 S1726709AbeLJIxb (ORCPT + 31 others); Mon, 10 Dec 2018 03:53:31 -0500 Received: from mail-wr1-f48.google.com ([209.85.221.48]:43674 "EHLO mail-wr1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbeLJIx3 (ORCPT ); Mon, 10 Dec 2018 03:53:29 -0500 Received: by mail-wr1-f48.google.com with SMTP id r10so9531181wrs.10 for ; Mon, 10 Dec 2018 00:53:27 -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=/Mqm5NLjImIYS16X8WHi66jKS9/dDWkoWlmg3vq+u2w=; b=E+7cjU7rX2G9g9Nq8/CJhtZLY5S59gQoL1eK7hZw1mzGeJ/Kky+rSwd5ze4gH8UGR9 gp5ojQC+RiYTFeKxyQB1Y2hks+6DVXQy0ma9PODdhZ8Se1wtHiUfBevJZPAD6eK4K927 yCW6LRV1J+mY/KgYBTorp3JtPy3kLev760zYU= 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=/Mqm5NLjImIYS16X8WHi66jKS9/dDWkoWlmg3vq+u2w=; b=PQdIamPu5guGzgHoU3Fs7cp5TPAkVvAXsOtpD4RE674YIVKm1w0L3o/AYqXkP09qvN 4uOxzJddpWaZtMBVPPUJTUqMjfqpkAipB10+fC7DR6RK9CSMZ79bBU+wr1YribI7oiJl wvehpzwY77upXjuTCrHje964BoPzdEmQMWHfMBzK2hI3Hgqt9sH36DGx6AX+EhtUCAR/ zv++u1b0x56DrXZ97Fym/kTBA7jr988ZuieqEfYQfr+xnmSsm0Ar+3vGQlVX9/QprXbS D5KPFzAmsFzi1+En+9dmcowaQ/sHmg+oj/LoiHD8HrX38yYoqMPB3HXGkrUa/SFRbxeH 0BHg== X-Gm-Message-State: AA+aEWbBW2o8ayg2AEGLWAHh6YOkVjhjDLjP7PzBkHNfcV5gvrXJYkzQ upj/B80fQbDDyyRaYwo5MTWX3Q== X-Received: by 2002:adf:d112:: with SMTP id a18mr9614787wri.17.1544432006964; Mon, 10 Dec 2018 00:53:26 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id m4sm9097351wml.2.2018.12.10.00.53.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Dec 2018 00:53:26 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan , Mike Leach , Robert Walker Subject: [PATCH v2 2/6] perf cs-etm: Avoid stale branch samples when flush packet Date: Mon, 10 Dec 2018 16:52:57 +0800 Message-Id: <1544431981-24144-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> References: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At the end of trace buffer handling, function cs_etm__flush() is invoked to flush any remaining branch stack entries. As a side effect, it also generates branch sample, because the 'etmq->packet' doesn't contains any new coming packet but point to one stale packet after packets swapping, so it wrongly makes synthesize branch samples with stale packet info. We could review below detailed flow which causes issue: Packet1: start_addr=0xffff000008b1fbf0 end_addr=0xffff000008b1fbfc Packet2: start_addr=0xffff000008b1fb5c end_addr=0xffff000008b1fb6c step 1: cs_etm__sample(): sample: ip=(0xffff000008b1fbfc-4) addr=0xffff000008b1fb5c step 2: flush packet in cs_etm__run_decoder(): cs_etm__run_decoder() `-> err = cs_etm__flush(etmq, false); sample: ip=(0xffff000008b1fb6c-4) addr=0xffff000008b1fbf0 Packet1 and packet2 are two continuous packets, when packet2 is the new coming packet, cs_etm__sample() generates branch sample for these two packets and use [packet1::end_addr - 4 => packet2::start_addr] as branch jump flow, thus we can see the first generated branch sample in step 1. At the end of cs_etm__sample() it swaps packets so 'etm->prev_packet'= packet2 and 'etm->packet'=packet1, so far it's okay for branch sample. If packet2 is the last one packet in trace buffer, even there have no any new coming packet, cs_etm__run_decoder() invokes cs_etm__flush() to flush branch stack entries as expected, but it also generates branch samples by taking 'etm->packet' as a new coming packet, thus the branch jump flow is as [packet2::end_addr - 4 => packet1::start_addr]; this is the second sample which is generated in step 2. So actually the second sample is a stale sample and we should not generate it. This patch introduces a new function cs_etm__end_block(), at the end of trace block this function is invoked to only flush branch stack entries and thus can avoid to generate branch sample for stale packet. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) -- 2.7.4 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 789707b..ffc4fe5 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1055,6 +1055,39 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) return err; } +static int cs_etm__end_block(struct cs_etm_queue *etmq) +{ + int err; + + /* + * It has no new packet coming and 'etmq->packet' contains the stale + * packet which was set at the previous time with packets swapping; + * so skip to generate branch sample to avoid stale packet. + * + * For this case only flush branch stack and generate a last branch + * event for the branches left in the circular buffer at the end of + * the trace. + */ + if (etmq->etm->synth_opts.last_branch && + etmq->prev_packet->sample_type == CS_ETM_RANGE) { + /* + * Use the address of the end of the last reported execution + * range. + */ + u64 addr = cs_etm__last_executed_instr(etmq->prev_packet); + + err = cs_etm__synth_instruction_sample( + etmq, addr, + etmq->period_instructions); + if (err) + return err; + + etmq->period_instructions = 0; + } + + return 0; +} + static int cs_etm__run_decoder(struct cs_etm_queue *etmq) { struct cs_etm_auxtrace *etm = etmq->etm; @@ -1137,7 +1170,7 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) if (err == 0) /* Flush any remaining branch stack entries */ - err = cs_etm__flush(etmq); + err = cs_etm__end_block(etmq); } return err; From patchwork Mon Dec 10 08:52:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 153246 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3327310ljp; Mon, 10 Dec 2018 00:53:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ud/3p2ksDxRAVNnu1c+kojDqiixfKxnKiUrlsSY/RyQmjAg6L2fbl5X/MJO5uqbqXhf+zS X-Received: by 2002:a63:4f5e:: with SMTP id p30mr10198863pgl.71.1544432017020; Mon, 10 Dec 2018 00:53:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544432017; cv=none; d=google.com; s=arc-20160816; b=VpfdMioBqgIEUqn/Sd3+J51N1E7vqDqYILVv34x5P1Ee3bQFRx7/szO38JYP59WANk 6UxXMD7fphinWjglfUJG+t2QZmVJwV4qVRlt4gN702dEGZGHiB864v2Ql/8555eLrtmK +koLx+T+1yWhcPyTOT94hgUqKcMyMcD0RZn1y4I6wxSMmZHe14gpvRTgMJBBcCTLPyUp QAlDfpEA2TZHdduQxfBpmo/WlIanFW5rzDPLqXqacAGIqia+n9TekQCGtZ3EWr8XoZv6 p2nzRWRqtvMbFMc7dbE5ofThEbgrFQ/A+PPa4MZNYs9HX6WJ40eBWYF8fERacp2aW5s2 BMSA== 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=UxbO/7Yb84DOLHcddrUr5aAiSlOBxbFaQ0ZxQ1p5BBE=; b=RxbsADbVDhRkij2aJtQYvoS9tfUC8st6Wxf/i6vumy/sZACmGDkBUqPSTs75Fzsu3Z HBJJ6vDyP54YAs7+Ozk/NkXOlRMXpLNuulNJRwuvak/F2Zmb5aYLgKLjPwV4TfoSt6Jv x92CAOuYbD4Y7iQwjY3r2ovDkV+U+JqS4eIDfZgb0NBd6mTN+RuzDsvegjbeHeWkGJtV SyEEJItXFjiAp6tG7Zr2WEk1hHGezCDKO0neWmBA9zYWSSsS5x7x2ZqRPmgHbV2j0RoF L0Gi9VhYiojqXkyl36Zyc9/pXAGkwZLYEsHMVJpaQ0PlLKwrRRA0aUM1trKL4xOMpFNs h8xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hh5hvVJ5; 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 h5si9082225pgk.249.2018.12.10.00.53.36; Mon, 10 Dec 2018 00:53:37 -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=hh5hvVJ5; 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 S1726730AbeLJIxf (ORCPT + 31 others); Mon, 10 Dec 2018 03:53:35 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33057 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbeLJIxe (ORCPT ); Mon, 10 Dec 2018 03:53:34 -0500 Received: by mail-wm1-f67.google.com with SMTP id r24so6069601wmh.0 for ; Mon, 10 Dec 2018 00:53:32 -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=UxbO/7Yb84DOLHcddrUr5aAiSlOBxbFaQ0ZxQ1p5BBE=; b=hh5hvVJ5pHoSWCWWZ4ZmtUGrWZD+w0mM5NhzpjThGctwh0L3Or/PAdk/IJ1Iqjiu9r XY0Okn9BmXzk08RMy52CyfRQzV2PJQmE9XSCGz+PYuGN7SkmbTRzoqhQkcuNlvNSXKuG /q+2uvk6kzBOoMoUmQcSZKwPG5PfDFp9JoUuA= 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=UxbO/7Yb84DOLHcddrUr5aAiSlOBxbFaQ0ZxQ1p5BBE=; b=qP1Ca9y2LiqNYPJ/PxVZk4b3pcZATRsgamIdl8xoWM2eRwLa7kq4LtrMVWYKwfWlVA +zl4EN5XIbpis32rIM574FCdrPGNYzC32nrWi3kEZKOrrt0o/0jfXJ7cPfMBCrOyPCIT Q96+ZoOJ7uIxJ0s6RY65LT43HCledXQyoSoY+OmhDFojJMRMqXUw7h8pCUR2nd6XRaXq eESZtJNivuEgHXSRFQ3zHYVFT/ioTzg0MYzF6tWlewNeUg4v4YUmVOF62nt34o9gm9+9 2GZN0nZT7Bs/l7ATmalLiQB8IMNznyhAbjThpP1izpM26eUeaSBNORECohBP1iibfd7J /vJg== X-Gm-Message-State: AA+aEWZIthH1Hf25xXlGo7H25gFDo53jPxeZMapKqEKSsB2x7Ja/Wilx 0eHshckmUVapFTgtI+ipj2+ytw== X-Received: by 2002:a1c:8d49:: with SMTP id p70mr10506505wmd.68.1544432011789; Mon, 10 Dec 2018 00:53:31 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id m4sm9097351wml.2.2018.12.10.00.53.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Dec 2018 00:53:31 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan , Mike Leach , Robert Walker Subject: [PATCH v2 3/6] perf cs-etm: Rename CS_ETM_TRACE_ON to CS_ETM_DISCONTINUITY Date: Mon, 10 Dec 2018 16:52:58 +0800 Message-Id: <1544431981-24144-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> References: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TRACE_ON element is used at the beginning of trace, it also can be appeared in the middle of trace data to indicate discontinuity; for example, it's possible to see multiple TRACE_ON elements in the trace stream if the trace is being limited by address range filtering. Furthermore, except TRACE_ON element is for discontinuity, NO_SYNC and EO_TRACE also can be used to indicate discontinuity, though they are used for different scenarios for trace is interrupted. This patch is to rename sample type CS_ETM_TRACE_ON to CS_ETM_DISCONTINUITY, firstly the new name describes more closely the purpose of the packet; secondly this is a preparation for other output elements which also cause the trace discontinuity thus they can share the same one packet type. This patch also refactors the enumerations in cs_etm_sample_type by converting from bit shifting value to continuous numbers. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 10 +++++----- tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 6 +++--- tools/perf/util/cs-etm.c | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 0b4c862..a3994f1 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -391,11 +391,11 @@ cs_etm_decoder__buffer_range(struct cs_etm_decoder *decoder, } static ocsd_datapath_resp_t -cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, - const uint8_t trace_chan_id) +cs_etm_decoder__buffer_discontinuity(struct cs_etm_decoder *decoder, + const uint8_t trace_chan_id) { return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, - CS_ETM_TRACE_ON); + CS_ETM_DISCONTINUITY); } static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( @@ -414,8 +414,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( decoder->trace_on = false; break; case OCSD_GEN_TRC_ELEM_TRACE_ON: - resp = cs_etm_decoder__buffer_trace_on(decoder, - trace_chan_id); + resp = cs_etm_decoder__buffer_discontinuity(decoder, + trace_chan_id); decoder->trace_on = true; break; case OCSD_GEN_TRC_ELEM_INSTR_RANGE: diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index b295dd2..a272317 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -23,9 +23,9 @@ struct cs_etm_buffer { }; enum cs_etm_sample_type { - CS_ETM_EMPTY = 0, - CS_ETM_RANGE = 1 << 0, - CS_ETM_TRACE_ON = 1 << 1, + CS_ETM_EMPTY, + CS_ETM_RANGE, + CS_ETM_DISCONTINUITY, }; enum cs_etm_isa { diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ffc4fe5..cea3158 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -562,8 +562,8 @@ static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq, static inline u64 cs_etm__first_executed_instr(struct cs_etm_packet *packet) { - /* Returns 0 for the CS_ETM_TRACE_ON packet */ - if (packet->sample_type == CS_ETM_TRACE_ON) + /* Returns 0 for the CS_ETM_DISCONTINUITY packet */ + if (packet->sample_type == CS_ETM_DISCONTINUITY) return 0; return packet->start_addr; @@ -572,8 +572,8 @@ static inline u64 cs_etm__first_executed_instr(struct cs_etm_packet *packet) static inline u64 cs_etm__last_executed_instr(const struct cs_etm_packet *packet) { - /* Returns 0 for the CS_ETM_TRACE_ON packet */ - if (packet->sample_type == CS_ETM_TRACE_ON) + /* Returns 0 for the CS_ETM_DISCONTINUITY packet */ + if (packet->sample_type == CS_ETM_DISCONTINUITY) return 0; return packet->end_addr - packet->last_instr_size; @@ -972,7 +972,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) bool generate_sample = false; /* Generate sample for tracing on packet */ - if (etmq->prev_packet->sample_type == CS_ETM_TRACE_ON) + if (etmq->prev_packet->sample_type == CS_ETM_DISCONTINUITY) generate_sample = true; /* Generate sample for branch taken packet */ @@ -1148,7 +1148,7 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ cs_etm__sample(etmq); break; - case CS_ETM_TRACE_ON: + case CS_ETM_DISCONTINUITY: /* * Discontinuity in trace, flush * previous branch stack From patchwork Mon Dec 10 08:52:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 153247 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3327348ljp; Mon, 10 Dec 2018 00:53:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/VmdSmCT6xBPGA63yYcxwJoSfuj5BhTvFDIz45ekkt43Rd9f3YFlXbr0NZQAybbRYzmULgp X-Received: by 2002:a65:6645:: with SMTP id z5mr10239442pgv.351.1544432020144; Mon, 10 Dec 2018 00:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544432020; cv=none; d=google.com; s=arc-20160816; b=IBykkPY1lCrd2zpw5AHLotYia9DgzlR+tODYxF+nfEfCTskWYuMbLzgyr0ih8K+zUa GIqwiUgcL6m5JQh8bbnpdsIQLd5B8ZbEoeZsAZBOC6EaxBPQ33OcDRef8EAvPUZH7B1a WB2VBQnq2E03Pdx8rWAC3I7m467ZQzRTGLqxWdkpu/xkBGLSpcVZB5RiAsbzDjWInlcg gqPSbcbVtly559jhxhVmQdbXjPaTX9gZbNFfe+iBcmqy/xCUPjYo4DxYE4pSExXJq5Mt LV0Up9h3nEUmwZcKfQXtPOORHLlD/7NKBrhTCLCtPhd62NZ0lkci9HJsZkcxt0j8WYxM 70ew== 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=WgMRTLtOLhYT8FlarRUnYgdidlPs5flIzaegKvjmyYI=; b=OoSNjkY8T/YmhqEbnjbYtobiIgRi9CZurNM5F8Kh+kN3CZAT88HW3vHO7PndXl+lrJ 2i6ee5J3L8k1qb/09jkg0VWzyJLZSxJLqWAIGqQr5HkjmgbsIkibTvjgz02tiqPvhXM2 Sy6fsKHzP23HdFXCHuplXLK+Pd/t89HvfS557KoQEYuzWzk/bOOBVWdI7Ogpe48+g6lY kAjCUZSges3e3rSWpcDzHUo+km2K+4vMAhdbFyBOCjjAukaSI8Vyg5Ch1Kf+/gJZeSNc E/0ENMxlc+QB8Y5f92PGcNzpT+DXPUTYCvbn+AgvoDtlF7T2ACCwDVH94kPAVVhOSclJ SThQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EiIUh07K; 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 h5si9082225pgk.249.2018.12.10.00.53.39; Mon, 10 Dec 2018 00:53:40 -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=EiIUh07K; 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 S1726752AbeLJIxj (ORCPT + 31 others); Mon, 10 Dec 2018 03:53:39 -0500 Received: from mail-wm1-f42.google.com ([209.85.128.42]:38722 "EHLO mail-wm1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbeLJIxi (ORCPT ); Mon, 10 Dec 2018 03:53:38 -0500 Received: by mail-wm1-f42.google.com with SMTP id m22so10301936wml.3 for ; Mon, 10 Dec 2018 00:53:36 -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=WgMRTLtOLhYT8FlarRUnYgdidlPs5flIzaegKvjmyYI=; b=EiIUh07KJ15nJAm0JkYmA6j0bfQk4wTHlH9S3w0vtyejd92gNNVA5+lB0Eg1QJSXxS znaz8c/sHTTuS60A565mN+yxnk5kPhiU58zhjcfDiArb+dsolwlfdQ/COw1ppFfum8nb FiwC5dTXlXR6XSd/DmNcLcKosB7fM4xj0KPIM= 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=WgMRTLtOLhYT8FlarRUnYgdidlPs5flIzaegKvjmyYI=; b=agXg9P1Qop5wu2iZL0odOM7ubneZz/rpRRNOf4axTTNdeoR2EUxKLT+oGgJ1cBCCDk 2ONAjqj7FgvHwWcDDK5J/Hd+GqcYeul2sLx8Fh0UtX8J+NqHwds9cK4fxN0iP9jmGhE7 t/fvJL43+DrNJFtxBYb5mCkY8h5Tq3SHHS47ijPB5e8gWrqXz7mGRL9bIY1wnQxXyX7w JJlRTmayKspznzWk+SDtlkus+nXDm2dF8Ca5j1CAfijqQRBFO98dWGfo8wWITnwKqYkA Pc1MHleRQA+kc8LQPtPYw3MdRueGvESTwqM0EYnifKlG6GQPvwzYdd/f9cFhcWfj/ugR giIg== X-Gm-Message-State: AA+aEWbl2lh2D/U73Lt5TY8k42+J3BlOKdG2PLaRyahTFOhw+eCpvK21 Q6xdruqlGAEalRmtnYenNJOCfg== X-Received: by 2002:a1c:a485:: with SMTP id n127mr10064898wme.15.1544432016030; Mon, 10 Dec 2018 00:53:36 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id m4sm9097351wml.2.2018.12.10.00.53.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Dec 2018 00:53:35 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan , Mike Leach , Robert Walker Subject: [PATCH v2 4/6] perf cs-etm: Treat NO_SYNC element as trace discontinuity Date: Mon, 10 Dec 2018 16:52:59 +0800 Message-Id: <1544431981-24144-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> References: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CoreSight tracer driver might insert barrier packet between different buffers, thus the decoder can spot the boundaries based on the barrier packet; the decoder is possible to hit a barrier packet and emit a NO_SYNC element, then the decoder will find a periodic synchronisation point inside that next trace block that starts trace again but does not have the TRACE_ON element as indicator - usually because this block of trace has wrapped the buffer so we have lost the original point that trace was enabled. In upper case, it results in the trace stream only inserts the OCSD_GEN_TRC_ELEM_NO_SYNC element in the middle of tracing stream, but we don't handle NO_SYNC element properly and at the end users miss to see the info for trace discontinuity. Though OCSD_GEN_TRC_ELEM_NO_SYNC is different from CS_ETM_TRACE_ON when output from the decoder, but both of them indicate the trace data is discontinuous; this patch treats OCSD_GEN_TRC_ELEM_NO_SYNC as trace discontinuity and generates CS_ETM_DISCONTINUITY packet for it, so cs-etm can handle discontinuity for this case, finally it saves the last trace data for previous trace block and restart samples for new block. Credit to Mike Leach and Robert Walker who made me clear for underlying mechanism for NO_SYNC element, Mike also shared with me for detailed explanation for why we can treat NO_SYNC and TRACE_ON elements as the same, so this commit log reused most of his explanation. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.7.4 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index a3994f1..46b67f1 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -411,6 +411,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( case OCSD_GEN_TRC_ELEM_UNKNOWN: break; case OCSD_GEN_TRC_ELEM_NO_SYNC: + resp = cs_etm_decoder__buffer_discontinuity(decoder, + trace_chan_id); decoder->trace_on = false; break; case OCSD_GEN_TRC_ELEM_TRACE_ON: From patchwork Mon Dec 10 08:53:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 153248 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3327423ljp; Mon, 10 Dec 2018 00:53:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/XSlWMbADxwy5FMtAs3Ji7WjtglnScO9mpMv0QnmnCahbQky4+3IGGnwSSqA+rEkzB/Z1/e X-Received: by 2002:a63:2bc4:: with SMTP id r187mr10057319pgr.306.1544432025275; Mon, 10 Dec 2018 00:53:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544432025; cv=none; d=google.com; s=arc-20160816; b=bOyp8DVYXPaC3dlmYJIUdLgO3VUlMZfBkkAhACcX1Ds9hnhCAtkUjonelzJteREVFc N21/qG70gcc2yByYo2yDlkdP2WdBPMbniQDmP8sLG6Et+df2lACzYz4zeJpmXnjwSX4d WlDD6MrJERHr/M6sNm9UeAlK2ngSfgpa8dsSYWfDucL0D/9CAfbuxIKCGILwk/Q/jaDT hnUshPZ5XTcC4siGfBu/Vfne68izXIXCEFXIV1rkueGrydJtEnf4+6havTMpdIbPx1/1 id78uil3hZo3y5T693OyIvz1gTx+ETZk1Dg6eloO1lNJl/LbNH6OgMq4laCMjzkx2a3A y8Fw== 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=vUyooLcyJUYiK6jffhRtzW6QvVrGY41s8t/va8y//+E=; b=o/onUEbncKktkGnaS8cGDYBXHzGQx04owayyG+H2wkgduUQHL78rpi7zsGQrLtsnB/ uZC/AZSri+UscrGgmzyMTQjTF8A7hA78NUoWF/z4PArJEwAC8lsmOHss1vqg+Vvu5VqG VL9zzHAuWNZG+2psFJrvQ1Ld707/dia/YsWGI4XVFFCva0G1/bu9Ph3m3f3U7NeHPzuP OULHRzbWcYERvuMc/BQSmOwIsQ0Am2o02L+1uX/Es9MzjbWulL78yc7x6rBdJKPlRb24 3w4B8O/tjTkoK2YT6SusV4KjeRsGtynZ6oBv4/TG/JKUSp0JblFdkc7Td+bLe75sK6zb zbrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P83Jx93Q; 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 a1si9324340pgk.495.2018.12.10.00.53.44; Mon, 10 Dec 2018 00:53:45 -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=P83Jx93Q; 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 S1726777AbeLJIxn (ORCPT + 31 others); Mon, 10 Dec 2018 03:53:43 -0500 Received: from mail-wr1-f47.google.com ([209.85.221.47]:46040 "EHLO mail-wr1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbeLJIxm (ORCPT ); Mon, 10 Dec 2018 03:53:42 -0500 Received: by mail-wr1-f47.google.com with SMTP id b14so9527587wru.12 for ; Mon, 10 Dec 2018 00:53:41 -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=vUyooLcyJUYiK6jffhRtzW6QvVrGY41s8t/va8y//+E=; b=P83Jx93Qf7l7qBaSRaK1K3yR6IZ6RtW2bu5lW7VjGrBx2KuWrCUeSsAe+V50Mc8w95 fhfDgA24iPzUWSoJgyngux5eN41dgd+rs2+8ZriiBvbRa/m7z8eYzxa0QirGPZ5i2EHg rKZ4jbQe2VFiiOxqjde3BE6J4nMBy+j6pXJ4g= 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=vUyooLcyJUYiK6jffhRtzW6QvVrGY41s8t/va8y//+E=; b=odwhZ60NNh5+m4X6avvbBwhs4RCoGSgjj8s766FsQIYIb/FkzHWUe/ewKESoqyQ81z H2tiaUAmARmRyXgQqZWtpo8dmM+2BcdJKirokRb3NbL8QKRwA6uq0J5/e6cXqEVHI3qM AXymu5VTLPyKqqDUNGlAyeUNOB/6acTJJEstZYIGrLtIygk5X5x1EAmkk0SOZRMWYOec DwkuCj/cyfzMQo0gHO7xsyFVkqe5AEyoCrL4v+acmLTSCnw8yPxGfQlgDN7Kucd1Ax5/ i86xtmO9fi9+3ZKwMlE2SIgCJA/x9VCVzGpvcuhxkjjr0jt1jShFXJXXS62i6gKPF8wC rdJg== X-Gm-Message-State: AA+aEWbQTgn9ej19Zhv/QJxWMWT5OA0tIUoVmHu96yIDiqBsS1Smbg/T mw6zD0RjPgOvCguxcLGsfi4SGQ== X-Received: by 2002:adf:dfd1:: with SMTP id q17mr9543064wrn.27.1544432020389; Mon, 10 Dec 2018 00:53:40 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id m4sm9097351wml.2.2018.12.10.00.53.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Dec 2018 00:53:39 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan , Mike Leach , Robert Walker Subject: [PATCH v2 5/6] perf cs-etm: Treat EO_TRACE element as trace discontinuity Date: Mon, 10 Dec 2018 16:53:00 +0800 Message-Id: <1544431981-24144-6-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> References: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If decoder outputs EO_TRACE element, it means the end of the trace buffer; this is a discontinuity and in this case the end of trace data needs to be saved. This patch generates CS_ETM_DISCONTINUITY packet for EO_TRACE element hereby flushing the end of trace data in cs-etm.c. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 46b67f1..bcb5c98 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -411,6 +411,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( case OCSD_GEN_TRC_ELEM_UNKNOWN: break; case OCSD_GEN_TRC_ELEM_NO_SYNC: + case OCSD_GEN_TRC_ELEM_EO_TRACE: resp = cs_etm_decoder__buffer_discontinuity(decoder, trace_chan_id); decoder->trace_on = false; @@ -431,7 +432,6 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( decoder->packet_buffer[decoder->tail].exc_ret = true; break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: - case OCSD_GEN_TRC_ELEM_EO_TRACE: case OCSD_GEN_TRC_ELEM_ADDR_NACC: case OCSD_GEN_TRC_ELEM_TIMESTAMP: case OCSD_GEN_TRC_ELEM_CYCLE_COUNT: From patchwork Mon Dec 10 08:53:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 153249 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3327457ljp; Mon, 10 Dec 2018 00:53:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xfhd3WDd14dX9RAWjY69mrhavEa9T/m6/8m6nMKVM6l03rmmKMJEq7zTlb87EYp0M/kjwL X-Received: by 2002:a63:a611:: with SMTP id t17mr10005335pge.338.1544432028767; Mon, 10 Dec 2018 00:53:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544432028; cv=none; d=google.com; s=arc-20160816; b=zBP5PLvxRRQPLO6HwMr1rSZpg5XQiQZxPtl05cCiRHO5WRD5bsQzgSWmCHujvjTJe2 vIzMXXZcia3qMVROonzaA3u6ExwRt611V9DASbSdpoul+IOQBNw14skLD38raUYoBlhN ztqlyfROnspfUkHCuxTMayV4UtyPXRS6WaI7066NE6CD1YQhoyaPn6HMDpBd8rsk3ySj qfaNrHvd0UJXcJsXWruDmhAcIlOa9RRSO30KVtXWng51JZtCqqJbAQn60m2v2MQpPQoD BgFbvyJCOc10k6Eu1RCH6lf1rgyRhzy2hz9dg0OeOWgkgueTPjapRS2+nIvtsBVqKdRG rJng== 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=wBtMgTL4LtL1DJrDKLwYryYgavh17FPkWFnVB2zuBc4=; b=oIHnzNOh1jPh33izRC6BzatK82YLkHhTF9MVn4lfLK9bVfxHEcjCXTDOlkbNRrFATZ HOonLk468FBP85/2YdjAZQ4WK+XhcfwA29fe9l/8g76DI1o8sUiQJQUyO5L4lHdFF6Mv KRzjZx2udL4gRRx5gmO78XIuLTN+aJuRs2+AENLFKmltR37+rIwXaKE9TqBfP2i1Vp/g IKalHZVfKwpkZcbegMyNEzZ7JU7uNzzjBSlaxXHV/Z0kV9xgpM6K7Rl2mv2fNKSPk/A6 gQd/numLkTsyEHGNDCoev/ScdyW3kCabp2/yq1bMOeC1BIb5y/me70DoM3/zqGRuxP1W qtDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SI4u3PnH; 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 a1si9324340pgk.495.2018.12.10.00.53.48; Mon, 10 Dec 2018 00:53:48 -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=SI4u3PnH; 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 S1726792AbeLJIxr (ORCPT + 31 others); Mon, 10 Dec 2018 03:53:47 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36701 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbeLJIxq (ORCPT ); Mon, 10 Dec 2018 03:53:46 -0500 Received: by mail-wm1-f65.google.com with SMTP id a18so10323864wmj.1 for ; Mon, 10 Dec 2018 00:53:45 -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=wBtMgTL4LtL1DJrDKLwYryYgavh17FPkWFnVB2zuBc4=; b=SI4u3PnHj0Ui8XvRsfTuB45S23mQBOET1nXbqq/Bxyi3qN9cmVj7zPjDBUN9FobUek XTkNuZ1a43RxLCzfSRnVAu2CmK0uYFHdZrobMzJy7ViVGhKerzXwji7OYQW4N5xjGwiA rXX/0NY1aDmOJN/WaMgxeWi1GCVYKRhH7L1rQ= 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=wBtMgTL4LtL1DJrDKLwYryYgavh17FPkWFnVB2zuBc4=; b=nJXwUsQuoovTULJKkbtV8ACG7cOHDnOFr0pLAMWsUMoe3wRDzaNCdrZ5NCdO9Yiooq itncuwBEYx5bvL0+GVtDGx6MJofnEBiVN2/LRA7TSKOeNRpm9FCrhC+HAvcd+znaczSl kZWnrlamL6N77NDopiRlV2k3e95uVjXxkU3F6mWh76Kd6I9+tEOb0huzA14jblXzKmrA QgC82QCed9Zaj7hcXMgbXfX9+Ps+Lrk6D1jtOSVcAu0RhmVSaS5KkJ0/HvrWVYtWmC0u rVQuiXjT7RutTDDHP/NZM9Lfh85ixq51FFNP/BqBuo+87jGFqgCsb8rLRVHBFsqgjN4Y m2Ew== X-Gm-Message-State: AA+aEWZCcFIMEo1ZEdsInEPlLO8BsrTgzq1qZRMRaARJ8q/KIYOWy5kt kse1V4rcnxQ8EcxCHaTdOUZJsg== X-Received: by 2002:a1c:6382:: with SMTP id x124-v6mr10361482wmb.145.1544432024892; Mon, 10 Dec 2018 00:53:44 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id m4sm9097351wml.2.2018.12.10.00.53.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Dec 2018 00:53:44 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan , Mike Leach , Robert Walker Subject: [PATCH v2 6/6] perf cs-etm: Generate branch sample for exception packet Date: Mon, 10 Dec 2018 16:53:01 +0800 Message-Id: <1544431981-24144-7-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> References: <1544431981-24144-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The exception packet appears as one element with 'elem_type' == OCSD_GEN_TRC_ELEM_EXCEPTION or OCSD_GEN_TRC_ELEM_EXCEPTION_RET, which present for exception entry and exit respectively. The decoder set packet fields 'packet->exc' and 'packet->exc_ret' to indicate the exception packets; but exception packets don't have dedicated sample type and shares the same sample type CS_ETM_RANGE with normal instruction packets. As result, the exception packets are taken as normal instruction packets and this introduces confusion to mix different packet types. Furthermore, these instruction range packets will be processed for branch sample only when 'packet->last_instr_taken_branch' is true, otherwise they will be omitted, this can introduce mess for exception and exception returning due we don't have complete address range info for context switching. To process exception packets properly, this patch introduce two new sample type: CS_ETM_EXCEPTION and CS_ETM_EXCEPTION_RET; for these two kind packets, they will be handled by cs_etm__exception(). The func cs_etm__exception() forces to set previous CS_ETM_RANGE packet flag 'prev_packet->last_instr_taken_branch' to true, this matches well with the program flow when the exception is trapped from user space to kernel space, no matter if the most recent flow has branch taken or not; this is also safe for returning to user space after exception handling. After exception packets have their own sample type, the packet fields 'packet->exc' and 'packet->exc_ret' aren't needed anymore, so remove them. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 26 +++++++++++++++++------ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 4 ++-- tools/perf/util/cs-etm.c | 28 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) -- 2.7.4 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index bcb5c98..6d89d0e 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -291,8 +291,6 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) decoder->packet_buffer[i].instr_count = 0; decoder->packet_buffer[i].last_instr_taken_branch = false; decoder->packet_buffer[i].last_instr_size = 0; - decoder->packet_buffer[i].exc = false; - decoder->packet_buffer[i].exc_ret = false; decoder->packet_buffer[i].cpu = INT_MIN; } } @@ -320,8 +318,6 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].sample_type = sample_type; decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN; - decoder->packet_buffer[et].exc = false; - decoder->packet_buffer[et].exc_ret = false; decoder->packet_buffer[et].cpu = *((int *)inode->priv); decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; @@ -398,6 +394,22 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_decoder *decoder, CS_ETM_DISCONTINUITY); } +static ocsd_datapath_resp_t +cs_etm_decoder__buffer_exception(struct cs_etm_decoder *decoder, + const uint8_t trace_chan_id) +{ + return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_EXCEPTION); +} + +static ocsd_datapath_resp_t +cs_etm_decoder__buffer_exception_ret(struct cs_etm_decoder *decoder, + const uint8_t trace_chan_id) +{ + return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_EXCEPTION_RET); +} + static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, const ocsd_trc_index_t indx __maybe_unused, @@ -426,10 +438,12 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: - decoder->packet_buffer[decoder->tail].exc = true; + resp = cs_etm_decoder__buffer_exception(decoder, + trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: - decoder->packet_buffer[decoder->tail].exc_ret = true; + resp = cs_etm_decoder__buffer_exception_ret(decoder, + trace_chan_id); break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: case OCSD_GEN_TRC_ELEM_ADDR_NACC: diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index a272317..a6407d4 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -26,6 +26,8 @@ enum cs_etm_sample_type { CS_ETM_EMPTY, CS_ETM_RANGE, CS_ETM_DISCONTINUITY, + CS_ETM_EXCEPTION, + CS_ETM_EXCEPTION_RET, }; enum cs_etm_isa { @@ -43,8 +45,6 @@ struct cs_etm_packet { u32 instr_count; u8 last_instr_taken_branch; u8 last_instr_size; - u8 exc; - u8 exc_ret; int cpu; }; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index cea3158..27a374d 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1000,6 +1000,25 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) return 0; } +static int cs_etm__exception(struct cs_etm_queue *etmq) +{ + /* + * When the exception packet is inserted, whether the last instruction + * in previous range packet is taken branch or not, we need to force + * to set 'prev_packet->last_instr_taken_branch' to true. This ensures + * to generate branch sample for the instruction range before the + * exception is trapped to kernel or before the exception returning. + * + * The exception packet includes the dummy address values, so don't + * swap PACKET with PREV_PACKET. This keeps PREV_PACKET to be useful + * for generating instruction and branch samples. + */ + if (etmq->prev_packet->sample_type == CS_ETM_RANGE) + etmq->prev_packet->last_instr_taken_branch = true; + + return 0; +} + static int cs_etm__flush(struct cs_etm_queue *etmq) { int err = 0; @@ -1148,6 +1167,15 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ cs_etm__sample(etmq); break; + case CS_ETM_EXCEPTION: + case CS_ETM_EXCEPTION_RET: + /* + * If the exception packet is coming, + * make sure the previous instruction + * range packet to be handled properly. + */ + cs_etm__exception(etmq); + break; case CS_ETM_DISCONTINUITY: /* * Discontinuity in trace, flush