From patchwork Tue Jan 29 12:28:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156977 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4602894jaa; Tue, 29 Jan 2019 04:29:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN7LZJPIAN6VrPP+/DA8jGhJegNMq30tmdwESvXiv+KriDKSpgE+7MdtDqGvr0NPHWY5I4K3 X-Received: by 2002:a63:5664:: with SMTP id g36mr23224827pgm.313.1548764996199; Tue, 29 Jan 2019 04:29:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548764996; cv=none; d=google.com; s=arc-20160816; b=XIahDMfZtg0jwDNpZvlXU21CHIV211ThlDlrspfM7pE8VgjK1RNSn6pEj329HWgJNE jYayCgK8Vr+BxAm0SKBIdzSE0yJUlLbcm1OT8XDTaQe5RQ47eEeRghxCvOq05Tkd21js dEC0QHn3+fTZYlCMzB2yppbZ6rwrh1lCSjblaLMVDVc3mqVKMdZu3Zw0j0e1mlqXZ4e/ 0sRdMutcfU1SRz626k5qrxdAxuxHiDLPncBCD+JKhaYY2S3aNscliViChYSZ0MgM2jcd 3KQvict+Awwt/gCE97sBVg5AUGlhjqWbLHYHZX8ZZmEnOdLe3uWYpWytALN63p563Acp aPOw== 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=euu22pFQ6c9B3mZ1+UtLKySuzqAo82xzEXBgVuSFGfs=; b=zINsaGEnCtcVJfeZBLmBHlCH5hOqHyGXOCTPhAaVfI+GSwZdYHEeY9lpm3yfg1DrbQ Q2yLV8+RttrRDylPckX6koieKtlnOmV9gFkVmFy6wz64/x24efa8ZL3gxksGUuu2aXd0 idD5mVcPHmYCDVuSzBwF1iXMQ20dIQQimtSX32kOlEqzPbT25ylAko0prJMIj1IkFqQv rLNAv25UyLIQq2oYeVrGoB02zHuSGBobQwkCrCpDktLuj+DkrWrA/tm280HNAJBiquqw 2QKXJ0D6RABpblrEGCYMWhpDgxTg7ki6b2PfMJIhIOpWtZbEh4iu2dZZ6XwCoZy545Ks EZ1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="AMhZ5/O1"; 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 n19si2116655pgd.271.2019.01.29.04.29.55; Tue, 29 Jan 2019 04:29:56 -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="AMhZ5/O1"; 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 S1728659AbfA2M3y (ORCPT + 31 others); Tue, 29 Jan 2019 07:29:54 -0500 Received: from mail-pf1-f182.google.com ([209.85.210.182]:36681 "EHLO mail-pf1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725772AbfA2M3w (ORCPT ); Tue, 29 Jan 2019 07:29:52 -0500 Received: by mail-pf1-f182.google.com with SMTP id b85so9599799pfc.3 for ; Tue, 29 Jan 2019 04:29:52 -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=euu22pFQ6c9B3mZ1+UtLKySuzqAo82xzEXBgVuSFGfs=; b=AMhZ5/O1hNqtAFBJUQruSRENmMh8lJg50fOVNoKhhzNkp8NA9s7yvPtNzKen+3YJG6 NUy8pnxLr5ZTx4OoqZTa1yDkaZnGz1VdeXBE77mXtYqat31xRQfRjh0touot1/iulW2j idEpIUGkLisvveyAZUiytbe6EauWO4R1IOHBI= 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=euu22pFQ6c9B3mZ1+UtLKySuzqAo82xzEXBgVuSFGfs=; b=pK1SGfOD7ScyP2V5xOvSL0U2GL/EXP3CrF64dnAjQaFgrj/ZgEdceorXHuyQNuDP3F BCr6U8qzsNbaw4rxfXW1WSKbJYg05fpZL7HqIC1v5hfItUzQKmpu6rBveW2SgsjK4rv+ x3lRTQOHqKXAU+RYkq+hKC/Mxbl1wICRjxQvTEuulyNMnEUzzqhPpJ2vVvWLX18O3P49 8RVeLFr/Ig8PcvzDnzS7h3Rmdu+LmQQdRk0GN6m6TbQZaj+xGk1Li4KBfF/RUJuhBPFq 3B0JBKRXi+ICBD+4duOpP3pUvcLN5xN4c6gTX2n/dJk9WW6eZmdbVq3HlF3DvZo2S254 l0SQ== X-Gm-Message-State: AJcUukePBH37vXqMf4PkN9Ma6+6/rL0u6L/fJ6tpD8XomTysCQSrFLSe KBKXHuzSSPRCZnZyRMSRpvNVdw== X-Received: by 2002:a63:d747:: with SMTP id w7mr22989225pgi.360.1548764991762; Tue, 29 Jan 2019 04:29:51 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:29:51 -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 1/8] perf cs-etm: Add last instruction information in packet Date: Tue, 29 Jan 2019 20:28:35 +0800 Message-Id: <20190129122842.32041-2-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 Decoder provides last instruction related information, these information can be used for trace analysis; specifically we can get to know what kind of branch instruction has been executed, mainly the information are contained in three element fields: last_i_type: this is significant type for waypoint calculation, it indicates the last instruction is one of immediate branch instruction, indirect branch instruction, instruction barrier (ISB), or data barrier (DSB/DMB). last_i_subtype: this is used for instruction sub type, it can be branch with link, ARMv8 return instruction, ARMv8 eret instruction (return from exception), or ARMv7 instruction which could imply return (e.g. MOV PC, LR; POP { ,PC}). last_instr_cond: it indicates if the last instruction was conditional. But these three fields are not saved into cs_etm_packet struct, thus cs-etm layer don't know related information and cannot generate sample flags for branch instructions. This patch add corresponding three new fields in cs_etm_packet struct and save related value into the packet structure, it is preparation for supporting sample flags. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 9 +++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +++ 2 files changed, 12 insertions(+) -- 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 8c155575c6c5..8a19310500d9 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -290,6 +290,9 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) decoder->packet_buffer[i].instr_count = 0; decoder->packet_buffer[i].last_instr_taken_branch = false; decoder->packet_buffer[i].last_instr_size = 0; + 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].cpu = INT_MIN; } } @@ -323,6 +326,9 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].instr_count = 0; decoder->packet_buffer[et].last_instr_taken_branch = false; decoder->packet_buffer[et].last_instr_size = 0; + decoder->packet_buffer[et].last_instr_type = 0; + decoder->packet_buffer[et].last_instr_subtype = 0; + decoder->packet_buffer[et].last_instr_cond = 0; if (decoder->packet_count == MAX_BUFFER - 1) return OCSD_RESP_WAIT; @@ -366,6 +372,9 @@ cs_etm_decoder__buffer_range(struct cs_etm_decoder *decoder, packet->start_addr = elem->st_addr; packet->end_addr = elem->en_addr; packet->instr_count = elem->num_instr_range; + packet->last_instr_type = elem->last_i_type; + packet->last_instr_subtype = elem->last_i_subtype; + packet->last_instr_cond = elem->last_instr_cond; switch (elem->last_i_type) { case OCSD_INSTR_BR: 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 a6407d41598f..7cdd6a9c68a7 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -43,6 +43,9 @@ struct cs_etm_packet { u64 start_addr; u64 end_addr; u32 instr_count; + u32 last_instr_type; + u32 last_instr_subtype; + u8 last_instr_cond; u8 last_instr_taken_branch; u8 last_instr_size; int cpu; 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: /* From patchwork Tue Jan 29 12:28:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156979 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4603012jaa; Tue, 29 Jan 2019 04:30:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN6hHbUAl6Bsd/xePJiKWbYWJGeYUEVl3QRxVaX9t92boTZ5cTNDHUk7G21GZr3xurOG2GLQ X-Received: by 2002:a17:902:14e:: with SMTP id 72mr25968675plb.287.1548765003832; Tue, 29 Jan 2019 04:30:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765003; cv=none; d=google.com; s=arc-20160816; b=xPvCHBqeEm3UAPYsk/BpGkdlcd8IuytuTCOgAX66sbhP4qnwTIUHfhX8btj8E2j92H /6R3RcImUhaKurpwInvdzeJM6g0c0Q73bmK2fnnb50XB9HJd+aFGwmZpwukdqIEwUaCy vSzVoPA8b2Z8d9k86ryk9dykX8UUVESay5XSCceLBUzJfNAbZRO6iUpOY8Eekh4kTFub kjUSUVVKa6IDwOp1SKlnhLhJZ7GitglnHGRZ7O18MgvK0yyBxvSZ5nQ01HOwOOvhRuHL vmRDFfGs/eqpshilBh0CZ0m1IyYacHC3ic8RkqyJv0lARRAu15kjxwj0J/pG/u+0a7T3 d0Ng== 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=wCTfSFlK4C7FXgdKOX/CUsRQoqsszJ7JLDVdsKNX608=; b=g+8h0BYg94tOiL/8gvzrlF+HYZqbPf3weyCIvdYbH8Qs4fkTbzDeYt+MuPdDu793aQ LP9P1kSEj9JOgbL9CDFp0vv/LMnopKyXc3GzpI6AL1raKcFXn4jrahRwfl03hRmmmGg5 AlQiIFbfaMr+3x9TysN+xDj8v9YRiLERZ1yF2lUG57HTlXBrGuMCkiJdhy76UyLDYEBB ZcuMTNIB7vBGD/SyeS69skiG13V99Qn9gOF99pkXa6lGHVgTD7g2NW+hQxAh6fPmltl8 cLGXT2wybcigI1SsrIAOebphuCCFQwvcMGjdMVMBJPSdAEdgSwvhrHhT36KSEWat6by/ Oafw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="h62oC/St"; 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 v7si35552921plo.12.2019.01.29.04.30.03; Tue, 29 Jan 2019 04:30:03 -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="h62oC/St"; 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 S1728758AbfA2MaC (ORCPT + 31 others); Tue, 29 Jan 2019 07:30:02 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36788 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725772AbfA2MaA (ORCPT ); Tue, 29 Jan 2019 07:30:00 -0500 Received: by mail-pf1-f196.google.com with SMTP id b85so9599964pfc.3 for ; Tue, 29 Jan 2019 04:30:00 -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=wCTfSFlK4C7FXgdKOX/CUsRQoqsszJ7JLDVdsKNX608=; b=h62oC/St4ysiVkeDn5+gNpBIxbddW/cR8Q7J5/A4VfBEdO0y1pPxXkDwcdTwEhsCOm HNrpKoUj0H8ltawqSDNgqMqrVX/gJchBmGIGkmYSr/HNTHnt1Aca8ZxacPUkQyhGRnEA kJnGIKcu8w8fqD5SjPk8Ip/Q2CnCFfeYeflJQ= 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=wCTfSFlK4C7FXgdKOX/CUsRQoqsszJ7JLDVdsKNX608=; b=kvOItoLewgm/Nz/4XX3abZ86ZLpqiLcUtX7whsTqwCIfkvA3C57OS8xCaELlEVnGaj ++BJmontwUixX2+rE9M5ddAn7yLDkFGnBGD6z4Rxo3RHroL+WccrBttHqCRd/T9Z1Nu2 ExTd7SzHEzic+aIlrCuPcWMCtY7nbxlEVeLbAgxSxE91pXYUachEtHRelljRJnu1JjV7 EMcr0R5X0sqQEqqKH79nWSVWlFSzgTEbN8ssPOyVrCMHm7VD4Q+Uj3wqFVOXQzRM1xoJ 7/thadnbqMqRW86sgeVk+kP2Dn6KPrvKpY1iK7J0FAY8h+sVLDXgL5PFNWz130DZ91IN G7Vg== X-Gm-Message-State: AJcUukd7APK2Qg1k/M/nFRnLlEj1o+UyhVrw+9rdWVQqmtC2fxAINPgx dthjxWTn/ICS+sejRpKiIgQBlIvRz6Y= X-Received: by 2002:a63:2586:: with SMTP id l128mr23899786pgl.104.1548764999906; Tue, 29 Jan 2019 04:29:59 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:29:59 -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 3/8] perf cs-etm: Set sample flags for trace discontinuity Date: Tue, 29 Jan 2019 20:28:37 +0800 Message-Id: <20190129122842.32041-4-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 In the middle of trace stream, it might be interrupted thus the trace data is not continuous, the trace stream firstly is ended for previous trace block and restarted for next block. To display related information for showing trace is restarted, this patch set sample flags for trace discontinuity: - If one discontinuity packet is coming, append flag PERF_IP_FLAG_TRACE_END to the previous packet to indicate the trace has been ended; - If one instruction packet is following discontinuity packet, this instruction packet is the first one packet to restarting trace. So set flag PERF_IP_FLAG_TRACE_START to discontinuity packet, this flag will be used to generate sample when connect with the sequential instruction packet. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index d05cac5295f1..1aa29633ce77 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1111,6 +1111,7 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq) static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) { struct cs_etm_packet *packet = etmq->packet; + struct cs_etm_packet *prev_packet = etmq->prev_packet; switch (packet->sample_type) { case CS_ETM_RANGE: @@ -1170,8 +1171,26 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) packet->last_instr_subtype == OCSD_S_INSTR_V8_RET) packet->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN; + + /* + * Decoder might insert a discontinuity in the middle of + * instruction packets, fixup prev_packet with flag + * PERF_IP_FLAG_TRACE_BEGIN to indicate restarting trace. + */ + if (prev_packet->sample_type == CS_ETM_DISCONTINUITY) + prev_packet->flags |= PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_BEGIN; break; case CS_ETM_DISCONTINUITY: + /* + * The trace is discontinuous, if the previous packet is + * instruction packet, set flag PERF_IP_FLAG_TRACE_END + * for previous packet. + */ + if (prev_packet->sample_type == CS_ETM_RANGE) + prev_packet->flags |= PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_END; + break; case CS_ETM_EXCEPTION: case CS_ETM_EXCEPTION_RET: case CS_ETM_EMPTY: From patchwork Tue Jan 29 12:28:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156980 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4603101jaa; Tue, 29 Jan 2019 04:30:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN6Lzt9YdqpPbmaqvuJG6zm0pMXztUnSu4N2R3YsXzYFhM0IL+uozI6lNwDNU+Xvx7AZrdHh X-Received: by 2002:a17:902:5601:: with SMTP id h1mr26416802pli.160.1548765010364; Tue, 29 Jan 2019 04:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765010; cv=none; d=google.com; s=arc-20160816; b=qqZ6kYGGIFY+xIQCM6jCS7zqgHXp6zaHQgAhqRv9ded5vWmoRhNs9TCrMGrbNvS3pI oS1qfPhwUBw+9bsNujwIetaNDJeQPrqYZNE4P9NC1LT4YnIbkbYhjDwSdubx2d1QRp5A SaXIJtx8S8fYkiWCmdk2/HffvS3jBoUkUq1SwzQWrtfT/Clue2Gmi+g0/UYr03/QMGuy kcvHwOnIJagg8pu7wUSXcZP5bVdl74VWBbqUXqXBYpnJgQFexFibGAbF7uAOA0zzZCLp bAYGg42M9Og0OvDTStRPM7YGclcxet6BcIngPhQrBufZ3UnmpgjNMqvC8m8b/4EL4qlF FaPQ== 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=3vgO5gz1slI+w2/pIHGVojFnCNFu6a/dztrTgaESmOQ=; b=A5trxv9BpcX8OH88CcOO9Wfx/62M5PU4gQWaeEZn0dugHN/0tYD7AV76ja7ricHvJ7 oQgEJcEoMGM5WmGwwg0FiALqdWMdEcw2PK+qrB+378pxK8C2shFRviOGIMPSVxF5puqp 7CYv3m7XzupjJDZiXcLU+2s17FyruZA/CSaJpaxfcRgVifbRH0S5VMDhiqFdv7rhvtcd rxetqxlCE6o0d9uV1WHG9FTQOP3Yj3R6Eh9f7QJIWsuf+h9sHxin40I6ugph8sPm0ywf WUe4fPPhB97rwJB6BIJvidGlekfetCOGtlC3zqgmD0969vfyDHAuEvWw5XUpLEGuHlEd D6xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZHBeadn6; 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 o195si1796038pfg.106.2019.01.29.04.30.10; Tue, 29 Jan 2019 04:30:10 -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=ZHBeadn6; 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 S1728849AbfA2MaI (ORCPT + 31 others); Tue, 29 Jan 2019 07:30:08 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37036 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728764AbfA2MaG (ORCPT ); Tue, 29 Jan 2019 07:30:06 -0500 Received: by mail-pf1-f194.google.com with SMTP id y126so9594403pfb.4 for ; Tue, 29 Jan 2019 04:30:05 -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=3vgO5gz1slI+w2/pIHGVojFnCNFu6a/dztrTgaESmOQ=; b=ZHBeadn6EB+AZwhwS4obP3N25LhIylyiAzNql7x5WU5QCtUeXFlJHaO+CkZeifZK92 B4jGrbFNVlvSC5Xh+3qBhDrUXe2KkutpVnU5u+aLkTwPvAZyhzXbRYLeFd4Hng7D+Dn1 N0S4vtT1Ls7F8E7eeXL86z9hplzgteqRG/jU4= 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=3vgO5gz1slI+w2/pIHGVojFnCNFu6a/dztrTgaESmOQ=; b=KI4vJoEF/XiQOE1K7RM1qnF5XftdakS83evsle7vcW3ei0rlT+M/OQ/JjhraQQvXnh QZ7otqK/iNUkplCNvKUt5WFV/KDgdqkIAHW5XZ/TAXXKOInsJuOD+UvaBMw/60Ss1S9Q 0GJcpXcCj0X9fm3/De8pM8aSktzPI0PUneSdGBbl4zsU0bXlFuI9gU/9jpHyvpRjXGmg aIZqevp1+IBbsc/mHfR4+XyhfnCMhzmrWgM9K8wyjRc3vt8lo6f/pSElC+oF+wZTnt8l 2Xu+5P9tNr6olsG/OHw4cSWAevhNbqFg6hHR14vwSKKqBjc/q1PSjP8Mqf338SFFX1W5 QbDQ== X-Gm-Message-State: AJcUukc9tfmYEqibBVgNsi1BXYdLNb8MB9V9PTA6OP4+HS4fqxNeKYCz sxq0dsPrx1bELi5cocMkVYxdjQ== X-Received: by 2002:a63:ec4b:: with SMTP id r11mr22995464pgj.44.1548765005530; Tue, 29 Jan 2019 04:30:05 -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.30.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:30:04 -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 4/8] perf cs-etm: Add exception number in exception packet Date: Tue, 29 Jan 2019 20:28:38 +0800 Message-Id: <20190129122842.32041-5-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 When an exception packet comes, it contains the information for exception number; the exception number indicates the exception types, so from it we can know if the exception is taken for interrupt, system call or other traps, etc. This patch simply adds a field in cs_etm_packet struct, it records exception number for exception packet that will then be used to properly identify exception types to the perf synthesize mechanic. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 20 +++++++++++++++---- .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + 2 files changed, 17 insertions(+), 4 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 e98ee49a1527..294efa76c9e3 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -294,6 +294,7 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) 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].exception_number = UINT32_MAX; decoder->packet_buffer[i].cpu = INT_MIN; } } @@ -331,6 +332,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].last_instr_subtype = 0; decoder->packet_buffer[et].last_instr_cond = 0; decoder->packet_buffer[et].flags = 0; + decoder->packet_buffer[et].exception_number = UINT32_MAX; if (decoder->packet_count == MAX_BUFFER - 1) return OCSD_RESP_WAIT; @@ -406,10 +408,20 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_decoder *decoder, static ocsd_datapath_resp_t cs_etm_decoder__buffer_exception(struct cs_etm_decoder *decoder, + const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) -{ - return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, - CS_ETM_EXCEPTION); +{ int ret = 0; + struct cs_etm_packet *packet; + + ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_EXCEPTION); + if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) + return ret; + + packet = &decoder->packet_buffer[decoder->tail]; + packet->exception_number = elem->exception_number; + + return ret; } static ocsd_datapath_resp_t @@ -443,7 +455,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: - resp = cs_etm_decoder__buffer_exception(decoder, + resp = cs_etm_decoder__buffer_exception(decoder, elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: 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 23600e57a215..012b4728a46f 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -46,6 +46,7 @@ struct cs_etm_packet { u32 last_instr_type; u32 last_instr_subtype; u32 flags; + u32 exception_number; u8 last_instr_cond; u8 last_instr_taken_branch; u8 last_instr_size; From patchwork Tue Jan 29 12:28:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156981 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4603249jaa; Tue, 29 Jan 2019 04:30:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ZY2ZrlFFoVXoeUyAKJPpBCNjXTQizxQxPXfeb209wMW1RjVpY9eVaIf51Y7aPxrrGXeJ2 X-Received: by 2002:a17:902:8541:: with SMTP id d1mr26149307plo.205.1548765018210; Tue, 29 Jan 2019 04:30:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765018; cv=none; d=google.com; s=arc-20160816; b=fwuf19FwMYzvtqIbb5JQOWfuTPPo8gPb1x4m27PNRjk/r5r0pzrm2nlfUtaMI/YaBk w/YMn8VwLJZaXHZ/lwwOJWM6ipGNiJv9C2JDzrXiLY18QBYyQBpR8L9iT2x+a/fHo3BB VV7BL05HuSfqU2NPdRfn17jdjGWOrqM+MuT6hiOXkTsfIFF4XXzEHTb57hdf3aSJHjEU a2tI5R465TRb0HPeC+DY0OHPDyl3pacu1StNG72xrQhBxisrOgYszleBxtuB1xSYWw3p 44HFpUGv+b5pY511FF18uemMu16+u+3ZaFiVTrJNJx2+nITT47N7RUnD9ilHAJxhgYtu sG5g== 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=NI1nWA7/IJcIbEMIXPw1bIIK+zBG3TZvrY5SOoR7CDk=; b=vuHU6Z/Od6fAyiP6CKnwEHtb8g1prAr/qnteo5ih5WgWMW+UmllPCASjj1CPWcGAlv 492Nt2OohdnNzTLDL3dhGJTs082+KUF8DEUGDFj5aD5rcAJrFGhvw32jfmPLXX7UZEVO EnZAUfx4958+9KO+ROXNtc8Ellg0WQpFmS/6T2r21bbT+vwl3Tw2PZlhdjvcGtDHuWwz bWmJ7Y1OECxO4fNuuWtqIrkhIAXxX+gZT9Pq3qnBQUl2hdfk/uHFFK9JLGtVhsKqqbNF R3h3c9jBZbeBRSkeQHoUMI0ujfCZj9dvpqpLACfLhMPktNwex3BqR/q51HmG+oVOxmSl Z21A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TE6BoR6h; 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 3si36008540plv.258.2019.01.29.04.30.17; Tue, 29 Jan 2019 04:30:18 -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=TE6BoR6h; 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 S1728968AbfA2MaQ (ORCPT + 31 others); Tue, 29 Jan 2019 07:30:16 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37492 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728892AbfA2MaM (ORCPT ); Tue, 29 Jan 2019 07:30:12 -0500 Received: by mail-pg1-f196.google.com with SMTP id c25so8682367pgb.4 for ; Tue, 29 Jan 2019 04:30:11 -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=NI1nWA7/IJcIbEMIXPw1bIIK+zBG3TZvrY5SOoR7CDk=; b=TE6BoR6hFdggH7YHDuwb8cRe27bwwsk/5RaPSpXmwz5OOYgzUHVwRalJl8jXhuvg/3 xLmJkGYEt1U+O8yQLxsAqMwgpxiUF1qxIFZzJhsydGI1/dK7SKd8g00ouzDuos8B0SDi uJF7+GRYQAreRW5KAcwoNSp50isZMNnmBkrVs= 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=NI1nWA7/IJcIbEMIXPw1bIIK+zBG3TZvrY5SOoR7CDk=; b=Kd+4ppoSGB6ZapFAg2m23mxXypXIYuGECyXB/YVcam2rK+LBmRrtzKM7Tg45mJO7uV x/rjQmMi9g6jK9umDiXcMz7Pb6sSstq4z5XGCU1XsMp8MkIn54nb0AEUFhvUQvp/Y4/r Y+IMx5Hf8b9pZJldW7iU/NuISCPnMarKmgjNYYpA3UdXAixI5vnLCQDHF5m3l1ExC7IV qiJjx/X6dAwsLB/AhDPhId2ljOn01ZHPZ81NTiQwwWFtNbqopbVFHV8Dcg/gkQmqp46J xpBzaW9JTsIpSjnnTAC72j3lJ/JWvhD12ySBfHsM6Kxq8ZxYDL519eDRyPTyxyS90J1p ZV8w== X-Gm-Message-State: AJcUukcr+wgr5GeAYlcj/zstl/qCEK6mU0s8ojM0DwjIMczfeXfxfCcZ hTSr0L1oYXxGmfe5/Kst7Em89A== X-Received: by 2002:a62:5c41:: with SMTP id q62mr26456042pfb.171.1548765010935; Tue, 29 Jan 2019 04:30:10 -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.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:30:10 -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 5/8] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Date: Tue, 29 Jan 2019 20:28:39 +0800 Message-Id: <20190129122842.32041-6-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 If packet processing wants to know the packet is bound with which ETM version, it needs to access metadata to decide that based on metadata magic number; but we cannot simply to use CPU logic ID number as index to access metadata sequential array, especially when system have hotplugged off CPUs, the metadata array are only allocated for online CPUs but not offline CPUs, so the CPU logic number doesn't match with its index in the array. This patch is to change tuple from traceID-CPU# to traceID-metadata, thus it can use the tuple to retrieve metadata pointer according to traceID. For safe accessing metadata fields, this patch provides helper function cs_etm__get_cpu() which is used to return CPU number according to traceID; cs_etm_decoder__buffer_packet() is the first consumer for this helper function. Signed-off-by: Leo Yan --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 8 +++--- tools/perf/util/cs-etm.c | 26 ++++++++++++++----- tools/perf/util/cs-etm.h | 9 ++++++- 3 files changed, 31 insertions(+), 12 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 294efa76c9e3..cdd38ffd10d2 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -305,14 +305,12 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, enum cs_etm_sample_type sample_type) { u32 et = 0; - struct int_node *inode = NULL; + int cpu; if (decoder->packet_count >= MAX_BUFFER - 1) return OCSD_RESP_FATAL_SYS_ERR; - /* Search the RB tree for the cpu associated with this traceID */ - inode = intlist__find(traceid_list, trace_chan_id); - if (!inode) + if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0) return OCSD_RESP_FATAL_SYS_ERR; et = decoder->tail; @@ -322,7 +320,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].sample_type = sample_type; decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN; - decoder->packet_buffer[et].cpu = *((int *)inode->priv); + decoder->packet_buffer[et].cpu = cpu; decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].instr_count = 0; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 1aa29633ce77..a5497a761db7 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -97,6 +97,20 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr) return CS_ETM_PROTO_ETMV3; } +int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) +{ + struct int_node *inode; + u64 *metadata; + + inode = intlist__find(traceid_list, trace_chan_id); + if (!inode) + return -EINVAL; + + metadata = inode->priv; + *cpu = (int)metadata[CS_ETM_CPU]; + return 0; +} + static void cs_etm__packet_dump(const char *pkt_string) { const char *color = PERF_COLOR_BLUE; @@ -252,7 +266,7 @@ static void cs_etm__free(struct perf_session *session) cs_etm__free_events(session); session->auxtrace = NULL; - /* First remove all traceID/CPU# nodes for the RB tree */ + /* First remove all traceID/metadata nodes for the RB tree */ intlist__for_each_entry_safe(inode, tmp, traceid_list) intlist__remove(traceid_list, inode); /* Then the RB tree itself */ @@ -1519,9 +1533,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, 0xffffffff); /* - * Create an RB tree for traceID-CPU# tuple. Since the conversion has - * to be made for each packet that gets decoded, optimizing access in - * anything other than a sequential array is worth doing. + * Create an RB tree for traceID-metadata tuple. Since the conversion + * has to be made for each packet that gets decoded, optimizing access + * in anything other than a sequential array is worth doing. */ traceid_list = intlist__new(NULL); if (!traceid_list) { @@ -1587,8 +1601,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = -EINVAL; goto err_free_metadata; } - /* All good, associate the traceID with the CPU# */ - inode->priv = &metadata[j][CS_ETM_CPU]; + /* All good, associate the traceID with the metadata pointer */ + inode->priv = metadata[j]; } /* diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 37f8d48179ca..fb5fc6538b7f 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -53,7 +53,7 @@ enum { CS_ETMV4_PRIV_MAX, }; -/* RB tree for quick conversion between traceID and CPUs */ +/* RB tree for quick conversion between traceID and metadata pointers */ struct intlist *traceid_list; #define KiB(x) ((x) * 1024) @@ -69,6 +69,7 @@ static const u64 __perf_cs_etmv4_magic = 0x4040404040404040ULL; #ifdef HAVE_CSTRACE_SUPPORT int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); +int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); #else static inline int cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, @@ -76,6 +77,12 @@ cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, { return -1; } + +static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, + int *cpu __maybe_unused) +{ + return -1; +} #endif #endif From patchwork Tue Jan 29 12:28:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156982 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4603351jaa; Tue, 29 Jan 2019 04:30:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN6CqNuOKY0qAaG2a3XZ6J/wIUW71Pz2BnHmQ96VUI2t/7AyV36c4ZdfJTjovb8fjy0vY1uh X-Received: by 2002:a17:902:a6:: with SMTP id a35mr25847098pla.201.1548765022662; Tue, 29 Jan 2019 04:30:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765022; cv=none; d=google.com; s=arc-20160816; b=TiPKKadpooZHenEI8pdvgkdQb2MfLSTjBEzbG5ctCXNo/LURE1PLlstQJiMC40Lg0T DYfmUldCZUbdJAMhFcHTSYraNruCfk8isVWR/ciAS/pWV0xDDlYC6vq/DL5H3Eh3Nn0t 1aNlbDosAD+BiqdW3JLiycn0iW8I+0DH/iL1R4NFqLRTfKcM1UyD0sfk02UL5F5yZz1q r3tus8TTqzirv7U71JuYsCFpX7SeUs/0hUHEtIxT2+0fkHYoQj5Kz5wneGzRAAeismWv /mHpnccqKIoUfTWurM1oom8S7bkkXIJITvJv3tWsEH2Lj/ZY9/upJRVWINaWr/weHdqf 6wCg== 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=LDRQG3UQxntyoi7kv39dKKGog1UFkbBd0dWoL+G3ZRM=; b=0RQYYGZCy6UtsBEHmAHfzdSmv3d2ywXQj0DVsE82ydJvW0Tsh+wg4JljbkadDlvBa1 QXJ2FVDNI0FL9tVJPNF6ddLC30b2SzV+tv1XerBR1R8zAM9Q9txRTEBvLaHHXNakQKwu 9exJZ7gZnDEZpREc0i1wqGGC+mzKZvHEkvdQbpAyLo5OmPMoWNMJZkerjV+b9cJCTXwE gDlKXZqpl6AiJcJYxepBZ1Duw994vlDaX+VpchR9bSngqzexw0rBwz23AuX5PoPmONa7 rrzzduD4btVbNrZxWhFvUiEVRFfF18WB3+UyLpRAsZfHd/YtCkZgBXyksDXWZq3dFUmy P4IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eHGHp8jR; 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 3si36008540plv.258.2019.01.29.04.30.22; Tue, 29 Jan 2019 04:30:22 -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=eHGHp8jR; 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 S1729036AbfA2MaV (ORCPT + 31 others); Tue, 29 Jan 2019 07:30:21 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42256 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728498AbfA2MaP (ORCPT ); Tue, 29 Jan 2019 07:30:15 -0500 Received: by mail-pf1-f196.google.com with SMTP id 64so9579483pfr.9 for ; Tue, 29 Jan 2019 04:30:15 -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=LDRQG3UQxntyoi7kv39dKKGog1UFkbBd0dWoL+G3ZRM=; b=eHGHp8jRAaV2wgbhIwcjRebSMqSMyg5DgX3bonjkii4dOULdoXvKBmMVhWht8D7sm5 kFHsfDvgvkrWZUb7WHcFWcjsyo89XO3owhDeFlz/exocxsTJdIjmuFp9/Q1/d9G1TGKr Ktft7EuXXzo0VnJKyRvEc7MgaPw+sYIeLkHLM= 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=LDRQG3UQxntyoi7kv39dKKGog1UFkbBd0dWoL+G3ZRM=; b=pSn+aJYRlHj+T8A4K+Ge82cjoREG/26M+nhTlzFr+6I4uWSdavbB+QEilheUEEBl7p XpVktydd48ZiHcVcr9FIrAjl4usW94rBfyy9gwT1tqgjzwHa/wc5rD/I2Hi6/QMTL7YX vee8dl1T3JYaIEWjwZejUT8JtcWbj8G1OXqY7JUPnZpGRMM/tiHJzIllmdpvA2XQTikX mveqRgqw/4MlDKR2glav85Bzs/y9jw51BdAHBCsNbgyiVQPbb8FiUHTMuP9YG7NyyOsi cOjLXQqb6zpLDQ1hoiqyHidzS3M9B/CpC9JkMqtxw5BZd2+aum6YR5PFYKSvM+wQN1/q nO7A== X-Gm-Message-State: AJcUukfBPppbCxDLPMAKww7O/DQNVWjmaY5Xwek0enRR7CU4/cWhnuse +4j80CZq79E5PxxRAALTFQamzA== X-Received: by 2002:a63:6bc1:: with SMTP id g184mr23992275pgc.25.1548765015042; Tue, 29 Jan 2019 04:30:15 -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.30.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:30:14 -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 6/8] perf cs-etm: Add traceID in packet Date: Tue, 29 Jan 2019 20:28:40 +0800 Message-Id: <20190129122842.32041-7-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 Add traceID in packet, thus we can use traceID to retrieve metadata pointer from traceID-metadata tuple. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 2 ++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + 2 files changed, 3 insertions(+) -- 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 cdd38ffd10d2..ba4c623cd8de 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -295,6 +295,7 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) decoder->packet_buffer[i].last_instr_cond = 0; decoder->packet_buffer[i].flags = 0; decoder->packet_buffer[i].exception_number = UINT32_MAX; + decoder->packet_buffer[i].trace_chan_id = UINT8_MAX; decoder->packet_buffer[i].cpu = INT_MIN; } } @@ -331,6 +332,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, decoder->packet_buffer[et].last_instr_cond = 0; decoder->packet_buffer[et].flags = 0; decoder->packet_buffer[et].exception_number = UINT32_MAX; + decoder->packet_buffer[et].trace_chan_id = trace_chan_id; 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 012b4728a46f..7e6a8850be4a 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -50,6 +50,7 @@ struct cs_etm_packet { u8 last_instr_cond; u8 last_instr_taken_branch; u8 last_instr_size; + u8 trace_chan_id; int cpu; }; From patchwork Tue Jan 29 12:28:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156984 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4603642jaa; Tue, 29 Jan 2019 04:30:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5fk5BVe2pxHN9H7glI2UPRfv39J11fX05yvpzEGQiFpQ3hgaCVbojuMe99l58XJzc7D4n8 X-Received: by 2002:a63:e516:: with SMTP id r22mr23974315pgh.256.1548765038271; Tue, 29 Jan 2019 04:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765038; cv=none; d=google.com; s=arc-20160816; b=gfkKO6K9HcltiHU4mSuU5oR2HtAKsAY3cL3xjNR5GeyPcGIygEZ67dnW675oViIhcq 5gEd12mekCrS40zUC5Afxe+h2Cx+TVi+ARoepOblLclV5Lrsa19mO5mfgiol/RFavonM /unw7/Z+Rp/73aAo5/U3GoQjGizZGyRCQLTMnGaLVcuGeYh1yMXTksLaIkvePyJhgtls Qh/xaec7h9ZiEjiAjTUMjmf3P+fnFbAliuFJOPd1s7GQdgeqGfShNO07LW21XBzd2zgj F5xHM6FNH7zoWIHGlIrQ7DUzBj88B058d0cRKZfcHnjOlmyJcAWgVI7m9z8CxnG/Lgse nS0w== 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=R4cK85uNm8FLfIgPLEXeXFwK11w5uqZvcYH5L04aX0o=; b=0LwROPX3JUY4wyFvwwcTV4RpCP+knLCnF+vLi1EM9cw2znSEdX5btFKbruXzi1TOOJ O8F4gmsyya9Yre4gmW/fP20gNb4fJ7oND3TtC0a95rSYirwNMY4oX+q9fEckise+PbTp zWuKk1Jw5z8iq/zR1DJCbBw2SYUPlVLvydfUHT1Sq81eCjXs3joZG7gNYxxP/MNrtfgU le86Xxs0XvrAUfncJKNO2zP4G+ON6wvMTma5Cntbd1yHHMry/1JqA58MSAKElRUHpe5w FixWhQFNCwn4VbCp0KTMgPqs1jsRW9BE1HUvFFO+fk8j7Q8Z+a5i+fHN8pEpdLrBcTz0 xbrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RNeK8FQ1; 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 f10si38547591pln.289.2019.01.29.04.30.37; Tue, 29 Jan 2019 04:30:38 -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=RNeK8FQ1; 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 S1728994AbfA2MaV (ORCPT + 31 others); Tue, 29 Jan 2019 07:30:21 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40601 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728575AbfA2MaT (ORCPT ); Tue, 29 Jan 2019 07:30:19 -0500 Received: by mail-pg1-f196.google.com with SMTP id z10so8677423pgp.7 for ; Tue, 29 Jan 2019 04:30:19 -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=R4cK85uNm8FLfIgPLEXeXFwK11w5uqZvcYH5L04aX0o=; b=RNeK8FQ1l+shdqvhL4WO4xXixFXnY9Wr9SQu0n5IK2G7qQWbBz3EZZQ9LQTdr6Rbqw UjsDO5iUd+a03mIaD65aHCqci80yXyEn0Q7rP4StdkJjZG8ubO8pvITsWZlaBZBNzidx DaN315rserWYta2zv2/CsnE8eudmOJfqaHv2E= 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=R4cK85uNm8FLfIgPLEXeXFwK11w5uqZvcYH5L04aX0o=; b=cGu9Q8UHgNDZNBJl+Nj5i/nV0MJoKxxfL/Up6MwdDWR8HxJRtVuW1eK2kL6xJj7viC To1onT7UXUy8BXoYTqQ5JxbC+/wLCl7g1zw7VC1gNKcxh3AigRrmz5kJtvWH6kVPU5KF pV//wCg7URyMzwLT7aUGzpTcEKQIjXc9EQOXnnJZyInRP/ItnLHiXarCRvbrpsJzkAfo pQVFWe2Xg8V4kdu9XT16TDZMXgBtLS+EnYk0vIJHjGk0HFXGnGaHWqNHk5Nel4m2QNQv HNcppwsxyIe/qsjPHa1mLMfaDE8meN/+FcpUj7BZ3o6ZWFQ9P4mVCJppH/ZVG3xcJUD4 02xg== X-Gm-Message-State: AJcUukdr4jo1piyMm8zq2OqFZqTpH589DDr1mjdx74zoJqB1KYiirWuv t8xo48YSWF6U/8/4iMDHnx1D3w== X-Received: by 2002:a63:1444:: with SMTP id 4mr23705310pgu.430.1548765019140; Tue, 29 Jan 2019 04:30:19 -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.30.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:30:18 -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 7/8] perf cs-etm: Set sample flags for exception packet Date: Tue, 29 Jan 2019 20:28:41 +0800 Message-Id: <20190129122842.32041-8-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 exception taken and returning are typical flow for instruction jump but it needs to be handled with exception packets. This patch is to set sample flags for exception packet. Since the exception packet contains the exception number, according to the exception number this patch makes decision for belonging to which exception types. The decoder have defined different exception number for ETMv3 and ETMv4 separately, hence this patch needs firstly decide the ETM version by using the metadata magic number, and this patch adds helper function cs_etm__get_magic() for easily getting magic number. Based on different ETM version, the exception packet contains the exception number, according to the exception number this patch makes decision for the exception belonging to which exception types. In this patch, it introduces helper function cs_etm__is_svc_instr(); for ETMv4 CS_ETMV4_EXC_CALL covers SVC, SMC and HVC cases in the single exception number, thus need to use cs_etm__is_svc_instr() to decide an exception taken for system call. Signed-off-by: Leo Yan Reviewed-by: Robert Walker Reviewed-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 215 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.h | 44 ++++++++ 2 files changed, 259 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a5497a761db7..a714b31656ea 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -97,6 +97,20 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr) return CS_ETM_PROTO_ETMV3; } +static int cs_etm__get_magic(u8 trace_chan_id, u64 *magic) +{ + struct int_node *inode; + u64 *metadata; + + inode = intlist__find(traceid_list, trace_chan_id); + if (!inode) + return -EINVAL; + + metadata = inode->priv; + *magic = metadata[CS_ETM_MAGIC]; + return 0; +} + int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) { struct int_node *inode; @@ -1122,10 +1136,174 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq) return 0; } +static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, + struct cs_etm_packet *packet, + u64 end_addr) +{ + u16 instr16; + u32 instr32; + u64 addr; + + switch (packet->isa) { + case CS_ETM_ISA_T32: + /* + * The SVC of T32 is defined in ARM DDI 0487D.a, F5.1.247: + * + * b'15 b'8 + * +-----------------+--------+ + * | 1 1 0 1 1 1 1 1 | imm8 | + * +-----------------+--------+ + * + * According to the specifiction, it only defines SVC for T32 + * with 16 bits instruction and has no definition for 32bits; + * so below only read 2 bytes as instruction size for T32. + */ + addr = end_addr - 2; + cs_etm__mem_access(etmq, addr, sizeof(instr16), (u8 *)&instr16); + if ((instr16 & 0xFF00) == 0xDF00) + return true; + + break; + case CS_ETM_ISA_A32: + /* + * The SVC of A32 is defined in ARM DDI 0487D.a, F5.1.247: + * + * b'31 b'28 b'27 b'24 + * +---------+---------+-------------------------+ + * | !1111 | 1 1 1 1 | imm24 | + * +---------+---------+-------------------------+ + */ + addr = end_addr - 4; + cs_etm__mem_access(etmq, addr, sizeof(instr32), (u8 *)&instr32); + if ((instr32 & 0x0F000000) == 0x0F000000 && + (instr32 & 0xF0000000) != 0xF0000000) + return true; + + break; + case CS_ETM_ISA_A64: + /* + * The SVC of A64 is defined in ARM DDI 0487D.a, C6.2.294: + * + * b'31 b'21 b'4 b'0 + * +-----------------------+---------+-----------+ + * | 1 1 0 1 0 1 0 0 0 0 0 | imm16 | 0 0 0 0 1 | + * +-----------------------+---------+-----------+ + */ + addr = end_addr - 4; + cs_etm__mem_access(etmq, addr, sizeof(instr32), (u8 *)&instr32); + if ((instr32 & 0xFFE0001F) == 0xd4000001) + return true; + + break; + case CS_ETM_ISA_UNKNOWN: + default: + break; + } + + return false; +} + +static bool cs_etm__is_syscall(struct cs_etm_queue *etmq, u64 magic) +{ + struct cs_etm_packet *packet = etmq->packet; + struct cs_etm_packet *prev_packet = etmq->prev_packet; + + if (magic == __perf_cs_etmv3_magic) + if (packet->exception_number == CS_ETMV3_EXC_SVC) + return true; + + /* + * ETMv4 exception type CS_ETMV4_EXC_CALL covers SVC, SMC and + * HVC cases; need to check if it's SVC instruction based on + * packet address. + */ + if (magic == __perf_cs_etmv4_magic) { + if (packet->exception_number == CS_ETMV4_EXC_CALL && + cs_etm__is_svc_instr(etmq, prev_packet, + prev_packet->end_addr)) + return true; + } + + return false; +} + +static bool cs_etm__is_async_exception(struct cs_etm_queue *etmq, u64 magic) +{ + struct cs_etm_packet *packet = etmq->packet; + + if (magic == __perf_cs_etmv3_magic) + if (packet->exception_number == CS_ETMV3_EXC_DEBUG_HALT || + packet->exception_number == CS_ETMV3_EXC_ASYNC_DATA_ABORT || + packet->exception_number == CS_ETMV3_EXC_PE_RESET || + packet->exception_number == CS_ETMV3_EXC_IRQ || + packet->exception_number == CS_ETMV3_EXC_FIQ) + return true; + + if (magic == __perf_cs_etmv4_magic) + if (packet->exception_number == CS_ETMV4_EXC_RESET || + packet->exception_number == CS_ETMV4_EXC_DEBUG_HALT || + packet->exception_number == CS_ETMV4_EXC_SYSTEM_ERROR || + packet->exception_number == CS_ETMV4_EXC_INST_DEBUG || + packet->exception_number == CS_ETMV4_EXC_DATA_DEBUG || + packet->exception_number == CS_ETMV4_EXC_IRQ || + packet->exception_number == CS_ETMV4_EXC_FIQ) + return true; + + return false; +} + +static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq, u64 magic) +{ + struct cs_etm_packet *packet = etmq->packet; + struct cs_etm_packet *prev_packet = etmq->prev_packet; + + if (magic == __perf_cs_etmv3_magic) + if (packet->exception_number == CS_ETMV3_EXC_SMC || + packet->exception_number == CS_ETMV3_EXC_HYP || + packet->exception_number == CS_ETMV3_EXC_JAZELLE_THUMBEE || + packet->exception_number == CS_ETMV3_EXC_UNDEFINED_INSTR || + packet->exception_number == CS_ETMV3_EXC_PREFETCH_ABORT || + packet->exception_number == CS_ETMV3_EXC_DATA_FAULT || + packet->exception_number == CS_ETMV3_EXC_GENERIC) + return true; + + if (magic == __perf_cs_etmv4_magic) { + if (packet->exception_number == CS_ETMV4_EXC_TRAP || + packet->exception_number == CS_ETMV4_EXC_ALIGNMENT || + packet->exception_number == CS_ETMV4_EXC_INST_FAULT || + packet->exception_number == CS_ETMV4_EXC_DATA_FAULT) + return true; + + /* + * For CS_ETMV4_EXC_CALL, except SVC other instructions + * (SMC, HVC) are taken as sync exceptions. + */ + if (packet->exception_number == CS_ETMV4_EXC_CALL && + !cs_etm__is_svc_instr(etmq, prev_packet, + prev_packet->end_addr)) + return true; + + /* + * ETMv4 has 5 bits for exception number; if the numbers + * are in the range ( CS_ETMV4_EXC_FIQ, CS_ETMV4_EXC_END ] + * they are implementation defined exceptions. + * + * For this case, simply take it as sync exception. + */ + if (packet->exception_number > CS_ETMV4_EXC_FIQ && + packet->exception_number <= CS_ETMV4_EXC_END) + return true; + } + + return false; +} + static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) { struct cs_etm_packet *packet = etmq->packet; struct cs_etm_packet *prev_packet = etmq->prev_packet; + u64 magic; + int ret; switch (packet->sample_type) { case CS_ETM_RANGE: @@ -1206,6 +1384,43 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) PERF_IP_FLAG_TRACE_END; break; case CS_ETM_EXCEPTION: + ret = cs_etm__get_magic(packet->trace_chan_id, &magic); + if (ret) + return ret; + + /* The exception is for system call. */ + if (cs_etm__is_syscall(etmq, magic)) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_SYSCALLRET; + /* + * The exceptions are triggered by external signals from bus, + * interrupt controller, debug module, PE reset or halt. + */ + else if (cs_etm__is_async_exception(etmq, magic)) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_ASYNC | + PERF_IP_FLAG_INTERRUPT; + /* + * Otherwise, exception is caused by trap, instruction & + * data fault, or alignment errors. + */ + else if (cs_etm__is_sync_exception(etmq, magic)) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_INTERRUPT; + + /* + * When the exception packet is inserted, since exception + * packet is not used standalone for generating samples + * and it's affiliation to the previous instruction range + * packet; so set previous range packet flags to tell perf + * it is an exception taken branch. + */ + if (prev_packet->sample_type == CS_ETM_RANGE) + prev_packet->flags = packet->flags; + break; case CS_ETM_EXCEPTION_RET: case CS_ETM_EMPTY: default: diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index fb5fc6538b7f..d76126e0e3d0 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -53,6 +53,50 @@ enum { CS_ETMV4_PRIV_MAX, }; +/* + * ETMv3 exception encoding number: + * See Embedded Trace Macrocell spcification (ARM IHI 0014Q) + * table 7-12 Encoding of Exception[3:0] for non-ARMv7-M processors. + */ +enum { + CS_ETMV3_EXC_NONE = 0, + CS_ETMV3_EXC_DEBUG_HALT = 1, + CS_ETMV3_EXC_SMC = 2, + CS_ETMV3_EXC_HYP = 3, + CS_ETMV3_EXC_ASYNC_DATA_ABORT = 4, + CS_ETMV3_EXC_JAZELLE_THUMBEE = 5, + CS_ETMV3_EXC_PE_RESET = 8, + CS_ETMV3_EXC_UNDEFINED_INSTR = 9, + CS_ETMV3_EXC_SVC = 10, + CS_ETMV3_EXC_PREFETCH_ABORT = 11, + CS_ETMV3_EXC_DATA_FAULT = 12, + CS_ETMV3_EXC_GENERIC = 13, + CS_ETMV3_EXC_IRQ = 14, + CS_ETMV3_EXC_FIQ = 15, +}; + +/* + * ETMv4 exception encoding number: + * See ARM Embedded Trace Macrocell Architecture Specification (ARM IHI 0064D) + * table 6-12 Possible values for the TYPE field in an Exception instruction + * trace packet, for ARMv7-A/R and ARMv8-A/R PEs. + */ +enum { + CS_ETMV4_EXC_RESET = 0, + CS_ETMV4_EXC_DEBUG_HALT = 1, + CS_ETMV4_EXC_CALL = 2, + CS_ETMV4_EXC_TRAP = 3, + CS_ETMV4_EXC_SYSTEM_ERROR = 4, + CS_ETMV4_EXC_INST_DEBUG = 6, + CS_ETMV4_EXC_DATA_DEBUG = 7, + CS_ETMV4_EXC_ALIGNMENT = 10, + CS_ETMV4_EXC_INST_FAULT = 11, + CS_ETMV4_EXC_DATA_FAULT = 12, + CS_ETMV4_EXC_IRQ = 14, + CS_ETMV4_EXC_FIQ = 15, + CS_ETMV4_EXC_END = 31, +}; + /* RB tree for quick conversion between traceID and metadata pointers */ struct intlist *traceid_list; From patchwork Tue Jan 29 12:28:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156983 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4603431jaa; Tue, 29 Jan 2019 04:30:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN5RUXdvMIozz92lpizH/cqAsyoClPuCqvHnYLiNXIfZwnPbLaXwr0ExCMrnOcPvF19UaHTC X-Received: by 2002:a63:c10f:: with SMTP id w15mr23315616pgf.199.1548765028052; Tue, 29 Jan 2019 04:30:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548765028; cv=none; d=google.com; s=arc-20160816; b=tW3hvbFlxCctgFb0rCSmZrJ3d9K1+5RZAo+LCRvvII37eUraK/sd1zJx6Rlgas0vtJ TRuDdk6uR9cOYCrr01kqFKaMf0Myc3U3goyiD7qPa0S4U67dJTeeNzUWCgkMsv/f1B+F cmrqVtPw+IZJ9j7ftjzSpSwuyHOa8w/gd9xGVHgPyvss1xdhAcTfHYW44Yd2gyLT0gOb hBgLZLYo2w8YIhhAg0diaTvwkyuLd7n7mo+TlFqtyMLVVwju0w9Jj4FAtxvzTiSomHtx TPGIxgLc4KypqRSAIWJQplDMomtbRYJZ+t2FdHpXptXd0s5VBtcNkhL0M5zjT/cujyy3 VwFQ== 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=ogFhqC1zhd8TWEoo9LulKJyn1R4ZPNj2Npeem7P1skM=; b=RO2SI2huir+uxosH4qCWRbrlC8ICvrmJ4R7iZO4efYy0zJzo0c4zQYL0FBrDMm1k77 PRICNdR3evcSv+6YQQZBx/a4QCXebJS0W6fo7cqnrEK36GVW/9ZgQdXVYDucoCB/dK/E qflM0sXqkILV1C3mAU06R4tRQFHx/QQLGEuhbZFE4hVrx851w2efyUvtt0zeHenK33KM 7Wx3pZZZJQle5zdqqpkJdqW0kYWDb9HDXfgo/aN4ZVLXOT0riACP2l0PAobXzHnIRh/B BUqy5NsXeDDtH10c9h3TjUK4xUVrkORJ86Cetp7EYt0c4wh0rVhapTLj/SVkdyCqGpzh kbgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f5iuxOB4; 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 v9si30900586pfl.45.2019.01.29.04.30.27; Tue, 29 Jan 2019 04:30:28 -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=f5iuxOB4; 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 S1729070AbfA2MaZ (ORCPT + 31 others); Tue, 29 Jan 2019 07:30:25 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33276 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728498AbfA2MaX (ORCPT ); Tue, 29 Jan 2019 07:30:23 -0500 Received: by mail-pf1-f196.google.com with SMTP id c123so9617490pfb.0 for ; Tue, 29 Jan 2019 04:30:23 -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=ogFhqC1zhd8TWEoo9LulKJyn1R4ZPNj2Npeem7P1skM=; b=f5iuxOB4+/EiUDieLqPoazQiHKzkdE0k7bWX4IyKwA6TPSdXGcwZvDDwL3pZWYmfIz +crFvLdSTsSVYeH0bQ+ZpRH+8RXevARQYNwQyn5XshyJLLBR8MgiFksN07gk6xsdMz/W h7PmMJkPJZ2SiFRRkVl52n7scjOW7Tb45rYlM= 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=ogFhqC1zhd8TWEoo9LulKJyn1R4ZPNj2Npeem7P1skM=; b=PSpZ5VPDwy0ilIkk81ezCSrZoR7LZbKBXp7VJ08p4SrnDvZyp9b5/KYuH0SnfXEP/R VlhD6E9133k8f+ELiF9DNzNY4GXka6xyi1J3M8Q4HerQ/kymxjzvLOc+XrtBf6uo/pjJ WQQzgYTZepYAs17KyF5yRFFDkoReYt369LAG86p0xTKIYtszqj/A/ot2QjKUc1tCb4+a FUDemEdAnA/4I6tRWvJk+/q/Qb2SX/B6jjpUolQwERYpLnhdQZPIAPZm1YhF7UEMlPB8 1GEMBSzuexqSFAQ8iD1YYSvshITDyCF9/a33UYspZU5NS3YYcp8D9mEAy/lqfHFG2dwp gT9A== X-Gm-Message-State: AJcUukc4hr+mSjrPtmrIi+8hsaGeFWBzu6+zc53+/YaLMNW1TW8Q5DLx /rlYBvihEQqd4RyiPa5jHwI7Mg== X-Received: by 2002:a63:304:: with SMTP id 4mr21493775pgd.99.1548765023004; Tue, 29 Jan 2019 04:30:23 -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.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:30:22 -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 8/8] perf cs-etm: Set sample flags for exception return packet Date: Tue, 29 Jan 2019 20:28:42 +0800 Message-Id: <20190129122842.32041-9-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 When return from exception, we need to distinguish if it's system call return or for other type exceptions for setting sample flags. Due to the exception return packet doesn't contain exception number, so we cannot decide sample flags based on exception number. On the other hand, the exception return packet is followed by an instruction range packet; this range packet deliveries the start address after exception handling, we can check if it is a SVC instruction just before the start address. If there has one SVC instruction is found ahead the return address, this means it's an exception return for system call; otherwise it is an normal return for other exceptions. This patch is to set sample flags for exception return packet, firstly it simply set sample flags as PERF_IP_FLAG_INTERRUPT for all exception returns since at this point it doesn't know what's exactly the exception type. We will defer to decide if it's an exception return for system call when the next instruction range packet comes, it checks if there has one SVC instruction prior to the start address and if so we will change sample flags to PERF_IP_FLAG_SYSCALLRET for system call return. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a714b31656ea..8b3f882d6e2f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1372,6 +1372,20 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) if (prev_packet->sample_type == CS_ETM_DISCONTINUITY) prev_packet->flags |= PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN; + + /* + * If the previous packet is an exception return packet + * and the return address just follows SVC instuction, + * it needs to calibrate the previous packet sample flags + * as PERF_IP_FLAG_SYSCALLRET. + */ + if (prev_packet->flags == (PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_INTERRUPT) && + cs_etm__is_svc_instr(etmq, packet, packet->start_addr)) + prev_packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_SYSCALLRET; break; case CS_ETM_DISCONTINUITY: /* @@ -1422,6 +1436,36 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) prev_packet->flags = packet->flags; break; case CS_ETM_EXCEPTION_RET: + /* + * When the exception return packet is inserted, since + * exception return packet is not used standalone for + * generating samples and it's affiliation to the previous + * instruction range packet; so set previous range packet + * flags to tell perf it is an exception return branch. + * + * The exception return can be for either system call or + * other exception types; unfortunately the packet doesn't + * contain exception type related info so we cannot decide + * the exception type purely based on exception return packet. + * If we record the exception number from exception packet and + * reuse it for excpetion return packet, this is not reliable + * due the trace can be discontinuity or the interrupt can + * be nested, thus the recorded exception number cannot be + * used for exception return packet for these two cases. + * + * For exception return packet, we only need to distinguish the + * packet is for system call or for other types. Thus the + * decision can be deferred when receive the next packet which + * contains the return address, based on the return address we + * can read out the previous instruction and check if it's a + * system call instruction and then calibrate the sample flag + * as needed. + */ + if (prev_packet->sample_type == CS_ETM_RANGE) + prev_packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_INTERRUPT; + break; case CS_ETM_EMPTY: default: break;