From patchwork Thu Aug 15 08:28:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 171399 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1892967ily; Thu, 15 Aug 2019 01:30:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3PRFiVJbCt/ASW1GkybBAEcvzRjGf6DZaQxHpMfDdHF5Ghdllfd6dhWlUsbYgF3bFEOMs X-Received: by 2002:a65:6114:: with SMTP id z20mr2657815pgu.141.1565857822734; Thu, 15 Aug 2019 01:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565857822; cv=none; d=google.com; s=arc-20160816; b=EfzS2X2e3w+KWm9maTjMwRhnMDZxu+HyFuA/ZNdZuo19h5ttluPNY8tL+FW28gzJ3n mI0YT63v0zicsoEMImFtaUfUSxUHaWcJ4oNHhZsDJUWfM3SeBvIuS2QtxGay1kYgpF+i YvDpZMQSMfHhI5uoAXZH69Rwt5seJVLwQdAyrPEF5ggquxC49y0aFGk8mq2XmNp4UKKZ mFHJTxkH/U8PElIzINnnyJiYegRch0tPo3IF24oRm2lLACU1fRMpi0zMkWQ1+j6GPHIK +xA46UdqUZKW1yM+uOIDAl1l9zrK1sH/MPQffLLDcGkLpkcHnubmp6wEIBOoCLiVtV1X y34w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=+667Tp6aRb+fNZrEkEuQBATyuYVr9DkCsoqrznJa5gI=; b=xXmBwgKDWRkMZG189FuGUf08uNPBEZkn8QFtVXIvSbe50AE4eHo+PeCwco9aseSR1i vX46EuacPMqRx49jZz8XzxtVr+t6/vBPRmReeeLDiQ8ZFIeA8ue8QnDutovYi/drFSUQ /nIR6HSZoV5dXt6iaEm6EaIv8ojU5iWLysifdhimOKjNCm2i3Awq3yi7Me13AoOYwP9Q hTAkC/DkN6qJnS4ewJmf73yKyVZ8sFWeyLXLD2XO6LFCUU8Qq1KvddfN2lA3wjgQjn+N OtsigChozCMwL54Eh5VEPbSnY3PFJXhXrD5VlekOm/EYM3rcX2o0iWAnh9439g4nRLnI iR2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E4+0ImEE; 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 h14si565966pje.101.2019.08.15.01.30.22; Thu, 15 Aug 2019 01:30:22 -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=E4+0ImEE; 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 S1730618AbfHOIaV (ORCPT + 28 others); Thu, 15 Aug 2019 04:30:21 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37347 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730534AbfHOIaV (ORCPT ); Thu, 15 Aug 2019 04:30:21 -0400 Received: by mail-pg1-f194.google.com with SMTP id d1so424398pgp.4 for ; Thu, 15 Aug 2019 01:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=+667Tp6aRb+fNZrEkEuQBATyuYVr9DkCsoqrznJa5gI=; b=E4+0ImEEmPUTDK4fbSUSMUuBr6/4JC/FSu2THIDBKuiY0uw4dfY0PcLLac2NKV4fdL Lu1s/lkKD6MbnYfJbTSSjBaxItiA+hRYtey95pRKPsZFxiDVxCF+8bajbx72J0ES0vBX pw2uYBoIHgnFvVUqdEeY+QSlr0JVcAWvI0ZUCVn5QLLkqpMUIu0b0qmLyTkVxEgnKLNs 5n1am8WziPrOPbM3o96E1pU2e62cCZawGs89rgQNOoSHQi3RHy5j6Nn1ZLXeSZQGMgw9 n7VCHaPMlt545E535ERJLwEchIyLatWHMEwcKBg9P6MYEwMGt073PlwjDm5xDeuIKQCz 4DNQ== 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; bh=+667Tp6aRb+fNZrEkEuQBATyuYVr9DkCsoqrznJa5gI=; b=OtDqfKK+XLE4q52PFH6YjhvVKT1C6GacM4uXI1zrWkHJowV+JMvuYYYfwBj4huXX2G T7nq4gnAIQjdaREMg/gxKHxh3ZEnScSTrEnB1jlDS03YZYKKFeSgqs7T8eNPtcKioc7M vAy3d9nDa8FTQwdRxuf8B1h9OoR9f+yRNrcBQKZGWRENnRgGex0RUp1EsJyyTmDD3Crq LHRBFAEEf2zUohwTSjWOze8TSr5G7HTZS0armnkDAxYsROFhEOcOdTvU4FfV4MdZijq5 JrfctRKHgvoGAzPWMQIWnbX68Qdj90JtFgPN9obtYelckiHCstjzY7L+GsEnFDYKsN66 6jGg== X-Gm-Message-State: APjAAAWWSUi+LBAv+Uroj9Wf2gji1bBLxmtNrBU3MJ82oFIN6++qdYMe zIMy8j+p18dVcYTxcb8br4br7A== X-Received: by 2002:a65:690f:: with SMTP id s15mr2562324pgq.432.1565857819808; Thu, 15 Aug 2019 01:30:19 -0700 (PDT) Received: from localhost.localdomain (li456-16.members.linode.com. [50.116.10.16]) by smtp.gmail.com with ESMTPSA id 1sm2217413pfx.56.2019.08.15.01.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 01:30:19 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan , Mike Leach , Robert Walker , coresight@lists.linaro.org Subject: [PATCH 1/2] perf cs-etm: Support sample flags 'insn' and 'insnlen' Date: Thu, 15 Aug 2019 16:28:54 +0800 Message-Id: <20190815082854.18191-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.17.1 Reviewed-by: Mathieu Poirier 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 */