From patchwork Fri May 25 23:10:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 137002 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp158628lji; Fri, 25 May 2018 16:11:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZolPX112dZYepLZAuFZfxEGOsHF8RJ6rG7O9Y4ffIzLA0fJZkzo1d2ACHuUX0TK3VKIwuOd X-Received: by 2002:a62:449c:: with SMTP id m28-v6mr4355919pfi.145.1527289861835; Fri, 25 May 2018 16:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527289861; cv=none; d=google.com; s=arc-20160816; b=obd5dp2R4A2TE+1PxX/pO4ckdN8Kl+r9RXtcGln8TROJjqTrOuEKZSo3gY07pKQ736 x+pZLTBTBJB62umH2To5U1Tho4+mlDWq6vlHVULhmZerPuKc3fJp4tp9Vey67ro3JRjC PfGISMOGFSTf8R7ZLrXDUokPMknp80wwHnwrBS5ia6mIhJ77FrqgbWS1mdUrp9b67OEq ehJZTfOIEMq0dkhv1myO2R7ANiLfxQhmtvj1TdhkImRo7DNYQYjkiabt7IZ46cZfunRf LK49zRcCy4C71SndYjjgs+QLHdp62Tnjiiiw5ATeQUFCQ0RcllhvlLVcYqMIcFA+xAfK 6l+Q== 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 q14-v6si2100637pfq.307.2018.05.25.16.11.01; Fri, 25 May 2018 16:11:01 -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 S1030789AbeEYXK6 (ORCPT + 30 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(-) -- 2.7.4 Tested-by: Leo Yan 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;