From patchwork Tue Jan 29 12:28:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156978 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4602949jaa; Tue, 29 Jan 2019 04:30:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN5/Q1PxJRxGhr5R4/44RVwn4gY5P3lQXkJIgKAKg865M8HAK09x9G7q+QFvL0IjR2nzH/6O X-Received: by 2002:a63:c00b:: with SMTP id h11mr23962923pgg.429.1548765000099; Tue, 29 Jan 2019 04:30:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765000; cv=none; d=google.com; s=arc-20160816; b=r2v/8ettvYn/74BwNdoXIHrHoc67grmFaujumf3oKppH6Q9Ea2AR6/zPPVJStLhO76 X1fFOgI6IBtzUFqd31F9z2ApLPZi2FK4ruM/UIhVnF0+ZANNageJpjpM9MJaTAOkBWxI eHT8iSFC848qQ36SO4emBrDU3vp6nR/6BhItXv35H1jFA6qdvltBPxnbRLTkmxRqyGLO rR0cxRWsIbln/5jXZq8n/Uiwis0u0cnAXrN/lbKYTn7ODl7UhYcBD9kkVoUSAYv1mUj/ v2cgbLiHvN2TwIKDDY5Qr7oT5IYGkQH0F/adz6tViuAkm66XdaEgkCY0Glc3PrW8tb2c 9aIw== 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=NXHex4rJuLfH8D97yO/llnplWW205AjgnNzINVC+tuk=; b=dtCRXxZlYsonKFTDH6aiW9+723z6IVwPNNyFo6FIP8kfY2eB3/Jg0baHN+PVKnpceB O57sIzc5G1RAV1/wp6tLExtk1Xi/xTWT7VVjyuvbmwGvUFqnqvHZlkgQ3BRtgjCu8Q1F XOfjLo2OGfAckf+1JM189Kh6uKBxjltvO/gbgtLzYcMefXjs62Hz63twOSMVjYQKP6zt xaESFSSUZ2iTJoVggsD5SPdylJ5u64m6ASZ2wKmTwDl9QOlukHBLqEVNY+gEnA6Z+zIV 3caD4yk0VYaEAZoQd8b1gI8v5SMU+bzUzqtSM84TTb57lZ3iszqRXEw97xTP6I9LArje qBdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OH02SIr7; 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 u20si15751780plj.129.2019.01.29.04.29.59; Tue, 29 Jan 2019 04:30:00 -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=OH02SIr7; 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 S1728718AbfA2M36 (ORCPT + 31 others); Tue, 29 Jan 2019 07:29:58 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33225 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725772AbfA2M35 (ORCPT ); Tue, 29 Jan 2019 07:29:57 -0500 Received: by mail-pf1-f195.google.com with SMTP id c123so9616889pfb.0 for ; Tue, 29 Jan 2019 04:29:56 -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=NXHex4rJuLfH8D97yO/llnplWW205AjgnNzINVC+tuk=; b=OH02SIr7lmpyJI7fcUXTkEvvzDfuGoMSKU6VQrh1wxYWrFWJB4Rj2tgUhSKMe7opN7 eX83yqvjheA7WHR3o4byOioL4diELLsOonhSd3Ilr7zJ50EcRai32r8gG7OBSgOlyR4V rKkL8JN7N1ilx6Fm2310WNgur9EVTuS3+aizU= 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=NXHex4rJuLfH8D97yO/llnplWW205AjgnNzINVC+tuk=; b=hiP9nrgqVqezax/BCqlNvGjmuP1o81mAErDc98J76w5K9Fq5/Ej4xEnxvbFGXXc3+3 j5rWBvDXbTDkuTtfCfckuNxc87GyDj9ys8TtpoSz1pADa4Lb64Y/21l3zm9zAIKDf1Xx lrgTzLOCPdUC0bsJZySb+O7Sl3N6bxDiazO6ffX/1q2fQeRDFWNQhvASbWUXsqkpTYtr OjR9BTfMahTVAIPK/OJENuFu0e+MClZHyaDaOs04qMWCBnez6GcKvX3q7UMLPt2SG8Dz i52hNgFIwDC51lmU21P5bWRNhRThirOSi2TYDvx4L39Od6PIwsmx7Mdk2E8bajPnSnqH k9dQ== X-Gm-Message-State: AJcUukcUAWDvhLroCXuXcZyCMeU5hNhyW9BGxlZ9y5ihTYSBrm4maEF/ rMNfK4TizRH59HyQ5TP/TbJXhg== X-Received: by 2002:a63:2406:: with SMTP id k6mr22671931pgk.229.1548764995958; Tue, 29 Jan 2019 04:29:55 -0800 (PST) Received: from localhost.localdomain (li569-141.members.linode.com. [192.155.82.141]) by smtp.gmail.com with ESMTPSA id h64sm59552502pfc.142.2019.01.29.04.29.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:29:55 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mike Leach , Robert Walker , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan Subject: [PATCH v7 2/8] perf cs-etm: Set sample flags for instruction range packet Date: Tue, 29 Jan 2019 20:28:36 +0800 Message-Id: <20190129122842.32041-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190129122842.32041-1-leo.yan@linaro.org> References: <20190129122842.32041-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 2 + .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + tools/perf/util/cs-etm.c | 90 ++++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) -- 2.17.1 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: /*