Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1910685imm; Sun, 27 May 2018 20:14:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZocnPCH2YWjYEKYx6tEzURmdJE/ndvnxaIjAxavuHbbbyZhwtDYXoraT11BI2h6tSfDqX+J X-Received: by 2002:a17:902:8345:: with SMTP id z5-v6mr11622002pln.311.1527477268028; Sun, 27 May 2018 20:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527477267; cv=none; d=google.com; s=arc-20160816; b=E5HZS2XI0RN6h+98R32z1EP2yeDYkxGsh3hQA/tNfuVb2oefYcFPxyARJYKkuvZMKP ZIb6Ob4i5nvJGbeKyJSO5yaJoY631g4Z42Q+X6cEM5nr3Al8ULHwe4Pg4k3a6kampRAo cu6SM/M3aaPrcBXINikMAFcuFlTiSLdtcSRM4gMcOL9lMyt9f+dUtdTrPB9Mue6uX7AB j9gkQ6Fik07Jb0L+TvtK8CVS6jm6Fk3Scl42SZaJsDwn/Z8A88sXu+fpLv15FCk5we9k Ll2Pbvna7dQn9Ap+EQCO4YmMUYgRcsN3tagjf4n0qLcC0pngXssZLJrc/sk326rbeiim ipgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Y0TNwqNxYTZX3DvPLZR0gv2LaRMLBoAPwb1Mnaz339c=; b=KXm7cIT2SxSBeV6KoGgqFLiiqK8Q9vbFt7XEpypRH51/Ca7eUvYF4c6BUemIHOK35q Y8dyv9JvE8Ng0gXssZ9QiBBAFgX7L4kuHFMZW8xj4kh3keLkvQya4dRwOfk3mw8+m6PA +fofWTVGQjF49rDexlSXnGIjl+Soy7OxllvpoJwYcnbfOA0nMCqeKOrHcuKjcoTLqkJ0 GW5V0Gct/kt7h1lJeB1c4WdpQWRMFaM/sXipudbnADzrCkr2+KGwg0sMsDf69unyK++7 oXaGhWml4cF/tcgy6iHM4RL6nibrZH/2N1wvrycrTzEsIIo6N8AcKBYiWNOcYHXliZaB vKNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FoDkJsHh; 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 q200-v6si11106211pgq.682.2018.05.27.20.14.12; Sun, 27 May 2018 20:14:27 -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=FoDkJsHh; 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 S1753040AbeE1DOC (ORCPT + 99 others); Sun, 27 May 2018 23:14:02 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50222 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752952AbeE1DOB (ORCPT ); Sun, 27 May 2018 23:14:01 -0400 Received: by mail-wm0-f68.google.com with SMTP id t11-v6so28306050wmt.0 for ; Sun, 27 May 2018 20:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Y0TNwqNxYTZX3DvPLZR0gv2LaRMLBoAPwb1Mnaz339c=; b=FoDkJsHheM8aBpJbnO0oZo4OC4bMnMMpjj5Z7Syzw0mwFpFB8ihboCu/OWiYjrVII/ Suke3L/cf2qjIq6XvDkrqf2ftpIeo5pe4RDrPo2DBfCZw+YuI61hiBrPOWTG1HhTxLfP YJH9HQSNMDY7/sYpaCqsZseXQPu9G+JiPwkuk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Y0TNwqNxYTZX3DvPLZR0gv2LaRMLBoAPwb1Mnaz339c=; b=HSypYCgi/o8OV5AXLvQyCLVzg2GcJS2DKJ7dO2z03IgLM+OjNi8kz1toqSQs1SFP+q IJwb1/OBwi4i5TL8qlho1jwbJnMwGxDL21EUzDRzZG1mnNBOyrOiTDlrvE7tGdkXO+yl sXw1ebx/YNGNpzKfaVoIAEokJ1Ak0CI2jQym6q8xQrPt7tWfHl6NFrJu/YaXEJa5B0fM oSRWxupGXVM6K0K5Zrcg9Y+cC5YV62yP8DzNaex5HiuRGteecz8xZ6skPsfBIN6iH5j5 Fr+tSKdMgOh/sQkQqVMyxunyehhjQGrS/kmtilCyS6zttQblVLRULejCUwVmPL0EZAVQ XSXg== X-Gm-Message-State: ALKqPwcKhDKdDMyIofNicBdvMSFoY7+gcsAUT5LDZ4JmzgeWqrDp6y2e aaHp6mDUkugg8LoMiSRfkqbUUoq/W0D4KzwUOhnuLQ== X-Received: by 2002:a2e:781a:: with SMTP id t26-v6mr7155161ljc.74.1527477240686; Sun, 27 May 2018 20:14:00 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:2049:0:0:0:0:0 with HTTP; Sun, 27 May 2018 20:13:59 -0700 (PDT) In-Reply-To: <1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org> References: <1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org> From: Leo Yan Date: Mon, 28 May 2018 11:13:59 +0800 Message-ID: Subject: Re: [PATCH] perf tools: Fix indexing for decoder packet queue To: Mathieu Poirier Cc: Arnaldo Carvalho de Melo , Robert Walker , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , LAK , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 >