From patchwork Sun Oct 28 12:34:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10658577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02A18109C for ; Sun, 28 Oct 2018 12:38:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0894329B45 for ; Sun, 28 Oct 2018 12:38:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9F8D29B62; Sun, 28 Oct 2018 12:38:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BBC9A29B45 for ; Sun, 28 Oct 2018 12:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iqN/8BROApcmje0/uJmJLOn+tOiX95NqWxQNz31uss0=; b=D9HQMaYL7QaKGaHiPXoYYv7kuk x/JLra6FIJ2T8brWAZNGK/Qqo/+TF0V7Je1DvVsVpFbTjDI7XsgDnPw9jnbcRMQJNU/TtWekEVloj P0LEBnmx3F1Y31kjIhXc36z/Xu9lE0U221mM1egEWNTqX56g0pTwxxmze3ggj/42EJ+3xt5UWwMUj c1Do/GtUzUBRgKV+IyHJw+v/bpN2zAcisfU8YjnnJ1nHCp77Pd2eTQ6+6gpineW/d12x82+/OM9J6 +VDmdQrxLoLgaSmdPHCHiQHivExznoDq9zyidG+PjaIAPrA5D6rwogLkuzAKOKNVvFgs4kvuvvprS 9G5ExIQA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gGkKh-0003na-U2; Sun, 28 Oct 2018 12:38:20 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gGkI3-0002bb-11 for linux-arm-kernel@lists.infradead.org; Sun, 28 Oct 2018 12:36:05 +0000 Received: by mail-wm1-x344.google.com with SMTP id s10-v6so5519574wmc.5 for ; Sun, 28 Oct 2018 05:35:24 -0700 (PDT) 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=U7cmISxeRZ1YwLrjSKN+D2EuVL5W5QQOYfw6cRMxHkY=; b=PXV2PMnMXWkkrw884OjFKnkkvnIqbKgFYlt9+5+3lrbb4vqDFR57bxltFMDRDDoIve tZ0Y4LydxU0z6ifAd1ZnyYgHWopiNMWFj+OwSf7hfACPkspB9qXdPq674pafwmWFYGh3 9XuzQZleiQM4sKwXrFTNqXlyaYrD7kgPBcLuY= 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=U7cmISxeRZ1YwLrjSKN+D2EuVL5W5QQOYfw6cRMxHkY=; b=CYzFzw3XvoMR8t6TH9dPolFgZA6zbyEgOmV8cT1INC72h1YtTSJDS2TGFVFY8gIkt/ Sqd7gq2npQnjlQDejw+Ok6okJr1w8OtDOuMHMHmpZnuyI8aeMD9amc6X700+1yjSzIM8 zuLig9w5MqseL2QUJ7q0mO4JqGDYBGYfUptHMVdGKMFzM4aOxIpE5TKbpukk+lq+Bsko FILgZ00UNGIKX9aZbeeso+EOEZzgfQ9Rn6See8Mn35v7ICe+T0gSh445y42O0hiZGHXN vY/3x1HVHVqEGf4Mgx+nmFLEhJ6uH671Ghxdx2BxGzlsvHoiWZpGY7EsjtPDV2uIbiqb 5yew== X-Gm-Message-State: AGRZ1gLuB0nhYXOAYrmLZUCqGBSxVjzC3fxXldDWT8nWxH/C1E308sw5 YkS5jbqhE7+B26OspXsWSHAVrQ== X-Google-Smtp-Source: AJdET5f4A3cSplygFF1kgFPUoNEz7N307lgE10SvyHq8ShPp8xvbjwKQvBC6/xNOTygE09C3hrfsUA== X-Received: by 2002:a1c:dcc:: with SMTP id 195-v6mr10665965wmn.117.1540730123521; Sun, 28 Oct 2018 05:35:23 -0700 (PDT) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id v30-v6sm18926830wra.67.2018.10.28.05.35.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Oct 2018 05:35:22 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML , Mike Leach , Robert Walker , Al Grant Subject: [PATCH v1 2/4] perf cs-etm: Track exception number Date: Sun, 28 Oct 2018 20:34:53 +0800 Message-Id: <1540730095-6732-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540730095-6732-1-git-send-email-leo.yan@linaro.org> References: <1540730095-6732-1-git-send-email-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181028_053535_102977_DA8BE93E X-CRM114-Status: GOOD ( 18.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When an exception packet comes, it contains the info 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. But because the exception return packet cannot delivery exception number correctly by decoder thus when prepare sample flags we cannot know what's type for exception return. This patch adds a new 'exc_num' array in decoder structure to record exception number per CPU, the exception number is recorded in the array when the exception packet comes and this exception number can be used by exception return packet. If detect there have discontinuous trace with TRACE_ON packet, the exception number is set to invalid value. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 51 ++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) 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 0f29534..efc4332 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -43,6 +43,7 @@ struct cs_etm_decoder { u32 packet_count; u32 head; u32 tail; + u32 *exc_num; struct cs_etm_packet packet_buffer[MAX_BUFFER]; }; @@ -368,16 +369,44 @@ static ocsd_datapath_resp_t cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, const uint8_t trace_chan_id) { - return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, - CS_ETM_TRACE_ON); + int ret; + struct cs_etm_packet *packet; + + ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_TRACE_ON); + if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) + return ret; + + packet = &decoder->packet_buffer[decoder->tail]; + + /* Clear execption number for discontinuous trace */ + decoder->exc_num[packet->cpu] = UINT32_MAX; + + return ret; } 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; + 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]; + + /* + * Exception number is recorded per CPU and later can be used + * for exception return instruction analysis. + */ + decoder->exc_num[packet->cpu] = elem->exception_number; + + return ret; } static ocsd_datapath_resp_t @@ -413,7 +442,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: @@ -501,6 +530,10 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, if (!decoder) return NULL; + decoder->exc_num = zalloc(sizeof(*decoder->exc_num) * num_cpu); + if (!decoder->exc_num) + goto err_free_decoder; + decoder->data = d_params->data; decoder->prev_return = OCSD_RESP_CONT; cs_etm_decoder__clear_buffer(decoder); @@ -521,7 +554,7 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, decoder->dcd_tree = ocsd_create_dcd_tree(format, flags); if (decoder->dcd_tree == 0) - goto err_free_decoder; + goto err_free_decoder_exc_num; /* init library print logging support */ ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder); @@ -532,6 +565,9 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, cs_etm_decoder__init_raw_frame_logging(d_params, decoder); for (i = 0; i < num_cpu; i++) { + /* init expcetion number to an invalid value */ + decoder->exc_num[i] = UINT32_MAX; + ret = cs_etm_decoder__create_etm_decoder(d_params, &t_params[i], decoder); @@ -543,6 +579,8 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, err_free_decoder_tree: ocsd_destroy_dcd_tree(decoder->dcd_tree); +err_free_decoder_exc_num: + free(decoder->exc_num); err_free_decoder: free(decoder); return NULL; @@ -603,5 +641,6 @@ void cs_etm_decoder__free(struct cs_etm_decoder *decoder) ocsd_destroy_dcd_tree(decoder->dcd_tree); decoder->dcd_tree = NULL; + free(decoder->exc_num); free(decoder); }