From patchwork Fri May 24 11:16:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165104 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437478ili; Fri, 24 May 2019 04:16:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFQNELbZZUT4rRtSEwtoHFVRJVYyEljoT/05P+7F3LWLd6SCoP98b8nFd0efiyKxfCf89r X-Received: by 2002:a17:90a:8c90:: with SMTP id b16mr8605738pjo.85.1558696615324; Fri, 24 May 2019 04:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696615; cv=none; d=google.com; s=arc-20160816; b=seAjsFT1bu+NsLXD8Vxa8gOPk71a6JK4Dzs5lwO9g2Goj5b8tWHZZp3cjnnV03F8rQ kK0BU5Pjp2zw0H3NFLFvf64R8umwVeiHg2mzROkhxRwUoGVBNL8iyA2Du9uOtsmyHUOP RBJPXGj+9IunTHmcLlj2eGRprAn4XMlYPj0+oPiXoNL38JcvxplU9qCJCYHra6uKB698 Qlq9WSvrJoV6YxjOqYj2E1r1ipDVO4M/1W/u0olQujdTeD/2bOOXDWveOkFAav2F7p2+ NkX6e6dFJVfRTYdlY+f09L13jAoZo/SXQmmtEVqzkONp3JzFv5KuJbcC6LqPUoKQGb2r QPsQ== 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=A0HzfJ8leQV9/Ia+5j4PgeiH8O0rzgjlyMwyBqLrNY4=; b=Ttae8DmkssiZWHLfKEgagdo/YOAdxIu7o6LwIXOagA580nZo0hiVZ0oDnojc7jjoXW 9JEwHqS+Ib9wZiqRVk7g0rS19xfSsYFMIL0iTrbpeK8Q5/LA9J5rC2ZvjoQITKHNP3ZN oyifxavvMfEpn9avvaMe2/Dyrzuw4mPwXxWSb2LDEADFLCNCz/6NHiiX4dycu3z8nwvV NFOQHguc11PAQwwxoc+fMy5IeyK6gBwGSvUSNgAFPg6tUM2O127uUrVMSv93QFBlFs8J pkSUBs0PPgJgmQzI7l8kWXiZTEnvinswXcpctvMpmxTceg3pF/Pcw295lm2f039+BWZe pSKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pvNpKcLs; 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 b1si3735560pgg.392.2019.05.24.04.16.54; Fri, 24 May 2019 04:16:55 -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=pvNpKcLs; 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 S2390894AbfEXLQl (ORCPT + 30 others); Fri, 24 May 2019 07:16:41 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46503 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390410AbfEXLQj (ORCPT ); Fri, 24 May 2019 07:16:39 -0400 Received: by mail-wr1-f67.google.com with SMTP id r7so9578114wrr.13 for ; Fri, 24 May 2019 04:16:38 -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=A0HzfJ8leQV9/Ia+5j4PgeiH8O0rzgjlyMwyBqLrNY4=; b=pvNpKcLsEz+1W37HcVISnMK4xkdCyLtbas0+BI0hYTjlzR/fSpFpW7oqy0Nk7KvHwx BxHl44BzkSqRlNJhucVvuVCrgCGGQO6decnRTfn12JuxgpSvDQ+ouiu5kba2JFwy+OJR BTJbBFDg17pyytm0KbCGpghu4BjNRDIVEmfXZCKwARZSevQBe/bE0pjHs6sFqG0qDgyc HxZ/NMWbPrzbIVMbeHXTU2Na9e01X8aT7e7OIzCXs7cgJKeK8otHCzSESBjs8q+8/0kV U/rQUYpkoIqbdy865VwfoCkjhL5vFxFEqLtJw+hixLdQNJ+JEjKHWzFXC+ULshxJrIc9 nYew== 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=A0HzfJ8leQV9/Ia+5j4PgeiH8O0rzgjlyMwyBqLrNY4=; b=Qg0BIgN9dDs0n4NAvSflcHsswb8dCK2IuRg/yyUpWNTkur6Ubm9BuKGOIltVeaGQ2b gCJDaYa0zXTkYpd588sn0haFz7719KuYMpDFVn51//jNs+rtx/onoae1JvAoCLkfzjWu 6l7P/HrJcK1BZwrC/0XOSDSeAuU0G6rNHvvTpkML8cM6sCiKmEbE3ma0VLijPZ8LYTWr FjiD4v3pA1D8LoOijavxHGXkS6wEb53CCTy1gfQ8HGivJptvZjqBp3oi3W1tEfAXUMbt FONgREhStDCQwgWKWZ5ETP5y4qmiqBZYZjUGzVcGmUER1B86M6RvKvy9FhbptCXnwrJX cRIA== X-Gm-Message-State: APjAAAU7q9Y5OriknPJZqgJiwu8qOTD8yF4pBihCm2pSq3ytIzPipAlS 0GuKfsMwFshilN7xbf8nl+dCziu5+pA= X-Received: by 2002:a5d:4945:: with SMTP id r5mr9522454wrs.328.1558696597623; Fri, 24 May 2019 04:16:37 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:37 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 1/9] genirq/timings: Fix next event index function Date: Fri, 24 May 2019 13:16:07 +0200 Message-Id: <20190524111615.4891-2-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 The current code was luckily working with most of the interval samples testing but actually it fails to correctly detect pattern repeatition breaking at the end of the buffer. Narrowing down the bug has been a real pain because of the pointers, so the routine is rewrite by using indexes instead. Fixes: bbba0e7c5cda "genirq/timings: Add array suffix computation code" Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 53 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 90c735da15d0..60362aca4ca4 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -297,7 +297,18 @@ static u64 irq_timings_ema_new(u64 value, u64 ema_old) static int irq_timings_next_event_index(int *buffer, size_t len, int period_max) { - int i; + int period; + + /* + * Move the beginnning pointer to the end minus the max period + * x 3. We are at the point we can begin searching the pattern + */ + buffer = &buffer[len - (period_max * 3)]; + + /* + * Adjust the length to the maximum allowed period x 3 + */ + len = period_max * 3; /* * The buffer contains the suite of intervals, in a ilog2 @@ -306,21 +317,45 @@ static int irq_timings_next_event_index(int *buffer, size_t len, int period_max) * period beginning at the end of the buffer. We do that for * each suffix. */ - for (i = period_max; i >= PREDICTION_PERIOD_MIN ; i--) { + for (period = period_max; period >= PREDICTION_PERIOD_MIN ; period--) { - int *begin = &buffer[len - (i * 3)]; - int *ptr = begin; + /* + * The first comparison always succeed because the + * suffix is deduced from the first n-period bytes of + * the buffer and we compare the initial suffix with + * itself, so we can skip the first iteration. + */ + int idx = period; + size_t size = period; /* * We look if the suite with period 'i' repeat * itself. If it is truncated at the end, as it * repeats we can use the period to find out the next - * element. + * element with the modulo. */ - while (!memcmp(ptr, begin, i * sizeof(*ptr))) { - ptr += i; - if (ptr >= &buffer[len]) - return begin[((i * 3) % i)]; + while (!memcmp(buffer, &buffer[idx], size * sizeof(int))) { + + /* + * Move the index in a period basis + */ + idx += size; + + /* + * If this condition is reached, all previous + * memcmp were successful, so the period is + * found. + */ + if (idx == len) + return buffer[len % period]; + + /* + * If the remaining elements to compare are + * smaller than the period, readjust the size + * of the comparison for the last iteration. + */ + if (len - idx < period) + size = len - idx; } } 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) From patchwork Fri May 24 11:16:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165105 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437483ili; Fri, 24 May 2019 04:16:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJOrAbUQUwSJgYCMrn4pvOEB77T7WpIn1i/SNBvHTiW/s/HZssEL/ovuxCFE5ROUXCLnWm X-Received: by 2002:a17:902:e08b:: with SMTP id cb11mr47059677plb.122.1558696615728; Fri, 24 May 2019 04:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696615; cv=none; d=google.com; s=arc-20160816; b=W1oIfbudZiUkZhSb5oBEGCMz2TKUR85eRxLEJkiosqaBCf2cbxOdWD6ZJjUpLpolBN QERr53gMP4smU3PBLBKV2JBVJr5Bk4WHrg+twX1PgBVAb4j3+Qph5JuyIDuEbM9wIMyy qlF0jwAFNZxVuXZUh3vPjFz2fzTQ8b+kM7MvtgIkyc+p7rL2xsSI7XMgzhVAt7SMABMf mQl8zvBcHNWa6hVdxWy56yuMxvNRYhBzQB7HjVFvXWLw3fxJbz4YOYAyckZkEHHJNDtB HHB+SWc3p3K0YFZT/cCY7wiCKU4k/jNdR2a6dwyWXsi3MOZ1fwxhUN9IWwn9upI/QU0g SJyg== 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=L7Wy/UoR346yun6rGdrn0w0Sk7Zt+3JLoV24BHUfklw=; b=l8pHedN2X3mgtr8hUof7Ftr3tc7YP2IEMBMxjK/tarQhk1WqYr5pOPFXpnGFjDXoj2 6GfdTiBwrfNJr0iTp00Yh6Uikb8kjHDmKor4uQNqjpnbFl3I6p4OI13415R4PTZNNBwX ObC8KbttwZhGaRSROGh8E3X6b144F88U3wNmxz6Ub2bTw+5qdeE5oSCl/2MFeAvqwTWE UaApHzp9MWxebZkdFcBTToR1pRq4JrrnVQV+396L0oIC5BhNSWKth6FfcHaXGsKCaClT i5J7Pzs2N2bXPY+Hz7f8DeAFTziGUiJa/qQDFd/HUrvby63j5yyHxHzLnKxLYoA9wc5A Ap0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="twWc4/+Q"; 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 b1si3735560pgg.392.2019.05.24.04.16.55; Fri, 24 May 2019 04:16:55 -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="twWc4/+Q"; 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 S2390971AbfEXLQp (ORCPT + 30 others); Fri, 24 May 2019 07:16:45 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40051 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390410AbfEXLQl (ORCPT ); Fri, 24 May 2019 07:16:41 -0400 Received: by mail-wr1-f66.google.com with SMTP id t4so1326384wrx.7 for ; Fri, 24 May 2019 04:16:41 -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=L7Wy/UoR346yun6rGdrn0w0Sk7Zt+3JLoV24BHUfklw=; b=twWc4/+Qzxo/D1UOnToCY0eDa73j5l1K8Qp94mmxWXgleAnqOFh7FoKKZXgEX4YCZ0 k2+yDABe/dRSA4VkRLWycdfvXMNAh72chSlPqCET2BGRhVfJyuoVFeS8WwFTy7HwZ5LZ RHnk8bGliEfW33uzlNY+eHQRjzpwMaHQtca8eb9UsIl+QVPTpYk0CQDqCU8rAZQL+VCQ jIEpo5lLqbJeJcRRObCrX2EcluaWMkAhvFRcRKq0/9bjxxpX1u2WV6zE+8uh2LN2M9Lr 57VthcvkM2QDAh+/7dH2ni5xz4/7svNg+4NpIlS7Md0oowPzqWjkGBq9JjBEZSOqfKy7 JRNA== 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=L7Wy/UoR346yun6rGdrn0w0Sk7Zt+3JLoV24BHUfklw=; b=BSZtwcg4XluQ7viQ4XtYkCMRR+pZBDGs6broLnFyYVZOxRfKGJU05aNpYeQhZrBbDJ IOdne5850jWKU/EMSHt3FT7t55FTGrfQM6sseI2S0Ns0tFfRwvOD7iNuMNbofWU7JzEG m77FeVdJZdA/WAHZCLyTjKgvvtDFQVCAQiAF992GEfQWj6XXpyalcqS5cpb7tSnFHCXH ocM3hKZiHKjIY5MEQAgYCcjUC+DwFZvhCPNOtIiYQv2qXRogTxhroQYsQdzEw4rMh3ZC CSaW7SYHG7MRz8qFDJZTDQKc3FxJ782tQYfDPQLzUg2O/ZTlARBtwK36AzjkL9E2uSm2 Sm2g== X-Gm-Message-State: APjAAAVQtPmAUCddQQPr33+EQuFaTbS9jAcWkyNEGdLagc3N0UhPmKnl nz0vrIoGANNnr3prAZP2NUuwmw== X-Received: by 2002:adf:e94b:: with SMTP id m11mr5174901wrn.133.1558696600480; Fri, 24 May 2019 04:16:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:39 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 3/9] genirq/timings: Optimize the period detection speed Date: Fri, 24 May 2019 13:16:09 +0200 Message-Id: <20190524111615.4891-4-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 If we have a minimal period and if there is a period which is a multiple of it but lesser than the max period then it will be detected before and the minimal period will be never reached. 1 2 1 2 1 2 1 2 1 2 1 2 <-----> <-----> <-----> <-> <-> <-> <-> <-> <-> In our case, the minimum period is 2 and the maximum period is 5. That means all repeating pattern of 2 will be detected as repeating pattern of 4, it is pointless to go up to 2 when searching for the period as it will always fail. Remove one loop iteration by increasing the minimal period to 3. Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 250bb00ccd85..06bde5253a7d 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -261,7 +261,7 @@ void irq_timings_disable(void) #define EMA_ALPHA_VAL 64 #define EMA_ALPHA_SHIFT 7 -#define PREDICTION_PERIOD_MIN 2 +#define PREDICTION_PERIOD_MIN 3 #define PREDICTION_PERIOD_MAX 5 #define PREDICTION_FACTOR 4 #define PREDICTION_MAX 10 /* 2 ^ PREDICTION_MAX useconds */ From patchwork Fri May 24 11:16:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165112 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437901ili; Fri, 24 May 2019 04:17:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRek8XYlwawNRBDQSPLvJyUoIn9/c4g2gnDGZA2lhpYN6dGJD1+fi38SWRWuKJiZyWQ+hJ X-Received: by 2002:a65:5244:: with SMTP id q4mr23703792pgp.79.1558696636668; Fri, 24 May 2019 04:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696636; cv=none; d=google.com; s=arc-20160816; b=wSYACvZOGUIaWuJ9T4zvDMYnNQBx0/EGl8SJh+RAiMGAs4BNFNlYOYoCLcE9sbYZnl 6yjb7pdC0mauwnOFBsGq7p5DD279ZpE6M76YMV1J2Ri6awkVfM9eLUuuc3X8MtswxL7R o9/Mhab+QrWhQGQ3DRQ8kDqzoKJh+L9bGNWHtdPvyvC6TvFUYf4mnI3LfhMn95OIiwG2 gVOpzyl3yHYls93m26fzw5CsuwrIHq56tK2frr8P5odYyn2iQF/RGvJdukZxnAzu8s/P SaejiQ0QNBQwGh3NzEbvEQuSjTYLNrB/jgfnS3oeYfUk+oWrrVK8GVAOrjSEB0AcWwRa qkAg== 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=wJ/OTTzXkpFYyCPQfFmBGF9g9r7JKprAJcxNABvYugk=; b=nxcDpgSlDYAvxOYhHMdOQaQEb9vUvOdvkQHM0OBpaBL6RHObyvVVF4gsbKBkI+3TzB 4DFQGaOS/Iv7Jba/YZ8ani+BBVjsdWHpHbX+C0tMqlpP2PurkuQ+7wSlLskoVeO9iyjx PLFj2P8E9PINTWAxZKdTnR/ySLAcTRfNfTl7HxgtFC0vb99VdrQNrD+N2QtmB2j3H0Ej I6lA8jocWLUfUbx5Y/4DMPVc+oyXWrhuzTXChMiKFsvvvVGGLN0Cv59ARP7A5qCES7WA rr0w4m4+Y7ft89odt25/xNszTjIWA4oFMbwU8jHGG9fgSjHSi0TTdJtpwh7O9BLWmU7e 8OHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gJ1stP/+"; 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.16; Fri, 24 May 2019 04:17:16 -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="gJ1stP/+"; 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 S2391121AbfEXLRP (ORCPT + 30 others); Fri, 24 May 2019 07:17:15 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40053 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390906AbfEXLQn (ORCPT ); Fri, 24 May 2019 07:16:43 -0400 Received: by mail-wr1-f65.google.com with SMTP id t4so1326474wrx.7 for ; Fri, 24 May 2019 04:16:42 -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=wJ/OTTzXkpFYyCPQfFmBGF9g9r7JKprAJcxNABvYugk=; b=gJ1stP/+skWInP/MCWzv188wslOchZmZz7clJcjMeGjOAKJVQ8ZUw6DC3QDutVoMw0 P9CD1wa68T48LNgzOL7NlendOV281v85ONTsvsKVKy7YZIlATB8R96UEy2fslY9V+hNP +AD88uTiybNf3E+9E77v6ACNBfmmGwR8DBJ4X0lOPm0ygG1/ayhIkfa66R06mrzcqHqz Bwge7jwBG8R++lmUEjjQwHdjlVQVZG28lqF4cR+8pO2kDAoNE7liSM+Qtt86AhCrDxw8 WyjbpoBwIOpNWeny42n9gNyVfmFWBgVcxTsD9vz4BKVE6P/Xyxvpx4mnB6NAQORjH68h RzTw== 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=wJ/OTTzXkpFYyCPQfFmBGF9g9r7JKprAJcxNABvYugk=; b=Vj+wcGup37+AcHBAjvkdaemg7BTh+xo0scB2v2SIAJStmD9VZMu43MhxNJjBIkMUpT JWp1i7G2U/Fqva8vNubkM+sk6stjGIqR0vveDSCyOBCoWdWJoZTNIUVpj2NycKmYwQ72 1giiEZ/gIZRJUQeY/bYobYMlQ37boxakP+390IlT8BTaBf1OF8oe3p0CAeUQvYDx9h10 LhfrNRZsbxe4bGgVoRkm6b8XYMiON4tg9HqgKa6jorM9UZjqE1su8zFlT+3cT0wwdlP7 CXgSuiv6iJNAgbqrryfTnXMM2M5+k4YJM7/Bfkpf8ZhoIBIuQeY0OmMljxxORxt5n5xe RBtg== X-Gm-Message-State: APjAAAW8WrC42vqAF/vP0Ap5rKCoexyxGMpaGR9CJugRtUGZ4FmYyPSp bRgczp0cysjn/NaSHHjOHWAh2lleLes= X-Received: by 2002:adf:e9ca:: with SMTP id l10mr4153207wrn.47.1558696601880; Fri, 24 May 2019 04:16:41 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:41 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 4/9] genirq/timings: Use the min kernel macro Date: Fri, 24 May 2019 13:16:10 +0200 Message-Id: <20190524111615.4891-5-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 The' min' is available as a kernel macro. Use it instead of writing the same code. Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 06bde5253a7d..8928601b4b42 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -406,8 +406,7 @@ static u64 __irq_timings_next_event(struct irqt_stat *irqs, int irq, u64 now) /* * 'count' will depends if the circular buffer wrapped or not */ - count = irqs->count < IRQ_TIMINGS_SIZE ? - irqs->count : IRQ_TIMINGS_SIZE; + count = min_t(int, irqs->count, IRQ_TIMINGS_SIZE); start = irqs->count < IRQ_TIMINGS_SIZE ? 0 : (irqs->count & IRQ_TIMINGS_MASK); From patchwork Fri May 24 11:16:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165106 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437489ili; Fri, 24 May 2019 04:16:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFeldyLWKBYZT0XygXGPYMZwwBgts+LCxeAj1HYPwp5GPN+fPqRhCJ+TIU5mE2Ded8Irp9 X-Received: by 2002:a63:8449:: with SMTP id k70mr103113106pgd.53.1558696616191; Fri, 24 May 2019 04:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696616; cv=none; d=google.com; s=arc-20160816; b=fbmbrs0sV2HPEuxNznz7uHi8wiO2naX/2cTQcEMqNWOGfS5Rl7WySuZYZn9KPqLukc bIBpWoRVn5SuzQi+cjNlxqSjS15okJw7EO9kW1brilqCGlF+rONJlbPNPWnG9g69z4Nt zIqhGX/jtIejuHV+scgOWtgEAMvtXLDrTFmNR0rRqfK4E2vuHOfAgTxzu7bgR6YdYnWs tvVgjzVvnSKgG75gfYCQYH2esEVRkROJPNN5q+ceh9lqbx/IPdgB3dx0XP+KuOIc4Lli UwH96wb2j9UeN+FIEPLrFc7SQFOEhyRHJ0Lb9zyfa6NxG2cWNOxslXZV2o4CFLQkIcOR 5mOw== 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=D2Cp7f/Qid/by7EIC98tg3BbhOaVwQta3p5eP2Mz3hQ=; b=WxHR2Sj6gYn36UJgJEEO8Wa47aIQRvxbzUlVTbWA+MRp9TLBn0LufDO2BUjeEPCUyS +FH+V4+m/ahnBchjy0X7UVJpCtCKk3x+4XVrF8zb654UPVowv2LxS2o3s6qyvnef4LaX lpddk85JPlAIATBln5g6ZrwVcPb0zVKg6q4M8kYLcoPU2lMkVp6lzhr4zLdsi053ZsWN kL+bQJCQQxI4uyGsz8vrIblYzD6ngs4C6pFiWsvqLbOtcUw2w9uZ2aq8jODIDSLj9r3j 5qwIRbjStMVnfAXAmYzl4m0mq0Kcnd1kfC5THcKOjKp99epk1L4ba93O3jiqwOzeyd8J Q9aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SYmw9u/B"; 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 b1si3735560pgg.392.2019.05.24.04.16.55; Fri, 24 May 2019 04:16:56 -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="SYmw9u/B"; 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 S2391003AbfEXLQs (ORCPT + 30 others); Fri, 24 May 2019 07:16:48 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35428 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390932AbfEXLQp (ORCPT ); Fri, 24 May 2019 07:16:45 -0400 Received: by mail-wm1-f68.google.com with SMTP id w9so2699490wmi.0 for ; Fri, 24 May 2019 04:16:43 -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=D2Cp7f/Qid/by7EIC98tg3BbhOaVwQta3p5eP2Mz3hQ=; b=SYmw9u/BJ1amgAo2T7+9N3JVa9edXzEA5XwgQqoQMkbnEG66y2My7j+uYTQliLkZ5G wA9s/2O5X1B23OTaAssAZqkSQG7H0FIYEIl98O0kAwj5fnLaqvu/WznalSN1VNHQHsa3 C2Ee/KA7/+/H1EyER8+3hFE2PHg0y77TF18FtIzduRBGHj0pAVpYwg3GCtGUmwEAyOdO kq+deYjKk+I+pLJefY9stJWTiwb51IIHZXQUqnwYT/unx3FHYircXFxYC/3b+akzVGQC I9K8RQxuAlz134Wu1krvsJ0ASORwtwDVQbjb7tDGIdPN5IxBeeHTnFhhM1qPXafxgn+F dBQw== 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=D2Cp7f/Qid/by7EIC98tg3BbhOaVwQta3p5eP2Mz3hQ=; b=LXSA1+ZEXOspJIqI1/7LDUKBPbt+dG6p97bJT5QiiR44Y5KYFCxcxf9nZEbmRGLm8D DGJCKutVsvBUAl9OLHlN190K+fQyUd8wyFgnXcNujnXqYMyx2FRaU5skD2dfjcCi9SpG hFjD0ivw5OkoC2DPUZGyq2xBBJ4VsPfd4140jpXxE9/9qtjswXFfJjTl516wGlOTDa9p FvOsOY9gl47yaE5GpSrQklBQbrPIUzuV95Cua5yiyLUY1v3uilGNCWUdTxptV8XAkdgr CA6EjtbUjYc1PhOa6O9gvQOR8Jd6gFUDe6rOMh4iRifFgahpWtUHY/GG2AIENut8Dm2g oi0w== X-Gm-Message-State: APjAAAUFfLxl9VH3C60spfVsoy77tgyvwBd8YjQ8GtYz8PMAVrvdzbst oiQEhLfRmLb+KovpNOjqNddioLepgFw= X-Received: by 2002:a1c:a815:: with SMTP id r21mr14796594wme.66.1558696603124; Fri, 24 May 2019 04:16:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:42 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 5/9] genirq/timings: Encapsulate timings push Date: Fri, 24 May 2019 13:16:11 +0200 Message-Id: <20190524111615.4891-6-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 For the next patches providing the selftest, we do want to artificially insert timings value in the circular buffer in order to check the correctness of the code. Encapsulate the common code between the future test code and the current with an always-inline tag. No functional change. Signed-off-by: Daniel Lezcano --- kernel/irq/internals.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 70c3053bc1f6..21f9927ff5ad 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -354,6 +354,16 @@ static inline int irq_timing_decode(u64 value, u64 *timestamp) return value & U16_MAX; } +static __always_inline void irq_timings_push(u64 ts, int irq) +{ + struct irq_timings *timings = this_cpu_ptr(&irq_timings); + + timings->values[timings->count & IRQ_TIMINGS_MASK] = + irq_timing_encode(ts, irq); + + timings->count++; +} + /* * The function record_irq_time is only called in one place in the * interrupts handler. We want this function always inline so the code @@ -367,15 +377,8 @@ static __always_inline void record_irq_time(struct irq_desc *desc) if (!static_branch_likely(&irq_timing_enabled)) return; - if (desc->istate & IRQS_TIMINGS) { - struct irq_timings *timings = this_cpu_ptr(&irq_timings); - - timings->values[timings->count & IRQ_TIMINGS_MASK] = - irq_timing_encode(local_clock(), - irq_desc_get_irq(desc)); - - timings->count++; - } + if (desc->istate & IRQS_TIMINGS) + irq_timings_push(local_clock(), irq_desc_get_irq(desc)); } #else static inline void irq_remove_timings(struct irq_desc *desc) {} From patchwork Fri May 24 11:16:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165107 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437495ili; Fri, 24 May 2019 04:16:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5IPu5/4T8GNDQGmjPbdsolDnBJmnQ4gJgt5J+hv/6q+6EAobWie9EDP+I1qga61BRAl8q X-Received: by 2002:a17:90a:af8b:: with SMTP id w11mr8461687pjq.135.1558696616597; Fri, 24 May 2019 04:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696616; cv=none; d=google.com; s=arc-20160816; b=H8U09s7ZqbXo5mhGYHapUiJighwaKAfLXhHJ8CEIPAZIPaVzgKjoSkW150cEeGn1qe dC9QMq++sVBCAb2oAfs2n7HbJelAbDLACY/po2UJsl64+EqzrrN+AxsxgGgmaWbiPOHY 5Str1s405VXwtn344QdqvcYRPv2vCsWIc61p4+za+eovldH+IEE50P0srxKDy8DgsB+o KlFDyqJR7jfobB7zGCChGDZRjDQjfKDeed3GRO+W7vsXUlAvSJnn3ehRa8BPjeHKJYnh DvkRdDYq0k20qW1VDd4hnFUE0syKI2Yf7334hn9e+rbayh2EIAgM1PyUf3NqNoylrU6Z +58A== 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=lvZ+JFSB5ojt72GfMWAJ6EobprUjj+jvH2Pe8i8Nlqo=; b=KqS8mq9KIQ9B/M1dJ8iW7wtc7JL60vvtdAQvK/BH/vVTFNK77HZ08Gs1fM1JEEki05 lRWHAupCEGg0OHb804WNwzK48BX2kqmiVx0YLrp7fiHqS8hr93PQXQ7cSvEn2gIBhHr5 IajhgIG6UYWcFtSMmDA2wxw9NVQQ2y341weJRvy67bvG5SnZbz6PC7ExqxVpk2tYe1zU MTOmZA7VpvO2RsYSXt1XAEEBVThtvqGSzYy1ucGlvN1R416I1LSveLQUPPSHQYTuTnPm 4YVExbdFkRUNHigLCNDC/UzMzHnXEtfPCENEKY1Hl5m43uI83u7G8lQK1m4kz8K/nglT aQSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vGhRLZdm; 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 b1si3735560pgg.392.2019.05.24.04.16.56; Fri, 24 May 2019 04:16:56 -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=vGhRLZdm; 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 S2391029AbfEXLQs (ORCPT + 30 others); Fri, 24 May 2019 07:16:48 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39001 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390973AbfEXLQq (ORCPT ); Fri, 24 May 2019 07:16:46 -0400 Received: by mail-wm1-f67.google.com with SMTP id z23so4742223wma.4 for ; Fri, 24 May 2019 04:16:45 -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=lvZ+JFSB5ojt72GfMWAJ6EobprUjj+jvH2Pe8i8Nlqo=; b=vGhRLZdmVNVGGcKBnIItowDcWfMq3Xaw389Y/cuQNZS4iDmNrDbBCBaX7j23/axhjX 3oooQ0egkgP8w5lyPAe/HAxKtMBDhYdSX6EsSAPyYt0P4Ww1aoQiSNAaVNud2QXu3api GFKQY8wfQlR7UqVc6obKc9SULzAyDlvH5R2p0WlFfPzuHL3nuHYEUAMGSY5GRG+XFDlk OcjsVTGANwjDrbjGYzwli5ZADNkJVqhkkRyxw6DWF+ygOhLiqJQI2GfBGj7Lf4fQS/E/ BXywzq0fUEuSt7fY19YaBAYj2KfVe34HZqK2TegGijJTDUytHGn2IupYEnTTU6nfhZDE dkxQ== 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=lvZ+JFSB5ojt72GfMWAJ6EobprUjj+jvH2Pe8i8Nlqo=; b=kXdt9D+c+tjMwJQ/+VRP8TfkTJDXvJM+qXO0Zgb1v6j8YUgtExdneT52Ys5kGG0rSR PKDtDuIqwXhYKDInBVr/Ne4MKg0JHocXt7u1f7whkKBc9B2+sxRny5pQwf+axJBtexby dDoFHQiXfHepvEsiN98DxKzLOvOe2XWKORY7q1fKB4W8dUn5gYgwIfbgoYHxlkYzh6Qf uOqzH5YCV2wCA5GJDXp6LJHzRHaZT5AQ/WxcmNCK1kk5hdOtZTXGTghu0Ysbli+2GBYU OQM68tXrTB3XLBkiQnQK8lcVFmD8Y/H89I8WkDSdqmT2I6QL33j4hknoT6ZAOWJgaj1F 9IwQ== X-Gm-Message-State: APjAAAVmbjBfq4gzg/EN3E/TEQ44c8FU+1YiSxLJZGSGT2KKBDDxwG4D kE7oP0ZLRcbqvuxSNNWBpajjFw== X-Received: by 2002:a1c:9a14:: with SMTP id c20mr15322201wme.104.1558696604433; Fri, 24 May 2019 04:16:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:43 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 6/9] genirq/timings: Encapsulate storing function Date: Fri, 24 May 2019 13:16:12 +0200 Message-Id: <20190524111615.4891-7-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 For the next patches providing the selftest, we want to insert interval values directly in the buffer in order to check the correctness of the code. Encapsulate the code doing that in a always inline function in order to reuse it in the test code. No functional changes. Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 53 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 8928601b4b42..02689e6168c4 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -431,11 +431,43 @@ static u64 __irq_timings_next_event(struct irqt_stat *irqs, int irq, u64 now) return irqs->last_ts + irqs->ema_time[index]; } +static __always_inline int irq_timings_interval_index(u64 interval) +{ + /* + * The PREDICTION_FACTOR increase the interval size for the + * array of exponential average. + */ + u64 interval_us = (interval >> 10) / PREDICTION_FACTOR; + + return likely(interval_us) ? ilog2(interval_us) : 0; +} + +static __always_inline void __irq_timings_store(int irq, struct irqt_stat *irqs, + u64 interval) +{ + int index; + + /* + * Get the index in the ema table for this interrupt. + */ + index = irq_timings_interval_index(interval); + + /* + * Store the index as an element of the pattern in another + * circular array. + */ + irqs->circ_timings[irqs->count & IRQ_TIMINGS_MASK] = index; + + irqs->ema_time[index] = irq_timings_ema_new(interval, + irqs->ema_time[index]); + + irqs->count++; +} + static inline void irq_timings_store(int irq, struct irqt_stat *irqs, u64 ts) { u64 old_ts = irqs->last_ts; u64 interval; - int index; /* * The timestamps are absolute time values, we need to compute @@ -466,24 +498,7 @@ static inline void irq_timings_store(int irq, struct irqt_stat *irqs, u64 ts) return; } - /* - * Get the index in the ema table for this interrupt. The - * PREDICTION_FACTOR increase the interval size for the array - * of exponential average. - */ - index = likely(interval) ? - ilog2((interval >> 10) / PREDICTION_FACTOR) : 0; - - /* - * Store the index as an element of the pattern in another - * circular array. - */ - irqs->circ_timings[irqs->count & IRQ_TIMINGS_MASK] = index; - - irqs->ema_time[index] = irq_timings_ema_new(interval, - irqs->ema_time[index]); - - irqs->count++; + __irq_timings_store(irq, irqs, interval); } /** From patchwork Fri May 24 11:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165108 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437504ili; Fri, 24 May 2019 04:16:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfZByDhA3nk1Zq2oWZfrNRNj3B6iifWFd9HpciwBwJ2YUSPwFo9DzgucA2u4FQsKsZqZn0 X-Received: by 2002:a63:4621:: with SMTP id t33mr103956312pga.246.1558696617038; Fri, 24 May 2019 04:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696617; cv=none; d=google.com; s=arc-20160816; b=tYgMOoeRhF6IaDBofYxwYfpXTpFC0LmhKhmlLy9RLXLl9KcCRYXoHF+93RUeb5PKhR /AczmUpLrs0tHIVEw+pMKqtQcxwnnsAYopgmNZ8tmnf9NMefp2Xzxwvc+jPv6rEaYlS0 qg9R4Y3pKjYO0ZVpjaUHM2LoonSFmj6oCORi19wm5UpbIvuQRngiLACFjXhBpzbbZc0U 6+pGlv8KkSe/Q2iV7f4QGKpLLVfoFvBOUpAisx9eYYlVUsqMFxJPhkFmGWCs2BQDozas zoCArVNZoNx3snzfGHZcCiRrbfOEHTQF0lsEfI63oRIqcIroz+ikbY7n/L45SlmoAgce Ls/A== 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=souP331Oq+W8OEzEyXCJt+UVddv/qpW21BrALRlGk+c=; b=vpiVXVLW0v2s2StLgPiWsUX0i4MKQ9kIIhWof+AFvNoFzjDb/RsfMzYdtylPIlN6be OOmgH4cM2zF4IPqUKey6j+UPOBJ/i+yVU9KWk/WoDRlIA5rPD32BWB5nzv17kmpf6Lk4 kNs3XOt0QI2uWHh2ubuXyHQXwfGTQPt93Jy/JnHPhFTM8Rr/ULB7NQ1OchiQrp2EpvG7 EaW+mP93mvlzkqEpRgWeHEHJEfvS6B1fO9tvkDA6OfCsVF7ppEuPLCwOiJ/ZY72w7OqH /iXLOTiOjs2jRkAAa71UynBrsV4qpMBdo1t+ci/f2ZNyiKlKU9i/fgyHYliLd4WYP8jw OZrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xyt+zJpz; 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 b1si3735560pgg.392.2019.05.24.04.16.56; Fri, 24 May 2019 04:16:57 -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=Xyt+zJpz; 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 S2391056AbfEXLQx (ORCPT + 30 others); Fri, 24 May 2019 07:16:53 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38194 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390960AbfEXLQv (ORCPT ); Fri, 24 May 2019 07:16:51 -0400 Received: by mail-wm1-f65.google.com with SMTP id t5so8810754wmh.3 for ; Fri, 24 May 2019 04:16:50 -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=souP331Oq+W8OEzEyXCJt+UVddv/qpW21BrALRlGk+c=; b=Xyt+zJpzGPfxYFUztM04ybiYYRMGFjg9eecowH1YjDKN0DOBzUxuBNqD90+skb9UXF xJB5eXf5KEpryelmD4taiI30IrYfk2bBVt6p9tKUlU5DlZJRHjCEaBkUL+WUhHYWYhrc K6y5qvIMZb6NaEO5MPBlwlg3T25b0JdvD/abGVJEXTgEaZMYA1MqaxMH8UDk0pA6A8Fw i83JpuadVbacbTe45ikDWErgEqmU236naBnj2bMQ9gU0627su71WZWClhnywb7BYwIF8 SXAh9hBs1tRT2kHxZcy6GIjfWdVckCXGlheyzg1tf2uSJgVRAzVtfB0xKf/oboNcQsBn JXGA== 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=souP331Oq+W8OEzEyXCJt+UVddv/qpW21BrALRlGk+c=; b=Od9mA+WRjhHdwAdLup+5OLbUEc6N1IlLyegzVVvveahPE5rqGoKtM3W4siw8Ouirn8 xkKymue4zSjAl3DQGYhDrbwW8XsAChY5QSzlANgo9q04vaRnWxTqdMNLYr9XWWjHXTNn 166fWty326sMr7ho3nv/wIBpucgkzLLOoXTOWks+rSw15qfDkVCEtXGp6TM0jhcBCJ1l ITjr811XzXXThCwHehmN2i4AnoPuDwnqo3SEPqqhxxaUWPk1qVwbpn3zQrwVy6Faoppr BJhecB9w4h1IyZtjXhM8kkKQjbZ8jZpaXETx0uybyQK138EpYqkFEfVWy9cWwW534Yvn 7chw== X-Gm-Message-State: APjAAAUVQdUZSqQzh0E/RKiP86Px38GujAsrNpXPLZAcojGw0wCMELFx A/hm5LJ/2OeDAfUGQdK5sBFGHg== X-Received: by 2002:a1c:2c89:: with SMTP id s131mr15183189wms.142.1558696610023; Fri, 24 May 2019 04:16:50 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:49 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, Andrew Morton , Masahiro Yamada , Petr Mladek , Kees Cook , Matthew Wilcox , Joe Lawrence , Mikulas Patocka , Tetsuo Handa , Sri Krishna chowdary , "Uladzislau Rezki (Sony)" , Changbin Du Subject: [PATCH V2 7/9] genirq/timings: Add selftest for circular array Date: Fri, 24 May 2019 13:16:13 +0200 Message-Id: <20190524111615.4891-8-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 Due to the complexity of the code and the difficulty to debug it, let's add some selftests to the framework in order to spot issues or regression at boot time when the runtime testing is enabled for this subsystem. This tests the circular buffer at the limits and validates: - the encoding / decoding of the values - the macro to browse the irq timings circular buffer - the function to push data in the circular buffer Signed-off-by: Daniel Lezcano --- kernel/irq/Makefile | 3 ++ kernel/irq/timings.c | 119 +++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 8 +++ 3 files changed, 130 insertions(+) -- 2.17.1 diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile index ff6e352e3a6c..b4f53717d143 100644 --- a/kernel/irq/Makefile +++ b/kernel/irq/Makefile @@ -2,6 +2,9 @@ obj-y := irqdesc.o handle.o manage.o spurious.o resend.o chip.o dummychip.o devres.o obj-$(CONFIG_IRQ_TIMINGS) += timings.o +ifeq ($(CONFIG_TEST_IRQ_TIMINGS),y) + CFLAGS_timings.o += -DDEBUG +endif obj-$(CONFIG_GENERIC_IRQ_CHIP) += generic-chip.o obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o obj-$(CONFIG_IRQ_DOMAIN) += irqdomain.o diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 02689e6168c4..dae04117796c 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2016, Linaro Ltd - Daniel Lezcano +#define pr_fmt(fmt) "irq_timings: " fmt #include #include #include #include +#include #include #include #include @@ -626,3 +628,120 @@ int irq_timings_alloc(int irq) return 0; } + +#ifdef CONFIG_TEST_IRQ_TIMINGS +static int __init irq_timings_test_irqts(struct irq_timings *irqts, + unsigned count) +{ + int start = count >= IRQ_TIMINGS_SIZE ? count - IRQ_TIMINGS_SIZE : 0; + int i, irq, oirq = 0xBEEF; + u64 ots = 0xDEAD, ts; + + /* + * Fill the circular buffer by using the dedicated function. + */ + for (i = 0; i < count; i++) { + pr_debug("%d: index=%d, ts=%llX irq=%X\n", + i, i & IRQ_TIMINGS_MASK, ots + i, oirq + i); + + irq_timings_push(ots + i, oirq + i); + } + + /* + * Compute the first elements values after the index wrapped + * up or not. + */ + ots += start; + oirq += start; + + /* + * Test the circular buffer count is correct. + */ + pr_debug("---> Checking timings array count (%d) is right\n", count); + if (WARN_ON(irqts->count != count)) + return -EINVAL; + + /* + * Test the macro allowing to browse all the irqts. + */ + pr_debug("---> Checking the for_each_irqts() macro\n"); + for_each_irqts(i, irqts) { + + irq = irq_timing_decode(irqts->values[i], &ts); + + pr_debug("index=%d, ts=%llX / %llX, irq=%X / %X\n", + i, ts, ots, irq, oirq); + + if (WARN_ON(ts != ots || irq != oirq)) + return -EINVAL; + + ots++; oirq++; + } + + /* + * The circular buffer should have be flushed when browsed + * with for_each_irqts + */ + pr_debug("---> Checking timings array is empty after browsing it\n"); + if (WARN_ON(irqts->count)) + return -EINVAL; + + return 0; +} + +static int __init irq_timings_irqts_selftest(void) +{ + struct irq_timings *irqts = this_cpu_ptr(&irq_timings); + int i, ret; + + /* + * Test the circular buffer with different number of + * elements. The purpose is to test at the limits (empty, half + * full, full, wrapped with the cursor at the boundaries, + * wrapped several times, etc ... + */ + int count[] = { 0, + IRQ_TIMINGS_SIZE >> 1, + IRQ_TIMINGS_SIZE, + IRQ_TIMINGS_SIZE + (IRQ_TIMINGS_SIZE >> 1), + 2 * IRQ_TIMINGS_SIZE, + (2 * IRQ_TIMINGS_SIZE) + 3, + }; + + for (i = 0; i < ARRAY_SIZE(count); i++) { + + pr_info("---> Checking the timings with %d/%d values\n", + count[i], IRQ_TIMINGS_SIZE); + + ret = irq_timings_test_irqts(irqts, count[i]); + if (ret) + break; + } + + return ret; +} + +static int __init irq_timings_selftest(void) +{ + int ret; + + pr_info("------------------- selftest start -----------------\n"); + + /* + * At this point, we don't except any subsystem to use the irq + * timings but us, so it should not be enabled. + */ + if (static_branch_unlikely(&irq_timing_enabled)) { + pr_warn("irq timings already initialized, skipping selftest\n"); + return 0; + } + + ret = irq_timings_irqts_selftest(); + + pr_info("---------- selftest end with %s -----------\n", + ret ? "failure" : "success"); + + return ret; +} +early_initcall(irq_timings_selftest); +#endif diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 0d9e81779e37..88e9f398ffd0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1827,6 +1827,14 @@ config TEST_PARMAN If unsure, say N. +config TEST_IRQ_TIMINGS + bool "IRQ timings selftest" + depends on IRQ_TIMINGS + help + Enable this option to test the irq timings code on boot. + + If unsure, say N. + config TEST_LKM tristate "Test module loading with 'hello world' module" depends on m From patchwork Fri May 24 11:16:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165109 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437549ili; Fri, 24 May 2019 04:16:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYzuOvmwfIhJGTW2qXqk+ms8gHRAAPFzznW58HJj1EYEYWEJUC8SoNt++R86GGh1BWuyYD X-Received: by 2002:a17:902:e409:: with SMTP id ci9mr95519480plb.103.1558696619416; Fri, 24 May 2019 04:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696619; cv=none; d=google.com; s=arc-20160816; b=PdjEXUxd+w7w8p96nAgg574j2wi8PZj56NJw6SzhlDR8+kHbc/B5WH6ZufyxJh/M5z IQaz219HZUgzrNxCYJcfq7xnxggCi4NvgT7y47FPDKzbMgiMYVUGInzW2ze3kmOHTqT+ zqbaf0BywUeLO5NKDhjLYP4k7NJnVGXI/zB8XYpGhFLG2hBfY6d+3DcoVumABaPaChAV mRHClLb9G5gEwPQT84zcivT3jkdOBgIw5uGFKI734XOPSoHt6EHaBBoepkBGcM/cbHIR wbBNYgsAI2nIbfgfvm/te+OES5Clxpdtdg+se7q/u9vbtkK8iap1au/WH5ZpaP9tOiSU f3zQ== 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=wiujqhHBG1u+vChiNTLfiUzCMKatKnSUp5prmw5DeT8=; b=AtexxSiAMnQPBLflG4EPcnhP01uBzUdC2oIJ+OypKneCjLyopk6osVz1WKaeNTcHmi d5cqshlAK5D5Wgg+8euLLltyTKnyCoSg7Qe9wO4BxetVoMgROZoJFQa2ghHP/ndKvnKu U2pC8/KROJGQyyQjmBQsPyixGSF4/BFoNTe3uxHyjy7vG0sroR17aWKZbEAqpPqNVXTa v7JaNs2Dqd78FfNbU3DQ1KvqMnl2SWz6Cu8qYuQze/9aso7/lXFwM5mlU1BmzvwrsHZ4 TJHoLDsdyAIMUPYk9uv58c1NwQF+Z6io5nTtNhoEawlpt29tNvh7Kh5GVgSDFaR/M6hf xBbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sBTX5s7K; 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 b1si3735560pgg.392.2019.05.24.04.16.58; Fri, 24 May 2019 04:16:59 -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=sBTX5s7K; 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 S2391079AbfEXLQ5 (ORCPT + 30 others); Fri, 24 May 2019 07:16:57 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35448 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391004AbfEXLQy (ORCPT ); Fri, 24 May 2019 07:16:54 -0400 Received: by mail-wm1-f67.google.com with SMTP id w9so2699951wmi.0 for ; Fri, 24 May 2019 04:16:52 -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=wiujqhHBG1u+vChiNTLfiUzCMKatKnSUp5prmw5DeT8=; b=sBTX5s7KZa/ifhEXk5dHA08ZgX/YQJeuwlp4wp3g9u8dAOkNYrbI8/kR7T6Ji7Me/v bv+nlZMqs/BgPVsS3YXV7TJtRlhWfOHom4W9y384Fe6/8kdhJgqcFcmvMCIJDnEVcz/w VdHwHyHAp1sdwmTGc8CUwwd1L0U7fr3ODfie/YOD9aukwLengiCU8ChLUdA5l3mK2nSl +9O9hxcCKeDMFOdKsZQ3Z6TbI15nbyBc6aPb7d6psOjVIVsD1Fe1ZXyfCSFnyi+ydpTk bP1X+G25dI5w+pGd2KL6QND/RxuZvUkRIABDpHJdyX7EWnJaGGTl3jg1299JAe8T3m1m wJxg== 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=wiujqhHBG1u+vChiNTLfiUzCMKatKnSUp5prmw5DeT8=; b=frM2JLMMmpG7b7/WIvzAvi8iK8C3KyY14+oB0SM2oAbdW8OXAeLGB72GZM3Lp5qqUg tM4/Oc0RAZcXYnp2CoDimqvZsWYz+TnLhVxsrd2RJ2kaL1nMM4nhge5ZZFvDWowyH+mI JqzIk259fBGNveqseLpAIZPugy61Q2Yj4lHROlgmJyFkg19xuJ21OIqr7Wg4HDylgOWh +OvEZJpBSO8jB2s8EPxrDbgvcw+LpWP+wiGfLuec/3bghCEhRVCE9OWZ6/toQOUBeNhi mb+hH8CptiRM4bjGdFGbURjzqIGvbUxpyvrlRdcbKPnxvR/OQedaye5oa0Cl70RILZ2k fhHA== X-Gm-Message-State: APjAAAUlHVWhw9epFMNlI+3G6J59zRxfbASIpwn9BMNL//v4l31U1DUu VE/Ft61Wc5YS8ppxLOo1w26ftg== X-Received: by 2002:a7b:cb85:: with SMTP id m5mr16100703wmi.85.1558696611440; Fri, 24 May 2019 04:16:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:50 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 8/9] genirq/timings: Add selftest for irqs circular buffer Date: Fri, 24 May 2019 13:16:14 +0200 Message-Id: <20190524111615.4891-9-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 After testing the per cpu interrupt circular event, we want to make sure the per interrupt circular buffer usage is correct. Add tests to validate the interrupt circular buffer. Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 139 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index dae04117796c..5e4efac967fd 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -630,6 +630,141 @@ int irq_timings_alloc(int irq) } #ifdef CONFIG_TEST_IRQ_TIMINGS +struct timings_intervals { + u64 *intervals; + size_t count; +}; + +/* + * Intervals are given in nanosecond base + */ +static u64 intervals0[] __initdata = { + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, 500000, + 10000, 50000, 200000, +}; + +static u64 intervals1[] __initdata = { + 223947000, 1240000, 1384000, 1386000, 1386000, + 217416000, 1236000, 1384000, 1386000, 1387000, + 214719000, 1241000, 1386000, 1387000, 1384000, + 213696000, 1234000, 1384000, 1386000, 1388000, + 219904000, 1240000, 1385000, 1389000, 1385000, + 212240000, 1240000, 1386000, 1386000, 1386000, + 214415000, 1236000, 1384000, 1386000, 1387000, + 214276000, 1234000, +}; + +static u64 intervals2[] __initdata = { + 4000, 3000, 5000, 100000, + 3000, 3000, 5000, 117000, + 4000, 4000, 5000, 112000, + 4000, 3000, 4000, 110000, + 3000, 5000, 3000, 117000, + 4000, 4000, 5000, 112000, + 4000, 3000, 4000, 110000, + 3000, 4000, 5000, 112000, + 4000, +}; + +static u64 intervals3[] __initdata = { + 1385000, 212240000, 1240000, + 1386000, 214415000, 1236000, + 1384000, 214276000, 1234000, + 1386000, 214415000, 1236000, + 1385000, 212240000, 1240000, + 1386000, 214415000, 1236000, + 1384000, 214276000, 1234000, + 1386000, 214415000, 1236000, + 1385000, 212240000, 1240000, +}; + +static u64 intervals4[] __initdata = { + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, 50000, 10000, 50000, + 10000, +}; + +static struct timings_intervals tis[] __initdata = { + { intervals0, ARRAY_SIZE(intervals0) }, + { intervals1, ARRAY_SIZE(intervals1) }, + { intervals2, ARRAY_SIZE(intervals2) }, + { intervals3, ARRAY_SIZE(intervals3) }, + { intervals4, ARRAY_SIZE(intervals4) }, +}; + +static int __init irq_timings_test_irqs(struct timings_intervals *ti) +{ + struct irqt_stat __percpu *s; + struct irqt_stat *irqs; + int i, index, ret, irq = 0xACE5; + + ret = irq_timings_alloc(irq); + if (ret) { + pr_err("Failed to allocate irq timings\n"); + return ret; + } + + s = idr_find(&irqt_stats, irq); + if (!s) { + ret = -EIDRM; + goto out; + } + + irqs = this_cpu_ptr(s); + + for (i = 0; i < ti->count; i++) { + + index = irq_timings_interval_index(ti->intervals[i]); + pr_debug("%d: interval=%llu ema_index=%d\n", + i, ti->intervals[i], index); + + __irq_timings_store(irq, irqs, ti->intervals[i]); + if (irqs->circ_timings[i & IRQ_TIMINGS_MASK] != index) { + pr_err("Failed to store in the circular buffer\n"); + goto out; + } + } + + if (irqs->count != ti->count) { + pr_err("Count differs\n"); + goto out; + } + + ret = 0; +out: + irq_timings_free(irq); + + return ret; +} + +static int __init irq_timings_irqs_selftest(void) +{ + int i, ret; + + for (i = 0; i < ARRAY_SIZE(tis); i++) { + pr_info("---> Injecting intervals number #%d (count=%zd)\n", + i, tis[i].count); + ret = irq_timings_test_irqs(&tis[i]); + if (ret) + break; + } + + return ret; +} + static int __init irq_timings_test_irqts(struct irq_timings *irqts, unsigned count) { @@ -737,7 +872,11 @@ static int __init irq_timings_selftest(void) } ret = irq_timings_irqts_selftest(); + if (ret) + goto out; + ret = irq_timings_irqs_selftest(); +out: pr_info("---------- selftest end with %s -----------\n", ret ? "failure" : "success"); From patchwork Fri May 24 11:16:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165110 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3437648ili; Fri, 24 May 2019 04:17:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRfC1avwZoeXi5bIS2Aaj/WYUhawFd/p5IyCYGutGNrobAL1pwCE/hvxJ7cdAwMcw27lq+ X-Received: by 2002:a17:90a:7344:: with SMTP id j4mr8596919pjs.71.1558696623634; Fri, 24 May 2019 04:17:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558696623; cv=none; d=google.com; s=arc-20160816; b=o43L3OWnPc2qK+k55t/GvfgVIWWp/2Pq7TODBDgooag5xhhit97ZDhKJMcjLyMP5KL 4TxwIIM0eGsD6Lz3qY7a8vA40WkAKICzau93dlys4wsW1Nv5vzUmL+HQrc7kt7R6B949 oKz1CmS5YLBOfsXWnMQg1edW8xvVhxQsUC8QoHlmLjVymfOW/EcBBrPwzpNSceD1F6IL k5XUpFcWq9BucK43AA273+1wzZgKSKITyQby4O3RSBMwtqm4BOfMpOrzqC7IfGFA8Xnr b4AlnXJi97Ayj/wLYMjKtt+A/RCncaC4SCJV3+Xnq2bElYzS8oUwvxuGd5PZ4+iv5aBe hYIA== 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=iYRnpnNRQ7/Yn4sCtvCK5+WUBHE5avZWWYPxLbImYZU=; b=G5nxOdBUznUhFtrsyw6jn0DB5+V+OpYGR3SWnQZ3DIscAD35Mh1sADLiqPZkrCC3lf kVH1CAu6Hxi7svwEeOFsmXkusxSqD3NOmPGH6VGUJEaBhozAftaC5+oDeISoWC1dgQah KSaCHbL+x4P5qidhdH5vUWpewE8I7dXsH9uXT8O1bHfP+9cMCJwwcmKWyZSVqR8zRIxq qmImr9suuoTFcVe6jzaOjBI6u6mT5FHUHRUGzvVN1FJHnWzrtrDYcZjXVgg0T0n5fKlm F1RobTD9KCziV+IulYZ1q56rLR4lQ3IQBsaKh1behW9JpTkNE4Fnkj90X4/1vXRyNSid 9Nzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rnm0jHfA; 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.03; Fri, 24 May 2019 04:17:03 -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=rnm0jHfA; 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 S2391103AbfEXLRC (ORCPT + 30 others); Fri, 24 May 2019 07:17:02 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35452 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390960AbfEXLQy (ORCPT ); Fri, 24 May 2019 07:16:54 -0400 Received: by mail-wm1-f68.google.com with SMTP id w9so2700021wmi.0 for ; Fri, 24 May 2019 04:16:53 -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=iYRnpnNRQ7/Yn4sCtvCK5+WUBHE5avZWWYPxLbImYZU=; b=rnm0jHfAzJ1AP8s88sisdQZ5nQbg3x8BdKbT5ATKq3y8Rvvg9GMLdi6LmAr+t24XxH 03Vl+bouHsiOY+/gkQ+nvo6h3zSCgChzAps95hweWo4EBPX2zO3Vt4gJisiMLRZx7dY6 XJEUp0L8pwD7v3nEeGEGFK44YIHBQWOZJHbgy+qNI+JUXwsnxa312EB1BG1g1Zscl0Ys Jk7JXT4zBXaOEDe/2DlkX4b3mEtotUM+OB6ji+4Rp60zc++vNUhBVERvBjnkDB4XVPcY jF7HD9bUDWqXH1YggzwV8bSzP3HKTaK7zsrwSTFyJgfHJ2BohOyTD6UqFtInrB8PfosK LHtA== 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=iYRnpnNRQ7/Yn4sCtvCK5+WUBHE5avZWWYPxLbImYZU=; b=Vs7YNgsJzQXce83BA+8XX5rv/MmCN6xfydM2iMLPR0tc3SaZJokV1JWgcM0AmHnJ4V 9T1NPsYoe7Sd65vnts5HVXmiAyIqV2QR1+1ciPW+TLcHABa1rUEeK1QKtWT7OHc9yR7G 7pJzx44xO72bakfGNji1Yzb0fnmyOp5hRk4AdpgsE5iqKa5gHrJKIKZv6jf5nh3Nc6Wq N8TwL/Mrc4szZSvsG9l85DYhApFqK17YvzyXqJc7gDmeueyPh0B1QvGTjkN9ihFENN3o Qeor6WD7R47mUl6VEa8sZUR83rUWWyhWQFQ1DAV1G6PgHjtNieuDkIZUKYctLkvTs9NM 7/Dg== X-Gm-Message-State: APjAAAWTppLanfu3II6NwljsqSIqfWvBGep0kKqeSexzfPqGJrUYe5Z9 mkLQpsRDdA2jdjKwj/RhNebYHA== X-Received: by 2002:a7b:c765:: with SMTP id x5mr9377556wmk.26.1558696612702; Fri, 24 May 2019 04:16:52 -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.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 04:16:52 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V2 9/9] genirq/timings: Add selftest for next event computation Date: Fri, 24 May 2019 13:16:15 +0200 Message-Id: <20190524111615.4891-10-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 The circular buffers are now validated at this point with the two previous patches. The next interrupt index algorithm which is the hardest part to validate can be validated with the tests provided with this patch. It uses the intervals stored in the arrays and insert all the values except the last one. The next event computation must return the same value as the last element we did not inserted. Add tests for the next event index computation. Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 5e4efac967fd..eb2bb1d1551f 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -705,6 +705,68 @@ static struct timings_intervals tis[] __initdata = { { intervals4, ARRAY_SIZE(intervals4) }, }; +static int __init irq_timings_test_next_index(struct timings_intervals *ti) +{ + int _buffer[IRQ_TIMINGS_SIZE]; + int buffer[IRQ_TIMINGS_SIZE]; + int index, start, i, count, period_max; + + count = ti->count - 1; + + period_max = count > (3 * PREDICTION_PERIOD_MAX) ? + PREDICTION_PERIOD_MAX : count / 3; + + /* + * Inject all values except the last one which will be used + * to compare with the next index result. + */ + pr_debug("index suite: "); + + for (i = 0; i < count; i++) { + index = irq_timings_interval_index(ti->intervals[i]); + _buffer[i & IRQ_TIMINGS_MASK] = index; + pr_cont("%d ", index); + } + + start = count < IRQ_TIMINGS_SIZE ? 0 : + count & IRQ_TIMINGS_MASK; + + count = min_t(int, count, IRQ_TIMINGS_SIZE); + + for (i = 0; i < count; i++) { + int index = (start + i) & IRQ_TIMINGS_MASK; + buffer[i] = _buffer[index]; + } + + index = irq_timings_next_event_index(buffer, count, period_max); + i = irq_timings_interval_index(ti->intervals[ti->count - 1]); + + if (index != i) { + pr_err("Expected (%d) and computed (%d) next indexes differ\n", + i, index); + return -EINVAL; + } + + return 0; +} + +static int __init irq_timings_next_index_selftest(void) +{ + int i, ret; + + for (i = 0; i < ARRAY_SIZE(tis); i++) { + + pr_info("---> Injecting intervals number #%d (count=%zd)\n", + i, tis[i].count); + + ret = irq_timings_test_next_index(&tis[i]); + if (ret) + break; + } + + return ret; +} + static int __init irq_timings_test_irqs(struct timings_intervals *ti) { struct irqt_stat __percpu *s; @@ -876,6 +938,10 @@ static int __init irq_timings_selftest(void) goto out; ret = irq_timings_irqs_selftest(); + if (ret) + goto out; + + ret = irq_timings_next_index_selftest(); out: pr_info("---------- selftest end with %s -----------\n", ret ? "failure" : "success");