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: 150762 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1711939ljp; Sat, 10 Nov 2018 21:09:25 -0800 (PST) X-Google-Smtp-Source: AJdET5fPkZbC1GC5a30whtBAArlnd+Qhr15fqdY4XfctRfxX9t9CDhCBGsttaE+4XzrIX6OPnWqv X-Received: by 2002:aa7:8685:: with SMTP id d5-v6mr15070773pfo.58.1541912965444; Sat, 10 Nov 2018 21:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541912965; cv=none; d=google.com; s=arc-20160816; b=bfpXj6WTBDz2QeuLloxYcqiPoKtoVUltmoqWIJc1N66u2O8u4NWaTmvFpNkuRd38hL qTp0TIGg1nAldtOwTlC4JAFXmZ5ptGmISTDo734B7mWXQb9RHO4qrORi9C2nsTrHMuIm fNDnAtL7IDWHvuPHkgUXRBPZXBbDzuchTQ3f7qhIMvw+AiY3RgzhNieozcd8iPfj3h6q il5igAK2UcyapW/+JXqebX9vKwrT4f3ablw0+NrC9A5ap0SWbZVuOGIR4r619hePhvub nKNk9pq2mgy0ZdQYuZWQZIe4FHh6Afm6LkyyKwkrbLDwjb3ewW0ALnpDAHVjaj60Y1ge 43jA== 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=pL2xknDZRwx/bgQqRwh/znrlZfSxh+MEAgrn8ZwKjac=; b=O2n3+7IQfnuZxmSH+vi+LV+jDbjilvDgIBT19UjOzILg+4aJlBtaM6FvoRg7CoPbcK zt3oYh5C+DAH9Fu7oLlGeP7wVO9IOMA6fcN7oMbc5NKeK0u1IfP1rq/Y4zzJctcLjb0O E8osooAVJEuJ2rWklXqSaX/LmtBQsRQTvqAJIcB2dsSr5lgNSFvLCaKGo9bIa5viArj2 myTEkoEcYejNIeJBojhW9rIr0oageUeb4CdeUqiKaztm5WL86bvJPbPtghAYfNiw4f9l c3WYSshdbsymyvSntEh6CYIYjefOMKbHVSekAe94qvaDOeF1fDg6lHJS22hwfbckGH9E 4IAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQgyYqdQ; 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 e11si6553348pgf.450.2018.11.10.21.09.25; Sat, 10 Nov 2018 21:09:25 -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=kQgyYqdQ; 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 S1727564AbeKKO4L (ORCPT + 32 others); Sun, 11 Nov 2018 09:56:11 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54138 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbeKKO4K (ORCPT ); Sun, 11 Nov 2018 09:56:10 -0500 Received: by mail-wm1-f66.google.com with SMTP id f10-v6so5386255wme.3 for ; Sat, 10 Nov 2018 21:08:40 -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=PXJkx2EehxVRQxp06XOYUvi+DlZ/NTYl/JdlYbcsxXbUkz0sEfl57v61BF7hO56+9U 0s9s4K++Dme8cJpinW+OZnaO5ht8qfeP+dhMemHILoShDVW7yKo/g0VQACMLL05ac6HB MsT6vMwzKCfrBAUatrYZdbnqpff+pKuomWPskPS/Rr0JIxta45N5+EKo8XueMjdPhsPS q5zrhMq946rUPNY/Aqz5IgiG1Z/aidyOzjhskT3leM35Py5EaX2RYweTsClTUGVMuADT sZqiw/kcxmb6mvp/K+WzWCCe/2NyHwI23gRyQ1DNmjLxHlrMqPqSKO3qILH9ZNbYP28U 0wBA== X-Gm-Message-State: AGRZ1gLb2yuAkYG/WvGNCBdXGTVfVFAIzbZ5MVwFuWBee6vB6fyiSX/j C7ZoARi2ichROwvChZL/QWO3y8XEAZP79w== 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 Cc: Leo Yan 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> 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 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(-) -- 2.7.4 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: /*