From patchwork Sun Nov 11 04:59:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150755 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1705980ljp; Sat, 10 Nov 2018 21:00:20 -0800 (PST) X-Google-Smtp-Source: AJdET5e2RqC9V5xFwGuIA4s4Ky/HnPhc6YZOp7ABaMoR40tNBrKVQRVLrciwfmLx166TcueOi4qz X-Received: by 2002:a63:554b:: with SMTP id f11mr3449308pgm.37.1541912420762; Sat, 10 Nov 2018 21:00:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912420; cv=none; d=google.com; s=arc-20160816; b=vLrJ97fa67bkbZTQUA2PT/MV/7xWR5maDxXXJZINm9OQTuB0/Z+NYdRC6uOqA3lOre BAfrpqElI3HXvDtz/5Zl+4k4TSoZIbhJBRbYUTL0K5i4uyaw0dBzU6S72GGCvaeIem+a Gx9roair/4rcodVyT7fC6KS1nKYX5efLc1Jal7ugzAV0gDExzXdGCR3eC80M/wN4xUSK DhP5ieuue26lu/tZolwYFApy7ym+mEegWpNeyYMayWoSfuYYgVYP4xp+ZhUtLpRowRpc EzxVHeeIsGIBRlnD36wZ37suGG8PpxvCF52fjJXX6QkJLF8iZ4vVoRNo3I03T8elDzY2 lDTw== 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=ZbLjNsAHRTQqCj6a1vHW0MpbOVGBpYLMhVIToqZ+NHM=; b=wP2UCS1epKl+A6mzwL8nThNRRk+8HFkvta+oyRzY884xy7Y+exl7iEl5oLG0HVEI2F +idVg7T/tDpnQBh3XyyuDcnNSR6R+AQ+P142LuVx0tv2lTnCZ+1roNkINIkMYAfiQPM2 1i3WbfBtOMPqRea4wdlpOcE0glsMFXwJdpLKRHGL6XWFlbEwXHjPFugpS6gPk/1obwMp BFoTMk5d98q1oI4evUSon8VZghuWNt+UE1X0cT6rFszoXf22SZp5TFynPzmq04LxqZlP XX38pbsi3ErWa7KBqoLNVILhKCpKti9CK7qFDZIomwIaNcpHyNm+huVg6SE3yhrsnmd/ M74Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kX3Ru026; 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 d9si10798807pgb.105.2018.11.10.21.00.20; Sat, 10 Nov 2018 21:00: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=kX3Ru026; 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 S1727503AbeKKOrn (ORCPT + 32 others); Sun, 11 Nov 2018 09:47:43 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36476 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKOrn (ORCPT ); Sun, 11 Nov 2018 09:47:43 -0500 Received: by mail-wm1-f67.google.com with SMTP id v70-v6so4777763wmd.1 for ; Sat, 10 Nov 2018 21:00:14 -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=ZbLjNsAHRTQqCj6a1vHW0MpbOVGBpYLMhVIToqZ+NHM=; b=kX3Ru026f/ESYt6B1mTZGk6Ey5ia7fEi5PJ8IB30wxK77FSFx+/TfmzhW8Rt1b9Mws oOALFaXam6s1cb/uM7MDCMsKmVuZD/KEnnc/V2aTzpS+VR8Sng/OTGhv8T2Hcedq4IC5 /gqUm0MrB1tnHKUHCkfhRdA9rVW2rc1/3D1h0= 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=ZbLjNsAHRTQqCj6a1vHW0MpbOVGBpYLMhVIToqZ+NHM=; b=nKVLLSOz1CWdNmJp5vXSngP3otcpnop2L8gxUNAGtKOsthsQBFUmhFLKrmpftqRUY2 FjHOAd4h6luqUeV9oUa20hC1tqaaBAs9uvk/eqC3YK4MjfAcU/hN1jaLc2v2uBZz5dE3 wPPBEctpNa7qPmOujPxXAAyuit0BfGCudOLr3a1n4kABbA5lHIECHnNmWZXDuH/gggu8 vnit9x1G/M4el/w2MCXlrXMrk2RGxfD9WbKy7iZd9WD8uU5Z8GCvSTKB01QgDEt+3gLS djyAinaGTomr3VAGeNoOgepI5F4SAstx9Ap/4Bvh8Gh7ruQYTWjdCJyJVt/mVybqRG+D xsaA== X-Gm-Message-State: AGRZ1gLlXH++AxEu3E3rvnUDfTIuOWsZ0ddLdcRgnTj4inmDVrGcNhpE q4QiwjUI4dQLXcrwDRjR+zuMbw== X-Received: by 2002:a1c:1a53:: with SMTP id a80-v6mr3928909wma.120.1541912413637; Sat, 10 Nov 2018 21:00:13 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id t187-v6sm4463802wmt.45.2018.11.10.21.00.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:00:12 -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, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan Subject: [PATCH v1 1/5] perf cs-etm: Correct packets swapping in cs_etm__flush() Date: Sun, 11 Nov 2018 12:59:39 +0800 Message-Id: <1541912383-19915-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912383-19915-1-git-send-email-leo.yan@linaro.org> References: <1541912383-19915-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. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 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 48ad217..fe18d7b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -997,7 +997,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) } swap_packet: - if (etmq->etm->synth_opts.last_branch) { + if (etm->sample_branches || etmq->etm->synth_opts.last_branch) { /* * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for * the next incoming packet. From patchwork Sun Nov 11 04:59:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150756 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1705985ljp; Sat, 10 Nov 2018 21:00:21 -0800 (PST) X-Google-Smtp-Source: AJdET5c9P/7KPnM6kYy25SvO4TNAY9IU+1L5zl62uQJu/xxopWL6j0nxvW7T5eMdCG7KEvX8KgvL X-Received: by 2002:a62:9109:: with SMTP id l9-v6mr15402955pfe.154.1541912421253; Sat, 10 Nov 2018 21:00:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912421; cv=none; d=google.com; s=arc-20160816; b=qrJwElPt/q7sHMgyAgYNlbhG4XfKltlmjPPlkiWAmUozqZ28nxc1NfQPkLsBgar692 Z5LtRLBwt3FjchFtUAUvbXxhxNKiRY5fETDnpJeGzJYh3PIFgudAdjlZyVnHnrTRuFnr C1hMZdv4UlLwEeSZZOsbA77UaEc5WQCzA4/3ZmNLS16T+eXsOtE+NNOJ0npu2QBVAr7c +wBQWXEgoEx2RmZqOolBbM4ADDw9E9p3FDzdGjzCPVytLWbdyDcQrO4F/MUHyzSJot49 HBz0O9P8icpw0ZFP+v4AbvAMSqZDT2W8Rl0Od8q87+9fT2+BVWoilvDwMvjnTL6L8E+t LdRQ== 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=GlLVr9yrcWWcrnJ7efExsQPwL3OrlynWDQhaVwy2gkU=; b=OvViLo7Q6bh0rAHeZQmTZoJpFeSB0FdgeACtDWHzd8GEXBlviNR4T2mux8JzWeJZkI DeW2Ip1EBUiwT51A3eAWvxu43EFrIQHBS9ZnjpgKu1IzYnhw0TUa//n5y5eBfzlNqsaA 3RyRCAaXaMV4tjsOtxqZJbfVhKoRT1WdyCPNTnXeNh2OlLWWaCvfcxKEJrJXtgMmgIej rHxU2kQFnX3ZfNphMN8iQKZaUNQr+fwuiwGXF63c0MT7QeS6AkM+0vaCnh5BTK6Cx4I6 SxMOQsQOGbX9FdGP6vLIqqq2ZXj9Vr2s5pDP2kf+hQPvOU5AesjubZpdBrWavvJni/2E 60dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zax5fOHT; 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 d9si10798807pgb.105.2018.11.10.21.00.20; Sat, 10 Nov 2018 21:00:21 -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=Zax5fOHT; 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 S1727541AbeKKOrr (ORCPT + 32 others); Sun, 11 Nov 2018 09:47:47 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38524 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKOrq (ORCPT ); Sun, 11 Nov 2018 09:47:46 -0500 Received: by mail-wm1-f67.google.com with SMTP id f2-v6so5193509wme.3 for ; Sat, 10 Nov 2018 21:00:18 -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=GlLVr9yrcWWcrnJ7efExsQPwL3OrlynWDQhaVwy2gkU=; b=Zax5fOHToS2p6UfHN0dl+LYAknkoVGAwHHbiN+XuzZBA9NU/Jwwl2WueViP7g5ivm6 bmZLBHRIzMTUFLo5xhr+tWi5+WmiYf9NkPvozoqidPO6jPYWLcZpGRBf/Oht74u/7teU bvpPmPMEA3aqB/3xKmeQy5s4VhhyAw2Xpd9xQ= 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=GlLVr9yrcWWcrnJ7efExsQPwL3OrlynWDQhaVwy2gkU=; b=Ngx9hmTokYlNYEe2m63Rd5RdW6G2XAO1QOmia1Zd45zvxd33zY94IhjF5iSQnp4hB0 qET3eBH9pyQDNI4d+eTq1uz0687eVqIIuQmhfWk66N3gMU72YpYMIPGh9DosVZzM2sMt 5888/I3Q2/5wPIAWiUfTcdCULngIvPpaplr61Z+jUcye0ZkiPSjM9bgKdXBy4LS67/xG DrRGK7Nrq9y/lxfxxfnhdwyVrE9r0K3T4H1dsqU9ouXTYi4Pn2JWrlmIIP/MlFiZaNJ6 H+OVPJnMz9mpxrnZRyeSs5jqSJIaPh+0fgxi/9/9s1INIfrBCAlB/GG3rPcjoh7eVyC8 sYog== X-Gm-Message-State: AGRZ1gJBePFE992jyqkN4cUplNXPE5SfSQScHmiR8Nf8swv3lcW/7rxu RgEO6mYscF+JWma5v+bco23QWvmLSa2hUQ== X-Received: by 2002:a1c:87cb:: with SMTP id j194-v6mr3643761wmd.2.1541912417568; Sat, 10 Nov 2018 21:00:17 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id t187-v6sm4463802wmt.45.2018.11.10.21.00.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:00:16 -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, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan Subject: [PATCH v1 2/5] perf cs-etm: Avoid stale branch samples when flush packet Date: Sun, 11 Nov 2018 12:59:40 +0800 Message-Id: <1541912383-19915-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912383-19915-1-git-send-email-leo.yan@linaro.org> References: <1541912383-19915-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 is to add new argument 'new_packet' for cs_etm__flush(), we can pass 'true' for this argument if there have a new packet, otherwise it will pass 'false' for the purpose of only flushing branch stack entries and avoid to generate sample for stale packet. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index fe18d7b..f4fa877 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -955,7 +955,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) return 0; } -static int cs_etm__flush(struct cs_etm_queue *etmq) +static int cs_etm__flush(struct cs_etm_queue *etmq, bool new_packet) { int err = 0; struct cs_etm_auxtrace *etm = etmq->etm; @@ -989,6 +989,20 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) } + /* + * If 'new_packet' is false, this time call has no a new packet + * coming and 'etmq->packet' contains the stale packet which is + * set at the previous time with packets swapping. In this case + * this function is invoked only for flushing branch stack at + * the end of buffer handling. + * + * Simply to say, branch samples should be generated when every + * time receive one new packet; otherwise, directly bail out to + * avoid generate branch sample with stale packet. + */ + if (!new_packet) + return 0; + if (etm->sample_branches && etmq->prev_packet->sample_type == CS_ETM_RANGE) { err = cs_etm__synth_branch_sample(etmq); @@ -1075,7 +1089,7 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) * Discontinuity in trace, flush * previous branch stack */ - cs_etm__flush(etmq); + cs_etm__flush(etmq, true); break; case CS_ETM_EMPTY: /* @@ -1092,7 +1106,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__flush(etmq, false); } return err; From patchwork Sun Nov 11 04:59:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150757 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1706090ljp; Sat, 10 Nov 2018 21:00:30 -0800 (PST) X-Google-Smtp-Source: AJdET5e5e0X2qiV3iun1i2d3vSKT3hNaX4lbalraeDnIkto7i+OWB4ngDfTNLMr8QjS1pl0LQO/X X-Received: by 2002:a63:36c4:: with SMTP id d187mr12912202pga.404.1541912430606; Sat, 10 Nov 2018 21:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912430; cv=none; d=google.com; s=arc-20160816; b=BdisTy7+8W4VKYqXMPebS6APvoy72/Pole9R6YwFkbEBI1PwRDeoojnhCFKcdm/TgU FgKg46Y+zlqmfe6Thmlp3asvtx+rkaWXpvFDIr/HfUheU4TJob8lsOvEc3Z3aXlmCQ9v 4q8gfjRGgCnWMvPannua4zAmymnvn9vShVMHH1TpbHmmUO1yBRkPRPYVNcLs1pZl/4fF OAkdnXAGESfnNHkheEZKZGU7YRj7BXl0Term2o/ofk+1rYDRrJbx8jHSfYED8DCPY+H3 0o7gXrtf7h8brSwMPrK7dGHidIXdFK1Y4qmekGNPS4CEGP4wxxAVPqbgbx4Fr/05rHWP Pu2Q== 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=fmD++TcGuvp1soHonkx5687mfGEN7WjEJXPPOJvoda0=; b=kmcc8bHlX8S8bEkun8hBrugcODeuQ2byUevrRNx8+0Ufc/D5RNk6r47LFXQYA2JjeP eRjI+yE3RNIq9XfKFzaSzOj+fCeEMISsFXRCp+VX2eCRcov9YPQjQUWMKIk3pFgV2Uda SDky0OkB+OLbRK/xYHa+pwhjmGJ4/sT/1y0KlSzkprFJ8MGQTRpbFjCiyN2WftxobIdH HaN6B5MXlJCvCY16ukewI4z0kUoiwJg6fIeeGyDBRWtMuGcmpZoMNxrN3vtNCp2dXOvW WOkmNxL7wlrD0CYGnqhtyGAbTKXJxIu9fiwKUHglXnl/MtvC8yJgXLqbjsdjd7uzKj3P 1u9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kUK19Me+; 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 63-v6si14809181pfg.234.2018.11.10.21.00.30; Sat, 10 Nov 2018 21:00:30 -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=kUK19Me+; 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 S1727575AbeKKOrv (ORCPT + 32 others); Sun, 11 Nov 2018 09:47:51 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38527 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKOrv (ORCPT ); Sun, 11 Nov 2018 09:47:51 -0500 Received: by mail-wm1-f65.google.com with SMTP id f2-v6so5193602wme.3 for ; Sat, 10 Nov 2018 21:00:22 -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=fmD++TcGuvp1soHonkx5687mfGEN7WjEJXPPOJvoda0=; b=kUK19Me+7lAMeZI7F+H+A9idmNoAgmo/vgIcfn3SurdVr8OkqgwqlG20A/EI2H83og tWTS8LHtNsWUTVmLPZg3TsDAtU1ND8JxG23SSG43hQr9hq6WNQMImR2XM4CZExxPMtA7 aYPEZ0FM2DfLMRHM7rsc4yjdBBFiMUfFXECEs= 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=fmD++TcGuvp1soHonkx5687mfGEN7WjEJXPPOJvoda0=; b=KO0nRavpQNduSQx3i81oncRMzen6RWE1+Bxd1iQIHci4Kumelg62epXco5AKgk2X8a UfrbU+YrGJ5oBL2EKEzkKXOAy/SQL06xxz+/PEXLE0c03WrM83jQh9cBsFELH7ns/LBJ 37ycEccvgiCsjHPlm3u3oqMI3Thlf++Zz0rlFBjcqX1ABy1zs59y12B3e5eITFMr1zs6 YWuwMBS27m6omaRwDmmTOIGOVvS7ja3T5ua/3nGOO1X3qPLT/H1f3DHZzEoxd6gaUgIu +zTkcixdr7Ma6NBf2IZV+k7HGfQ5hPAkVhPmlJ312XS4pYk5RsnzYVzUd7R8hfGfGLCb 2WpA== X-Gm-Message-State: AGRZ1gJsEYrOPbD+NQBRMonwXzJPQ8DLLb4S5ThSUB7FV6Hq/mi4l3vG mcYETmJd6tatzmt/tNFqavrmB8PgXvfgdQ== X-Received: by 2002:a1c:a757:: with SMTP id q84-v6mr4054957wme.61.1541912421659; Sat, 10 Nov 2018 21:00:21 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id t187-v6sm4463802wmt.45.2018.11.10.21.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:00: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, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan Subject: [PATCH v1 3/5] perf cs-etm: Support for NO_SYNC packet Date: Sun, 11 Nov 2018 12:59:41 +0800 Message-Id: <1541912383-19915-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912383-19915-1-git-send-email-leo.yan@linaro.org> References: <1541912383-19915-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 As described in OpenCSD (CoreSight decoder lib), in the decoding stream it includes one trace element with type OCSD_GEN_TRC_ELEM_NO_SYNC; the element indicates 'either at start of decode, or after overflow / bad packet', we should take it as a signal for the tracing off and this will cause tracing discontinuity. From the trace dump with 'perf script', sometimes the element OCSD_GEN_TRC_ELEM_NO_SYNC collaborates with element OCSD_GEN_TRC_ELEM_TRACE_ON to show the tracing flow have been turned off and on, in this case the cs-etm code has handled TRACE_ON packet well so we observe the tracing discontinuity; but in another case it only inserts the element OCSD_GEN_TRC_ELEM_NO_SYNC into instructions packets, we miss to handle the case if has only standalone NO_SYNC element and users cannot receive the info for tracing discontinuity. This patch introduces new type CS_ETM_TRACE_OFF to generate packet for receiving element OCSD_GEN_TRC_ELEM_NO_SYNC from decoder; when generate sample, CS_ETM_TRACE_OFF packet has almost the same behaviour with CS_ETM_TRACE_ON packet: both of them invokes cs_etm__flush() to generate samples for the previous instructions packet, and in cs_etm__sample() it also needs to generate samples if TRACE_OFF packet is followed by one sequential instructions packet. This patch also converts the address to 0 for TRACE_OFF packet, this is same with TRACE_ON packet as well. 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 | 7 ++++--- tools/perf/util/cs-etm.c | 15 +++++++++++---- 3 files changed, 25 insertions(+), 7 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 5efb616..9d52727 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -369,6 +369,14 @@ cs_etm_decoder__buffer_range(struct cs_etm_decoder *decoder, } static ocsd_datapath_resp_t +cs_etm_decoder__buffer_trace_off(struct cs_etm_decoder *decoder, + const uint8_t trace_chan_id) +{ + return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_TRACE_OFF); +} + +static ocsd_datapath_resp_t cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, const uint8_t trace_chan_id) { @@ -389,6 +397,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_trace_off(decoder, + trace_chan_id); decoder->trace_on = false; break; case OCSD_GEN_TRC_ELEM_TRACE_ON: 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 9351bd1..a38c97c 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,10 @@ 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 = 0, + CS_ETM_RANGE = 1 << 0, + CS_ETM_TRACE_ON = 1 << 1, + CS_ETM_TRACE_OFF = 1 << 2, }; enum cs_etm_isa { diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index f4fa877..2a0cef9 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -517,8 +517,9 @@ 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 TRACE_ON and TRACE_OFF packets */ + if (packet->sample_type == CS_ETM_TRACE_ON || + packet->sample_type == CS_ETM_TRACE_OFF) return 0; return packet->start_addr; @@ -527,8 +528,9 @@ 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 TRACE_ON and TRACE_OFF packets */ + if (packet->sample_type == CS_ETM_TRACE_ON || + packet->sample_type == CS_ETM_TRACE_OFF) return 0; return packet->end_addr - packet->last_instr_size; @@ -930,6 +932,10 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) if (etmq->prev_packet->sample_type == CS_ETM_TRACE_ON) generate_sample = true; + /* Generate sample for tracing off packet */ + if (etmq->prev_packet->sample_type == CS_ETM_TRACE_OFF) + generate_sample = true; + /* Generate sample for branch taken packet */ if (etmq->prev_packet->sample_type == CS_ETM_RANGE && etmq->prev_packet->last_instr_taken_branch) @@ -1085,6 +1091,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_TRACE_OFF: /* * Discontinuity in trace, flush * previous branch stack From patchwork Sun Nov 11 04:59:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150758 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1706096ljp; Sat, 10 Nov 2018 21:00:31 -0800 (PST) X-Google-Smtp-Source: AJdET5d4iU8OBr4N7uOVGaudUmI9dcOrrQ7ciaj5Q7VKL5nVgVbkPhFI7d+3psol7RBWQT2PORBr X-Received: by 2002:a62:250:: with SMTP id 77-v6mr15729031pfc.16.1541912430932; Sat, 10 Nov 2018 21:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912430; cv=none; d=google.com; s=arc-20160816; b=xR0Y5YBs/1DPI2VaRS3VbhVo9y46xIx7/SDOWaBMCESxQYWyYS++bHevgsQc5C477v 8RwrO82cr5FtNlKo7tUNVrhnPtkhxNbwoRvYOwo/ZjK4rxzlpUa/LIv/gYacndQ6MHu1 XqQBTqhQv4VuoXIhUkQ4Y5oBgfaca81G3L2cpcqafkV7u9OHQugNKj1+gNVBpruIyBp6 llB2fwgOgkwEPfZSVFSeq9R7gzAwkP+W8lg9eVzMd/sOpETLfvCYXvGJlP/wMom4faU8 yLBSbwfqIX/KIMzVkIcjeAEnQBIQxqezaHfY8YjAtjzJiPosH0EDYljj725w+q4P+taA cQTA== 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=r42JAcC4xD23EwVm77cfqI4lnpyXT4DHtW2OTOkNuyQ=; b=Qfs8QT6dMdmBnjV2oWl5kM6SeeGE7AFZFl0CPdqCz8ub795byKjO6MonCIOfkJ04i+ bdcxpGLG0CEWxUnVwVj5aoGNOwpANL9jg7VR8UkcTHuhqgdf3M9l5ydGzFQ/1ek4WVWK +YUrjqLX5m04daMDZwkx/rflVctnIl867wXOIinvuxEVVgr3jBp2eXbQXR5B0WBwJMeR 7iy0r3JHfZUQ7uaI51bbEqaAFhrx6Q76peMrPiT5eizoTn3zj+fvpeso29v88q+gLkAr ESxvWzQpK6jQSUHMMdJxUPYpVqs6dRhzMfG9BRIiv5DdV/sDPqxvgBUm92dGg6LPxgg9 1ebw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3mp1ml1; 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 63-v6si14809181pfg.234.2018.11.10.21.00.30; Sat, 10 Nov 2018 21:00:30 -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=Q3mp1ml1; 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 S1727613AbeKKOrz (ORCPT + 32 others); Sun, 11 Nov 2018 09:47:55 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34333 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKOrz (ORCPT ); Sun, 11 Nov 2018 09:47:55 -0500 Received: by mail-wr1-f67.google.com with SMTP id j26-v6so5850046wre.1 for ; Sat, 10 Nov 2018 21:00:26 -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=r42JAcC4xD23EwVm77cfqI4lnpyXT4DHtW2OTOkNuyQ=; b=Q3mp1ml16u22ZjAMIb4zMwp256Th9H6BpIP4qB3YeOb/Mfi2BNQ176XUbKAr8Il5K/ S+kS0uAZM8212ozC+aBjVVRdM2OdWXq5wzXFGXzCYPNknA6E/16eT+Gv/TVqYt/iz/hl muYb2k/CcP6Tad/U+AHQsBszd0NXTvL3ona8A= 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=r42JAcC4xD23EwVm77cfqI4lnpyXT4DHtW2OTOkNuyQ=; b=tfXFgyyFmMUXD6oonb5+Uf30qChLAN+/HTAnKyjjgs1iHM9tcfK/G3zIwbbAu4rdz+ 60Ou/+5QeXo+58GFwz7EbRkbTIR5pQrgiRKxKJFCImbEmmJiP3kLGtJ04nPspsQcaHf1 Ryr6w8mVOZ4mzHOm9Z8ckwGYwRTnN20NsmvRlAoUZjLRtcfCanqFB7rfaZnGsZP3+i6I dLa7Slg6Rg9NWD5eLiQyy39w77jj+89bxRUaac64I3bAEtg6wKkwv3etunLY0oixCDb+ AfdfvIp5xN+Iexijm2FU2NEGhQbaxs7RvNGW89DJJsmGK09Pe6Fp82c1HNhahWcRt0rJ K4nA== X-Gm-Message-State: AGRZ1gKXlsLHTjiaEL0yFqIWeTUtthnCFAuztp+trxa8aZpbC9slsyrH QyFwCKGhDDWUzB0X/5rcptvO+9zk12/+hQ== X-Received: by 2002:adf:f24d:: with SMTP id b13-v6mr12334822wrp.142.1541912425654; Sat, 10 Nov 2018 21:00:25 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id t187-v6sm4463802wmt.45.2018.11.10.21.00.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:00:24 -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, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan Subject: [PATCH v1 4/5] perf cs-etm: Generate branch sample for exception packet Date: Sun, 11 Nov 2018 12:59:42 +0800 Message-Id: <1541912383-19915-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912383-19915-1-git-send-email-leo.yan@linaro.org> References: <1541912383-19915-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. 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 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 9d52727..b8cb7a3e 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -269,8 +269,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; } } @@ -298,8 +296,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; @@ -384,6 +380,22 @@ cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, CS_ETM_TRACE_ON); } +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, @@ -411,10 +423,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_EO_TRACE: 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 a38c97c..0d1c18d 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -27,6 +27,8 @@ enum cs_etm_sample_type { CS_ETM_RANGE = 1 << 0, CS_ETM_TRACE_ON = 1 << 1, CS_ETM_TRACE_OFF = 1 << 2, + CS_ETM_EXCEPTION = 1 << 3, + CS_ETM_EXCEPTION_RET = 1 << 4, }; enum cs_etm_isa { @@ -44,8 +46,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 2a0cef9..455f132 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -961,6 +961,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, bool new_packet) { int err = 0; @@ -1090,6 +1109,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_TRACE_ON: case CS_ETM_TRACE_OFF: /* From patchwork Sun Nov 11 04:59:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 150759 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1706143ljp; Sat, 10 Nov 2018 21:00:34 -0800 (PST) X-Google-Smtp-Source: AJdET5fsxZyUbNTFjCCUf34oq8wFNAz1FEpBdYvEI37dEJAMQYL3B/sUqaXqiXJzFlY/cRumnhsg X-Received: by 2002:a17:902:bf49:: with SMTP id u9-v6mr15372289pls.10.1541912434535; Sat, 10 Nov 2018 21:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912434; cv=none; d=google.com; s=arc-20160816; b=p5nWCWL1tf6soyNbZwbQlIU6ffN0K/RoqnwxZGFTSLIdaRRBpxJvRfbnUpvz51rzw1 ZmFb2BvUYBf6qo5w/T7cOhii21I76XjgI3Q7KDXUGM7Jm8aR2zz2y212UkM465zNFVFM kyhyob9ZYRfzxFxRapUnqkdSzNdFtmp1Wkzt/PWV0jUpNLuv8GM4Qp6dl8yUxZz1Bbtq 9rbtKRfD6GtV9UfilTrVhKFEv9x/QQfJCbIPqH/nnqZgQ8tp3WVhqg6lfUJTwBMRuse6 rCNCP9xzggutync1i3p2yZNTJRNLZx3NFx/Qla749pIM0z4uVV5YhhqfSFpfe9ghjzZx LWfQ== 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=jZ25mbwgDMiV9nnmDqIiPF/+ngrYDveBFk4YG++0cIY=; b=K1sbBZpFc/b5u6BksBPfG45SR7iC8znqETRPzfLlEx1DffVpok7cgSRzpOc0GxEVsl 00BvxEHZTa7Me+AtH4UJ9PKlP2jBvAb3qgSJx1CKbFBGcA71KiNCpeUfSZT+dIi+grrs /5f3HyDHz3H69izsA3vMemDxcbYt1Z0xnaqh3OIXsSrJT7cPfMHU6SDgYjZgInyxdtya vnOtEvr2CnED8ydD8R3OsK13c7vPEBD3nQtFvN5MyG/N2Xomf/yzH2gYBM//Pwy4/7r/ BbDEeXYfVudTfxUWtotk9kCEOqjF2ToQarEGprDFglVYDq2CfnMHPVgGtUs1ggSY3AN4 HLzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uro2G0dQ; 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 k8-v6si13208369pll.241.2018.11.10.21.00.34; Sat, 10 Nov 2018 21:00:34 -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=Uro2G0dQ; 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 S1727655AbeKKOsA (ORCPT + 32 others); Sun, 11 Nov 2018 09:48:00 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52907 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKOr7 (ORCPT ); Sun, 11 Nov 2018 09:47:59 -0500 Received: by mail-wm1-f67.google.com with SMTP id r11-v6so5384144wmb.2 for ; Sat, 10 Nov 2018 21:00:30 -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=jZ25mbwgDMiV9nnmDqIiPF/+ngrYDveBFk4YG++0cIY=; b=Uro2G0dQHwvBrnMO0YlyZHQuZdz4eHov8QSnTHeJXpXHZE4EslFv4WZa/aa0BWvr5P /P+v6ux/xQWLYb+MXHaEmdAhp902+Pnz5FFAhZoGdDtW3TOJpyvXfNOt+1YuKYM2PYRQ GeTIXm0slFqj9EKsR3koIfPELL0Ly8Mb4B3wE= 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=jZ25mbwgDMiV9nnmDqIiPF/+ngrYDveBFk4YG++0cIY=; b=oSnI8fCcgY7JNf5TzXEVBFYqXciY+SxzUY1ndjxxtZUm7W31PdFpOmD/qieZaL/s/Z FNYhy27PGn0NBkrx2kN4il6v1mXKKRQd1TsO9jVVT0VSXqn/1d8AwqHgjLysEd8+LjH/ yn6QtA00SiZde2Ev862SelwWbDgFA7GYClPp9oP8glmSGYi66TTD0ImeJe+/lsRixRBZ /sUwfsTzCadvrXETn6rzua2TLVdY74GKnaL7uQ4c9Gr4B0kOfnUI/bMQ+zx2L5Sc7Kx6 NHGrWXCgUKo1WXRIoLtUw8hWK4/zI8SMvtdiSHDcLjmQTBae1dpQrerYqQ1vvq/sl/9U SuAA== X-Gm-Message-State: AGRZ1gJ2k7z+ELIRYP3Tp8vY7UyHycK8bnk2xoQxWA3E1+KJTvBSXzKg UTSjV1l953PPyCURoGcESE3ZJw== X-Received: by 2002:a1c:af47:: with SMTP id y68-v6mr412603wme.33.1541912429566; Sat, 10 Nov 2018 21:00:29 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id t187-v6sm4463802wmt.45.2018.11.10.21.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:00:28 -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, Mike Leach , Robert Walker , Al Grant , Coresight ML Cc: Leo Yan Subject: [PATCH v1 5/5] perf cs-etm: Track exception number Date: Sun, 11 Nov 2018 12:59:43 +0800 Message-Id: <1541912383-19915-6-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912383-19915-1-git-send-email-leo.yan@linaro.org> References: <1541912383-19915-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 When an exception packet comes, it contains the info for exception number; the exception number indicates the exception types, so from it we can know if the exception is taken for interrupt, system call or other traps, etc. But because the exception return packet cannot delivery exception number correctly by decoder thus when prepare sample flags we cannot know what's type for exception return. This patch adds a new 'exc_num' array in decoder structure to record exception number per CPU, the exception number is recorded in the array when the exception packet comes and this exception number can be used by exception return packet. If detect there have discontinuous trace with TRACE_ON or TRACE_OFF packet, the exception number is set to invalid value. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 67 ++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 8 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 b8cb7a3e..d1a6cbc 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -43,6 +43,7 @@ struct cs_etm_decoder { u32 packet_count; u32 head; u32 tail; + u32 *exc_num; struct cs_etm_packet packet_buffer[MAX_BUFFER]; }; @@ -368,24 +369,64 @@ static ocsd_datapath_resp_t cs_etm_decoder__buffer_trace_off(struct cs_etm_decoder *decoder, const uint8_t trace_chan_id) { - return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, - CS_ETM_TRACE_OFF); + int ret; + struct cs_etm_packet *packet; + + ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_TRACE_OFF); + if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) + return ret; + + packet = &decoder->packet_buffer[decoder->tail]; + + /* Clear execption number for discontinuous trace */ + decoder->exc_num[packet->cpu] = UINT32_MAX; + + return ret; } static ocsd_datapath_resp_t cs_etm_decoder__buffer_trace_on(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); + int ret; + struct cs_etm_packet *packet; + + ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_TRACE_ON); + if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) + return ret; + + packet = &decoder->packet_buffer[decoder->tail]; + + /* Clear execption number for discontinuous trace */ + decoder->exc_num[packet->cpu] = UINT32_MAX; + + return ret; } static ocsd_datapath_resp_t cs_etm_decoder__buffer_exception(struct cs_etm_decoder *decoder, + const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { - return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, - CS_ETM_EXCEPTION); + int ret; + struct cs_etm_packet *packet; + + ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_EXCEPTION); + if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) + return ret; + + packet = &decoder->packet_buffer[decoder->tail]; + + /* + * Exception number is recorded per CPU and later can be used + * for exception return instruction analysis. + */ + decoder->exc_num[packet->cpu] = elem->exception_number; + + return ret; } static ocsd_datapath_resp_t @@ -423,7 +464,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: - resp = cs_etm_decoder__buffer_exception(decoder, + resp = cs_etm_decoder__buffer_exception(decoder, elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: @@ -511,6 +552,10 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, if (!decoder) return NULL; + decoder->exc_num = zalloc(sizeof(*decoder->exc_num) * num_cpu); + if (!decoder->exc_num) + goto err_free_decoder; + decoder->data = d_params->data; decoder->prev_return = OCSD_RESP_CONT; cs_etm_decoder__clear_buffer(decoder); @@ -531,7 +576,7 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, decoder->dcd_tree = ocsd_create_dcd_tree(format, flags); if (decoder->dcd_tree == 0) - goto err_free_decoder; + goto err_free_decoder_exc_num; /* init library print logging support */ ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder); @@ -542,6 +587,9 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, cs_etm_decoder__init_raw_frame_logging(d_params, decoder); for (i = 0; i < num_cpu; i++) { + /* init expcetion number to an invalid value */ + decoder->exc_num[i] = UINT32_MAX; + ret = cs_etm_decoder__create_etm_decoder(d_params, &t_params[i], decoder); @@ -553,6 +601,8 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, err_free_decoder_tree: ocsd_destroy_dcd_tree(decoder->dcd_tree); +err_free_decoder_exc_num: + free(decoder->exc_num); err_free_decoder: free(decoder); return NULL; @@ -613,5 +663,6 @@ void cs_etm_decoder__free(struct cs_etm_decoder *decoder) ocsd_destroy_dcd_tree(decoder->dcd_tree); decoder->dcd_tree = NULL; + free(decoder->exc_num); free(decoder); }