Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2954332imm; Mon, 28 May 2018 20:50:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZooTEZDq9l27Z9BUjEZVVM3/Yc+5jQe3wD+my4Q0yJcGYcJx5MBrlMbZRxlIrMYUR8jDlLz X-Received: by 2002:a62:99d7:: with SMTP id t84-v6mr15827474pfk.252.1527565855760; Mon, 28 May 2018 20:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527565855; cv=none; d=google.com; s=arc-20160816; b=DcCaEjQXQnnwSp8JGrhdOSHf/ssqgy2YNkkULTNXRNOOFdOq1albF4KAqMghgm4hAb TuxA2/G94Pr6/qB8FxCQl3NA1epVaMxjGtSDSH8AmjouI9Ee7vp/su7sKhwUurGRuAKF pUQCGCgafyvqxs+uFGlBJ6OJxkFwP9mhrmX+HYIcy+dBHyF4z8cWmGP1NPZOglm9FsDl 0dB0YRCV68UbL1PBV3FIy92BABav/mlhp+Wzqv1V+QUEuhRdPqgTDiDrvXJqFsSXChre 78bBM3oMHaX1OysmZqIdl12dN+nOlmC36dsDAiRXi59cniST591GBy495TIr5xjNMJOg lhVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=gasJ+vJxZr2gSS8or5ipJK2vTREkAID1wcZQ3zrBtdg=; b=vc/sHcrgsKpsS6bQzN5BmKE2FFh1kGS8AHma/hqrcwd3YfFCO7UVllPrNlE/s81SFC POefi+wHoGIo5mKWVMy+ZZE8T7WWMdJ2/MBYc9q2iESCd9FqPf/0/8ISybPPE3aGJn/v jo716CGOKzN8uRFBqKoOu8uhFo/6ETWet4ZM4zakAlRgMx32p7B2aBdwIbZnqYHdOH/2 Xx+Eb4SHLf946B9dUYqbtOOYHOybonTS3ILrpJC129YYnasPhlaUkJ8BdCOOXZfdWesN MXLru9cMja8/UlZwKyuQQ0OzaFMNUlmXkPjIu6THHiv1Pz4ULFXd8p6buDT8y2Az0KVf d5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1UXCYLyh; 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 f3-v6si32406432plf.436.2018.05.28.20.50.41; Mon, 28 May 2018 20:50:55 -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=1UXCYLyh; 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 S933580AbeE1TiC (ORCPT + 99 others); Mon, 28 May 2018 15:38:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:38714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933558AbeE1TiB (ORCPT ); Mon, 28 May 2018 15:38:01 -0400 Received: from jouet.infradead.org (unknown [190.15.121.82]) (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 8637C20851; Mon, 28 May 2018 19:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527536280; bh=YmGqJebes+42ITQo95zwfqxWFiJeLbec0zaLe237G24=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=1UXCYLyhzYeGRJEoIy4DXo8tLfq1IRKAwRYOsMIyDaNnDgg3stp4PpqssMpiQCipH tF7epIcOR3K0WcJU1lzVhHpZ7H7Ep5wlZPyduj5z05MMK2+HRVjRgj7fqjo4jy3QuY 3vc6jS1G9HQHah94OD++mpRcazSBKEE1vh6lizm8= Received: by jouet.infradead.org (Postfix, from userid 1000) id 279F31468D9; Mon, 28 May 2018 16:37:58 -0300 (-03) Date: Mon, 28 May 2018 16:37:58 -0300 From: Arnaldo Carvalho de Melo To: Leo Yan Cc: Mathieu Poirier , Robert Walker , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , LAK , linux-kernel Subject: Re: [PATCH] perf tools: Fix indexing for decoder packet queue Message-ID: <20180528193758.GF25467@kernel.org> References: <1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, May 28, 2018 at 11:13:59AM +0800, Leo Yan escreveu: > On Fri, May 25, 2018 at 05:10:54PM -0600, Mathieu Poirier wrote: > > 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 > > --- > > 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); > > - > > I tested this patch and confirmed it can work well with python > decoding script: > > Tested-by: Leo Yan Ok, applying this patch, after having read Mathieu's response. - Arnaldo > Actually, I have another idea for this fixing, seems to me > the unchanged code has right logic for decoder->head, and I think this > issue is more related with incorrect initialization index. So we can > change the initialization index for decoder->head as below. How about > you think for this? > > 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 c8b98fa..b133260 100644 > --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > @@ -249,7 +249,7 @@ static void cs_etm_decoder__clear_buffer(struct > cs_etm_decoder *decoder) > { > int i; > > - decoder->head = 0; > + decoder->head = 1; > decoder->tail = 0; > decoder->packet_count = 0; > for (i = 0; i < MAX_BUFFER; i++) { > > Thanks, > Leo Yan > > > decoder->packet_count--; > > > > return 1; > > -- > > 2.7.4 > >