From patchwork Tue Aug 20 19:27:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 171829 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4862264ily; Tue, 20 Aug 2019 12:28:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWaM9T8J7UCxh/Hp5gg/ZKu8lW+UXkE9a3yq2Gn/mP2lfIy7CW1LrQ7anzXqqvhQTqpmyi X-Received: by 2002:a17:902:447:: with SMTP id 65mr4129979ple.68.1566329323157; Tue, 20 Aug 2019 12:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566329323; cv=none; d=google.com; s=arc-20160816; b=0c0FguH6QaXguFkopS1BpRkFCG+o0DzwTTNeEUWfzAXzZszFgmiXuqibCzx10KYSqH 2BLscL5nfzVQujxXFMyWGgl2lUtHR391WObv/VLUciCJRolx3+O9SkKunXeiM2i9PF6G UbX9hKNSTOCnS16ue0QO1Ad5ORmhJQKsfkakjKPghJi0d+MitRFvmDkBsfeWEWZwteZi voU0yV26ne/G5/3Imr91SQg2sGccmmaV9yasvsnPkYvX18bt9SxSDJTSnjfFpuux8asN Rcbu7WmAsufyYTZ7prZmWNZDHLbIR4SKeNXByK/68wA5YOBuLxq3sbwLtwbaa2HtBHdk YzCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YsbKoz4Re/2xN2ve9Gc87qyhAkJmmHq93xR2VkwM/ek=; b=v8bzihfib5R7um1qqy9bt0S+62UfXa7PD9BQ/e/Js3SpfXk8juiP2/+G3hAsBHtW7l a1PALs7TmmRlddVwpW/v+tI+HDuCi3tOXfyN6UpFf4KKsMEn23N+t0yD+u4FkIpBSv/1 dNFkh3qenKMUFzcE+wlWiQcnlc466keLfihZemA2lAuMTCjM8hgX+sjHh4rYJif7AjGN gFb0D/eAZjIL7/frPsHOPWAxedtwV4EgKAlJ0VgCOF0Ky/TgBUutE1vX2KndJYu/umez uqgcKw6hA5mMZMVee/ZpbQHq9ltxYNpZKfRMaK7ERJertYudhcGW463p2FCDE+VJldz0 A6Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=glezjKsK; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si9648952pgh.359.2019.08.20.12.28.42; Tue, 20 Aug 2019 12:28:43 -0700 (PDT) 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=@kernel.org header.s=default header.b=glezjKsK; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730909AbfHTT2l (ORCPT + 28 others); Tue, 20 Aug 2019 15:28:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:41396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730466AbfHTT2k (ORCPT ); Tue, 20 Aug 2019 15:28:40 -0400 Received: from quaco.ghostprotocols.net (177.206.236.100.dynamic.adsl.gvt.net.br [177.206.236.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8C70D22DD6; Tue, 20 Aug 2019 19:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566329319; bh=nyQDcDGVNc52qwyCVzLDl29QlA+MDVXD/S7ZPOvV3AY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glezjKsKTTE8U3A0qUcMpTsgKWzjLZL70stlvw3BUEPBC5o+zym5w+Y6FSaGwaCcO rNNiGdk+VgKfsBjQMzOGeSFJbFqSpePlaattXdccUWwUJaDVMU7XlDlK9d70quAsvX +2UN+dHgnkk2vja2Scbl1QFibkr3HyWjod710Npg= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Mike Leach , Robert Walker , Suzuki Poulouse , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 11/17] perf cs-etm: Support sample flags 'insn' and 'insnlen' Date: Tue, 20 Aug 2019 16:27:27 -0300 Message-Id: <20190820192733.19180-12-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190820192733.19180-1-acme@kernel.org> References: <20190820192733.19180-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan The synthetic branch and instruction samples are missed to set instruction related info, thus the perf tool fails to display samples with flags '-F,+insn,+insnlen'. The CoreSight trace decoder provides sufficient information to decide the instruction size based on the ISA type: A64/A32 instructions are 32-bit size, but one exception is the T32 instruction size, which might be 32-bit or 16-bit. This patch handles these cases and it reads the instruction values from DSO file; thus can support the flags '-F,+insn,+insnlen'. Before: # perf script -F,insn,insnlen,ip,sym 0 [unknown] ilen: 0 ffff97174044 _start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 ffff97174938 _dl_start ilen: 0 [...] After: # perf script -F,insn,insnlen,ip,sym 0 [unknown] ilen: 0 ffff97174044 _start ilen: 4 insn: 2f 02 00 94 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 ffff97174938 _dl_start ilen: 4 insn: c1 ff ff 54 [...] Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier Tested-by: Mathieu Poirier Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mike Leach Cc: Namhyung Kim Cc: Robert Walker Cc: Suzuki Poulouse Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190815082854.18191-1-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) -- 2.21.0 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ed6f7fd5b90b..b3a5daaf1a8f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1076,6 +1076,35 @@ bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq) return !!etmq->etm->timeless_decoding; } +static void cs_etm__copy_insn(struct cs_etm_queue *etmq, + u64 trace_chan_id, + const struct cs_etm_packet *packet, + struct perf_sample *sample) +{ + /* + * It's pointless to read instructions for the CS_ETM_DISCONTINUITY + * packet, so directly bail out with 'insn_len' = 0. + */ + if (packet->sample_type == CS_ETM_DISCONTINUITY) { + sample->insn_len = 0; + return; + } + + /* + * T32 instruction size might be 32-bit or 16-bit, decide by calling + * cs_etm__t32_instr_size(). + */ + if (packet->isa == CS_ETM_ISA_T32) + sample->insn_len = cs_etm__t32_instr_size(etmq, trace_chan_id, + sample->ip); + /* Otherwise, A64 and A32 instruction size are always 32-bit. */ + else + sample->insn_len = 4; + + cs_etm__mem_access(etmq, trace_chan_id, sample->ip, + sample->insn_len, (void *)sample->insn); +} + static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 addr, u64 period) @@ -1097,9 +1126,10 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, sample.period = period; sample.cpu = tidq->packet->cpu; sample.flags = tidq->prev_packet->flags; - sample.insn_len = 1; sample.cpumode = event->sample.header.misc; + cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample); + if (etm->synth_opts.last_branch) { cs_etm__copy_last_branch_rb(etmq, tidq); sample.branch_stack = tidq->last_branch; @@ -1159,6 +1189,9 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, sample.flags = tidq->prev_packet->flags; sample.cpumode = event->sample.header.misc; + cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->prev_packet, + &sample); + /* * perf report cannot handle events without a branch stack */