Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp458233imm; Thu, 31 May 2018 03:47:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK1JKxqjnRWukUtaacL0IXyQBGy2yE9hswts+KeYU3SksIJfll2Py5WIb1zT+/QlsAyvwh+ X-Received: by 2002:a63:720f:: with SMTP id n15-v6mr5243704pgc.12.1527763623740; Thu, 31 May 2018 03:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527763623; cv=none; d=google.com; s=arc-20160816; b=ZHvGpYinZR35ZZREdDEH+R3HBy3b/p1JybkodlSd23Kq1Z2lSfq/dom6KxpY+2bwQZ X9WHU41RMv5RolpsJ0wCJhoTNM1FpUvNNNJ4FiEbuT/eFwzsScvXVvnb7WOwOm29DTgD LW+ngK6EdLZEiqx2+8kYiPlt2IKwgLbAsi/pKg/nAxtM/PCavIxeCrEpi90HkMS1c1G+ RAB0QM0XjdD691z7OQ0TTTprvMg911Ka3o6SEHXwpHtdvxu1/W81DK9L9JIRqCmxV4Ba d5Q1gBEc1ondZ32BoW04EfF04hxm+7zNwoAunTITtIPWoGLHEzDqEi9QxZNo6TpU5C+Y MegA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=m8rkL7sRi7JfCXGseqTOGVDRDtDBbW+DSaPoUvePgI8=; b=FXlm1xHFWxObLvGjeS/SteHBl7CRt3u+cFbC9auprqmlJZ7w2Uve3Vf0Jk/JYG9q0s htINhb5GKgr/CtVZ6QL26lMjbCNu6HsEarXkmzcVhUdL3zTLhQdf98J0lVqg1BlfmqDH FA5hOMAhfEfl/R1m3WF0t0A4ZNC1C9ObW5nDzYbLAje4xopCG+cdpyJn0Xl16c7eWlJE x9uzVAIfoTZvdmL5EBRPNTTWAiBhEearZPH1B3FP/XZB0qj9FUND5T/N4Hae8XSKULE5 nTTNyTqNF2WulgTqcAx9BxzxjnaNd5cyUU5LiAV6Nj3kxxk52pO9oLPW+QOFbVdacv6z yRSw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 82-v6si12168772pgh.144.2018.05.31.03.46.49; Thu, 31 May 2018 03:47:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754612AbeEaKo6 (ORCPT + 99 others); Thu, 31 May 2018 06:44:58 -0400 Received: from terminus.zytor.com ([198.137.202.136]:53029 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754597AbeEaKo4 (ORCPT ); Thu, 31 May 2018 06:44:56 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w4VAiWgf3525404 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 31 May 2018 03:44:32 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w4VAiW0c3525401; Thu, 31 May 2018 03:44:32 -0700 Date: Thu, 31 May 2018 03:44:32 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Mathieu Poirier Message-ID: Cc: jolsa@redhat.com, tglx@linutronix.de, leo.yan@linaro.org, mingo@kernel.org, hpa@zytor.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, acme@redhat.com, robert.walker@arm.com, namhyung@kernel.org, peterz@infradead.org Reply-To: peterz@infradead.org, namhyung@kernel.org, robert.walker@arm.com, acme@redhat.com, linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org, alexander.shishkin@linux.intel.com, leo.yan@linaro.org, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de, jolsa@redhat.com In-Reply-To: <1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org> References: <1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf cs-etm: Fix indexing for decoder packet queue Git-Commit-ID: e2ab28521a588785c3e053098ffe607b5ff54634 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_48_96 autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e2ab28521a588785c3e053098ffe607b5ff54634 Gitweb: https://git.kernel.org/tip/e2ab28521a588785c3e053098ffe607b5ff54634 Author: Mathieu Poirier AuthorDate: Fri, 25 May 2018 17:10:54 -0600 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 May 2018 15:38:40 -0300 perf cs-etm: Fix indexing for decoder packet queue The tail of a queue is supposed to be pointing to the next available slot in a queue. In this implementation the tail is incremented before it is used and as such points to the last used element, something that has the immense advantage of centralizing tail management at a single location and eliminating a lot of redundant code. But this needs to be taken into consideration on the dequeueing side where the head also needs to be incremented before it is used, or the first available element of the queue will be skipped. Signed-off-by: Mathieu Poirier Tested-by: Leo Yan Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Robert Walker Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 c8b98fa22997..4d5fc374e730 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -96,11 +96,19 @@ int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder, /* Nothing to do, might as well just return */ if (decoder->packet_count == 0) return 0; + /* + * The queueing process in function cs_etm_decoder__buffer_packet() + * increments the tail *before* using it. This is somewhat counter + * intuitive but it has the advantage of centralizing tail management + * at a single location. Because of that we need to follow the same + * heuristic with the head, i.e we increment it before using its + * value. Otherwise the first element of the packet queue is not + * used. + */ + decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1); *packet = decoder->packet_buffer[decoder->head]; - decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1); - decoder->packet_count--; return 1;