Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3042035ybl; Mon, 19 Aug 2019 11:10:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHRXpXG2QCbM9PFk0mTdkKT16Jt8VQmZEXzcwg5ZHj4IQgj5DtUojy9aysgQJ2STKgLUYL X-Received: by 2002:a65:6815:: with SMTP id l21mr21524354pgt.146.1566238246648; Mon, 19 Aug 2019 11:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566238246; cv=none; d=google.com; s=arc-20160816; b=Lsu4tKgKseRvIJecQW/EhjrEmT33Dl7nvUqylin2Ut68xXtnYKL0UyUE4wIiQW0AFK diL+UsAPpVjXsfOp34lMa0fgLySLBGnYVBxfbuwsG9l5exhzkp2xutM7v26AtaqMmEsC 8KYWe0wE5cvRTn8WtGJU8LuX0hhs6AjPuwxcAnuxM01Oc1wb9cCBl/3o+Kic/Ky1oPEo 7Fx0wzE/SdKDyieFyKBLjrXCeFBwAzX0NF6YYHGbnXs2sIU+cM8tlk6/5SNwqACwKLOs SKFYc7Lx1VlbfE9CpL/4eDrZ6s/KE/+Gnzhw4jzA3bD34K6bD9DjTt0vGRdjhhcsC9i2 ZFEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=4jVeMKqF0pwcZE17bYM4UMPdWdsEiK+mCc9lzyMLHMc=; b=b3Wy9X9iSqJVn0BptgSUQTKVu6Rq3DjxXV22LzLSlHQ+2YIg0balYIwPLyJvsZQcfk E6AcNnyOJs91PKfZKhUrIHw8+J5lDXyU6bJRqF6oeag56rJoaFnyHjDdWN3Nw2u8Br2Q V5D79/lknVLnlhjfTCd1SzLlOlB9A/p/AN7chAZGCp8VaPY7PJkHkzFDGLBXFUstuHTe BrFYpD/UGfYl5isBuu/iGkVFMtudH0cuXyh3hnM7i17J9yvtJnlMhjZ0iE+A3Qd3W4vQ hYAdXDchBLxjsRhPQAQjYqAoFp0SeBvGSfHUmwT3Lm7FvTk0YJhcszI20iQbGijoScIK jagw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CI98HHXV; 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 6si10438837pgt.13.2019.08.19.11.10.31; Mon, 19 Aug 2019 11:10:46 -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=@linaro.org header.s=google header.b=CI98HHXV; 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 S1728099AbfHSSIi (ORCPT + 99 others); Mon, 19 Aug 2019 14:08:38 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:37857 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbfHSSIi (ORCPT ); Mon, 19 Aug 2019 14:08:38 -0400 Received: by mail-io1-f65.google.com with SMTP id q22so6325553iog.4 for ; Mon, 19 Aug 2019 11:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4jVeMKqF0pwcZE17bYM4UMPdWdsEiK+mCc9lzyMLHMc=; b=CI98HHXVmd99fvPNsV4vYEp6ZKxKOep5wn4vOHu+t9xkOh/RcMtEVKx6lyvMgprZ5K 1tgp7lyV+IFY0XMkrMfql1sNyPEBhxNko8dl4ppzriAMAG6iLAbq3wAFmUM1sIIfAOv2 0W4Htk7pJC62PHt6wopwjz5uWLK/h2Sgb6StBcn4S5k8WzXe04SVLSqaJUOKJC717Yk3 lmlpYPHnu4+BWKSS+75MAvuQrhhjbH9QbSkaF2BDqmeRA+ks04Gp8ihYjlJdiIX8EB28 txwv6cUGhTMoPvqyg5sBWqyyKAX2fLtMkTHtKaAWVbFVVX4FE89agNfPIIVvkbA/YMQ8 DIPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4jVeMKqF0pwcZE17bYM4UMPdWdsEiK+mCc9lzyMLHMc=; b=mhLIP6BUdKKLt/19FHSNDWa835w3HW7zJJmAG/8BHK9fA5TVF057/4UzBlYRvb0saQ N4+DwrXOr09IC8HNsXJMw5XXXP4NtXRdaWtZ0EmKd2OZclYw6dsyJPP65QTY1uYb4tqY rzhWtV9GAqnTXDbuusqKcl+oa+MIXy05pf+7mhDmCDtSstTbk32/0q9xrzaBL3Nko2yM L2SDV7GoN2jiDYgLhMBh/Pn2Xh1Q3DX8gOI2n5qpL+8CJDynLe1+Ymv1lshVog9++oti dekCXEMnc2gq+7L2kK06U6p62d7lR1i9g4Tsgw8ArPXzj3XTEyD92EWyvNYWxzDDCHPh SuPw== X-Gm-Message-State: APjAAAUWq+b/+wzI/R90UHwTx9/Wygt2PVLlbvEm+wFhZUiVerVdBm39 /KB01uv1qr3vQFT9l6jHm445F3XvMANVlfsa5375JA== X-Received: by 2002:a02:8663:: with SMTP id e90mr21939784jai.98.1566238117387; Mon, 19 Aug 2019 11:08:37 -0700 (PDT) MIME-Version: 1.0 References: <20190815082854.18191-1-leo.yan@linaro.org> In-Reply-To: <20190815082854.18191-1-leo.yan@linaro.org> From: Mathieu Poirier Date: Mon, 19 Aug 2019 12:08:26 -0600 Message-ID: Subject: Re: [PATCH 1/2] perf cs-etm: Support sample flags 'insn' and 'insnlen' To: Leo Yan Cc: Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Suzuki K Poulose , linux-arm-kernel , Linux Kernel Mailing List , Mike Leach , Robert Walker , Coresight ML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Aug 2019 at 02:30, Leo Yan wrote: > > The synthetic branch and instruction samples are missed to set > instruction related info, thus perf tool fails to display samples with > flags '-F,+insn,+insnlen'. > > CoreSight trace decoder has provided sufficient information to decide > the instruction size based on the isa type: A64/A32 instruction are > 32-bit size, but one exception is the T32 instruction size, which might > be 32-bit or 16-bit. > > This patch handles for these cases and it reads the instruction values > from DSO file; thus can support 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 > > [...] > > Cc: Mathieu Poirier > Cc: Suzuki Poulouse > Cc: Mike Leach > Cc: Robert Walker > Cc: coresight@lists.linaro.org > Cc: linux-arm-kernel@lists.infradead.org > Signed-off-by: Leo Yan > --- > tools/perf/util/cs-etm.c | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > 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); > + The code seems to be correct. I have also tested this patch. Reviewed-by: Mathieu Poirier > /* > * perf report cannot handle events without a branch stack > */ > -- > 2.17.1 >