From patchwork Sun Nov 11 05:07:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10677493 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 27EB713AD for ; Sun, 11 Nov 2018 05:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17EA22B990 for ; Sun, 11 Nov 2018 05:09:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B54A2B993; Sun, 11 Nov 2018 05:09:07 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 964BF2B990 for ; Sun, 11 Nov 2018 05:09:06 +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=NEnoy4L5GoZ/Wn0nUisp7nb3RyVbCxKzYnZMA+p3tpk=; b=OGdP9Quca+ddtCxu06mdOE5ADa Degg73o77n8bmtcEzEug6Ipf2gyZvwp3pJdppD5QD2NRWPjBIFYLFfogxzgE9MtXzsKiXpyMFRPg7 dEhZEbJgPLjFgidPRUB3VAcRk171H4UqXInNab86prA954lOUe3s5YJ/BePi5FiSKGXFhOknQTfez 2tmRPKeYEgA+yAR+ZhFj0NYWU/1S4Zh6L72ZH9HwojHhDcOa+7XXDVGpzPLDd/g4cvDtkoS2+A/vy 4i9gXwIpYmspYPYjMLb4pi6Rd6F05ab/irfbjjDfqU0f0ngH09CaKdehd3B0wJD7Q20Y1owuk7Dos Kx4RWzcg==; 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 1gLhzc-0007OO-Nh; Sun, 11 Nov 2018 05:09:04 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLhzP-0006x1-6h for linux-arm-kernel@lists.infradead.org; Sun, 11 Nov 2018 05:08:52 +0000 Received: by mail-wm1-x343.google.com with SMTP id t15-v6so5242275wmt.0 for ; Sat, 10 Nov 2018 21:08:41 -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=pL2xknDZRwx/bgQqRwh/znrlZfSxh+MEAgrn8ZwKjac=; b=kQgyYqdQSKpbnqwzWAvdB/oKD3LzuVUyZUN0jf65YU7d65DqRtXR1tqf9objsH0bWn h5bsPDarwmSjDUILJSqluaLGlL2x7c+tk2BS2Uvf+bd2Bqfb2CpG2uLR17mj0cmH66ns /LPm3OxoxSGB/QDvKDyOWonsbd1qp9lsGOyRU= 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=pL2xknDZRwx/bgQqRwh/znrlZfSxh+MEAgrn8ZwKjac=; b=LN9ae4plNBzakQfdg4kTwo8h8gdqu2rH3bULSb9PQTx9ZSHSt9Yq42P2qRY1lmls32 uj0qoI97AMOT17jod9+99bi/fQLMlY6Ote3lfiVgcAfVhkl9oOE7W3F2OjM4DEOjm/Yb Fx0ar2B3+Tecj0gbHmWODy+ORkEaeBDxgZy5fmccY7NB6ncXAFjvE9wcIs2Ssqj7pYDN PR2avcvUBCXEPlCFwSmgF6gA2bcAxq0XTGBI9gNm6Xf6oS4KGLILeXM71Hz7M8WhIXLK mmPivDOwZGTJAfrB3BKNAPCKl1KrgISSvA8nHMAaDUYucMJTSDbWbD3vMwy3CXyT16Qp r24A== X-Gm-Message-State: AGRZ1gIy0Xu6iNxkAoHPGHGri7jYB+J3E3dn+G6la0QSP9P/gX9mZiyV vkY7NlwbDkA6OQWnPlW9P6RXZg== X-Google-Smtp-Source: AJdET5fIMe8rnnM02LlmxpuUq9PQiV8scd0EiDBdVwD0p+/Kf2B1mFCJv/4C47ZUOvcmuXJORiUbUQ== X-Received: by 2002:a1c:6754:: with SMTP id b81-v6mr4118328wmc.104.1541912919839; Sat, 10 Nov 2018 21:08:39 -0800 (PST) Received: from localhost.localdomain ([209.250.228.18]) by smtp.gmail.com with ESMTPSA id b66-v6sm4471045wmb.21.2018.11.10.21.08.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Nov 2018 21:08:39 -0800 (PST) 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, Mike Leach , Robert Walker , Al Grant , Coresight ML Subject: [PATCH v2 2/2] perf cs-etm: Add support sample flags Date: Sun, 11 Nov 2018 13:07:56 +0800 Message-Id: <1541912876-20967-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541912876-20967-1-git-send-email-leo.yan@linaro.org> References: <1541912876-20967-1-git-send-email-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181110_210851_308417_2BA1906F X-CRM114-Status: GOOD ( 19.68 ) 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 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 three fixing up for sample flags based on the packets context: - If the packet is exception packet or exception return packet, update the previous packet for exception specific flags; - If there has TRACE_ON or TRACE_OFF packet in the middle of instruction packets, this indicates the trace is discontinuous, so append the flag PERF_IP_FLAG_TRACE_END to the previous packet to indicate the trace has been ended; - If one instruction packet is behind TRACE_OFF packet, this instruction is restarting trace packet. So set flag PERF_IP_FLAG_TRACE_START to TRACE_OFF packet if one, this flag isn't used by TRACE_OFF packet but used to indicate trace restarting when generate sample. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 455f132..afca6f3 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -676,7 +676,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->sample.header.misc; @@ -735,7 +735,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 = event->sample.header.misc; /* @@ -878,6 +878,43 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, return 0; } +static void cs_etm__fixup_flags(struct cs_etm_queue *etmq) +{ + /* + * Decoding stream might insert one TRACE_OFF packet in the + * middle of instruction packets, this means it doesn't + * contain the pair packets with TRACE_OFF and TRACE_ON. + * For this case, the instruction packet follows with + * TRACE_OFF packet so we need to fixup prev_packet with flag + * PERF_IP_FLAG_TRACE_BEGIN, this flag finally is used by the + * instruction packet to generate samples. + */ + if (etmq->prev_packet->sample_type == CS_ETM_TRACE_OFF && + etmq->packet->sample_type == CS_ETM_RANGE) + etmq->prev_packet->flags = PERF_IP_FLAG_BRANCH | + PERF_IP_FLAG_TRACE_BEGIN; + + if (etmq->prev_packet->sample_type == CS_ETM_RANGE) { + /* + * When the exception packet is inserted, update flags + * so tell perf it is exception related branches. + */ + if (etmq->packet->sample_type == CS_ETM_EXCEPTION || + etmq->packet->sample_type == CS_ETM_EXCEPTION_RET) + etmq->prev_packet->flags = etmq->packet->flags; + + /* + * The trace is discontinuous, weather this is caused by + * TRACE_ON packet or TRACE_OFF packet is coming, if the + * previous packet is instruction packet, simply set flag + * PERF_IP_FLAG_TRACE_END for previous packet. + */ + if (etmq->packet->sample_type == CS_ETM_TRACE_ON || + etmq->packet->sample_type == CS_ETM_TRACE_OFF) + etmq->prev_packet->flags |= PERF_IP_FLAG_TRACE_END; + } +} + static int cs_etm__sample(struct cs_etm_queue *etmq) { struct cs_etm_auxtrace *etm = etmq->etm; @@ -1100,6 +1137,8 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ break; + cs_etm__fixup_flags(etmq); + switch (etmq->packet->sample_type) { case CS_ETM_RANGE: /*