Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3507484imm; Sun, 17 Jun 2018 22:12:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI6NM73ho3gC4hcZhLp8vCUEWaYZVZc8MdulVxoH9VmN4EsLf5rAJUV80xDmP2x4jbiuL/A X-Received: by 2002:a63:64c5:: with SMTP id y188-v6mr9910609pgb.37.1529298767351; Sun, 17 Jun 2018 22:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529298767; cv=none; d=google.com; s=arc-20160816; b=RuL/XaGzXoWORVYtK2kKgN+AtOIxNwY4zFHyufyWLadAAZtbsAVbLKBNB7iA6O89V9 VYf+pH6nLb7tKowfS/BrXb32D0khPkZYD8DjkNUzlycUten1yVuysZYFXpFUOuwimcws iUsk467vTezTRvuYBBh75Gw8SDdHSUgbrZ1SuyfmQJO5OInomcd1dAb4LOeYn9Z94LU3 dX9/dD8ObKe2dUe1qaYSa2UaT/By3RLHobVlOs1Q8JWODD6PkgsgRNH5DeUZGlQoFkOp dP7diB9nDS0qQ+o0wzl3YPZA4g/Yg4+azVgn1JqUNwQNa9ya7okQKcc+0khg0nJ7uHAg O7Hg== 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:arc-authentication-results; bh=RhXey0Jlqp5lMh1Tvv94h72eqzeQPgFS1KWBXkgo+88=; b=gmW3Wj6p9Hs56c5ycqyIj91nfm1x5nRJi92n9dTbdvlsSVxyU9F/aDLLIKIPIbrzl/ mkPWiNFrG0MOaDyuIL8wHpm368shkeX7ei5sBBdJ5ITZ18iethaaaTAg223gIPQY8jzE PEWFh9wqxcnKI44EXAfkD373gUzXljar808iGfmwEm6oohh1A24C7rAkFictFtRdWGfq Mfm5+esA6TB8BmlHLQr5EIVVb/6qX5O2wS1kWHILxmY2PeEZz0n2fuHP76Msy36vEDbX DpDUKR1mPnlvmb4Oht/sRVH5yWYQEr3zDIkIP/k5n1Xed9c0chgJNH4GMORMavjNfu7e UH0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sy8DMrZ+; 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 r24-v6si14135245pfi.147.2018.06.17.22.12.33; Sun, 17 Jun 2018 22:12:47 -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=Sy8DMrZ+; 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 S1754727AbeFRFKv (ORCPT + 99 others); Mon, 18 Jun 2018 01:10:51 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40735 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754714AbeFRFKp (ORCPT ); Mon, 18 Jun 2018 01:10:45 -0400 Received: by mail-pl0-f67.google.com with SMTP id t12-v6so8348976plo.7 for ; Sun, 17 Jun 2018 22:10:45 -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=RhXey0Jlqp5lMh1Tvv94h72eqzeQPgFS1KWBXkgo+88=; b=Sy8DMrZ+0L8KlPCHh3m6ZxpNJvameyteO5e2eariergV3cFQiXG71LmQaUWKOMpz9q uIqJmfpH6/DiryKCLnhSqJwAAy/jWqbwRBu5z9LgKWULVtlxBlkkMZPehdxsOQQCF74/ WdRcJnbHLd/0+YaZPjdqh/Wtie/b+tJXiYnhA= 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=RhXey0Jlqp5lMh1Tvv94h72eqzeQPgFS1KWBXkgo+88=; b=RsC3zRzfsrK6H04nVWBSjD4izP3SpqeTAV7Q+wWLwnQFDnFZyDH8/3G4603zG9bjfl ZqJq3Rlqzw8KFOJQ8e9fehDOF0jgiFFx4n9tEsGUldNEBe7cR/LrgAoia5/pG0mFudvo dtQeReYvJ2UWFdT0JEvHoXnp2c9W5Ji/XsMNmULsOSTwnsNC7bkP27A5CBfDbcV84EDQ 6Cq5X/+/lnQ+PAJzejmlrqxruVzzDoBFzNzWz8jgPwhgQevE4/zsRiebA52FLNYJ7TZy Ftb5+Tl0WeiAv+xws7b5yF2W7jmnVqCOZjjY9+tRDFZbT5drFsXE3Jor3bqUzrJTYkIs zLWQ== X-Gm-Message-State: APt69E3SNuXDu479CicTpJHwTONA0761Oxf7nS9+Z1RGKdae1Vfqalxx x8XKoysDBjnRHWwwhWkiINj7pdK8TtA= X-Received: by 2002:a17:902:9685:: with SMTP id n5-v6mr12366608plp.15.1529298645013; Sun, 17 Jun 2018 22:10:45 -0700 (PDT) Received: from localhost.localdomain (li1181-92.members.linode.com. [45.79.82.92]) by smtp.gmail.com with ESMTPSA id l15-v6sm29051710pfg.88.2018.06.17.22.10.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 Jun 2018 22:10:44 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Kim Phillips Cc: Leo Yan Subject: [PATCH v1 3/6] perf cs-etm: Fix start tracing packet handling Date: Mon, 18 Jun 2018 13:09:56 +0800 Message-Id: <1529298599-3876-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529298599-3876-1-git-send-email-leo.yan@linaro.org> References: <1529298599-3876-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 Usually the start tracing packet is a CS_ETM_TRACE_ON packet, this packet is passed to cs_etm__flush(); cs_etm__flush() will check the condition 'prev_packet->sample_type == CS_ETM_RANGE' but 'prev_packet' is allocated by zalloc() so 'prev_packet->sample_type' is zero in initialization and this condition is false. So cs_etm__flush() will directly bail out without handling the start tracing packet. This patch is to introduce a new sample type CS_ETM_EMPTY, which is used to indicate the packet is an empty packet. cs_etm__flush() will swap packets when it finds the previous packet is empty, so this can record the start tracing packet into 'etmq->prev_packet'. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + tools/perf/util/cs-etm.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 743f5f4..612b575 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -23,6 +23,7 @@ struct cs_etm_buffer { }; enum cs_etm_sample_type { + CS_ETM_EMPTY = 0, CS_ETM_RANGE = 1 << 0, CS_ETM_TRACE_ON = 1 << 1, }; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 8b2c099..ae7c9c88 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -924,8 +924,14 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) int err = 0; struct cs_etm_packet *tmp; + if (!etmq->prev_packet) + return 0; + + /* Handle start tracing packet */ + if (etmq->prev_packet->sample_type == CS_ETM_EMPTY) + goto swap_packet; + if (etmq->etm->synth_opts.last_branch && - etmq->prev_packet && etmq->prev_packet->sample_type == CS_ETM_RANGE) { /* * Generate a last branch event for the branches left in the @@ -944,6 +950,10 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) etmq->period_instructions = 0; + } + +swap_packet: + if (etmq->etm->synth_opts.last_branch) { /* * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for * the next incoming packet. @@ -1023,6 +1033,13 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) */ cs_etm__flush(etmq); break; + case CS_ETM_EMPTY: + /* + * Should not receive empty packet, + * report error. + */ + pr_err("CS ETM Trace: empty packet\n"); + return -EINVAL; default: break; } -- 2.7.4