From patchwork Thu May 31 10:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 137347 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6417683lji; Thu, 31 May 2018 03:33:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI5VgJTnHNDxf3VZ1PqA9ZQK6oPN86fZcLDfdx7ApcsL1jd/u+IHBEwvxKwWJhHk0neiFCf X-Received: by 2002:a62:b2c4:: with SMTP id z65-v6mr2792630pfl.21.1527762785791; Thu, 31 May 2018 03:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527762785; cv=none; d=google.com; s=arc-20160816; b=bwEll44HeY0usV4ub6lka3sj0d6FhwYX329CUYfBXkf5lw2RyYCcQCuzZalV7nRWq8 QNIzR6bSLiPF4PEWcOP+hNZ/j0Vs7Cn2r4QZaNyjYKAK2G7c6nGMw2DDo55xh8vryInv Hpv8l7u1Wap8OauBjWUmVkChDuD/E3Fohrcz3+y6wQ8ePRict+Ggqcyt45o1wHxRYxWP urWfytlOPmEXxLCnN0f9EIfqLMfkbEyGnMgF2/ZFvZDq60bjX48Ip55+5ifj/D7K5MZG nHiLQ90tVo3ZeCGBPPzzD2DFJ4Re6PEqHC1W1IipD/jVoUdIukyoCWJKMMoXjKEQ4YXb IHoA== 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=XGs3YbR6/IHY8E3Z8pTl3fXWT7uK+qxXsNaXYK92xhE=; b=vhc4Od5wOxaDGW3E6YGVhUX6ewlMow2cHFXTh3XTMzO0Td5bfG1ja+GeZpr9bJiLqo L/fa99n8ldO7nHXnuwNqYEFXc60PQRNUOCkReaZYpLAW1/ysjPPBkSg9FYwiO3MGfTn0 wJj070MkJSwjZOZbcmF6SVopqrLSaiDzuO6Dq6UZHxk2xp0oFXck6YXwSu92x2UxoWR3 s5cAIuKsngYXNJ8pcOlqe94/mGyUDdrNLx4gu/R2j3Wt4734cMFnTUBmaKmMi/cphN25 87fLkKnWUCltQDoLa77iRCmlPr6uQyRgIWBnu528VgL2YTfpSpj1mKr6vdvRLN9deKGJ 83zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M46TxJAD; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v41-v6si36811392plg.451.2018.05.31.03.33.05; Thu, 31 May 2018 03:33:05 -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=@kernel.org header.s=default header.b=M46TxJAD; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754494AbeEaKdC (ORCPT + 30 others); Thu, 31 May 2018 06:33:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:57078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754539AbeEaKcs (ORCPT ); Thu, 31 May 2018 06:32:48 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3E1CA208B1; Thu, 31 May 2018 10:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527762768; bh=DDVrNuv+pJ7wHR4n5ft/aSnTjLyvq5NXUpk0Fu1bYLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M46TxJADQG7IsAbZx0hMEF1Hhd3v0vuB6J2ozKKR7AoGsa85BEUkkuLYa3AZ5IBgy qg8CsgL0BDuYCfycMGi605n1KuzuifKqm2/hDxX8BaH5sxoA0X0JW/fiQRzaSyR5Ds 4vdPgnnerZbudq79GlukrQ75bEcVP5bXB5bDsCmQ= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Mathieu Poirier , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Robert Walker , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 4/7] perf cs-etm: Fix indexing for decoder packet queue Date: Thu, 31 May 2018 07:32:17 -0300 Message-Id: <20180531103220.24684-5-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180531103220.24684-1-acme@kernel.org> References: <20180531103220.24684-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Poirier 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(-) -- 2.14.3 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;