From patchwork Mon Jan 15 18:13:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 124548 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp751847lje; Mon, 15 Jan 2018 10:13:37 -0800 (PST) X-Google-Smtp-Source: ACJfBouyjXEt/TrknRt3cpHTPmHS7lGYTntmlH9YSUrPTxY5RRoB8OvVDfdXf5PrHMeImHNr+Tnz X-Received: by 10.99.143.10 with SMTP id n10mr29423423pgd.212.1516040016827; Mon, 15 Jan 2018 10:13:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516040016; cv=none; d=google.com; s=arc-20160816; b=lnHYusbOemvXEkRaxIoBWHws0nbnsYZwO6y3alaZgpjNV9tDBSP5lu10RtO8VVzAZe UwH/vneETtEpLR95+KrJ7fVON3ZleDvPGMeMZiXOP9nNpgvOCo5uKaCX53vFvcEf9rLs FY4bv0lr+FGmuTsKuzy0a+cYKCIFNz6vbd+9C5f5IPTtFfJGReiHOWKDf88yLc1c/aY4 vUDfhPYdlGnvzQJDpNvLx42UI2/NFo+GPqq1BF9vAk+AZFSpmZterMcYzLDkcFpVf1YH ndM/HcW9IdJjgXgnCpslhSdiY8Iq9oTH95i6ggHEIBfrc/lprsXxWE+2DTvzKhSn1caH sPyw== 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:arc-authentication-results; bh=5jFdWvQHmBRzHkJxZHbVXWO2q05IMe9m2gaQjutTajQ=; b=E16CjOn4uim/2qQNxdk5VnOd9JdyOiCnVg7AF9bqu/r7sHCTAjSJjW3JLC9JDCIIpP hn54dgnYcSwe3obfmTfgMoZJ3gzvmAxjthP2MXieF+Q9kLYFigoyS1aP0WQYbIFpFdpS QR5G71oaaJRCVHa6IZ3RPd+Y3QoifRTzp8lfLDRQBqsvsIUS/AdRnRd/IjA/3XwY60/6 Av6CrYg4hKU9xiW4GJzrAj8nQ4WZ9fJWz9dqZrcPy3rgt0ub8slnlQ2w9hhGc354pZXZ hSOSJCR//bcvKOWXZyFgOKUYIV2G9V7CbQfO23F+EnrVytW8fhB4xeAPKkwTH3a5tL+f 4v0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IuShW6u0; 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 t14si130799pgc.793.2018.01.15.10.13.36; Mon, 15 Jan 2018 10:13:36 -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=IuShW6u0; 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 S1751306AbeAOSNe (ORCPT + 28 others); Mon, 15 Jan 2018 13:13:34 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:34160 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751142AbeAOSN3 (ORCPT ); Mon, 15 Jan 2018 13:13:29 -0500 Received: by mail-it0-f65.google.com with SMTP id m11so9119525iti.1 for ; Mon, 15 Jan 2018 10:13:28 -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=5jFdWvQHmBRzHkJxZHbVXWO2q05IMe9m2gaQjutTajQ=; b=IuShW6u0WX/mUwV5k0VxXygFBM6BBXt3FihdHG8sbfW11j5m+XyLutyL3qGTLT/iVC wis6E1ZhoYzl8MRApy4LlTLKLUubqjsmTa6QqfPt+5G+ED/kNtSQchf6Dy2Q6rCQuyCa /njtlWsGRIsvoUjFDjCIMtuygU5aQ3ktJfNrg= 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=5jFdWvQHmBRzHkJxZHbVXWO2q05IMe9m2gaQjutTajQ=; b=NuUkBxHOyV8w55WJS0qoMovXWilQpwaPoas/MOr1MHIQcf7xeQiGmE7kskxFWw+wLt AjpRytthp3RVGDnNrQ/gccv9rWro1XIaeFwtsNK5MIOsQZiqEK4PdUSQzJhzAJCfG+mP ljBaBV8kYDlzslrK/1uCSGZkNDFQVa4nUmAMKXFn5dkTBLXyrCTbfpC7pfP0VrDrv1bX NEv5P9BYdJdCPCsXEjNburY9F/Svjj2q9YYpu88X6bxrn+6ALxUJPDwhhtyn24L9+RMC ynGWo9jr6lTXM9/JP8JHaum00nRWEPnD3GDcHY1W7D13WDlVmhCBLGeQlW3sZBhgqqQ6 hMfw== X-Gm-Message-State: AKwxytfV6YfYcnRQMAp2T9Q7uWig2TZeA4bUbPhOefGu3TlqSn2GNkzy MF2TFCS5EZ976llsJj7ckMhNaw== X-Received: by 10.36.39.138 with SMTP id g132mr15175681ita.89.1516040008597; Mon, 15 Jan 2018 10:13:28 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id w142sm231480ita.25.2018.01.15.10.13.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Jan 2018 10:13:27 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, adrian.hunter@intel.com, mike.leach@arm.com, suzuki.poulosi@arm.com, jolsa@redhat.com, kim.phillips@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 05/10] perf tools: Add support for decoding CoreSight trace data Date: Mon, 15 Jan 2018 11:13:09 -0700 Message-Id: <1516039994-314-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516039994-314-1-git-send-email-mathieu.poirier@linaro.org> References: <1516039994-314-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding functionality to create a CoreSight trace decoder capable of decoding trace data pushed by a client application. Co-authored-by: Tor Jeremiassen Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 119 ++++++++++++++++++++++++ 1 file changed, 119 insertions(+) -- 2.7.4 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 6a4c86b1431f..57b020b0b36f 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -200,6 +200,121 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) } } +static ocsd_datapath_resp_t +cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, + const ocsd_generic_trace_elem *elem, + const u8 trace_chan_id, + enum cs_etm_sample_type sample_type) +{ + u32 et = 0; + struct int_node *inode = NULL; + + 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) + return OCSD_RESP_FATAL_SYS_ERR; + + et = decoder->tail; + decoder->packet_buffer[et].sample_type = sample_type; + decoder->packet_buffer[et].start_addr = elem->st_addr; + decoder->packet_buffer[et].end_addr = elem->en_addr; + decoder->packet_buffer[et].exc = false; + decoder->packet_buffer[et].exc_ret = false; + decoder->packet_buffer[et].cpu = *((int *)inode->priv); + + /* Wrap around if need be */ + et = (et + 1) & (MAX_BUFFER - 1); + + decoder->tail = et; + decoder->packet_count++; + + if (decoder->packet_count == MAX_BUFFER - 1) + return OCSD_RESP_WAIT; + + return OCSD_RESP_CONT; +} + +static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( + const void *context, + const ocsd_trc_index_t indx __maybe_unused, + const u8 trace_chan_id __maybe_unused, + const ocsd_generic_trace_elem *elem) +{ + ocsd_datapath_resp_t resp = OCSD_RESP_CONT; + struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context; + + switch (elem->elem_type) { + case OCSD_GEN_TRC_ELEM_UNKNOWN: + break; + case OCSD_GEN_TRC_ELEM_NO_SYNC: + decoder->trace_on = false; + break; + case OCSD_GEN_TRC_ELEM_TRACE_ON: + decoder->trace_on = true; + break; + case OCSD_GEN_TRC_ELEM_INSTR_RANGE: + resp = cs_etm_decoder__buffer_packet(decoder, elem, + trace_chan_id, + CS_ETM_RANGE); + break; + case OCSD_GEN_TRC_ELEM_EXCEPTION: + decoder->packet_buffer[decoder->tail].exc = true; + break; + case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: + decoder->packet_buffer[decoder->tail].exc_ret = true; + break; + case OCSD_GEN_TRC_ELEM_PE_CONTEXT: + case OCSD_GEN_TRC_ELEM_EO_TRACE: + case OCSD_GEN_TRC_ELEM_ADDR_NACC: + case OCSD_GEN_TRC_ELEM_TIMESTAMP: + case OCSD_GEN_TRC_ELEM_CYCLE_COUNT: + case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN: + case OCSD_GEN_TRC_ELEM_EVENT: + case OCSD_GEN_TRC_ELEM_SWTRACE: + case OCSD_GEN_TRC_ELEM_CUSTOM: + default: + break; + } + + return resp; +} + +static int cs_etm_decoder__create_etm_packet_decoder( + struct cs_etm_trace_params *t_params, + struct cs_etm_decoder *decoder) +{ + const char *decoder_name; + ocsd_etmv4_cfg trace_config_etmv4; + void *trace_config; + u8 csid; + + switch (t_params->protocol) { + case CS_ETM_PROTO_ETMV4i: + cs_etm_decoder__gen_etmv4_config(t_params, &trace_config_etmv4); + decoder_name = OCSD_BUILTIN_DCD_ETMV4I; + trace_config = &trace_config_etmv4; + break; + default: + return -1; + } + + if (ocsd_dt_create_decoder(decoder->dcd_tree, + decoder_name, + OCSD_CREATE_FLG_FULL_DECODER, + trace_config, &csid)) + return -1; + + if (ocsd_dt_set_gen_elem_outfn(decoder->dcd_tree, + cs_etm_decoder__gen_trace_elem_printer, + decoder)) + return -1; + + return 0; +} + static int cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, struct cs_etm_trace_params *t_params, @@ -208,6 +323,10 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, if (d_params->operation == CS_ETM_OPERATION_PRINT) return cs_etm_decoder__create_etm_packet_printer(t_params, decoder); + else if (d_params->operation == CS_ETM_OPERATION_DECODE) + return cs_etm_decoder__create_etm_packet_decoder(t_params, + decoder); + return -1; }