From patchwork Sun Oct 28 12:34:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 149611 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2936566ljp; Sun, 28 Oct 2018 05:35:27 -0700 (PDT) X-Google-Smtp-Source: AJdET5fe8DGaOqjhuEjbGPlySQsX3OCeWy5oSGp4vdlR0ITb+pXj/17m+jun/63ZqB66J34HjuBD X-Received: by 2002:a17:902:96a:: with SMTP id 97-v6mr10088142plm.32.1540730127810; Sun, 28 Oct 2018 05:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540730127; cv=none; d=google.com; s=arc-20160816; b=X+SAZC4nwchl6Bq6svZ/TQ3VYVfdjfLMrexMgN0ReayNoijv4yj+mc66DzUqyjrQNB DX748s7PYRYH5yPu8HIYISQ+7Gumvt4UL78lIb1Jy+7LUHj+yjir+EArXdq16BWfn0Sm JJ1sMNxPzPN8mMul7Umm7ofzIqp3ZLVq0i0/yYnzMOAccM4Rkrec4qnuQ0c2fp716Sp7 8gMaPT23d0AQ/GfDo2ND2ZaoTakwM7Cvam7LG6jgbBYWl3ohS82x3p/GIR1zGL7gcVE5 1uM9KLZ4RVp9RY2KT9d5spklCNCuTNjxgg702qQ3v2mICR8hugpfx69SVYWyJI9rC9SI FPiw== 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=s+NHTUB7pfNBjEo78ziP+WElxaiTy4RpvBG7rDrtCt8=; b=iGdY+CI4UyAjQcMkRUnXPBYNLuCajjI+qnwyogmV4F0KdyVq6kRPRK8Lihx50yl9cV VvbMwdYh5oN8GA0GsNZckVjVGNLRhP0bjRV8/no2dh1mIcoXb8QkJpObgYhgnWP8aVG8 gvNk/RyinvFL5xFlb3tZElYVVqbdxhsPbms8xJ9TXfZleUYrMXVvT9FD6Mh7Q+w0h3kc 4nDhtgq4Yc+ENwCqHEQSXORlgDT/Cv25tB8hrFKGv5gbxAKnbkVMGhBMJsSUV1Nz+CW6 qhp7XYpaNhz+/FT+wlKgE/tv0V2Ne64EQTrssB5RG3Ghg3jkVOMnNXqxAXgfv5mqbwGL DWsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O938Kxdj; 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 b12-v6si17522079pgj.87.2018.10.28.05.35.27; Sun, 28 Oct 2018 05:35:27 -0700 (PDT) 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=O938Kxdj; 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 S1727591AbeJ1VTw (ORCPT + 32 others); Sun, 28 Oct 2018 17:19:52 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40843 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbeJ1VTw (ORCPT ); Sun, 28 Oct 2018 17:19:52 -0400 Received: by mail-wr1-f67.google.com with SMTP id i17-v6so5666600wre.7 for ; Sun, 28 Oct 2018 05:35:20 -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=s+NHTUB7pfNBjEo78ziP+WElxaiTy4RpvBG7rDrtCt8=; b=O938KxdjH1YaBQ+tWXcEau6a4x8JQ1yYnl7fGZ6xehfBJpTkzHWkbt5nfYQeB12rkG EUJhfO/syosPDB/hPaheH6xWf8bfc4dfkd0bJhXgHn39NxKpFUT4exI1T2DmTYcCXrLo 1Ka776AyGMn1ZkW2HxmjBI2Nz4xiGjPE4skNQ= 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=s+NHTUB7pfNBjEo78ziP+WElxaiTy4RpvBG7rDrtCt8=; b=PtF84oXMHInLDGTQ8vo9T0v/mLk/71bnFixNuw/7tBuxEya9GR857X76EavRlzozsV CNdp+Qflh9PqdwGKYp4XYi8yXs2RZYWOVU2h1Gtfb8P32UwWlPFvZGx/X3FYwj6pIMp1 ykFprJxF1XV5YzXbb3cT0/XTkl6w0HYTZQCe8/Tedbth8kN+J5f1dAzmzXs6qxNlnF8Q WmET/rSmnideD7BC6YY7DdqIIdUL/bAVkW4hTFdjrIxXyKk5pgSUAGQtGFIiwyi56DAl vk0h5VEyQ9thNAgw/brhmQn37dSQRgl2nvYvYuCG0/e5CsQK+L19KR/eXGka9HW9RFYA b/Uw== X-Gm-Message-State: AGRZ1gLEw8s+lUHA8BVlNZ8ZjBLWvN/txnDXt+feeauesnFUsl18INhA dwk94exI3Mzxl0108WwP/mqMvQ== X-Received: by 2002:adf:c748:: with SMTP id b8-v6mr11494754wrh.134.1540730119443; Sun, 28 Oct 2018 05:35:19 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Oct 2018 05:35:18 -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 Cc: Leo Yan Subject: [PATCH v1 1/4] perf cs-etm: Generate branch sample for exception packet Date: Sun, 28 Oct 2018 20:34:52 +0800 Message-Id: <1540730095-6732-2-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The exception packet appears as one element with 'elem_type' == OCSD_GEN_TRC_ELEM_EXCEPTION or OCSD_GEN_TRC_ELEM_EXCEPTION_RET, which present for exception entry and exit respectively. The decoder set packet fields 'packet->exc' and 'packet->exc_ret' to indicate the exception packets; but exception packets don't have dedicated sample type and shares the same sample type CS_ETM_RANGE with normal instruction packets. As result, the exception packets are taken as normal instruction packets and this introduces confusion to mix different packet types. Furthermore, these instruction range packets will be processed for branch sample only when 'packet->last_instr_taken_branch' is true, otherwise they will be omitted, this can introduce mess for exception and exception returning due we don't have complete address range info for context switching. To process exception packets properly, this patch introduce two new sample type: CS_ETM_EXCEPTION and CS_ETM_EXCEPTION_RET; for these two kind packets, they will be handled by cs_etm__exception(). The func cs_etm__exception() forces to set previous CS_ETM_RANGE packet flag 'prev_packet->last_instr_taken_branch' to true, this matches well with the program flow when the exception is trapped from user space to kernel space, no matter if the most recent flow has branch taken or not; this is also safe for returning to user space after exception handling. After exception packets have their own sample type, the packet fields 'packet->exc' and 'packet->exc_ret' aren't needed anymore, so remove them. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 26 +++++++++++++++++------ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 10 ++++----- tools/perf/util/cs-etm.c | 28 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) -- 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 5efb616..0f29534 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -269,8 +269,6 @@ 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].exc = false; - decoder->packet_buffer[i].exc_ret = false; decoder->packet_buffer[i].cpu = INT_MIN; } } @@ -298,8 +296,6 @@ 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].exc = false; - decoder->packet_buffer[et].exc_ret = false; decoder->packet_buffer[et].cpu = *((int *)inode->priv); decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; @@ -376,6 +372,22 @@ cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, CS_ETM_TRACE_ON); } +static ocsd_datapath_resp_t +cs_etm_decoder__buffer_exception(struct cs_etm_decoder *decoder, + const uint8_t trace_chan_id) +{ + return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_EXCEPTION); +} + +static ocsd_datapath_resp_t +cs_etm_decoder__buffer_exception_ret(struct cs_etm_decoder *decoder, + const uint8_t trace_chan_id) +{ + return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + CS_ETM_EXCEPTION_RET); +} + static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, const ocsd_trc_index_t indx __maybe_unused, @@ -401,10 +413,12 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: - decoder->packet_buffer[decoder->tail].exc = true; + resp = cs_etm_decoder__buffer_exception(decoder, + trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: - decoder->packet_buffer[decoder->tail].exc_ret = true; + resp = cs_etm_decoder__buffer_exception_ret(decoder, + trace_chan_id); break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: case OCSD_GEN_TRC_ELEM_EO_TRACE: 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 9351bd1..217bcc6 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -23,9 +23,11 @@ struct cs_etm_buffer { }; enum cs_etm_sample_type { - CS_ETM_EMPTY = 0, - CS_ETM_RANGE = 1 << 0, - CS_ETM_TRACE_ON = 1 << 1, + CS_ETM_EMPTY = 0, + CS_ETM_RANGE = 1 << 0, + CS_ETM_TRACE_ON = 1 << 1, + CS_ETM_EXCEPTION = 1 << 2, + CS_ETM_EXCEPTION_RET = 1 << 3, }; enum cs_etm_isa { @@ -43,8 +45,6 @@ struct cs_etm_packet { u32 instr_count; u8 last_instr_taken_branch; u8 last_instr_size; - u8 exc; - u8 exc_ret; int cpu; }; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 908bf9f..00a95d7 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -933,6 +933,25 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) return 0; } +static int cs_etm__exception(struct cs_etm_queue *etmq) +{ + /* + * When the exception packet is inserted, whether the last instruction + * in previous range packet is taken branch or not, we need to force + * to set 'prev_packet->last_instr_taken_branch' to true. This ensures + * to generate branch sample for the instruction range before the + * exception is trapped to kernel or before the exception returning. + * + * The exception packet includes the dummy address values, so don't + * swap PACKET with PREV_PACKET. This keeps PREV_PACKET to be useful + * for generating instruction and branch samples. + */ + if (etmq->prev_packet->sample_type == CS_ETM_RANGE) + etmq->prev_packet->last_instr_taken_branch = true; + + return 0; +} + static int cs_etm__flush(struct cs_etm_queue *etmq) { int err = 0; @@ -1048,6 +1067,15 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ cs_etm__sample(etmq); break; + case CS_ETM_EXCEPTION: + case CS_ETM_EXCEPTION_RET: + /* + * If the exception packet is coming, + * make sure the previous instruction + * range packet to be handled properly. + */ + cs_etm__exception(etmq); + break; case CS_ETM_TRACE_ON: /* * Discontinuity in trace, flush 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: 149612 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2936573ljp; Sun, 28 Oct 2018 05:35:28 -0700 (PDT) X-Google-Smtp-Source: AJdET5f1lNa/xYLEopbuknswONTPa2Cd+vV0RElCI/levgoOAO6+ditBknWhXfYS8UAm+xqIkCJW X-Received: by 2002:a17:902:bd01:: with SMTP id p1-v6mr10269472pls.63.1540730128203; Sun, 28 Oct 2018 05:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540730128; cv=none; d=google.com; s=arc-20160816; b=UzvxUp4m42fniW3BGHG50oU/KYjqqCNQGAxXRMhgmc5eUVT2AFlxwXJgH/KJWeOvjr lhxdKjQbwBQCAYMoRTi1oZsKX6xQYMzaO0Jc8xRwWS7frOTVQr8w1xwbGTWbvPKFpPI2 OB0s3n23vg2ReqfpPvfby7wmO6jGTmiEFz0VzTf9KxBHTeTbr2pJM1UcAVEpKCe/S373 cp/bimKjcP9Bix+6ZP0ird8U46eMCJ1zC2YFnXcvDV+FULJxa3nUbGtaIFF8333BCCUQ bM2Co1HHALa89BDqjJNz9Ar5Ax8rQTp0+g/1ncB2hSJb1LUuPASpusikUnTjwK6CADsO Exzw== 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=U7cmISxeRZ1YwLrjSKN+D2EuVL5W5QQOYfw6cRMxHkY=; b=ntbv64pMTEnz45IABNI/5GujVPHFSI0C145JAjC+YXkmnbIEpS7m+6e8K/44FEWjul UmGalM/QtRv81GU6PwLZrZnW+IkltlrHP+qKfelPABgx1CqS/kZbUJOtLva1VKeF1vaZ vh/RGFSS0jK0lXHivsFSa+sMlt2loiwknY52Ee08PJY4PSC0b+ipGwB0+oV0WGp8hp+w BHOJAvou0HKRVIIpmMoruQ9Y0qXJrqRRIurprI4TPOPaqUbrkfojn0sMVkThR4w9dOqw KY+HDXHq7Xm/yGvnk8jhvd31X1xfYcOWoyWdr27RBXrjsEadQx1DjVm3I1cWnMtKOHog N3cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PXV2PMnM; 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 b12-v6si17522079pgj.87.2018.10.28.05.35.27; Sun, 28 Oct 2018 05:35:28 -0700 (PDT) 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=PXV2PMnM; 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 S1727610AbeJ1VT5 (ORCPT + 32 others); Sun, 28 Oct 2018 17:19:57 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52102 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbeJ1VT5 (ORCPT ); Sun, 28 Oct 2018 17:19:57 -0400 Received: by mail-wm1-f68.google.com with SMTP id 143-v6so5493448wmf.1 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=VEU5+jnsvC1/TZeKfs+CA4dErbbNfH0gPpWztj4hgTe8JK4YMGNgW4wprEjG1LyZMb KG8f6n0WcwVSRJAO4pLbfTo+R/axI5TJDeRFqsiGhF2EfmJPh0cOvR4MHBEGodMG+VIP r6veoW1tn9Kpq1gs+f7Ol8SlvB7PgBuZRNgmck05rfmvGhKxhrSyupJBi6VoY4Ut6B2F CFTd143rta6hqcsFE6jUEO+48+Q4I3nQwdnrQx/mwZm1tn+UcBQrOEGF0noGvOWnBB3O BtsIkUFYL+lePjIsdqyc/r453CW++Eqsbf/aKlvusMQ7clBXSkrq7VsbwoeBLETgxa6U SuRw== X-Gm-Message-State: AGRZ1gKmzgR5RcwDZnl0f8YAYmwiBlqp7Z+odpk0NS8n0xycoCG2EsHC +lrc5V1ne3imOI9K9uTk49LnOg== 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 Cc: Leo Yan 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> 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 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(-) -- 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 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); } From patchwork Sun Oct 28 12:34:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 149613 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2936749ljp; Sun, 28 Oct 2018 05:35:41 -0700 (PDT) X-Google-Smtp-Source: AJdET5cH5zmJszsVXo6IMjJBf8Ai2oPUzBoq2pRi24iY2Ld9AFGGvg1t2DnqHBJagpYHq55AMWHn X-Received: by 2002:a63:907:: with SMTP id 7-v6mr10052329pgj.121.1540730141837; Sun, 28 Oct 2018 05:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540730141; cv=none; d=google.com; s=arc-20160816; b=bL6bvXCM+zGtPtDfDIBp+6UDOx2r+lXExXpUqTrQVWNq/j+Kz8F0lxq5/Fm6i7HFrz hVc/RGgzamyw2Z+2hhlwgMFWfcvQ1y9e4modGxEA+s1cpFNMwbXaaJvdTB0KsuXcfE89 62ko7Q5JjbIdBCsgmMXw03MJePJvp009EVJeyBlOL5RUXrPDuF9PjFtcPR1PbFBrsTaq MXLhvM/lrjb7VUDeTh76S1N6ItwDJqpLPaQnMvc3C6RRtv1YRzw696ANQoJBhN0MdLZ3 2DUuWNYQadhJ6Ru3CHVBI6Ez3+cJvj6dfOf3j16sZPIFyZ3stXEgyoVhbWWA5KpDV11W gubw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g10rRHd0ZhNu2NGwcQ3gXngqsbd7SmjVfDWdOWtq8fo=; b=kwPmibOpgFWDaFfRz/aNXhs2xbivWxkY5xwHrk2KgORYmSJ9rQD2IJQYdWCq/9kzzM X3EBpCiVAh6Vqd3icc5SA/ZZfibtFvqq6w0+0QjBGxV0YtSyYO+k6p3PwHiiTWvZ3Zdu dG4/t80mM+AcxYLrSbMW5T6MfTMsvlqU+HWEQHnpbVgEXH9bROhsAebR2VZZ3ctmLFoF uQeA0002cuUBG+nH8dfV0ScVsBS6PcWMbPCScxpiU6b/oS4Q+SPvHy2uiNIc0n0KHedb H0wVMFek42hCrOJzQDxeW57juemdxtuW/eT+BSe+xHxRW/4p4ZPp5nmkxPD+IdforWY8 Hwnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eDUG84Td; 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 k192-v6si17286895pgc.415.2018.10.28.05.35.41; Sun, 28 Oct 2018 05:35:41 -0700 (PDT) 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=eDUG84Td; 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 S1727629AbeJ1VUC (ORCPT + 32 others); Sun, 28 Oct 2018 17:20:02 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46748 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbeJ1VUB (ORCPT ); Sun, 28 Oct 2018 17:20:01 -0400 Received: by mail-wr1-f66.google.com with SMTP id i4-v6so5683925wrr.13 for ; Sun, 28 Oct 2018 05:35:29 -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 :mime-version:content-transfer-encoding; bh=g10rRHd0ZhNu2NGwcQ3gXngqsbd7SmjVfDWdOWtq8fo=; b=eDUG84Tdbb/bWq4gfurvvSY9Y+ww+etsL/R4LFSjQfuRDsyX8X/ECEWdl7yIUCQFSR vko76xzZdUGknWZOMx/WwNb1o4FrSDDsy9NwKac+z31ZI7BvxZCci/f8xviVYp5DvzZP uo7HvTZNebjYHVUGa3iVouUpGYtYY/U6j7JOQ= 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:mime-version:content-transfer-encoding; bh=g10rRHd0ZhNu2NGwcQ3gXngqsbd7SmjVfDWdOWtq8fo=; b=GYF3aEjOu2WtQrObDUfaFG4pC5JdyWBy6olVVjcdSVU7E2fMHIrJgPiG7poqEBdTGk SNMGC3WrLY1xk1XYoXqLX50FRdVDG86oMM3gGyq5YdVgFJK0S19+7XqvezuEbV0+6Z0+ +njmA+o37IC8IZis6G7qLkD2+4qnMcdJhcpYLr2cjKw0jqpO4y+Y9k6V05oOQzU5Jp0I U2jFksFAGa5NbTubcC41O7AOW+hQ+5vB37SPE4/i9N1BPgEEHTK8Zi7rcqwvMGFEN/yf C6Ai1gYaEW2B5BdhN7hgvy4U1FLRHReDOXXffXxZsuQfxyjSvXxUCT/EwoVJNRiRXT+h 9Pxg== X-Gm-Message-State: AGRZ1gIlxWu1yF7URnje5MI1i3ZyTYLHqqJcSCRFMl9rNjcTtLK2oLOA vmzdC4P83Ty+6sc8fRjjxeDfTA== X-Received: by 2002:adf:b612:: with SMTP id f18-v6mr10592519wre.120.1540730128387; Sun, 28 Oct 2018 05:35:28 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Oct 2018 05:35:27 -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 Cc: Leo Yan , Andi Kleen , Adrian Hunter , Arnaldo Carvalho de Melo Subject: [PATCH v1 3/4] perf cs-etm: Set branch instruction flags in packet Date: Sun, 28 Oct 2018 20:34:54 +0800 Message-Id: <1540730095-6732-4-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> MIME-Version: 1.0 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. Arm CoreSight ETM supports different kinds instruction of A64, A32 and T32; this patch is to set branch instruction flags in packet for these ISAs. The brief idea for patch implementation is describe as below: - For element with OCSD_GEN_TRC_ELEM_TRACE_ON type, it is taken as trace beginning packet; for element with OCSD_GEN_TRC_ELEM_NO_SYNC or OCSD_GEN_TRC_ELEM_EO_TRACE, these two kinds elements are used to set for trace end; As Mike suggested the packet stream might have more than one two TRACE_ON packets, the first one TRACE_ON packet indicates trace end and the second one is taken as trace restarting. We will handle this special case in the upper layer with packet queue handling, which has more context so it's more suitable fix up for it. This will be accomplished in the sequential patch. - For instruction range packet, mainly base on three factors to decide the branch instruction types: elem->last_i_type elem->last_i_subtype elem->last_instr_cond If the instruction is immediate branch but without link and return flag, we consider it as function internal branch; in fact the immediate branch also can be used to invoke the function entry, usually this is only used in assembly code to directly call a symbol and don't expect to return back; after reviewing kernel normal functions and user space programs, both of them are very seldom to use immediate branch for function call. On the other hand, if we want to decide the immediate branch is for function branch jumping or for function calling, we need to rely on the start address of next packet and check the symbol offset for the start address, this will introduce much complexity in the implementation. So for this version we simply consider immediate branch as function internal branch. Moreover, we rely on 'elem->last_instr_cond' to decide if the branch instruction is a conditional branch or not. If the instruction is immediate branch with link, it's instruction 'BL' and which is used for function call. If the instruction is indirect branch and with subtype OCSD_S_INSTR_V7_IMPLIED_RET, the decoders gives the hint the function return for below cases related with A32/T32 instruction; set this branch flag as function return (Thanks for Al's suggestion). BX R14 MOV PC, LR POP {…, PC} LDR PC, [SP], #offset If the instruction is indirect branch without link, this is corresponding to instruction 'BR', this instruction usually is used for dynamic link lib with below usage; so we think it's a return instruction. 0000000000000680 <.plt>: 680: a9bf7bf0 stp x16, x30, [sp, #-16]! 684: 90000090 adrp x16, 10000 <__FRAME_END__+0xf630> 688: f947fe11 ldr x17, [x16, #4088] 68c: 913fe210 add x16, x16, #0xff8 690: d61f0220 br x17 If the instruction is indirect branch with link, e.g BLR, we think it's a function call. For function return, ARMv8 introduces a dedicated instruction 'ret', which has flag of OCSD_S_INSTR_V8_RET. - For exception packets, this patch divides into three types: The first type of exception is caused by external logics like bus, interrupt controller, debug module or PE reset or halt; this is corresponding to flags "bcyi" which defined in doc perf-script.txt; The second type is for system call, this is set as "bcs" by following definition in the doc; The third type is for CPU trap, data and instruction prefetch abort, alignment abort; usually these exceptions are synchronous for CPU, so set them as "bci" type. Cc: Mathieu Poirier Cc: Mike Leach Cc: Robert Walker Cc: Al Grant Cc: Andi Kleen Cc: Adrian Hunter Cc: Arnaldo Carvalho de Melo Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 168 ++++++++++++++++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + 2 files changed, 169 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 efc4332..cbfd730 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -303,6 +303,7 @@ 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].flags = 0; if (decoder->packet_count == MAX_BUFFER - 1) return OCSD_RESP_WAIT; @@ -417,6 +418,171 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_decoder *decoder, CS_ETM_EXCEPTION_RET); } +static void cs_etm_decoder__set_sample_flags( + const void *context, + const ocsd_generic_trace_elem *elem) +{ + struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context; + struct cs_etm_packet *packet; + u32 exc_num; + + packet = &decoder->packet_buffer[decoder->tail]; + + switch (elem->elem_type) { + case OCSD_GEN_TRC_ELEM_TRACE_ON: + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_BEGIN; + break; + + case OCSD_GEN_TRC_ELEM_NO_SYNC: + case OCSD_GEN_TRC_ELEM_EO_TRACE: + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_END; + break; + + case OCSD_GEN_TRC_ELEM_INSTR_RANGE: + /* + * Immediate branch instruction without neither link nor + * return flag, it's normal branch instruction within + * the function. + */ + if (elem->last_i_type == OCSD_INSTR_BR && + elem->last_i_subtype == OCSD_S_INSTR_NONE) { + packet->flags = PERF_IP_FLAG_BRANCH; + + if (elem->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 (elem->last_i_type == OCSD_INSTR_BR && + elem->last_i_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 (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_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 (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_NONE) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + /* + * Indirect branch instruction with link (e.g. BLR), this is + * branch instruction for function call. + */ + if (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_BR_LINK) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL; + + /* Return instruction for function return. */ + if (elem->last_i_type == OCSD_INSTR_BR_INDIRECT && + elem->last_i_subtype == OCSD_S_INSTR_V8_RET) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN; + + break; + + case OCSD_GEN_TRC_ELEM_EXCEPTION: + +#define OCSD_EXC_RESET 0 +#define OCSD_EXC_DEBUG_HALT 1 +#define OCSD_EXC_CALL 2 +#define OCSD_EXC_TRAP 3 +#define OCSD_EXC_SYSTEM_ERROR 4 +#define OCSD_EXC_INST_DEBUG 6 +#define OCSD_EXC_DATA_DEBUG 7 +#define OCSD_EXC_ALIGNMENT 10 +#define OCSD_EXC_INST_FAULT 11 +#define OCSD_EXC_DATA_FAULT 12 +#define OCSD_EXC_IRQ 14 +#define OCSD_EXC_FIQ 15 + + exc_num = decoder->exc_num[packet->cpu]; + + /* + * The exceptions are triggered by external signals + * from bus, interrupt controller, debug module, + * PE reset or halt. + */ + if (exc_num == OCSD_EXC_RESET || + exc_num == OCSD_EXC_DEBUG_HALT || + exc_num == OCSD_EXC_SYSTEM_ERROR || + exc_num == OCSD_EXC_INST_DEBUG || + exc_num == OCSD_EXC_DATA_DEBUG || + exc_num == OCSD_EXC_IRQ || + exc_num == OCSD_EXC_FIQ) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_ASYNC | + PERF_IP_FLAG_INTERRUPT; + + /* The exception is for system call. */ + if (exc_num == OCSD_EXC_CALL) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_SYSCALLRET; + + /* + * The exception is introduced by trap, instruction & + * data fault or alignment errors. + */ + if (exc_num == OCSD_EXC_TRAP || + exc_num == OCSD_EXC_ALIGNMENT || + exc_num == OCSD_EXC_INST_FAULT || + exc_num == OCSD_EXC_DATA_FAULT) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_CALL | + PERF_IP_FLAG_INTERRUPT; + + break; + + case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: + + exc_num = decoder->exc_num[packet->cpu]; + + if (exc_num == OCSD_EXC_CALL) + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_SYSCALLRET; + else + packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_INTERRUPT; + + break; + + case OCSD_GEN_TRC_ELEM_UNKNOWN: + case OCSD_GEN_TRC_ELEM_PE_CONTEXT: + 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; + } +} + static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, const ocsd_trc_index_t indx __maybe_unused, @@ -462,6 +628,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( break; } + cs_etm_decoder__set_sample_flags(context, elem); + return resp; } 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 217bcc6..34e093e 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 { u8 last_instr_taken_branch; u8 last_instr_size; int cpu; + u32 flags; }; struct cs_etm_queue; From patchwork Sun Oct 28 12:34:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 149614 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2936756ljp; Sun, 28 Oct 2018 05:35:42 -0700 (PDT) X-Google-Smtp-Source: AJdET5dNx+JBFDU41mMy9sAGDFjlWNomvQesbYkYwnxdnkKquJ/tL5AhwVSr06lHsoDWlTWwxKh4 X-Received: by 2002:a62:e048:: with SMTP id f69-v6mr11035684pfh.208.1540730142254; Sun, 28 Oct 2018 05:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540730142; cv=none; d=google.com; s=arc-20160816; b=z+u0Zq/aY7CoE2iXVvgPP6uMqQZK9iQGmrim/PVG44uD4VwUKFQCuX+K34UBZUkCHa WcbAlqSrVOKT2za9+LXcTjWsVxZmjlKsmT1nrgq1ZONQt3xRjYIHnwH0DkTw6YSZ18XV darmtL1TD0DGdZf34bae113vnEgkQMu1gwAVJAfrVJKt74a9ng2nKfk9ruNys1JA5RQ8 4AlZyijrm6lXCY0QySZ/KTsAsucb0y6NLVQ2pzE7JzL178dyKO/X1pVMfSfr+DLmavyI xUA0hiRqei7+X/HZJmcrnAiT+QeY7z2/e4YaiUfRDWIpqdRgTJ3REeoVPvtSIcwtmNz/ YMKA== 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=XgY8Dmsgnyr0i5Rac8Jw8Y7UJTS++BaAcXwdM3B2J1U=; b=hUv5cvfmHT69tr7lYylLuIkZ6v7zEg4PF8fqGl++liHxVILk/iKhZiuSKbncNComZ3 /GkG1DEyXFTxvR7ai7z4iYD9UcEgMYDk9DHdvkiKFSlYWGGObx0rw++wIM57QLnHV7Ak PaYMkGYtbFylfEjlE8k9JajfCyXJHHy1x79ujOTZ5vrHI9KQmw7hAv3YZOm77RovhAP/ dESrXZQOsSUMBCtGmU8Kq8In3/oUu6QEW8BdMcCxI2q66MMTU3P2VnyH5MLy44nl2Xhx YJPcUgcgsIjwbpANsUWk3xuxJb2wo53JCWSZVeRzEYDRw/m+JETvfsCqjNs+WIfs9BS1 muzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OtudAmWs; 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 k192-v6si17286895pgc.415.2018.10.28.05.35.41; Sun, 28 Oct 2018 05:35:42 -0700 (PDT) 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=OtudAmWs; 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 S1727650AbeJ1VUF (ORCPT + 32 others); Sun, 28 Oct 2018 17:20:05 -0400 Received: from mail-wr1-f53.google.com ([209.85.221.53]:35879 "EHLO mail-wr1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbeJ1VUF (ORCPT ); Sun, 28 Oct 2018 17:20:05 -0400 Received: by mail-wr1-f53.google.com with SMTP id y16so5730469wrw.3 for ; Sun, 28 Oct 2018 05:35:33 -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=XgY8Dmsgnyr0i5Rac8Jw8Y7UJTS++BaAcXwdM3B2J1U=; b=OtudAmWs506HqkYJfYy3vJ55svZ6VkX2cZMqUz9i+JhuoF2ntYElB0mEaTq2N1lkkD 5vH4qtzn7Fk7FwM70EGM5ZXMMBL2jYbFDNAxCFaUwUYNGUMRDgBfQXVTtu2FzQYvOM1B PqGdvhB4hSFV3uF3d+76h3QcSxjkjqPyWirAI= 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=XgY8Dmsgnyr0i5Rac8Jw8Y7UJTS++BaAcXwdM3B2J1U=; b=ZTnn4YekZTQ+7TaCR8Lh2oXbaepKELgKqPan4YTPgQs2f1W604m05Ov1DfJQyZl6Tq lSJzVfq+v4OpQHVQEDpXWuU+fKg+DfBEYys+YV9PTv5IaTuziR3K5p0Lw/Uoyca6n1P4 93rn6Mvot305zl5rlTAJqzrGQDnasbBRXXjoO4VnGyiaf8u/cm6tbyadSKAxp2fkNzI4 lh4RCZPrPuJn/YFDyuU79ZlLaLNq0VFDow+btzOtW54QdNd/u1VuglJwqE/sfbNkg0ti b0kzQ2+qVCPfhNGiVNBxq45zMGxKcWSOZERumXElRhsRKDstv2JE6XxrAx0ccfT1yvFX 2+7A== X-Gm-Message-State: AGRZ1gJ+zIvHETUYkYRGc36EjlYjEfLNmL08id+m88C2ALzgaiVHQSF6 ZDZjiqEiI22pWUR2SsrE/342HA== X-Received: by 2002:adf:ef41:: with SMTP id c1-v6mr10536749wrp.33.1540730132437; Sun, 28 Oct 2018 05:35:32 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 28 Oct 2018 05:35:31 -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 Cc: Leo Yan Subject: [PATCH v1 4/4] perf cs-etm: Add support sample flags Date: Sun, 28 Oct 2018 20:34:55 +0800 Message-Id: <1540730095-6732-5-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have prepared the flags in the packet structure, so need to copy the related value into sample structure thus perf tool can facilitate sample flags. The PREV_PACKET contains the branch instruction flags and PACKET actually contains the flags for next branch instruction. So this patch is to set sample flags with 'etmq->prev_packet->flags'. This patch includes two fixing up: if there has TRACE_ON packet in the middle of instruction packets, the TRACE_ON packet indicates the trace is discontinuous, so append the flag PERF_IP_FLAG_TRACE_END to the previous packet; if the coming packet is exception packet or exception return packet, also update the previous packet for exception specific flags. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 00a95d7..7e36dcf 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -655,7 +655,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->header.misc; @@ -711,7 +711,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 = PERF_RECORD_MISC_USER; /* @@ -945,9 +945,13 @@ static int cs_etm__exception(struct cs_etm_queue *etmq) * The exception packet includes the dummy address values, so don't * swap PACKET with PREV_PACKET. This keeps PREV_PACKET to be useful * for generating instruction and branch samples. + * + * Also update flags so can tell perf it is exception related. */ - if (etmq->prev_packet->sample_type == CS_ETM_RANGE) + if (etmq->prev_packet->sample_type == CS_ETM_RANGE) { etmq->prev_packet->last_instr_taken_branch = true; + etmq->prev_packet->flags = etmq->packet->flags; + } return 0; } @@ -965,6 +969,14 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) if (etmq->prev_packet->sample_type == CS_ETM_EMPTY) goto swap_packet; + /* + * The start tracing packet is in the middle of instruction range + * packets, this means the trace is discontinuous; so need to set + * the previous packet flag to PERF_IP_FLAG_TRACE_END. + */ + if (etmq->prev_packet->sample_type == CS_ETM_RANGE) + etmq->prev_packet->flags |= PERF_IP_FLAG_TRACE_END; + if (etmq->etm->synth_opts.last_branch && etmq->prev_packet->sample_type == CS_ETM_RANGE) { /*