From patchwork Wed Jan 17 17:52:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 124899 Delivered-To: patch@linaro.org Received: by 10.46.62.1 with SMTP id l1csp132080lja; Wed, 17 Jan 2018 09:54:28 -0800 (PST) X-Google-Smtp-Source: ACJfBose7t8KlZzcyv2ET2IaWaigrYDwen+r0tvZpKLI9sq6e7Qrn9WUqf7Rn4IswcsszP0l3oQ5 X-Received: by 10.98.91.193 with SMTP id p184mr38714661pfb.16.1516211668529; Wed, 17 Jan 2018 09:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516211668; cv=none; d=google.com; s=arc-20160816; b=wBzo/HXkvDj/8EBSJvgUV+FxFR4WwQ5imx2tT3syeUu0RSrO691MiZlZS8SEDzTHy+ HOPrt9fuDZwMMpomVc9xtDTEg3ykOzAwJ6wImWUO7Q2kqqiZcYMHDoSPO2egwUbFdRhI 0Yz7IEq+/va1cN11TgSySRGGYkwJpoH/W15+a8Gy5yzQQJXidENuahz/X/6o5KFgt/Xr nW8KH3D5DDU3N1gL+qFGNdq7Wsh8/s65nPry+hYm48ZoehfiS/yBR//VFnAoLIVnA4Mm 6HKtPv8M4/tasRw3J94oMA7AppuylUlUkBKC00hoiErP2DK9x78eSIAbuf5Ppexfj8jh 7jow== 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=ml/7DsdbbMCUqt+7JyRd8YNJdyY6ZQk0fwPkbRoodIfLTJ8dbblGBgEDuKmH6Po25s VwSV6LAT0dS/1MY4SZ+jJXXgk88YYkaTGYaZ8wx3z/EmTQ/PwIehUCCDnpwbN5PM0E2g s8u0gUFmAXz3/RBDfC5efTWGXsfexN39BWPOU9gggogViK6zNzxY1ZW+EuKXqW3udPAR MlEoQPd5dExKqgkqZ73wKUFKLmMl7/DpabqOIY7hEdAgK/iWrOh6BEMnMNYHoQEVXScg grT6CXvQlPL1JxAayxBfLx15tjly04xM2Pl3WHVU5q7ZhRpJOOBuKNvjc2Z4F/L2xb62 CAoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DOWC0VB3; 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 c24si4459941plo.608.2018.01.17.09.54.28; Wed, 17 Jan 2018 09:54:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DOWC0VB3; 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 S1754612AbeAQRy1 (ORCPT + 28 others); Wed, 17 Jan 2018 12:54:27 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:37223 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754381AbeAQRwf (ORCPT ); Wed, 17 Jan 2018 12:52:35 -0500 Received: by mail-io0-f193.google.com with SMTP id f89so13722890ioj.4 for ; Wed, 17 Jan 2018 09:52: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=5jFdWvQHmBRzHkJxZHbVXWO2q05IMe9m2gaQjutTajQ=; b=DOWC0VB3Nyl+LlXVUWtDKW1wIy3cOw5pY0vpcB6JwInHcx6TX/1d0f+b0IvbEEy8qF jsAtqpYPV6jNqS44+ZG7NwGJs/jPKMqyLH2o4vK475Ta4cBRF0fehJ2WwMfBY4x8jKKL zC0dIZLWkaiQqd9/GMTfOoH/cCu70/gtiWzT4= 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=DaMeOLnmAu1pFkLKaDthssCS8TZyCNPuRENtud3xy5WY/loWnCHfj9hgCnnAyLx2LK BAPE7YDLZ0ilJguCplVm4d1s3X4d2+63OT3v91FGKS68K9Snf5MFV0BaIe/XQCVd0+5f AkMBHSoxyK4BnsaNfrZs+fFz4kR9QCKwWnkYyaEj2AXxbRRHTXQeuDRIJz8eGc/2jvsl iohcLAyRZ7ioC2j/UICc/BLMRVKPCHaFqL6OIW8N+9hAuNTH/9dVDSF2c1kM0jquYL+k lOZTvdEaCIzdzNFT44ICuMIJ+DT+2K6tJar8EQ1umQteM+w50xBrOMzvKZ/EYXERcNCC oG4w== X-Gm-Message-State: AKwxytdxOZmm5+2vKZOkDDdSiS6ijXYEhayLnoE1EXqSzYM6Xc8MqCD4 ETTq3GyXyq0I7xBstdMhI/3unw== X-Received: by 10.107.9.69 with SMTP id j66mr22528624ioi.91.1516211554768; Wed, 17 Jan 2018 09:52:34 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id h72sm2694392ioe.61.2018.01.17.09.52.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Jan 2018 09:52:33 -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 v3 05/10] perf tools: Add support for decoding CoreSight trace data Date: Wed, 17 Jan 2018 10:52:14 -0700 Message-Id: <1516211539-5166-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516211539-5166-1-git-send-email-mathieu.poirier@linaro.org> References: <1516211539-5166-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; }