Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp627259imj; Sat, 9 Feb 2019 04:53:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IYp7XGzzapQRdECg/m4gkncCGaBtBb+L0NnpEzF6G5uHkzDnsouI4bJq7D50rkMU9RgDiTa X-Received: by 2002:a62:36c1:: with SMTP id d184mr27632629pfa.242.1549716793937; Sat, 09 Feb 2019 04:53:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549716793; cv=none; d=google.com; s=arc-20160816; b=PmR0JXMem60rQworzDAfcpA9BfqjKc1B9cRiCP2C+fLdT6hVC+9YbxXhMIn7LkF0pW kKO2CpMTqRcJ5NA0ulU3JwLirqDfA2K7CJ6RINhDE57oSWzfdUOotq0Owy7KXWmkyiZC ZTdSrhGc68Vw5zAHNoYEzo686wyDs99RcNjs5ZGGRcd1cZ0AQRHRQ0k8KBSrbIqwl+o/ oLBgXUUTkE3QU8pT2kPP5Bt0Jt+oitzpoOtkCT4ToFT4rLGRWJUOA8Mv6Mf/pDt6D4xP 2NAXUrPJMRtNDdgygpsPmmodiTJ+HnEVR1Vgc/fScBS55J4arn7aN+1WX0nO7XqwY4d8 mJPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=/vP9Tqz98HpkXq4Rky9kKF4f41svijFACYabpkZrlLo=; b=XfWtW68jsl19YzoMEqI6zgrcEG4SMCLQJ0K6vyMKRYpPhQ1fpatY7R0AFqeoRQqBxx MK4l4MRJKQBCWZ2y/gH0s4yHpQDq0ahZs97rtaLu/xoiMx+lRBZpbSixOWFPS9u8Y/O1 YKh3NH/ZLmcT3LOq5+xMGgV9ar3UyohqIw/GbOvch03jnn98VxWZqmhPaBmOKn5shaEc DcbEYzITa4LhpdhDvSdXppZhHn4BGJhFxh2BtNpL8ut3ub9rRMYhFvibIH5VU/4/SJIr HWUslRsRViyH5w4L7OCkB+OBMDkuhZ9xyzjUbNb9+dhmVd76NWSdxckhMEqd3zzIEvE3 nxeg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v190si5280441pfv.8.2019.02.09.04.52.58; Sat, 09 Feb 2019 04:53:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726975AbfBIMw0 (ORCPT + 99 others); Sat, 9 Feb 2019 07:52:26 -0500 Received: from terminus.zytor.com ([198.137.202.136]:60859 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbfBIMw0 (ORCPT ); Sat, 9 Feb 2019 07:52:26 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x19CqEg22632914 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 9 Feb 2019 04:52:14 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x19CqDhD2632911; Sat, 9 Feb 2019 04:52:13 -0800 Date: Sat, 9 Feb 2019 04:52:13 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Leo Yan Message-ID: Cc: alexander.shishkin@linux.intel.com, suzuki.poulose@arm.com, robert.walker@arm.com, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, tglx@linutronix.de, hpa@zytor.com, leo.yan@linaro.org, mike.leach@linaro.org, coresight@lists.linaro.org, acme@redhat.com, namhyung@kernel.org, mingo@kernel.org, jolsa@redhat.com Reply-To: linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, robert.walker@arm.com, suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, leo.yan@linaro.org, hpa@zytor.com, tglx@linutronix.de, acme@redhat.com, namhyung@kernel.org, coresight@lists.linaro.org, mike.leach@linaro.org, jolsa@redhat.com, mingo@kernel.org In-Reply-To: <20190129122842.32041-3-leo.yan@linaro.org> References: <20190129122842.32041-3-leo.yan@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf cs-etm: Set sample flags for instruction range packet Git-Commit-ID: 06220bf472f2bd8f67bb776df73090945ee786ab X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 06220bf472f2bd8f67bb776df73090945ee786ab Gitweb: https://git.kernel.org/tip/06220bf472f2bd8f67bb776df73090945ee786ab Author: Leo Yan AuthorDate: Tue, 29 Jan 2019 20:28:36 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 6 Feb 2019 10:00:40 -0300 perf cs-etm: Set sample flags for instruction range packet The perf sample data contains flags to indicate the hardware trace data is belonging to which type branch instruction, thus this can be used to print out the human readable string. Arm CoreSight ETM sample data is missed to set flags and it is always set to zeros, this results in perf tool skips to print string for instruction types. This patch is to set branch instruction flags for instruction range packet. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mike Leach Cc: Namhyung Kim Cc: Robert Walker Cc: Suzuki K Poulouse Cc: coresight ml Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190129122842.32041-3-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 2 + tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + tools/perf/util/cs-etm.c | 90 ++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) 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 8a19310500d9..e98ee49a1527 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -293,6 +293,7 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) decoder->packet_buffer[i].last_instr_type = 0; decoder->packet_buffer[i].last_instr_subtype = 0; decoder->packet_buffer[i].last_instr_cond = 0; + decoder->packet_buffer[i].flags = 0; decoder->packet_buffer[i].cpu = INT_MIN; } } @@ -329,6 +330,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].last_instr_type = 0; decoder->packet_buffer[et].last_instr_subtype = 0; decoder->packet_buffer[et].last_instr_cond = 0; + decoder->packet_buffer[et].flags = 0; if (decoder->packet_count == MAX_BUFFER - 1) return OCSD_RESP_WAIT; 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 7cdd6a9c68a7..23600e57a215 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -45,6 +45,7 @@ struct cs_etm_packet { u32 instr_count; u32 last_instr_type; u32 last_instr_subtype; + u32 flags; u8 last_instr_cond; u8 last_instr_taken_branch; u8 last_instr_size; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 27a374ddf661..d05cac5295f1 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -12,6 +12,7 @@ #include #include +#include #include #include "auxtrace.h" @@ -719,7 +720,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, sample.stream_id = etmq->etm->instructions_id; sample.period = period; sample.cpu = etmq->packet->cpu; - sample.flags = 0; + sample.flags = etmq->prev_packet->flags; sample.insn_len = 1; sample.cpumode = event->sample.header.misc; @@ -778,7 +779,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq) sample.stream_id = etmq->etm->branches_id; sample.period = 1; sample.cpu = etmq->packet->cpu; - sample.flags = 0; + sample.flags = etmq->prev_packet->flags; sample.cpumode = event->sample.header.misc; /* @@ -1107,6 +1108,80 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq) return 0; } +static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) +{ + struct cs_etm_packet *packet = etmq->packet; + + switch (packet->sample_type) { + case CS_ETM_RANGE: + /* + * Immediate branch instruction without neither link nor + * return flag, it's normal branch instruction within + * the function. + */ + if (packet->last_instr_type == OCSD_INSTR_BR && + packet->last_instr_subtype == OCSD_S_INSTR_NONE) { + packet->flags = PERF_IP_FLAG_BRANCH; + + if (packet->last_instr_cond) + packet->flags |= PERF_IP_FLAG_CONDITIONAL; + } + + /* + * Immediate branch instruction with link (e.g. BL), this is + * branch instruction for function call. + */ + if (packet->last_instr_type == OCSD_INSTR_BR && + packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL; + + /* + * Indirect branch instruction with link (e.g. BLR), this is + * branch instruction for function call. + */ + if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && + packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL; + + /* + * Indirect branch instruction with subtype of + * OCSD_S_INSTR_V7_IMPLIED_RET, this is explicit hint for + * function return for A32/T32. + */ + if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && + packet->last_instr_subtype == OCSD_S_INSTR_V7_IMPLIED_RET) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + /* + * Indirect branch instruction without link (e.g. BR), usually + * this is used for function return, especially for functions + * within dynamic link lib. + */ + if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && + packet->last_instr_subtype == OCSD_S_INSTR_NONE) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + /* Return instruction for function return. */ + if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && + packet->last_instr_subtype == OCSD_S_INSTR_V8_RET) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + break; + case CS_ETM_DISCONTINUITY: + case CS_ETM_EXCEPTION: + case CS_ETM_EXCEPTION_RET: + case CS_ETM_EMPTY: + default: + break; + } + + return 0; +} + static int cs_etm__run_decoder(struct cs_etm_queue *etmq) { struct cs_etm_auxtrace *etm = etmq->etm; @@ -1158,6 +1233,17 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ break; + /* + * Since packet addresses are swapped in packet + * handling within below switch() statements, + * thus setting sample flags must be called + * prior to switch() statement to use address + * information before packets swapping. + */ + err = cs_etm__set_sample_flags(etmq); + if (err < 0) + break; + switch (etmq->packet->sample_type) { case CS_ETM_RANGE: /*