From patchwork Sat Jan 19 01:43: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: 156109 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903575jaa; Fri, 18 Jan 2019 17:44:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN57PcJGylFZPNKRdi6Qu0tKyHpB0h6sTK4bx7ZlkcbIU0Mzg5UzID/+V7dlTmVlYq7FBTj8 X-Received: by 2002:a63:f141:: with SMTP id o1mr20356545pgk.134.1547862269883; Fri, 18 Jan 2019 17:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862269; cv=none; d=google.com; s=arc-20160816; b=lrD/E7E7Ma5LvSCdI6w3xodyd1StK2ST695OE+JDeFnk+j5QrTmuUXdYgXT6Ep59Hu J68qILER066g3+5W5hZu/AHtkcxgwGR8BZHaL3ya+x8S6qnadjjdc3hv0424mvCTZoJd +Vi8YqAaBh1/dclSaqefVGe910bXSHaJJRiud6XN1Cjy1vnVxfoW9SnsNH7SncaaZHCY 0RqwsqeLF3HtTuHXmSrdTtHxRRewkDLquzDPtpmOjGoH+SWLc7eXuotGMbYHiWRmA8v5 DqX9Zvq6d9UStXJjlv5zOeV84NQW8ytkQ4MEF5834AZksIRbWIjhCTvOxXjounBD0ACq UdDw== 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=jETu+BduxrzXdBTSoIHDOv28Ri7iXymF5DJaIor1gtI=; b=dz0bxG0OTapGLGTwblvL/Ta/mGPoLyyyufaTSpLS6SAkTMqN5hM5EjcT4VhRKsJ1EL R4W0N0wTgULFM+sxq74mhOXXRdS6x398uanq+ZidRskSCNRgKQ/nWh4A9dS7skC16l4c WFAO1me4dGwvfFWrNNpv1sohw67foM50bvTFbqBdP0ePW4Vx7e4UrFwSi+r1C015jCIZ YSP5gp9niBXYOiwoe8uTMwSdmDBsFo4WgvjTrywWeqlHf/Avel/OyGHDd3QZCk25qJev olsQ30+Xgbq1aVAP2WxCfes/wb6nXuMW85yOfntaaVME7EzTUrkjnYFepmtWsNm4eP+g d1zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UJR/ZDiL"; 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 o68si6904714pfo.140.2019.01.18.17.44.29; Fri, 18 Jan 2019 17:44:29 -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="UJR/ZDiL"; 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 S1729920AbfASBoK (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:10 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44095 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727713AbfASBoK (ORCPT ); Fri, 18 Jan 2019 20:44:10 -0500 Received: by mail-pg1-f196.google.com with SMTP id t13so6856536pgr.11 for ; Fri, 18 Jan 2019 17:44:09 -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=jETu+BduxrzXdBTSoIHDOv28Ri7iXymF5DJaIor1gtI=; b=UJR/ZDiLrjsIi9UcHwH4vY5U6Z90QraRTn+RRpSe4uSHbu8vCGNQiDKM6DoVc7aJoU 9deaQGz1NS/r9W8SPTrMsbninLi8UUuIVDTKQ0/eo21TQ4WaMoF4BdRzhKmdgklUljK/ ZjkVKboyhwsZShHi77LZBbotd/1pNsLp0lXdM= 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=jETu+BduxrzXdBTSoIHDOv28Ri7iXymF5DJaIor1gtI=; b=cR7kck29VPueE875yHJF2PE3j5Vs8romOmeJzavHFjSTk5F8NlquWofRe4qEHYCG4a HYItyg1T6q3zBam5Sg37LWXjOqM5rIFYLK13ncO/tGeif8B37/09dW5U1fqAgBBkMLdg K9JGGadlkqgMYdjC2ZUcvGFWW/b5/VX8hvvf7cvuOBpFCMOPXOo7+fX2u9FXN5eEUn86 W0B6oXzVDrq9KHfYg0D1ayFztggIwy38/i0SvBmHBlYPni07Pd7cSY8f7OGpvQ4+AZMc P++4pBB5w+7sp9tt7ypBzXKZ+MmV/+GCgBAlI/Wn6nypoEzGhG6XpyVxz8wrrTGIZFDy AnDQ== X-Gm-Message-State: AJcUukeA/eRFostUQypQx5AVsVm/J2cIv7S1C0wIMc0sdP2iOrxq2H+M mI+/Gu1XC7jSdRWtBeGJGsf5UQ== X-Received: by 2002:a62:6204:: with SMTP id w4mr21762120pfb.5.1547862249054; Fri, 18 Jan 2019 17:44:09 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:08 -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 v6 1/8] perf cs-etm: Add last instruction information in packet Date: Sat, 19 Jan 2019 09:43:40 +0800 Message-Id: <20190119014347.27441-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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 --- 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 Reviewed-by: Mathieu Poirier 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 Sat Jan 19 01:43: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: 156110 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903580jaa; Fri, 18 Jan 2019 17:44:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN4/N/i2RDYNxOkl914NNH1iks1YeasILLR5JSTqjO/ZgowZsziwiVOo18Q7syGxnPTjCyMc X-Received: by 2002:a62:442:: with SMTP id 63mr21283337pfe.156.1547862270244; Fri, 18 Jan 2019 17:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862270; cv=none; d=google.com; s=arc-20160816; b=qcLPp+teUlVgIokTkI/ZeUE5J0rKKamxeGomMsMpZsPDqW/ZCkFcEPmYKXbqe6WvLq 2X7+IzrqhW3YiiEPWHzDxuOrMDbcsjr2K4HJIRu433XigTTR5mf4o8juXSdw14EShoA0 Hb7bNCliRzvAgXAJP+z9jZ/dhtKqf5+ldgEtYFT6zF260xoC4AzfXF6YyP2FCY98QCLJ nXQWH59EhBv2ZDn/+KuvjtdKAWUBSuvUP7uxpj2RqI2pfzrBgxUUy4NhViWe0n0BmcBp GMhnRARRHPs3+9tAX1Hc9Yp09ctgNCOsbc8Hq2AIeBePgtf9mmMofUPVJq9FsSd33II/ JkkQ== 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=XJIZCAPULyAuE6ru9p7H4wc2p68zHe0RBmLv7q7ns4s=; b=lRYNSo+NZs8lKzeHWVMh0KZMuEXIj4AqdJ0+qJT3Qc/SCSvxdX1lSBIG5TlaCZfr2L 5kJREM3ymawYxCnJcsyvroF+F3OCx00Q8REajJL7+a0hCkLNNCKbTDPXI/dwoEhIZk71 Uv+ZDZ8iwnGOrm5VNbG6cTT9xJMEGJqWom13e/CnG+Wtc7j2PE4SnD4b6oGthZwYqY0K znfP4Fo6AK7khh3T7inKZ/Ahg2Qpiq0NjlrExAib8oxi0iAHyIWgZPBzh1hOwQWR3dL9 qvzRKqTPH99oOuwbL2zUb5H52SaWl2SsayhXqpH5QQdlU6bsCRw5f7u5MsmdL36mSZ3o hseA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jxwOsEBj; 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 o68si6904714pfo.140.2019.01.18.17.44.30; Fri, 18 Jan 2019 17:44:30 -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=jxwOsEBj; 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 S1730250AbfASBoO (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:14 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:33686 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727713AbfASBoN (ORCPT ); Fri, 18 Jan 2019 20:44:13 -0500 Received: by mail-pl1-f195.google.com with SMTP id z23so7114324plo.0 for ; Fri, 18 Jan 2019 17:44:13 -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=XJIZCAPULyAuE6ru9p7H4wc2p68zHe0RBmLv7q7ns4s=; b=jxwOsEBjpjW0GJM/td1qH6zm7wudD+4sCp+8LXIz47JqSIhwAYsVSdJMNFpmXa/Gla gXQ8sbU+tXqH2huWye7ZW+i+yzoLz/8MHpjFQXGqqXrsWCjt/7/K9XlkWQuPD4IwL78R 9GKQY/WlRP/b+G0i5FVvT3xxK9hJP5yXG0u/M= 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=XJIZCAPULyAuE6ru9p7H4wc2p68zHe0RBmLv7q7ns4s=; b=N20tDkKTGjDtx6GosHhxQvCpQMFV4RIN/Sy5O0UDy+cMYHcUMbbY4YHFdylWJ9zW4c ZWgYxbqH+wrkLrgKbJycxiJlwZwi7udKkJVo5LmBompRrrzvSgC80fTuUe69KHS3KpL/ r31nWyjdQJ9FDTKvBnxc095qnjn1NQil7ZRyDNJ8RQTHuZHo1JFBQa7MGRwRdNxUCgbH +ziSO7WFcUKMhlxIDwKAZl+UwsEIHrZ58byY1U3wrdAOyl0y+5aeShOCwd4uAYOIog7Q Bk5pYLbnE4MYsaNIXjSevPmlv5352UKssZUpr7Muf2H25iuZXoP4z1DyUTcpAdP6gt7Z qnKA== X-Gm-Message-State: AJcUukfy47ljqZEH83oRB7+x1pbUzEd7VL0qH3ODyiL5L3CGJ361HRnp zn6e6kkYkaoGRnT/WDThzH9QZQ== X-Received: by 2002:a17:902:b48b:: with SMTP id y11mr20633017plr.200.1547862252857; Fri, 18 Jan 2019 17:44:12 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:12 -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 v6 2/8] perf cs-etm: Set sample flags for instruction range packet Date: Sat, 19 Jan 2019 09:43:41 +0800 Message-Id: <20190119014347.27441-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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 --- .../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 Reviewed-by: Mathieu Poirier 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 Sat Jan 19 01:43: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: 156111 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903592jaa; Fri, 18 Jan 2019 17:44:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN58zcM6t6i6O45EptPryJgDc13zJ1XAp8yZlxHERKPzntJLWKiu8tLz7Wy/IAhQqzf8TYVs X-Received: by 2002:a63:104d:: with SMTP id 13mr20070363pgq.303.1547862271205; Fri, 18 Jan 2019 17:44:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862271; cv=none; d=google.com; s=arc-20160816; b=ifp8Nsf2Vo7lWcGplzaUiQgt4hCic3XRKtAZTWcs+QMC8eUdfH8rs1ZEMxWOxea0Xe n0ZnygJIb9IZASTtzab0x9XAJZqVzy55juqcEBqymzykDHxcxVpTrF3g5xRvjaeYrfsU s5Ypo5grl7Ni7Igc4GH6c5vZ+M432759Zt+pYH53WDYswl1ZZCDS0G1eucpkxj7uTtBs S+lJR997cxVB3oVlmVsIOxieJDxFC4F4IKrTTgjy6PFDnVLfoINcO398OCNh6EcwyNZU VwRJanMjfrlSUVmqtHpQmyuIxtcWjL5r8IPS66h93NmGtJkfUqVEYDLUwNQL2i/1kb5A DjpQ== 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=apzqr2DPBRKwMWYdw7mN2gcZix8iFxXQD+UIs2uAD/8=; b=TlnTjdy5M+Ds+IfC4iyHAvTPiIzGnDexbQ6+qCSxk6OgVeqTG7cKMOB26N8OjvV8g2 dZV7xpvIYj12ZDYG1dCtF3Wk8NTVanLbFgoamxVIQMnbzhpHk3dd3hUlRTxQR7wG/Dmm NW4rkGTmf/kIeEpF6PK/EawEkav+BMSQUtiqgoV7Y6bXRu0O/xJNnTx/c4oyhkFznGe5 iKv2CX97BzcPhE2o4wXL32O5pqQbLL8fR1k04Zt6oE7mw151I9azqHGs79L8ScEPXCTj FBFFiR2hrml6aFtygEep8Y+SrGurt2KaeTABID7vyvgwpncalqfaaT8KQKfcEjg2S6eL /+AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PiMbxk9o; 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 o68si6904714pfo.140.2019.01.18.17.44.30; Fri, 18 Jan 2019 17:44:31 -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=PiMbxk9o; 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 S1730312AbfASBoU (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:20 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33840 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730262AbfASBoR (ORCPT ); Fri, 18 Jan 2019 20:44:17 -0500 Received: by mail-pl1-f196.google.com with SMTP id w4so7105132plz.1 for ; Fri, 18 Jan 2019 17:44:16 -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=apzqr2DPBRKwMWYdw7mN2gcZix8iFxXQD+UIs2uAD/8=; b=PiMbxk9o8YY2tVjT3ff/E+/k0qmzfKhgGNsgDhImweyyi3d6rdLRJL2sTjMAjzFyx3 kNoFWUkUmRpDfUJGqWEtwRE5WiItb8AOQRRnrGKmMgSG9N5WulWUt4ln5TA6zoeBlKxm 2k3tLnjb+Cc5RyA8fu959FOaaWTwFmPK+7zWM= 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=apzqr2DPBRKwMWYdw7mN2gcZix8iFxXQD+UIs2uAD/8=; b=se8Wj2gdADGecgj9XDTaQPBNNPUmt6bPAh49z3pjiFMUn89J2OoDWq8v0e9vI/0ps8 tQ/wlak7tyNc7krGu6pFLCLZcqWetGsE0k1HIJ7sBksN2Ox/Ik2fMaVmefUWIUREqplm BAFMgiYS7h/L20kPxPkURnv/JNvmJd35bV5I212R/oc1a1AKYeMQTdc9GlJIb6zDRBck 7JcZn/QV9ofiEacLxAyK2TSRT6Xk1BJOOdVZfbqp/PjpcepL0NW15Qcx5YGtL556Q3Cx QHYzVccq5SHzeT5P5T0/wv0+2H3rO7Pb++evKsUoKNE49s6VqVy4LeujiRJdFfDoFBl6 8ovg== X-Gm-Message-State: AJcUukcjgEZpgZ5JdHmblKjZS/Sx1UNlx5p2rOP5NCBXQ9bjoRDlTcFs UePxUhuCHrMdnHC7Vre5FwUeSA== X-Received: by 2002:a17:902:2969:: with SMTP id g96mr21194637plb.295.1547862256537; Fri, 18 Jan 2019 17:44:16 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:15 -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 v6 3/8] perf cs-etm: Set sample flags for trace discontinuity Date: Sat, 19 Jan 2019 09:43:42 +0800 Message-Id: <20190119014347.27441-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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 --- tools/perf/util/cs-etm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.17.1 Reviewed-by: Mathieu Poirier 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 Sat Jan 19 01:43:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156112 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903597jaa; Fri, 18 Jan 2019 17:44:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN6aseMGwpCsG8yXirC+mDqc/z51QkEu/WrOwciIXn5jarYr0TZ6Wy2IJVU/ZOzOpQDBwW9K X-Received: by 2002:a17:902:d68c:: with SMTP id v12mr21146955ply.4.1547862271518; Fri, 18 Jan 2019 17:44:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862271; cv=none; d=google.com; s=arc-20160816; b=gYAQo3nLxhkUXnuYn//sTsU4EUKcAmeRpq4eCy+XVSDAj/btWvzIUU0AVRlFdeVsdK eLB9PgH3FggvNLYDsGez5hmTALK91Cb06iEdT66HwMw2tC62AHcbnXWteXT+KGrzZmuF nkhm0DFHBGu0U1oo2UiVldRMuR+eMxG81XT8KTTS4EZj0dyklMznYV+8R6Bay6sFXi/z +mdc9QSIQC7eHldyOGdtB4jf7n+QnzYFh9OgE/VAzOX08vtm1jMIB5Z4GelpYBJ/S5oI lx9tnM0IIi6QlnLjU/70+YGg8BdC/fdBgiww1gFkVbi1+S/zsCkqNwsMSPCFKChZBmJ6 QxrA== 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=/5nYzCIEonlNYJwustO+jm4nIH/Vxt/bPuViPJ/LH/8=; b=SEhX72NYEfdHrW8A3Ls+4tb1326qKeYOrMr1QggUp076WwaftAwxmG/QTPuwR8utlc 4ZYix2CsUbUqMKsV93t6M7jdvYa1EHTrrBrJBU8HFjFqsL7PpnfUuJCgNRnCBCvjp3E5 Ln76Ka9qDMB216CkV6/AAJJYnW2xFy7XLBwAYY/1ojHaMPejePoZzoWpCi0Mz2jowJkC iFZgju9VUWGM9PgvnHNVhm4gYh+u5j2xEjSZ2owjuj3st6I/SdZkHb2uLs5L9goNUF3w gbBlu//WmkZ90nE41YGFTsA9WdiLmMF7JWyhsjJ7dB+o+n5B5hT5A84bPqLfaFnFx27o bvEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EZsfAJvS; 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 o68si6904714pfo.140.2019.01.18.17.44.31; Fri, 18 Jan 2019 17:44:31 -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=EZsfAJvS; 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 S1730337AbfASBoY (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:24 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43277 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730316AbfASBoV (ORCPT ); Fri, 18 Jan 2019 20:44:21 -0500 Received: by mail-pf1-f193.google.com with SMTP id w73so7423012pfk.10 for ; Fri, 18 Jan 2019 17:44:20 -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=/5nYzCIEonlNYJwustO+jm4nIH/Vxt/bPuViPJ/LH/8=; b=EZsfAJvSkY0JpLAG58uwHeVgtm7PsF23KfAEWoyRjoyzJwjDTosNRAdCgkT313oLM8 bzhOZZyiI66l6s8ZZuOQKuP90WeRlCjou5eGcYsbL1SK/DgAgJaGoXs38uiUKiSz+hia OAdOz9gvbXx6g7LU2+WzjLo4aXJBbuWIpgFmk= 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=/5nYzCIEonlNYJwustO+jm4nIH/Vxt/bPuViPJ/LH/8=; b=RWJRwhLzx3t9O04nLjcMpwSLiESEL+uxVdQzYub2ZesYv+ZTVVCKzgdsAZmWvjMish q8HoIO+215q5eKtapoMqwmM/4Md5oGEkC3Ml1T9SCvNOrf+QIOAurQ1ITNW+g/3pNsda YAOu+WkESsRQthBpVyIsFlXIf1vvA2rFpUk3rHXH7qOPUVtmrgglTdFdJmanypgyxyjl GAbLiemGjNzSGaHE5oh7DjcXO6ix4+3ISZPnExfzlaQFvr7KBXUhhg09BbUY2+GRVZII O0iJSQkJZdve5Ex+0s6uzRcA/IZL4ZpfClnZvSGhF61SOQgLegL2fT5i+uqFDj6myTv9 2mlQ== X-Gm-Message-State: AJcUukd+i5hsxfPPpGCFxJePpuYr3hHlRT+FVbUTx9F2f9OgeoNFmjpo tE9fGtvIxJ5C48XE5/1C5x0p0Q== X-Received: by 2002:a62:47d9:: with SMTP id p86mr21124099pfi.95.1547862260243; Fri, 18 Jan 2019 17:44:20 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:19 -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 v6 4/8] perf cs-etm: Add exception number in exception packet Date: Sat, 19 Jan 2019 09:43:43 +0800 Message-Id: <20190119014347.27441-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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 --- .../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 Reviewed-by: Mathieu Poirier 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 Sat Jan 19 01:43:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156113 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903609jaa; Fri, 18 Jan 2019 17:44:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN7yrQRl2yLoufGv8WnOktmw/mXyB9//0f64sZzRm6GEA8wKrrOg6eRaAr8NMnG3N0o5wpDT X-Received: by 2002:a63:3c58:: with SMTP id i24mr20317532pgn.284.1547862272435; Fri, 18 Jan 2019 17:44:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862272; cv=none; d=google.com; s=arc-20160816; b=vyTl7ZcF5uETWkr/Te/l8xx1NGrGlkk9EIf6nxpLQCz5cLffkbbfvkItuVrUcHN7sE kNkmZda+WwYfpLNrKio1p+DiVWNIVIkiP62uMqoCJ07apiHcaVFbwA5Z9DCQxYfZzPsp 7iFNpAET28AkwguKDBUqHR8g2gYbKRPirAdSzdjUYc7zXDi1xXWZ6o2Z2+/5JqkpJKw6 ciQ5xEJX8E6KwOemZh4JBC6+vxWhVlbD8/MzzEheN2ZJ88Tz+igAHTZIS2xkZ7adGf6Z VqBYlzJPD7PaNGCUoLlXnB3uyvQGXFHxDOrN6hIazdL/RVK1mjea1SzVmktL0RXQNLbm nPJw== 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=GNlj8CHga4sec3MzFSUyZCmaJEDR0dqJiCOQWV34Lwg=; b=Y1Mqt+WeeqLJVtscVCzdkQOZLOqUPogJm1a9A/gOkfvxe16EsYdxwF86qsM4+TYBmv g67ZHuaiFJii9x54icr6GfWdm4sRJezlZQLIALCpCKHYZhRX+D0npwNf+Yq6l/A3lZsN WtaIC072TlCpTHCUwxGhFFspa+a57R5YnHb74sDNtF1igs9dkXtA5KMsvR4QYy8NCwXL 4bl0VmZRSCL1FCb+Z1jgIvV7T8eNKF4MvMyoWD/bKujT9FRdRXPTYzE8RpFZXTgRSydx HWLZYQQY6NN2wfBqBMg3ACQbpmpYc4sL5zqTE+IKaUjrOOCRlWaIM7BwBPAXJcBuZ1kO ugcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d9/yUcOS"; 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 o68si6904714pfo.140.2019.01.18.17.44.32; Fri, 18 Jan 2019 17:44:32 -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="d9/yUcOS"; 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 S1730363AbfASBo2 (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:28 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43282 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730331AbfASBoZ (ORCPT ); Fri, 18 Jan 2019 20:44:25 -0500 Received: by mail-pf1-f196.google.com with SMTP id w73so7423054pfk.10 for ; Fri, 18 Jan 2019 17:44:24 -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=GNlj8CHga4sec3MzFSUyZCmaJEDR0dqJiCOQWV34Lwg=; b=d9/yUcOSin4bxjn8Whp6+X9Zkebs+EERMQApdnrwEnD3ayPT2ciqwRCFFbkl52HzId Cpe22qP9YpExSI5/YvvYs7839fowLLC4gAimKXuV47/3XafCv5644fFnj7LVnTQKcIqH 6f7ttgHT7tX6aL+ZLrKZg9+KVZUx2qI3yL2Ew= 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=GNlj8CHga4sec3MzFSUyZCmaJEDR0dqJiCOQWV34Lwg=; b=t0x3JdDR9FceAQ0YPWpmHoo/gXsCb3cVNdV8RqdrcQHeDKbwWpDwrd4cfBf7qbV2SC jefhswwXaqWwHnmP5PNWieNxSnSW61ZHMvrVd1OjIwn3uSaCKmAJtmwLfG3+cFm9t87l 9xr8oGBkuBdFq1wMo538GJp4HiZrK/M0gUMr4IWVUXfWBnb2buD8X/Im7kzMqV8OzmYQ 4KNuRYXdyYw6l/q5zFxCRyXtNDNQzxhVQ8VXCUV+qlgAZFVllpwXKhZDCP6oKcznn56I r6PQXLxPNCvVJGuQIkhnCLB9Zzz4G8k8oN06y0tNuzEXf/NQDaupteWIJPmjGBg+1Po3 lTtg== X-Gm-Message-State: AJcUukeFxOmJkLa6b3Y+61MdXlmPjQ2YXbPZqVyUGxe7rWhkQTdbd1Xi K0d09rRmIu+acendIPqmL/8yJQ== X-Received: by 2002:a62:425b:: with SMTP id p88mr21930903pfa.137.1547862263994; Fri, 18 Jan 2019 17:44:23 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:23 -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 v6 5/8] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Date: Sat, 19 Jan 2019 09:43:44 +0800 Message-Id: <20190119014347.27441-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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. For this reason, a reliable way for accessing metadata array is to use traceID to find associated metadata; by accessing metadata content we can know not only the CPU number but also for ETM version, which can be used for sequential change for setting sample flags for exception packets. 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 | 37 ++++++++++++++++--- tools/perf/util/cs-etm.h | 4 +- 3 files changed, 37 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..e89989fe0a5c 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,20 @@ 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. + * + * The conversion between traceID and CPU logic ID number has to + * be made for each packet that gets decoded: firstly retrieve + * metadata pointer from trace ID by using traceID-metadata tuple, + * then read CPU logic ID number in metadata. + * + * It's not safe to directly use CPU logic ID number as index to + * access metadata sequential array, e.g. when system have + * hotplugged out CPUs, the metadata array are only allocated for + * online CPUs but not offline CPUs, thus the CPU logic number is + * not consistent with its index in the arrary. For this reason, + * we need to fallback to use TraceID-metadata tuple as a reliable + * method to access metadata. */ traceid_list = intlist__new(NULL); if (!traceid_list) { @@ -1587,8 +1612,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..5d70d10f3907 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) @@ -78,4 +78,6 @@ cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, } #endif +int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); + #endif From patchwork Sat Jan 19 01:43:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156114 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903646jaa; Fri, 18 Jan 2019 17:44:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN7n/coE8IZawO7mrOqQXeauS4JlxnnbwlRucFlaW4a1FT6ucDOxtROtMu/iwUSHAIaxLGLq X-Received: by 2002:a63:82c6:: with SMTP id w189mr20205480pgd.344.1547862275728; Fri, 18 Jan 2019 17:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862275; cv=none; d=google.com; s=arc-20160816; b=OTUaWLyDUSEDLk7Pkb7dLMoKuRdVZ1aUTcYoLKGsLkMIMOwOgn0Wk7tPJtantlNnFf Vw2sZlk+eUuqpXaDDYVRb/qUQNCXJCwr5iINc01HN+aFR9MB8LNipQuS5k+kzZ+MF7so ewqRivPQgkxdSNqys2gb/rI/Zp84QUAbdi848EQ3rTOx6irRvpOSwhgoZyBMfq7DNOQ4 w/kY0TosfzVOCWfvZ4xTyNkJb08WHCImlAGiaW+bTSJ452TUWMIg6nmsQ+8I+gUgJXmi DcQO69Hq4Qki3irNbHsBYXAXzkgIcsWkrwOTmENLzDBWZEObOtVZKojkUuWbHQ3gG4Ug jnMw== 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=7CGHnFgA52zKXZDyd8sb3sbv9trI6e0tJf8G4Od6mhA=; b=OX+8jk3i8dPvdW5oybQZx5u9ZtV9HkfQ/LHVL9yKn1YOrHDp0yV8GJygxhRsRGI5k8 hy+NJKBJsePTZLtxifHMqAn8duWf5stqU1x5ZVfdmp1IUe9WbpgR9rTR9aXkqV4z5DDf TZAKklg+xWPIb6/V1eHOssbfPIpGw/tAAln3cVpcS+MNWAhKEKfl/RQay8sJlnL842ho GooESArv47xOI9cEQQlQjl1a851LZtQzB6PZ2Qsg5aOpRJt/S/6eNuHQeDlK5odp594v K647uXEtg7csT9aLUfLX8ejMA/SKbqcSUsrsD0x4Cv9iXaXO3NCjtMwYLfRquLMFsBPQ BF1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WMYRDZcJ; 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 z5si6306664pgj.177.2019.01.18.17.44.35; Fri, 18 Jan 2019 17:44:35 -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=WMYRDZcJ; 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 S1730381AbfASBoc (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:32 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43365 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730353AbfASBo2 (ORCPT ); Fri, 18 Jan 2019 20:44:28 -0500 Received: by mail-pg1-f193.google.com with SMTP id v28so6856583pgk.10 for ; Fri, 18 Jan 2019 17:44:27 -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=7CGHnFgA52zKXZDyd8sb3sbv9trI6e0tJf8G4Od6mhA=; b=WMYRDZcJWZlYjwF1keRnofNHQ/JvhjLXBuV4YJrQeX715ddKNk2tbcOviRlR15l1dQ 0+17juqn231qo7yLpvMLBrExKoWNYpeEb+zrt0VbeW9PuU4S/eHptD0y7nX8eABIPC45 psLPGy9eTt3CpLPyJvCL8/L63pAy9i7YkA3hQ= 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=7CGHnFgA52zKXZDyd8sb3sbv9trI6e0tJf8G4Od6mhA=; b=RjyO8gWSSHxkTlnI0629SdOEjnG5C/akURsFPIv9yBkmcIaoYO8yGXDVrfgNLv0Ahs LhyxdnOD44Z3jS+9mTLfuz8Mv0alzPlrCO0HnSlolgUycwYovbY8ZcK/Ra+MlqlIPDCy TmLEaxmf7+snKMrdz0+FVjINT2DFVcPTETsLXLpf0gQtIwJOZttOuhKMh8T8KjzZ8dzG xj8SpDFTYRQ7t8y1ew1gpZIuxoU6OJJ4IkDQVdKucAk9L4wYH6JjDW+86oSE6ENVLaly vsoWJWD1rptAGPbCG0+pqXGXe00XU2HxAaZf91A6d/Plq/P4Qp8FhOWXah4shytCVnWL PJIg== X-Gm-Message-State: AJcUukdlHMyU9qNu5UqsmRxdvyu/WLzOBO+/6mDI8aKtNffU2Y8Td5Hj 6BwNMcwTkLdkF9hb86V/+Fdwow== X-Received: by 2002:a65:4646:: with SMTP id k6mr15151021pgr.153.1547862267613; Fri, 18 Jan 2019 17:44:27 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:27 -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 v6 6/8] perf cs-etm: Add traceID in packet Date: Sat, 19 Jan 2019 09:43:45 +0800 Message-Id: <20190119014347.27441-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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 --- 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 Reviewed-by: Mathieu Poirier 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 Sat Jan 19 01:43:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156115 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903701jaa; Fri, 18 Jan 2019 17:44:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN5UgfCrOGvEomejW0Tb/YoZt9Wah0f5zGZRnadTcEkzJuKmffd3Z3QROzmS6mtnjtNgquKC X-Received: by 2002:a62:6b8a:: with SMTP id g132mr21773955pfc.201.1547862280481; Fri, 18 Jan 2019 17:44:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862280; cv=none; d=google.com; s=arc-20160816; b=xN0fX/02/ifTDpJKL3VYUZ+A+tpwxHKOg54mMf+Vye8LKnLfMOUoNcWaLQywCc2ZPm 1qgormetfQIwLsvZRVA/uZjOed/MauzB10fmFOx/1+xqHO6P6/CpRDDvsqFvUI+B8qxu gQebrfj57TIquXLrLTPByyj73KVVM2HkTtSEza9joKt/uAPIFYpDqlgiCoRcWBm8VGGW H2I58fu2shu6UXZrfj5iql76gyUXcZNL/APQucQ/jDMX3ZWxo4O4tLLMsqzuu13+9WuU Q5jmx8ec75C9Zhj+jYFV3HKhu9wFblhM8uuFbYFregaDUWsb8RF0aQBz5ketxxqGEsVs 7l4A== 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=o1aW2CGhgLBcMWaKcauQr3Shg1QlhxeZRzbbJRZFOWM=; b=XChR981AtMApy4nV2AJPdn1FQPb7bMcWvuI0Va43h5lFK7Ywi02AY4io1WKEbZ0rHA d76cZw+rupQOjgUp9st1kwxfHKDWiLwuJ103bBE8ORKcHa0IFjUo3vXMS7hmjpi0WVDn gEYsOmQPHtiCkDk8tAxhI5MKZfiMYhxu7KY5sUS99b/zEZOgK0dgmjfZr82X603j5tYk c9yjUhMEizlxKkPoA+wsVB2DLA7jf3XAOb7RWtLqTTOWhfDFCzDYFrpufRWn8DchC5A3 41fQb6g6+IvMKf0vwipRskDhnt2XU2v4FAYfbB9amqn00lIJahjXg+hZmnNYepRd1U2d 7pDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XMV6KsRA; 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 i198si6342512pfe.289.2019.01.18.17.44.40; Fri, 18 Jan 2019 17:44:40 -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=XMV6KsRA; 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 S1730396AbfASBoi (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:38 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33311 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbfASBoc (ORCPT ); Fri, 18 Jan 2019 20:44:32 -0500 Received: by mail-pf1-f196.google.com with SMTP id c123so7454792pfb.0 for ; Fri, 18 Jan 2019 17:44:31 -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=o1aW2CGhgLBcMWaKcauQr3Shg1QlhxeZRzbbJRZFOWM=; b=XMV6KsRAVwwNiIFygSUxuEJEjfFTxYEYRKWJo1A+OrtikQWyXy2FPU4cCy9KtMlX8t WCM0//koL8tlXt22zOFIf5XsM1Q3LwGzm99etd3piH3q0PF+GFj5soqmS6GfcxJwSqvg X5BmOa7kv9EYniirAnTQYA5uSQkKqNlNu2DiQ= 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=o1aW2CGhgLBcMWaKcauQr3Shg1QlhxeZRzbbJRZFOWM=; b=r4hGDSUAkI8S8092GvOEladDUlnT6l81gsmTlSHXFNNqlCzVdhz+JO7TVRqoPwxN2f FEpWZo1p+vDcOpk3fbAusWtYHCgGnyyu4D7vm6Ys1aQsDBlxE7WFLscXyRF6uszediaM 2/WltcFx9hcnbZAhf94z2pgx29qiPG09KvJxwIGxNVdmxzPt+pLZwJHTAcJvlXi5fRg8 Rq68eqQfJOjhSV5CsgvWW1rUbJzgXB6sjbgHJseVR6uNSso/zu5y7jhQhUUkiv8R8qxe CLLyP/Uk3hRN2jor4M5QH7+l0bGHMAeXQr8WDPzGhtYyhg2X2JlTIkISix8W/sWcJtyb 5JJA== X-Gm-Message-State: AJcUukeeV5wwP0bk37ZWSBHUftuLJMZQX4K0nw2oWFkWTOHtPo6BEkBl Y+xNGc+dwoW0qVgIjBi81pepmQ== X-Received: by 2002:a63:70c:: with SMTP id 12mr19418009pgh.352.1547862271298; Fri, 18 Jan 2019 17:44:31 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:30 -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 v6 7/8] perf cs-etm: Set sample flags for exception packet Date: Sat, 19 Jan 2019 09:43:46 +0800 Message-Id: <20190119014347.27441-8-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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. Reviewed-by: Robert Walker Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 215 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.h | 44 ++++++++ 2 files changed, 259 insertions(+) -- 2.17.1 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index e89989fe0a5c..052805de6513 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 5d70d10f3907..7bd16ea8a62d 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 Sat Jan 19 01:43:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 156116 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3903729jaa; Fri, 18 Jan 2019 17:44:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN5wet4EAy2h7kBWXxazMCIS9gMPJMw6mtct0bkXAG3ihiHiZd9k2bXUoik6C4yqRtb1XiaZ X-Received: by 2002:a17:902:128c:: with SMTP id g12mr20497095pla.146.1547862283145; Fri, 18 Jan 2019 17:44:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547862283; cv=none; d=google.com; s=arc-20160816; b=YARRSCYqgUgeg17k1OVTLINzAU7CL8Vui+tf1UaZLmF1nNyyOagKy0+a7XY9t/Wbwt NimC/4W28Q5icc/AoMOCA+cuAJes5anxsHQPxYLGokCLR8BAKqkd0bodf4DMpfnNF+1T oZu1AE6KlTDuproC1luT5FnSmRXB88AN5ZM4wovy41Am7HOZEEU3LlZSlYGJO3TPlCjw 8VqD9JkXTw2QoO7AC7GWmLf9S948LwIiG5QpaizcXo2VpnjF7XoWpAONcLIQ/ZJ2QtV0 mznpfJnRQcLJxrd7yQbOFMARt9tMja/JQNetYLtVve4JQ7nBlgQS/2bJyxu5TtPkxwcx YMsQ== 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=LZ4bZwBosJupXg7CIOURZH9virkdhXUo2HCt4H7yUU8=; b=ixuihdStCsODYdMBY7Kirk5lxX36zJus3ldupE136LK0/bLajuQNnbck8sQE/e4+1k Bs4oeCGS1b8DKY73D9Zxq0tL0vr2bd1AYz/uocaWCdtVbzK7b7sh42T/PqPeC5nKNStl k05PNyzVrm9LEPXkxe4PHa0mc3Ef1GTTliX8tv0JlZ1iBuLm/ILq2pl2rx6qlVNKdVnA zW3SX7n6np+jvhyo/qjFf6zGA6k607FJKjJ+cliZjK4wOZpnrgHJB+7EyNJ5/OrVZuUL nos6lzK2vfD/wSGde3Jpg63i33abtAytmemwRpHDk4eh36n9t8rS/pXVfm9I9b2njCOB Oojg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Fe57EdFx; 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 y8si5767520plr.92.2019.01.18.17.44.42; Fri, 18 Jan 2019 17:44:43 -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=Fe57EdFx; 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 S1730409AbfASBok (ORCPT + 24 others); Fri, 18 Jan 2019 20:44:40 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40647 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730353AbfASBog (ORCPT ); Fri, 18 Jan 2019 20:44:36 -0500 Received: by mail-pg1-f194.google.com with SMTP id z10so6868361pgp.7 for ; Fri, 18 Jan 2019 17:44:35 -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=LZ4bZwBosJupXg7CIOURZH9virkdhXUo2HCt4H7yUU8=; b=Fe57EdFxK6kI+lHGwpQH8xnNTbrW0/jksnNtirzNJTrXF8NB+Akxw9ig42x6GxIgan Oqpnn4Vm9OzKKdSFU4ZTGFM9yj9O+2/xO9KyLf2DrXvq1d1wcKLzzHNSPAwaev1q0PG/ Y87VHwpzpGjJjzFZi8R6PVtBv/Bwy+jbiiAe4= 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=LZ4bZwBosJupXg7CIOURZH9virkdhXUo2HCt4H7yUU8=; b=XfMjcypSBWuPGvZbOd7BioNU2Kh/b+S0LpYvEYQy1y2n1+ZX8FVmyDx62Sv7Q3raqm smqEhUaC0lFbXdiWzw7Rb4WT+Hp5Ve04yqRnHIOYEmYYvBr36uHbCVRiX8YVaKozUKvx r/xNM7Dk2gg9pzO2vjNzwvh7U5saQN+ygBCglXZTVpB8SYpD6sz5soVakLWq+6eUrGFo YxT2moLF3pb6GXE0yeJhzg7ZWPHXjO0+SEXZZNe1xaTyl5THV5a86h68xeglCKqIEol8 4dwCGEGTciNVtyab73Ko5ZCIWgRK69OQjBN4+4YBCXumeWjORbCE54Bq+jrhoTdkgEDJ eD7A== X-Gm-Message-State: AJcUukcBB3l92JxRjftKahbi3W98GuNn+mG6+yR7H1O1z5TfQAdUnJmw NcAa3VaF/wPFH2vgx+AM+lBVVA== X-Received: by 2002:a62:2082:: with SMTP id m2mr21222637pfj.163.1547862274868; Fri, 18 Jan 2019 17:44:34 -0800 (PST) Received: from localhost.localdomain (li421-24.members.linode.com. [50.116.3.24]) by smtp.gmail.com with ESMTPSA id d21sm8648436pfo.162.2019.01.18.17.44.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 17:44:34 -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 v6 8/8] perf cs-etm: Set sample flags for exception return packet Date: Sat, 19 Jan 2019 09:43:47 +0800 Message-Id: <20190119014347.27441-9-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119014347.27441-1-leo.yan@linaro.org> References: <20190119014347.27441-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 052805de6513..7547a7178f46 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;