From patchwork Fri May 24 11:16:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165111 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437806ili; Fri, 24 May 2019 04:17:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcY1rpbtJ/WTwlQSyn33UpzzwdjFezh+CkHWwrBEHZBs6fR3jrBXwmcJ/55H2O1kAOgTTE X-Received: by 2002:a62:a511:: with SMTP id v17mr83788677pfm.129.1558696631169; Fri, 24 May 2019 04:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696631; cv=none; d=google.com; s=arc-20160816; b=Ubmi1kTIJk99+TI0OBmn1GdbQgG4H867eN7XIy2qWxzDpwgIQ+Nwbbus/quHHNkBGt sIJ9O9bPY0uhMYEuq+omHiLScFM/AWfgu+BjPdgmrdKxO2Yz+iOCeKIUQkHh2aOsODJY 6PKz0c9J7a2HFCtFZjPvXofI6YuoE93FevjBnSqh/DPP4iA2mJaiL5C2Z+HpvCjGfD8K 0qs7H8OZzNqV1j8OFRHD5JLG1G4gJC6UFeqsHMJQVMAnVKxOCXdLkZcVtOKS52oAoFuL NxDsgGWRR7AiWPRUfzriCrrRSab2WmNE6o+mHk1kdTSRh6JbFBUGc9/LqHH0tkqw8v8X Ht+Q== 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=EmgL1Y86BuoQl+2pi1yfnzqerUh1zmgys1boIM7w6OcuxcDyVesTKAFbl2beoEDLdV ul4tSm/gjambSpc133b6s9zP+UqZg267xcJ5hzRzwOCf0fst9tbkkGKoGspKr6IS/j8i jDzTEaCSGkYZOEDgt+Uzhlr+CIIYCbHFapHpiQLHIZ6q0bYm+n5bbdrElvOSmkSWDq5e 2w3eaU+sX+jOQ6UadjlMmqWq9/YKTWwxNRvF87SDKW9sfW1JQuSubg53jDnbnPnpdWq5 Q0yOU75QmNneZg5d7c2Lh6LcHEjDOa5THQwQnt8NcuoDD9bKxOh7BV/YJGRbiC7KZf2W D4dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iSt+KozE; 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 k19si3674055pgh.143.2019.05.24.04.17.10; Fri, 24 May 2019 04:17:11 -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=iSt+KozE; 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 S2390936AbfEXLQo (ORCPT + 30 others); Fri, 24 May 2019 07:16:44 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34823 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390856AbfEXLQk (ORCPT ); Fri, 24 May 2019 07:16:40 -0400 Received: by mail-wr1-f67.google.com with SMTP id m3so9608696wrv.2 for ; Fri, 24 May 2019 04:16:39 -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=iSt+KozEePLOt00yptQg4U7xEgXqAzfPyZlBkSB8rsZ6OtjxaUBKIKfXhMXsFcAIeO 7pqnkJ1PnIUul3tBicMbE4tvxLzoY8nwY3BJMY5WRPcpba6j6U+Dy3VT7aWbblAnr2RJ bbZYAKKTaNyKHWEsMfMPp8fwTi61DSxczu3LyxUb0kQ9bI2wMoVLDKlluuRJf8N+e+7u bUHhO/KAuOc9Z025MWY10RgUNyLmgblRzh8SCdg3cdLZw5bhKee1+D36cMdUfpweXETK o6hAXcY0BvphSPze1AadEQV24/Xah6W9/xGxs6oiHXeHiCZNzp6NL9wj2vkVi0k2qO1m R2tQ== 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=LjbiqOpt4TKWIpN5OnxJEdBV0KTzhtoTqrAFPUkEoAMj8gWdMWPh6mNCGlSn1AFRmQ YZ9uVUtRf11wRZ2yLBnMpAqfs7aPRy+28mhnwWQCd4mpWd1lw2omHPeXG5O8iWnP3LAF 76sp482b/FElip8e65Yg9Gh6+YYalMLyou4wvsjbociuoSAwcuyGowDCgdwt1teJvRID 8iAZ3sNOqKE6k/x4Y2+UGKgvJamtUbG/jcRQUhGg6QzlMzvmpF8GfJ0pnrYNEOCNjR9D X1HkZ1fLrKGK2xw//RgfeXRvlLrIz3UR2BD67Zt/vDhXJ4UBIfmXRE6ui64RglNRGZmP X79g== X-Gm-Message-State: APjAAAVrqeBImLYXQ7PSqLk+lIrGLfX5JE5BeDb0/R2VZ02780Qcx/58 EAirU/1LiW8y/JyS2oFC0gMXoa9Ilik= X-Received: by 2002:a05:6000:43:: with SMTP id k3mr62372855wrx.234.1558696599149; Fri, 24 May 2019 04:16:39 -0700 (PDT) Received: from clegane.local (73.82.95.92.rev.sfr.net. [92.95.82.73]) by smtp.gmail.com with ESMTPSA id h12sm2575392wre.14.2019.05.24.04.16.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:38 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 2/9] genirq/timings: Fix timings buffer inspection Date: Fri, 24 May 2019 13:16:08 +0200 Message-Id: <20190524111615.4891-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524111615.4891-1-daniel.lezcano@linaro.org> References: <20190524111615.4891-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)