From patchwork Fri Dec 15 16:44:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 122128 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp707635qgn; Fri, 15 Dec 2017 08:46:38 -0800 (PST) X-Google-Smtp-Source: ACJfBouzx7v9VMj7c/nback5Lk+/bIbRu3opgCLAxhz7OC8Z9rAGCRkxuPxotIk5wTkfhB/woXwX X-Received: by 10.84.174.131 with SMTP id r3mr14052237plb.358.1513356398044; Fri, 15 Dec 2017 08:46:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513356398; cv=none; d=google.com; s=arc-20160816; b=cx24T5GryQ4I1fHK7t146FltttOe3hJ91ogApzlummgl0Vb0YkXgCTI5TcjfL/xXMM pPi5r6CQTjWncLfUoHwtPwvwqrBophvdBf4akKmpc5qV+wP+dbLe4lbdOihd3u4J2nsa zvsXB9dIqjxRzdW4rRc5GIUgAdWInIYq+At7C2QmNIAqWSJBOWhq76LYQo3JEhlPSlA/ CcZpfaNQ5KUWMGDaN5OCZyAdBr8UMF4DfFv4mHp+zX0kryeWlVz0HdhkV9vOfMmphlOD NQ+vceeXxFVFU53UcSZ/jwsLCPVTAbE3DFY92r3Ty7sk6p+WFX3jiaysI2rSaTagzyFi 0cGQ== 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=0qlbcGSevoxbMfafnJNf9z8slnJsfvSGD7bwutmnDloPJiROYgqGMeBxqpQ1jTtTiC Y7i14YrLRquFI3Miu2uKM6qhMGCsAHfDH+IgGWrgNsu8qUkXtSyoVgc5aKWfASfR/+Fv 4c3t0Z9VgdA+Ux74Pfjo0M5Ig/vwBYBhL2dN2QH8ZcIu/VM5fPskPY2lRgTh+C8XtAww ZrroYTvUrgTyeBlu6GSN/HkhRI6F3QN8kDqHqiGQ5x7soYO0i63TbIPAm29FYm2pzDOj cWHcP9K3UqkE9FhPLdJp52UVZVLezLTAH+9GhultS6gkuoo1wV6vYLUL0g32J3rcGNIt OxLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Oz6PGCrg; 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 b3si5239597plb.293.2017.12.15.08.46.37; Fri, 15 Dec 2017 08:46: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=Oz6PGCrg; 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 S932523AbdLOQqe (ORCPT + 24 others); Fri, 15 Dec 2017 11:46:34 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:45479 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756885AbdLOQpP (ORCPT ); Fri, 15 Dec 2017 11:45:15 -0500 Received: by mail-it0-f67.google.com with SMTP id z6so20874175iti.4 for ; Fri, 15 Dec 2017 08:45: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=5jFdWvQHmBRzHkJxZHbVXWO2q05IMe9m2gaQjutTajQ=; b=Oz6PGCrgKDuoXcqGb1V1gduCY+GDHKS9QRLYhJBRjnPUJQkpEYJn97xJ1ntSev6771 kxZUKFQPsKX+2g8183Qtok8V3dD+87Hp3E4dEXUHoldS691Mymd36crXmX5ewNDeBQbC gvLQ5DQW37Q2JWFPLJZ6hkrx4OoX1P0/hGfms= 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=Shhv/UXc5up8fPFmlPWDqRIwQ8XUdrCAwGTx0CZ72zCY99GoVc+3bkURQOxSa6S/KJ eDbFF5pDVNXodWgBKMB/u082izO+Mvb5RLALS4IoeZ2WgFEMSmvY8Wr4dcefd0F8CVme pS+t4+rgLRUKvqh8Ae0A1ULdY7uRMEuW5bLkn55+U1+91ewGbpdkc+s82zqMYAj/7RCn W2gtKzMjg5aeF/43lDbrjix51PGGDMzaNELclE5l20Z7jVKJYkUWP34ZaJBO/0/SZICk +jQmyl9YhAqtUg9ch3Uw8Xa39V+4C0h6Tye1AnCs7jMT/BEQWUhaPrUztxUaAAcl+Abt KxCw== X-Gm-Message-State: AKGB3mKYxNpNM4kbnY00mWc42ITEMhfEQ45eQOEQ/MiV3zj3/tZTUU3I amsVtfSSiEEmqRw53VTLR4Q7Zg== X-Received: by 10.107.198.67 with SMTP id w64mr12637212iof.264.1513356314871; Fri, 15 Dec 2017 08:45:14 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id q132sm3631732iod.26.2017.12.15.08.45.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Dec 2017 08:45:13 -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, tor@ti.com, jolsa@redhat.com, mathieu.poirier@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 05/10] perf tools: Add support for decoding CoreSight trace data Date: Fri, 15 Dec 2017 09:44:54 -0700 Message-Id: <1513356299-26274-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513356299-26274-1-git-send-email-mathieu.poirier@linaro.org> References: <1513356299-26274-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; }