From patchwork Mon May 28 08:45:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10430057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B0EF5602CB for ; Mon, 28 May 2018 08:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F83F28A72 for ; Mon, 28 May 2018 08:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 901D428A74; Mon, 28 May 2018 08:47:11 +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 autolearn=unavailable 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 A496628A72 for ; Mon, 28 May 2018 08:47:10 +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=uYNLOjmf0CDZ/ry8KmERBdqk0irEoGH2p5K5hRQr0GE=; b=DWejLw7CJnukvWtn9RGggPknzX ZgIflC+xbQuELKYJV7VRVGsIkx7X6REXRHWKzsSR4USXKNNSF3gygkB0uAxuXPiSmzQLMv6asxMpL SQ2IGtrdYc4LI/XhpTGExH1d/iloo+ZrsIFersCzMFfkAf0ne6eylUxFtn8tnoBrIq3JPEt2kyOuf tpVmkzWFZvBvg9zbZQaA8AipBU/kFk9ZzngkgV+QBXP+Wgqd8xMz1uiLj0xncSiiJdukGbg5IpJE4 SABESW677XpxGDVy6OiRgTNoBB7jOOnzq3x4A3JObTgq1vCWZ8EykYFGST7xaWem/m+O5gqxMrK8/ vSdmJh6Q==; 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 1fNDny-000087-7v; Mon, 28 May 2018 08:47:02 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fNDms-00086I-3b for linux-arm-kernel@lists.infradead.org; Mon, 28 May 2018 08:46:11 +0000 Received: by mail-wm0-x242.google.com with SMTP id l1-v6so30018987wmb.2 for ; Mon, 28 May 2018 01:45:43 -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=Lji3vyYRuIF5z4NfQhW1RnWAxHyPoIpzDIEswsoWVp4=; b=WW+eEcGyCWeBef21OlxgVGrVRY0JrUSYpwUYryP9DwNie2RnnC10cn/vF9cCOsDJnX RA6kiEYtWInbK1Y/AS/2rPsb7ZxXgmNdshKZAQk3kdQUBmHqbBDUE4pIau+SqgQmI8YE rNa6QaFMqBrNtyKPOCKcxm1icUtgeMb0MTLEI= 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=Lji3vyYRuIF5z4NfQhW1RnWAxHyPoIpzDIEswsoWVp4=; b=Cy8doR4b821VjL9wvEaJqJrAg6gnmo6gaQLVs50suZeaSLfwFUKcwwDUFpVoeWTUc2 5Eddg6iXr6GkU4u7BrKsQV9h2h9CH/HhhocJ/PjotZkF6saXW/sw5GUs2Jyto5vj+k81 9JqQonedKZ6X3Fb0hXer8cqGzYDPVTS6bQp22eb85yYv1gVhhvw4jNQ6JinDHZvVAFOn wRT3Rv6tYTAKz67etgMZJp/RzDDzb5gTEEAffZDFAdaPl345OiIUwPc38FkTHrbUp9/J y8B7gnkEqoBZiZTyQhFDczpgeYIwgkcgT6L6AjWTgusmTxZrxUHHuF3eOHGfhu1ROW4q 17fA== X-Gm-Message-State: ALKqPwdNzGo5CLGuWcjgvHAiEd5ROYOYCc0qPh4WOzW6yRy7Z94H15pi ZM0yCpYg7iKHQGSV+CeJMEqhRQ== X-Google-Smtp-Source: ADUXVKKUubwAJi1bK/XminLYjfDaz4v8Mbcqxw7xV7eVmNehtPHg+zwA4GcLljNqReqE3y38ssk8Ug== X-Received: by 2002:a1c:a54e:: with SMTP id o75-v6mr1723268wme.157.1527497142290; Mon, 28 May 2018 01:45:42 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id 123-v6sm21783013wmt.19.2018.05.28.01.45.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 May 2018 01:45:41 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Jonathan Corbet , Robert Walker , mike.leach@linaro.org, kim.phillips@arm.co, Tor Jeremiassen Subject: [RFT v3 1/4] perf cs-etm: Generate branch sample for missed packets Date: Mon, 28 May 2018 16:45:00 +0800 Message-Id: <1527497103-3593-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> References: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180528_014554_199489_152F1441 X-CRM114-Status: GOOD ( 25.91 ) 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: linux-doc@vger.kernel.org, Peter Zijlstra , coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Alexander Shishkin , Ingo Molnar , Leo Yan , Namhyung Kim , Jiri Olsa , linux-arm-kernel@lists.infradead.org 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 Commit e573e978fb12 ("perf cs-etm: Inject capabilitity for CoreSight traces") reworks the samples generation flow from CoreSight trace to match the correct format so Perf report tool can display the samples properly. But the change has side effect for branch packet handling, it only generate branch samples by checking previous packet flag 'last_instr_taken_branch' is true, this results in below three kinds packets are missed to generate branch samples: - The start tracing packet at the beginning of tracing data; - The exception handling packet; - If one CS_ETM_TRACE_ON packet is inserted, we also miss to handle it for branch samples. CS_ETM_TRACE_ON packet itself can give the info that there have a discontinuity in the trace, on the other hand we also miss to generate proper branch sample for packets before and after CS_ETM_TRACE_ON packet. This patch is to add branch sample handling for up three kinds packets: - In function cs_etm__sample(), check if 'prev_packet->sample_type' is zero and in this case it generates branch sample for the start tracing packet; furthermore, we also need to handle the condition for prev_packet::end_addr is zero in the cs_etm__last_executed_instr(); - In function cs_etm__sample(), check if 'prev_packet->exc' is true and generate branch sample for exception handling packet; - If there has one CS_ETM_TRACE_ON packet is coming, we firstly generate branch sample in the function cs_etm__flush(), this can save complete info for the previous CS_ETM_RANGE packet just before CS_ETM_TRACE_ON packet. We also generate branch sample for the new CS_ETM_RANGE packet after CS_ETM_TRACE_ON packet, this have two purposes, the first one purpose is to save the info for the new CS_ETM_RANGE packet, the second purpose is to save CS_ETM_TRACE_ON packet info so we can have hint for a discontinuity in the trace. For CS_ETM_TRACE_ON packet, its fields 'packet->start_addr' and 'packet->end_addr' equal to 0xdeadbeefdeadbeefUL which are emitted in the decoder layer as dummy value. This patch is to convert these values to zeros for more readable; this is accomplished by functions cs_etm__last_executed_instr() and cs_etm__first_executed_instr(). The later one is a new function introduced by this patch. Reviewed-by: Robert Walker Fixes: e573e978fb12 ("perf cs-etm: Inject capabilitity for CoreSight traces") Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 93 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 20 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 822ba91..8418173 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -495,6 +495,20 @@ static inline void cs_etm__reset_last_branch_rb(struct cs_etm_queue *etmq) static inline u64 cs_etm__last_executed_instr(struct cs_etm_packet *packet) { /* + * The packet is the start tracing packet if the end_addr is zero, + * returns 0 for this case. + */ + if (!packet->end_addr) + return 0; + + /* + * The packet is the CS_ETM_TRACE_ON packet if the end_addr is + * magic number 0xdeadbeefdeadbeefUL, returns 0 for this case. + */ + if (packet->end_addr == 0xdeadbeefdeadbeefUL) + return 0; + + /* * The packet records the execution range with an exclusive end address * * A64 instructions are constant size, so the last executed @@ -505,6 +519,18 @@ static inline u64 cs_etm__last_executed_instr(struct cs_etm_packet *packet) return packet->end_addr - A64_INSTR_SIZE; } +static inline u64 cs_etm__first_executed_instr(struct cs_etm_packet *packet) +{ + /* + * The packet is the CS_ETM_TRACE_ON packet if the start_addr is + * magic number 0xdeadbeefdeadbeefUL, returns 0 for this case. + */ + if (packet->start_addr == 0xdeadbeefdeadbeefUL) + return 0; + + return packet->start_addr; +} + static inline u64 cs_etm__instr_count(const struct cs_etm_packet *packet) { /* @@ -546,7 +572,7 @@ static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq) be = &bs->entries[etmq->last_branch_pos]; be->from = cs_etm__last_executed_instr(etmq->prev_packet); - be->to = etmq->packet->start_addr; + be->to = cs_etm__first_executed_instr(etmq->packet); /* No support for mispredict */ be->flags.mispred = 0; be->flags.predicted = 1; @@ -701,7 +727,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq) sample.ip = cs_etm__last_executed_instr(etmq->prev_packet); sample.pid = etmq->pid; sample.tid = etmq->tid; - sample.addr = etmq->packet->start_addr; + sample.addr = cs_etm__first_executed_instr(etmq->packet); sample.id = etmq->etm->branches_id; sample.stream_id = etmq->etm->branches_id; sample.period = 1; @@ -897,13 +923,28 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) etmq->period_instructions = instrs_over; } - if (etm->sample_branches && - etmq->prev_packet && - etmq->prev_packet->sample_type == CS_ETM_RANGE && - etmq->prev_packet->last_instr_taken_branch) { - ret = cs_etm__synth_branch_sample(etmq); - if (ret) - return ret; + if (etm->sample_branches && etmq->prev_packet) { + bool generate_sample = false; + + /* Generate sample for start tracing packet */ + if (etmq->prev_packet->sample_type == 0 || + etmq->prev_packet->sample_type == CS_ETM_TRACE_ON) + generate_sample = true; + + /* Generate sample for exception packet */ + if (etmq->prev_packet->exc == true) + generate_sample = true; + + /* Generate sample for normal branch packet */ + if (etmq->prev_packet->sample_type == CS_ETM_RANGE && + etmq->prev_packet->last_instr_taken_branch) + generate_sample = true; + + if (generate_sample) { + ret = cs_etm__synth_branch_sample(etmq); + if (ret) + return ret; + } } if (etm->sample_branches || etm->synth_opts.last_branch) { @@ -922,11 +963,16 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) static int cs_etm__flush(struct cs_etm_queue *etmq) { int err = 0; + struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet *tmp; - if (etmq->etm->synth_opts.last_branch && - etmq->prev_packet && - etmq->prev_packet->sample_type == CS_ETM_RANGE) { + if (!etmq->prev_packet) + return 0; + + if (etmq->prev_packet->sample_type != CS_ETM_RANGE) + return 0; + + if (etmq->etm->synth_opts.last_branch) { /* * Generate a last branch event for the branches left in the * circular buffer at the end of the trace. @@ -939,18 +985,25 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) err = cs_etm__synth_instruction_sample( etmq, addr, etmq->period_instructions); + if (err) + return err; etmq->period_instructions = 0; + } - /* - * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for - * the next incoming packet. - */ - tmp = etmq->packet; - etmq->packet = etmq->prev_packet; - etmq->prev_packet = tmp; + if (etm->sample_branches) { + err = cs_etm__synth_branch_sample(etmq); + if (err) + return err; } - return err; + /* + * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for + * the next incoming packet. + */ + tmp = etmq->packet; + etmq->packet = etmq->prev_packet; + etmq->prev_packet = tmp; + return 0; } static int cs_etm__run_decoder(struct cs_etm_queue *etmq)