Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp61513imm; Fri, 25 May 2018 16:11:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoT7Xq1SjgUluJ6D1XSKBIzkeoLXxEHpNzBVxVqa8Nj9vZTn54+SXxpIN8iepSsSyNbnR5b X-Received: by 2002:a17:902:5851:: with SMTP id f17-v6mr4538962plj.32.1527289888296; Fri, 25 May 2018 16:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527289888; cv=none; d=google.com; s=arc-20160816; b=AY0D0FxpZ0FtViotTnZmU20PfDPBpIEpn1VvMYjXqLqKxaY3JvgIXsSmg6N1vjQ7fl /zuMcXCbTdDYlOvZEwxOFGhwAWQAlAeQMWTgtiF94rHEoFL+kMlv25T5n5cxFn2FymEY Pcv3XegGHeXWOH9bLQxadF/AGdfuDzOKP5NNIBaG1toyKuf+ERC2uJ0sJpHQs6ksPGLe J4lVQlU47JEnnj79VeGCnjY3VGid4epBKhR0w9SXQ7TwWFId7c7q/Ns9gYqwlwHAvpIZ xJjPwB0FDwMimnmqQqeaVPXC2i5FXcbHscJh0ZgTxhyE/NgmG3+C+T0jPR0+wgxMd/P9 GHDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Q7Cf8VUclqKjH/JO+JJG8wVrb40AA1Kj8w1A1khM6fI=; b=m/gFv+NDGjG4aQo9f0evtKltMKQtsfmM+oxKs+oB06lrtaAJc9607VuvAIyvd3ONDY 38kyr7K7H7ka912vpimVJNc0NH7dDC9KU69bqTv1AYdWlZb5KiAnBbFN2WNdZoHWSJOZ hJUVfsPq0+vzp1Q0LY3sRpS/Dz6UOcdE+SKrfCNNM4vDUjYmkiM/TQZ8I/dhsEvzwt0I LeP9qvP6xFvnwcLJxIiZm7HALFANLUldOorXa9qbia1RGfKSJlBU92EexSNxYKTHBrCf 9E49igFBXf3WCsrDiIGuYf00yFNJD35xHIWu506/6jYkkz7wpZUw1HNzVxxDtOr05PjY sjoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUYgfpH/; 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 38-v6si25100936plc.446.2018.05.25.16.11.13; Fri, 25 May 2018 16:11:28 -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=AUYgfpH/; 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 S1030774AbeEYXK6 (ORCPT + 99 others); Fri, 25 May 2018 19:10:58 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:43532 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030538AbeEYXK5 (ORCPT ); Fri, 25 May 2018 19:10:57 -0400 Received: by mail-pf0-f195.google.com with SMTP id j20-v6so3224907pff.10 for ; Fri, 25 May 2018 16:10:57 -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; bh=Q7Cf8VUclqKjH/JO+JJG8wVrb40AA1Kj8w1A1khM6fI=; b=AUYgfpH/NlZRdcigcLYTopHSn05qilaKJzi9AlRNUNoXKCPvuUDn9ZZWB6YLdA7KtY nC/lONpEl25t7h4kAS7bhy8d4OGncAdCj2seHMtOGEm+ARqLBmdJJt7J3jeMrryKzskq ynQ3+5hsOGAI8zCbZNWVG2yAySBTYhzoCys7o= 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; bh=Q7Cf8VUclqKjH/JO+JJG8wVrb40AA1Kj8w1A1khM6fI=; b=k0JmAN3D2Kup/nz11S9l5EKbzUFPaJTqn1iM8cXOnpUEWmHf6f/85B7zTXxu7NLYdj kM7I2mmAPHd/uSCUrIuKUMKlwMcQ5Uih48PRybtoYi8kxHzHDokrdhxSysi8eydEjP4+ h+R0dA6b0TpaOWVx1FimG39ZkqJ5OGf4efLvVTq/OOYnNwf7ONmV4Zsl4XubzDYSm2MP b7+kK3FjHzXSWFhJlrn2wjp3w5QIOA0X9UyorUbV/iaygcTttjS7l+G7JhTc3/2Hubof 08JDGE8pFAe58Dh7v2BDP4fgsheGY8kaXQnIgZODZfXs+T4etXBX7ovUSX27K02ZpiNz qt1A== X-Gm-Message-State: ALKqPweBNBEE7CWON/0xlmq4LxR02we2j2l7f+edLpcZ7n7DzpjMWbub CFH/PlERo7GmqluKHdxRphaRsw== X-Received: by 2002:a62:3c10:: with SMTP id j16-v6mr4357902pfa.7.1527289857142; Fri, 25 May 2018 16:10:57 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id x71-v6sm70329927pfe.47.2018.05.25.16.10.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 May 2018 16:10:56 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: robert.walker@arm.com, leo.yan@linaro.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf tools: Fix indexing for decoder packet queue Date: Fri, 25 May 2018 17:10:54 -0600 Message-Id: <1527289854-10755-1-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); - decoder->packet_count--; return 1; -- 2.7.4