From patchwork Mon May 13 10:29:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164017 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141265ili; Mon, 13 May 2019 03:30:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqy56qLMMwNM+CsctNkG3FWAV2siD11jhFpRQkQtMOkuq4FN2SuRB414FNdf+3IqYvfe45uG X-Received: by 2002:a17:902:8343:: with SMTP id z3mr29674309pln.240.1557743414289; Mon, 13 May 2019 03:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743414; cv=none; d=google.com; s=arc-20160816; b=bIzw6xhIlPryouzrVq6GIP/0nnrsvckNo/gAjMYgGlAvxiVCgyncrGI9IQS3aeHnqf /xsM4dFE13XsWaf4VLFQUrDrVmBLAKRrOfRUm96Kr/01Y0zAgNED7Yl52sfOyK+7o2zr K2srAu25dPVxirju0ppbBkh8j1Z+tj9r9KA0VlvtwoD8XPjLwjW24lbyGINR8C9Wcbvb 9JJZJw8Wvhl/nNI9horN3PXd7U/FGOXbe/gfIzJtYGtIHJk13zxJ+eGPsvn7q6JtjCOr E6Lj04rlGFkKFF13i+GusBwLUnnWqbz+C41/CihiU04qShrgZob3/Bwlmx0CR1GbgSJ/ hi7A== 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; bh=OVCnRskmJCeqZXRUtBHTU3a0dRFZnt0B8APXmqZl1PE=; b=0i+yL6r1DnJFCKFTFHm4nBRcGiBFJBwla8prtPzNS83i8vRDhhZekGTHjAdDDb8p5V EH7jfK61Cb3yZWaNU2mhEQ+pj8Y5F5jOVYfJ5H5KI6RPaDuEvGhR5xsyHBclPVDycnHD MBt40GGIWULPdJltEyQZJJxSBJNrIiFcvC5CRs/vRX2CJ9f0W9UT2V7HADCUi+UJMLHH ljbCIhD5jJrX4s43s/opwskGRj7EYxNggxTGgfAmk/8YTFREGRZzcSMgr8do06FQ5z9r Flqz9tgi+13nUKd2scqMoW5UhfZn9BygDyiMbthIJljtWhBJw0KwqDPXJMqoUF50gA8S mWAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dCjmqheu; 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 n8si14997508plk.108.2019.05.13.03.30.14; Mon, 13 May 2019 03:30:14 -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=dCjmqheu; 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 S1728633AbfEMKaM (ORCPT + 30 others); Mon, 13 May 2019 06:30:12 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36959 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbfEMKaH (ORCPT ); Mon, 13 May 2019 06:30:07 -0400 Received: by mail-wr1-f66.google.com with SMTP id e15so2219254wrs.4 for ; Mon, 13 May 2019 03:30:06 -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:in-reply-to:references; bh=OVCnRskmJCeqZXRUtBHTU3a0dRFZnt0B8APXmqZl1PE=; b=dCjmqheu9OCwBZAEeNAV56ihyvGOc9X0p3J9Kl5gUc+31+Qi6NFQAoJhzZuU1zIOfa 2e59iMszAI3DOIwYF6e1EeLWiL1gGSMifaEib95F80Q6lIJ8vj09T/ZRby7HdJbYVrbX dUwrVAKH9wIQjAQeIfw/TULMWkAEm2mUb+ABsfQcp5SQpTSyJjU7KlOhQIGwLyqui1a1 /iW2Zqtydfj05piNB/nUJyOJYPq549bCbF1irA9Q9WwEAuOI9HFZ0xtK2qpb/7vhap0A T7dyeMNhrPzV4WvDwDFaUIB6Q9oFVQYSVtzTBpTq41FR4lVB+9tMy0c4AySmz+L6Q1Fs ejAA== 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:in-reply-to :references; bh=OVCnRskmJCeqZXRUtBHTU3a0dRFZnt0B8APXmqZl1PE=; b=oZ0V64V94dZk5oPPAeumoakd37BcmLtjlzEsHECupnRAIk5PMgZcH51AcjI72FaZhZ 7C+EhaC0uDxF1PgtBevKmm3BeJI2uxNuaSLOvH7+T2YLjNk9UPXqTsCa6S4ycQNwku3v YPwkjubhOAGUH+Bb6+lFtwbkB3T+RaTxlYydJ/GmiVfAJ+qTLWvAWHLa3OIQe8DdeEle njXiX6+boCw7x1GJ6ukb1t6DrFEidEF/KeQQap1GLB7CusJwtmzFkBr4Gv46eZtgHNy3 Dg3MIgS7mVC8fsE88TBAxNcDawTQogn+z1Lmiy/W6NfrDr+nNHCkKN9WlwNgBSXyuKDr C4Ag== X-Gm-Message-State: APjAAAUs96uIm2scT35I71u1JxlJN0/DNOyE+yE00hbgY3JKcm2QTtam ZtCrrNQeJF5bXXiBb80AU2pdpg== X-Received: by 2002:a5d:6703:: with SMTP id o3mr3610617wru.183.1557743405941; Mon, 13 May 2019 03:30:05 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:05 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/9] genirq/timings: Fix timings buffer inspection Date: Mon, 13 May 2019 12:29:46 +0200 Message-Id: <20190513102953.16424-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It appears the index beginning computation is not correct, the current code does: i = (irqts->count & IRQ_TIMINGS_MASK) - 1 If irqts->count is equal to zero, we end up with an index equal to -1, but that does not happen because the function checks against zero before and returns in such case. However, if irqts->count is a multiple of IRQ_TIMINGS_SIZE, the resulting & bit op will be zero and leads also to a -1 index. Re-introduce the iteration loop belonging to the previous variance code which was correct. Fixes: bbba0e7c5cda "genirq/timings: Add array suffix computation code" Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 60362aca4ca4..250bb00ccd85 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -267,6 +267,23 @@ void irq_timings_disable(void) #define PREDICTION_MAX 10 /* 2 ^ PREDICTION_MAX useconds */ #define PREDICTION_BUFFER_SIZE 16 /* slots for EMAs, hardly more than 16 */ +/* + * Number of elements in the circular buffer: If it happens it was + * flushed before, then the number of elements could be smaller than + * IRQ_TIMINGS_SIZE, so the count is used, otherwise the array size is + * used as we wrapped. The index begins from zero when we did not + * wrap. That could be done in a nicer way with the proper circular + * array structure type but with the cost of extra computation in the + * interrupt handler hot path. We choose efficiency. + */ +#define for_each_irqts(i, irqts) \ + for (i = irqts->count < IRQ_TIMINGS_SIZE ? \ + 0 : irqts->count & IRQ_TIMINGS_MASK, \ + irqts->count = min(IRQ_TIMINGS_SIZE, \ + irqts->count); \ + irqts->count > 0; irqts->count--, \ + i = (i + 1) & IRQ_TIMINGS_MASK) + struct irqt_stat { u64 last_ts; u64 ema_time[PREDICTION_BUFFER_SIZE]; @@ -528,11 +545,7 @@ u64 irq_timings_next_event(u64 now) * model while decrementing the counter because we consume the * data from our circular buffer. */ - - i = (irqts->count & IRQ_TIMINGS_MASK) - 1; - irqts->count = min(IRQ_TIMINGS_SIZE, irqts->count); - - for (; irqts->count > 0; irqts->count--, i = (i + 1) & IRQ_TIMINGS_MASK) { + for_each_irqts(i, irqts) { irq = irq_timing_decode(irqts->values[i], &ts); s = idr_find(&irqt_stats, irq); if (s)