From patchwork Mon May 27 20:55: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: 165224 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616494ili; Mon, 27 May 2019 13:55:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/fgDOza6ysGhd5G1/UAm+z0RSra49CeXzyYdusUtmuYzkTgfxA6b2GRFTHVtTKvyEfM1f X-Received: by 2002:a63:fa4a:: with SMTP id g10mr127536463pgk.147.1558990546957; Mon, 27 May 2019 13:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990546; cv=none; d=google.com; s=arc-20160816; b=bTPMa2Q1/LItbkt7ypJcnkHopBisvfkG8DYkj4h4aP7fZ9ntNhq4QRPY5PeUBdcuMB X0Y0xNDigyhUxHHc1B16Kt3B/EXW9vjTc07rNnL+Ftlv/QCz6Y+pUJyj5HNvnudRTAzc NG8g5Vt2kDDt8dLv3XCYyiFVQMksuoPxm/XGWthdD1YQRRUYhbsZcf7rF1tyWHi4w6ZF SamzGOLQ9pRcYiZHRbCoLL3lH2DmWdsZG1FQKYMnARZ6/nA1Ts+ntSBHHeRKcn6jWc8d vq38XnecTNYMEclI7hi+koj+MJQCu+FH0aaXdwawRMpfcitSNfd1oQnwQ5u21si1NrnV pmLQ== 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=lTcJJUHPBZrrX04wBrI5geMIeaqBLm2JwprDLfuI4WQ=; b=mJr7in1rlZTLVT/AzLVZH8Arz48crh8e+NxLc7Foypk/UFaUHdajUeijJsXa/Jo1xk GghifqB3w/o3xSebQL9A47t0yD2QuXMQy4jGZV/bH7/JgySZCJ+RiR9sKD4BEQDIqgRD z1UqTgKFYpcKAcdgaljKe0ZRl1KwGNLNvTOWIYtbgGLpL3ecEedONKcEO07q6M2TZ5Tt Q4gqQUI+GuS2iFMRrSOJvog3M0i0ARVglNBPQSJoWG5ALL8rVufngMnlsqGggpkCpX1v NwM01C6AIJ3Ocsuy9w63pirS2+MruB3yjsmebtmljzdktAD5PP5m/+BUXAzpiuLuFC4j dSgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hRUituCU; 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 31si20378810plb.30.2019.05.27.13.55.46; Mon, 27 May 2019 13:55:46 -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=hRUituCU; 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 S1727295AbfE0Uzo (ORCPT + 30 others); Mon, 27 May 2019 16:55:44 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39050 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfE0Uzn (ORCPT ); Mon, 27 May 2019 16:55:43 -0400 Received: by mail-wm1-f68.google.com with SMTP id z23so609403wma.4 for ; Mon, 27 May 2019 13:55: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=lTcJJUHPBZrrX04wBrI5geMIeaqBLm2JwprDLfuI4WQ=; b=hRUituCUL6zlQFvBPkeIcnyXJzilIaTWZfysfx2y5BvWZn1RBFzD9onDgp3PfrG3Za 7M/zPlqSqK2BBu1d//QEZwsidxL4WdKJMvPlpljHdztK0U22Ma/2IPA6RU0h+YyeTaKa 51wjGzMl5ZMHfIO4cA01nMy9owwGDXZGBOQi6ieahJ5oke91Hl36D5D9ZVgAvCoRnQ3e bKCV9gvijSDZzTOBUbTRcLuzfBRkevL5csRNLXyr5/gU4DRXIiIInF+SRcew3VyB2ifG Ho8h+wTDNMT+WcGt3EsXjkqnrN/C2BwrRMHO91QV4PKUPhQUaWvreWCnyv+NzI50megQ iAAg== 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=lTcJJUHPBZrrX04wBrI5geMIeaqBLm2JwprDLfuI4WQ=; b=py5HC6No34OxnpESPjZQyz2KuU0KjtmvKw3FzDig6LrjzKshnPLY8/VS5JUCNPecg9 fBizFriSpYdonFNKme3sg6T6b6TiTl2BYw9V2ZoRGqQY9j0CNQfr+F++326qEmyU3K2q /5XiGIZjkon3xrymI5WIIGYsLDetbty6cm+VedOwhSHBwDVgNUXqNe7MkKuc6cY+17jA eNFqBLBtGQQaovoMukd9UxFAnPakQK7Ok7xbAw5eTSp/PmvmNqeS87AGb3t17WV49/iS yuroB8h0gxzKPZfzC2ntALKX6uccDDhBvV+oglwVuhR6bMEbuQq+1IVSDIza+ezoo7UE FtFg== X-Gm-Message-State: APjAAAWDU4cwzhKKaMpjKPnj7MDt8PCE60D15xVXLo6bl39HSaWWwzb+ udmYKhfmhDskGrFqU0Glvns+SQ== X-Received: by 2002:a7b:ca43:: with SMTP id m3mr585012wml.45.1558990541563; Mon, 27 May 2019 13:55:41 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:40 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 1/8] genirq/timings: Fix next event index function Date: Mon, 27 May 2019 22:55:14 +0200 Message-Id: <20190527205521.12091-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 | 51 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 90c735da15d0..4f5daf3db13b 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -297,7 +297,16 @@ 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 beginning 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 +315,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 Mon May 27 20:55: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: 165225 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616584ili; Mon, 27 May 2019 13:55:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6f6aoEO7TPrtqLFpC0RRc4vQ5/QxMymqIa8N3Gyk7klUYw3Cf7zQnaF2X8cKVOnwP8V6s X-Received: by 2002:a17:902:868c:: with SMTP id g12mr23566589plo.323.1558990554871; Mon, 27 May 2019 13:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990554; cv=none; d=google.com; s=arc-20160816; b=Fx52RYGfIMHjRMG+bz9ezgWBHrsPVrATnunURZV7d9wwC+eNHVSH3NQzvimE8iBxeq mNZDNCPvk6SgfGG8ZXKZXxi11G0ZxyPz6NaEKX0M9pt0JylKBHcUdBFSNeW9Zl4mCoZX rTm8EYdtvtEHdxjSYUsK8w55wNmUVRQnJ6BLAt7qYul/9RR2CqBCKW9KXLRhH7DDuj2X SudzKzvpOOFUOkzuknK6VspIXePPgEV8rtKfARLqAVbh0n7gUbgH0/E3pMtzwlDK7ytR ezYF/WKr92QjUeDoW0Oa546fH+ilYjxm/TINHbicshDwLMw46DAXAdERZXmXEb4NcCRI zwZA== 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=HugjAdec+ECusQ75/a+e3QzpsFyAQQ56btTZ6ZtG3KE=; b=KPaNDUkINdxC9gQdviNsw9RnlWoF7zWnHz5tF/6QqXWeBWl3zzPNNONHQ1jYUjQpJa T+BDGaRH1/dJf1blylrAokJcLtd6NCfx557Vj1XL45WpIzYBHhu2WhGAXNjuksN8l+T0 UPoy5/fbEiz1Aj7tcECbhWr+Yxfo44NkNqJwN8mZVpjax74EyqxwfSgTFAbdntOaZ50K eua56BAzYsWiScba40MBfZq9POLJGUPJ+Pbo+7XTd9KbMAjiUia3SPajL7nowyu63Ne4 bkWN2gFchOkBLOY6bgExAeAclynmsx2j2yTp9ZwjxPPiA5wsaLUrlPlgLP200Pojo5ev om9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YpEk8xi3; 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 l27si17850333pgm.172.2019.05.27.13.55.54; Mon, 27 May 2019 13:55:54 -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=YpEk8xi3; 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 S1727333AbfE0Uzr (ORCPT + 30 others); Mon, 27 May 2019 16:55:47 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33369 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727271AbfE0Uzp (ORCPT ); Mon, 27 May 2019 16:55:45 -0400 Received: by mail-wr1-f67.google.com with SMTP id d9so17972561wrx.0 for ; Mon, 27 May 2019 13:55:44 -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=HugjAdec+ECusQ75/a+e3QzpsFyAQQ56btTZ6ZtG3KE=; b=YpEk8xi3Kr8+aIDze86ayOZcZ9ze8h5GcwnO+F2a4CZ9wJpYnMSy8LAy+LtiwW4FQ+ ChjYrp6913P5x/dO9fHl/1/eEQo/OXl0oMBWh9KHX1+AKUMjNJDiEbltihff8/o3Y2qm xLH4jhBQXBO/aHL8kNhF457fYnjcQQJ+/Wie/zWbOLE/mJlYn29jfKDvMnQ2UF4IZV0f l5UDv5HFNt/fLqPqIIjO9azcxlp7/A9KUugru56YnSIVQ4u5K+fhtrLMG7mHsZDhJL0G YEFQSdoChEPkUzD/fQT/1pR6xspSCeicvBgHtTvEYZ/t6GeCYtu9Eh7fCbG7d3IAglzC Ttwg== 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=HugjAdec+ECusQ75/a+e3QzpsFyAQQ56btTZ6ZtG3KE=; b=FXEzsCJxPkbQVXgVQlzhP7L6Hg0PfJIP4LACyg+kgpOzks+hUI15c1yythncDTm7O+ NOK3CDroHYaPdESLzIbck/BLqRM5eUuF21eilmq4A2vcjsgAUNIGTgPcq2gKfvNRaTJF 2RC6fgWCQt+OkZl0GIDc3Il3O6zML8bOECQvV3Uy17SHWf5d5Mqp2nXkXqi10d1U7g4D iJ8JD7M6yREjOqXyUqOaY/bkQp6d5Fe4Tq90oZ485WTlKCXXkrqOOpG85KLuPruQs5OA PtCJrXZBWbyN7BnHSurXY/jF3V4ax6Lawhl1eekP6OA9WtCLZG8P0AUt6O/3C2V4g1LY 7D+g== X-Gm-Message-State: APjAAAXe/XPNJ1mfHNR0Xy0HVSPduaOu3OvA11glOQwM5/nob3TiJRo5 KVLHl+5iMyjN1fm/yGXNupSiVYe4C3w= X-Received: by 2002:a5d:4089:: with SMTP id o9mr208488wrp.6.1558990543774; Mon, 27 May 2019 13:55:43 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:42 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 2/8] genirq/timings: Fix timings buffer inspection Date: Mon, 27 May 2019 22:55:15 +0200 Message-Id: <20190527205521.12091-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 4f5daf3db13b..19d2fad379ee 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]; @@ -526,11 +543,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 Mon May 27 20:55:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165226 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616590ili; Mon, 27 May 2019 13:55:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzINY9aLe1FM2pmPTfSL2Se7uDc571EIzxi8zBTJ7alWIQAMo7icFVXs6n3pnnGcWxkeWUD X-Received: by 2002:a17:90a:be0b:: with SMTP id a11mr860961pjs.88.1558990555278; Mon, 27 May 2019 13:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990555; cv=none; d=google.com; s=arc-20160816; b=t9CNdX4L9Bfwga1LXyeRSCUUfIa82CrjDBw6wRJxsHo/VfTMkZQkPMDMpRhHe3j+4x ge97dhLtWbkc36/i9qik8qniMyHwqEwniPAmLNWhRFNNmZDU7526/MtPG/U7aIQvm5lo yD6DoQi9esTKYDS98iNLNS4Cw7mmJy+W1bFQSZ5j7Ga1AgiEADIrcIdWlFajqsLU6akz X/K86qzF3eqAhu0MD5EESQx3bnVIz54rjlZwe/ejgG4S4SQ8bldqdoTCKkR+DsqDl7oO yEEixz5VeHZu5o9bkyjnzaySShB+2JvWwQuNdg5Qyj2qL+zZy+3sc23AYGCHrn0+rIir iVjg== 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=q6ZhvfBGbl+6q1sQb52SrU1ERF5WJa7s4b+iAbTaZGw=; b=nXHSlWVwwZL+YGtQPwyMYGJewkvXOLu23G4ked8bt9S4dMT3RKtlXloWaZIPYNcQ9m XuAeTgu/cQDkxwsqHrCuXA0obBdM369nkRzmWYgc23fbKT1i8oka+kZkMzm1PQ14ozbX aCtcutHYJjG/RcFlsN3lMCP/cAE9qNMTDtpiUCO+ijYIePxZRLReNgy6cHtxV41Fp7at XOFlF4BAZqVizutpmJRZNws5pVNhKfXwwKG+JmtHPN+/HzsJqzFN0Fu89POGSQKROFE1 yu9hoKrjwJjCAK3IGx5npAFJ27EJsD9SmImFpx/3nXggZWD7EZmPyk+q28GUS5V1oKxx b7hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ajP3I39P; 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 l27si17850333pgm.172.2019.05.27.13.55.54; Mon, 27 May 2019 13:55: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=ajP3I39P; 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 S1727364AbfE0Uzv (ORCPT + 30 others); Mon, 27 May 2019 16:55:51 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39454 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbfE0Uzq (ORCPT ); Mon, 27 May 2019 16:55:46 -0400 Received: by mail-wr1-f66.google.com with SMTP id e2so9189084wrv.6 for ; Mon, 27 May 2019 13:55: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=q6ZhvfBGbl+6q1sQb52SrU1ERF5WJa7s4b+iAbTaZGw=; b=ajP3I39Puo+dxnCTFyLhawYAzrXoh5nwu6fXrQNgJH/tlhYbHwYcsyAQudHZJKB2I7 +G7y9/LeTb8SFvTP0SZ7RQeLDs1lX34oTsxuB7/ytrN/mKEPcelK6iNTUQnacS9rAwmz 7XZBY7quoXZRrLw8QcAR+6g1htYZKkiqllAXNj7kA1ZbHurIe1KDN/4NMR7xXbG7dV5B vs4HdwqM7xaIrPesWIuvUVh7gRDLSnX14AGsTDBrjAczicTDfitLTFMwYmLs44BSHuQH v18eb3XeA4mCJXuxc5UBRAYwWUkaOyUHQI/s/tkOjrXiyDocLWP9MsBZPvD1s0IKt38x XW5g== 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=q6ZhvfBGbl+6q1sQb52SrU1ERF5WJa7s4b+iAbTaZGw=; b=E/YJscFZuewGRGUO/SyAmZ/28j3NkYszGJuZSnNCspFHT4941eZcCChYj+WdBH+0lb Ld7g/QHheEKo/5e8058C0H8RnTQfiXl3pePaNQwTmH65XTR2B1aWRepmJJcjWSpgq8Gr Ne5l5jBylMAfP2ZPJJaM+VFDzD2+y8uUvJoxGad5ykPT043nqCnjAzsjb6sQOoimscn/ el5CKbv/Vpzp2Ix7PXoBZFvj4DeYaTTHWvOIV1ZBNPdoOr95Ahwc6mQeGXsug0r8MCX5 uAtllZIzvJiT2oh6N8KjwQ4Uben4K+KMAxHFCR0l8NEE7vJYAXGQHxoYOkmtGp+2Ye7g xfCw== X-Gm-Message-State: APjAAAV86Jav/7jb9JZKdgyiyrjH2ZEIW16AwgGUFHX7ZlEiEmgP4iLs MpOUvY/PX7Pogx8I9pPLnBlmzWzLW2Y= X-Received: by 2002:a5d:49d0:: with SMTP id t16mr13357007wrs.324.1558990544988; Mon, 27 May 2019 13:55:44 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:44 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 3/8] genirq/timings: Optimize the period detection speed Date: Mon, 27 May 2019 22:55:16 +0200 Message-Id: <20190527205521.12091-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 19d2fad379ee..1d1c411d4cae 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 Mon May 27 20:55:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165227 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616599ili; Mon, 27 May 2019 13:55:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOaWnvStYnw+n9vJRu9CdP+v3V9kFrDTusREpyRZV2ObPZYagDJKh2WgDmEt6Al63n4yhU X-Received: by 2002:a17:90a:730b:: with SMTP id m11mr839930pjk.89.1558990555674; Mon, 27 May 2019 13:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990555; cv=none; d=google.com; s=arc-20160816; b=rhVGlJs7znesRFwEwSNk+nJvIwbBSo/bCx5LO0bXiAhNVLZcUOhE3fh8jMhKeklXB6 5MUIMrO+ygd++pI0T7leXwEgXzP8azA2x/DuUBha8je8OtWn+3+PktbVzxijCW8/jm83 EO9qDYowXTe/Wn0nwF+njTiKOZUFSOUFAls4/DRdfGgM37LzKiDJt7radKy3bvYUCm8f VUz1kL4IbC5CCjNyTnMtUOcTHoOCdUaj3A1hsJCqg3icrliQSzrAWnwoKe8rhYtFWdbQ NdY9x+Y2PO1iG0JhwnKiD9OYY2k+KGewxSkgCr438KmDBPWIlOWA+iCiig0fZTAKevfu rwCQ== 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=F5WLBLviZ8Ci8QUUL3QnLvuHKFfZ+ZTKWaJdSpBzl3p18aYJrjy+rx68nZXgoA5R69 z2JA9JgHKGPfAB29jHKzDE9x9s2R7/VR7vi9vS5EE/TsZoit81MWOv8SZYz2+wf+x0ZN o0dsQEZBzaumKRkTv9lEOlhOOk+kwVBmIID+AdT/ufRXS3n0ZiexwtNHmoVrHgyrJNzL VZFQUiHqNzQ8r2AEdfTqL/lVPAiSEM/kdP761g6f+nCMf+KTJRgbWMHhB365I6p0szFf q12Rxw/PeKOw9nUKax0PnjgGzcMQaIjdyV6FCzr1/Musf6wS4jxGulNAiQshFgxbxEGW 2FFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EePZvjMZ; 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 l27si17850333pgm.172.2019.05.27.13.55.55; Mon, 27 May 2019 13:55: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=EePZvjMZ; 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 S1727383AbfE0Uzw (ORCPT + 30 others); Mon, 27 May 2019 16:55:52 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35827 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727320AbfE0Uzs (ORCPT ); Mon, 27 May 2019 16:55:48 -0400 Received: by mail-wr1-f67.google.com with SMTP id m3so17972340wrv.2 for ; Mon, 27 May 2019 13:55:46 -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=EePZvjMZcgu/kixTEABhJt4zmZ4II7f9mSzF7+7lCB7Jc4MuoxmuTuvlRWq4xGGY3d 28M0CRfZtHnrnjGfsbNmCBnAwnJI7TdO5zojYKV58xxPLtyCf+qaYlQg94txEKEFI7qx TTDo+fIzQYYxfPbdE0se2j2i9RVbv216RwKnsH4NJ6mTAGmJl48ObP4g4u3cm96kUSHU 7su+KIDLSHZsTDCgRYH0U54dWWk/EJ39kDDXzURrwvGMsGu6NUxUgkpybASzQ9u1a220 eWGPiXVVCq4od8z6k/6IFtEuD+ZnR3itJc48TxbeiSefi2CWfCCowpV0PWLcFCp9fm+l G4Hw== 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=L1jg19Vhw1/2n5X40wLaVlaVJF/aUR4scbD5suaArcaueybbsExVbFLnguzjmOdcSP I9mINmFUdZpztqLOcXDeamY7VZDcTzx0kyZSALdeEEmhiGfaMxstjKYGpO7+WYTcsqO/ PL8yDEr/Q53V3cbduyaJFgE13EL8knDqJjJrLnGmj3RIL6JAQY5j6xKjRf4wzJdz5LCP Jmv0v/sQ5RWAUboaJJ48oUTTfiAfUPBk4eNtx50dfO9XbJSxp2OyK2JVZ/kqCTcbMpl7 faoJh6CusH29Kj9cMpSKDbedmgnBFQUDoWpfxIhIr3CKqXxu083qsk0EpSI3sx/d0d0D Rr5g== X-Gm-Message-State: APjAAAXKF5YuVxmeP5m74ZCRymBujx4B8UH9N2RqoPfvlv94goQiitdi mTV8k14yigVtmSn1EgrTjzwinpcKwWE= X-Received: by 2002:adf:f2c2:: with SMTP id d2mr1977240wrp.153.1558990546120; Mon, 27 May 2019 13:55:46 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:45 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 4/8] genirq/timings: Encapsulate timings push Date: Mon, 27 May 2019 22:55:17 +0200 Message-Id: <20190527205521.12091-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 Mon May 27 20:55:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165228 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616626ili; Mon, 27 May 2019 13:55:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfgUg2ROo23+xKjl2kMEYfVDpZN4B+GZTfZy7aoHXF/nxY1TV62R49H6LVK0/cn2LXHC60 X-Received: by 2002:a17:90a:1b0b:: with SMTP id q11mr869168pjq.80.1558990558199; Mon, 27 May 2019 13:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990558; cv=none; d=google.com; s=arc-20160816; b=Z2r5qRPPWynGodggR5ZMdBBQn469q/tYgHkWqnO5hbXSdtRb9hPDnpQWsnfjZ4YOWb H6KFUDc9+WY+JLQc6eovPxj/A1cOIT7mVl9VFquYAvJHfbjo7tOaqUXPpx10VRfitMC0 Lv0JDFp3DlfGtCpe+2Lmv0Ck1EamqmHTSTyalGKejpKhplxB2UhokufoLZ5DfclFivKM 7MISVyq8iehMLvq7TsRdHXN/SP6QQFGFpJRxzkvlVx5HaPu4PlZYqh1Lo2xLoRu7k36I 99xIGjBYkshyqWWUBwpcvkdAQrhXCImh/BqV0YdGR8YX+nBTv0yzgVzr/BFSAYsHas20 KDKg== 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=Phs2DAaIK8MGXZ+i6+CFVkqUm3dtIclSkuWO2pGztkE=; b=JqQp8T5KZZ+fi3ceTaMCUekGob+Wtl9I+zvuBGLXFAsbiVwzgbhO6O5Qrurvv4a4za X/PHbLs6rWi2fPpkb4bDH3Xs1lVmuBOhrjlnUcVKNsBLDpPNwjQEU+Msyq13ZFzFafGj YOF+o8EG4dMcexDFI4glqziqeswlNuAQVsW97+G4sAeaheURkeW352ugpmhEzjUgVZt9 iJXu6M6kD7NEwgN28BD4mmGzpkU2R/VaVBkrI28KU1IKJmh5NfOevrvsOSt4R3jDHJRT Tsklp7PBHVfGZXrn6k2fifYZluv6NwgY2q/sacZrM/a3RoNT0biWrcQl0gj6jp7Uvpr3 jtPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LdCuBNGl; 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 f38si19562113plb.339.2019.05.27.13.55.57; Mon, 27 May 2019 13:55:58 -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=LdCuBNGl; 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 S1727408AbfE0Uz4 (ORCPT + 30 others); Mon, 27 May 2019 16:55:56 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46372 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727334AbfE0Uzt (ORCPT ); Mon, 27 May 2019 16:55:49 -0400 Received: by mail-wr1-f65.google.com with SMTP id r7so17935634wrr.13 for ; Mon, 27 May 2019 13:55:48 -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=Phs2DAaIK8MGXZ+i6+CFVkqUm3dtIclSkuWO2pGztkE=; b=LdCuBNGlJJhVhaMjz2Ob0A6FFGgflwHEr1m4VkQRC8uyp3qf0DtuLOOUf9QDtX0mt7 PXOVc2yDJCfimzO2B8rszVt0iQoABJL3VH9ccDUE02n9TkoGLI2hfkcOzFJjI/FR8f8v 0dR4hOk8/uJBVlWhQvn3jjN2tW46cyldxbjtAH5T//KdZJ8478OoP474TtMz+t4K1W8U V5xNeX1QSOx7LMvHQ9mg8ESQ3XZSnBk8IOyPXzDOvdtaKB4xEf8ZIxdfPCxg7liqthYF SU1smHtrAQX7yNBv6G5jUhIuZaqc4L/qsgC/XSEvSu2ja9XO9XODQscfqn3lPCJQTdZ9 6cBA== 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=Phs2DAaIK8MGXZ+i6+CFVkqUm3dtIclSkuWO2pGztkE=; b=iYq1zPsg+/nuCUkiNM30VP1qy147uJdgGQoAbPMUIM5UKJ2UfKNyamzJw0mr7uX7bB tMH7Q3ZMWkGQCmmibJIQtKG+HvYNdXzhtqAjxdhJ8D+iCvAhjykhl5UNweadFj/GxtyJ /jQZ/1oVSebCThYJhZoUukJWLS5pse9fcE2H525NewjMxwb78YNaK01fUYysvK13uU9s 0wgL9kp3EYhxkX04H+b0Cn2fMrWBJ1cpAXMFV+w/ItrERSR6i1DdaHS8MYdtsqnx6w+r S0J5OxcMYjwfL3MiqWDsq3vajVMtWUlEPNSgivlUplj1u5RDBuXgfK3SpwiBr+1aDliE MwSw== X-Gm-Message-State: APjAAAV3rP8CjnD4c/BVUP5jIOomaKRkvb/D3wnbQUTdhbxS1+ZI5h1t hSRPH2f5O1rPWZJ59XKsXwe4A3D40X4= X-Received: by 2002:adf:e550:: with SMTP id z16mr2515773wrm.146.1558990547233; Mon, 27 May 2019 13:55:47 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:46 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 5/8] genirq/timings: Encapsulate storing function Date: Mon, 27 May 2019 22:55:18 +0200 Message-Id: <20190527205521.12091-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 1d1c411d4cae..bc04eca6ef84 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -430,11 +430,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 @@ -465,24 +497,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 Mon May 27 20:55:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165231 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616795ili; Mon, 27 May 2019 13:56:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqx18ngqyrlktU+2Q6cH6P9zzqlG3AzG21k9U0jhV/YJ04clFnKhJQ9ZfG/f/IyNspgfohgR X-Received: by 2002:a17:902:e683:: with SMTP id cn3mr107343527plb.86.1558990569884; Mon, 27 May 2019 13:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990569; cv=none; d=google.com; s=arc-20160816; b=k71ULXSDciXFHdD3Y2V47k3fNh1B7jQc8tbS7nnsGsrjK0YxNnomeEDSLfqXRayNs8 z0V1xRzQ3Avz6Ozx3fdUHq97uHqzIVw1iOSKaOjdUYLR5HuXDemJPkxEo1PewuqNvS6r vxgr9bEpj8Vlqu9znU6nNqvlDnV9RDS0nVBU3+jmfiOXRiwu8SghMD46s695C7GX1U6e xWFpqZjk1DFrfJ2QxRqvKpDzZggvTxAxX9SECo04WAKPzJsiJo9RVSFXiP0MABRqpNLn hz1CLU+cc/IbYCNfRhBqVSyYakTCfDXvrGFGLVq3UUNo8/0wL5YZKKDMDXiuZuJip4PM JFWQ== 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=3EcKBS+YKo3m/rDQQfdwEg1iam0jndfNmBU1yOpEDAI=; b=pZwzqjKqxSMcYsEQTggw/lgVgDFf5k6w9aZvo/DDtc6EsUkPTc+C6UNGn7e/219JSv N97Xtc/SWTHQtvW6+C3H3KQCDfDvpHKVbEH73SNBnFHJG9fILyqGOMIouIZVlOxLDd3v TdTSpttrxBFwNGOef2YupMbVlWx67at3hCbog72+xs2BxYIo97AF5/Rv8l0uYXjhpYOy OCMf9g+qET5bN79tQ3F9EM9VFskV+ZcJvy+5SZx5pgRHkYXCg2+1DpbqyFDoErar+muF nlcG/5Rb8DCW2RbWwPYfC3Dt/dbBHEFUcrvU4UNhGt5WJV5iW7ken3px5NlAAWvH+KRX 39yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H+15z8Hv; 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 q14si17966816pls.327.2019.05.27.13.56.09; Mon, 27 May 2019 13:56:09 -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=H+15z8Hv; 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 S1726866AbfE0U4J (ORCPT + 30 others); Mon, 27 May 2019 16:56:09 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38601 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727339AbfE0Uzu (ORCPT ); Mon, 27 May 2019 16:55:50 -0400 Received: by mail-wr1-f67.google.com with SMTP id d18so17964082wrs.5 for ; Mon, 27 May 2019 13:55:49 -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=3EcKBS+YKo3m/rDQQfdwEg1iam0jndfNmBU1yOpEDAI=; b=H+15z8HvXF/zzfs0l/ZnUHpoMoMdSceLC5gFrtJ5hncag93GyM8kl1Yq3wCL3MEetp E1Hc1r88GlXdnI2kzuUz6RwtfM19dfRHQKtVprYw3VoFM4j7ptsEgWYfHW0FFLUjYV1A hxJzRY7tfciFd7HVDSUI366zpNXurB5sN2UKRComEIrxmZ28Ndsivwo7pKDdPLWadpk/ SVkJQmA8IGyyGupkrOsjpmoBJS5clGMkW+glwG3DjuE8aefYMsGDo9zZhEHC/QI8rrQr dbJpXLrY9tdIFVK1SOIqctcIt3ZAFHAJaYFlxrIjxkK30rWc1tCQwqfEbZsTfrRQIiXB eSJQ== 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=3EcKBS+YKo3m/rDQQfdwEg1iam0jndfNmBU1yOpEDAI=; b=r6JqTOFjWVcV7tOiwSGd+i6GpDPeemesVvJznyFpqlrLTr2Q3qpRHuuZkbFnTjIwzO A4M1qJZWVm/FBdguIdrSDiIE4SbIMG3BQK2lmTPcv5LejL8ss5TVdfbpoedj4ggxIQqj M3mdOQD7HVtXqAJWKNVm73XTCooi9m0oMW3qeEmGFMNVyLs1b+7EaT9VqvmmKTyQucHV G04n/OnMw/JTniydY1Jc+qfH4KlMJzGG0bKOGGvVOfDGZc0N0O2Rao07h/VXp8UrE1f0 iXtO47TDjOTvjJYe8NuXlFJMkVF3S2F3TTd+vALSAsFNAxsn8AI4n2xUIhL+M1ra2anc 9HwQ== X-Gm-Message-State: APjAAAX1DGMfVmAe88F879a9XoxfdAFJ14OgY97OplNPG0if7FL9cFo6 jNVhjC6JjBty3pnsBZgUyewbNA== X-Received: by 2002:a5d:4e41:: with SMTP id r1mr1401110wrt.66.1558990548445; Mon, 27 May 2019 13:55:48 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:47 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 6/8] genirq/timings: Add selftest for circular array Date: Mon, 27 May 2019 22:55:19 +0200 Message-Id: <20190527205521.12091-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 bc04eca6ef84..95b63bdea156 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 @@ -625,3 +627,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 Mon May 27 20:55:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165229 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616658ili; Mon, 27 May 2019 13:56:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX5ZGDQwxr+wiACRdAJUqNk7q1Mp2C9r3CRSbj07ZCf1yH//08J+xpUzrU0hJsmdysSV09 X-Received: by 2002:a17:902:2883:: with SMTP id f3mr22640576plb.111.1558990561098; Mon, 27 May 2019 13:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990561; cv=none; d=google.com; s=arc-20160816; b=OXMZ3EPesb3XXDOaI/Mr3qUmKJUEK7JlWH8Ean+mLyj99bx/ZeieZP+VvDq+cfDvnz p6prDYdtf4lJu0AeLBGyreBZw7qgeiVxYp6Wk4ChgdVTPmOYsyMQuScmPDmtG+A4L9zj pmdVnBOrvQYnaWgRzN4NUqn+gS8q7SJsSV1F+IXraA/HPpvMAZtkj1Q//SjCPmho2qIx YzfRSLVo2SAVeKKpOBXF3xuLQDfRDVNA6zt9AqicITwLjVnjp++4DdtyTfPSrjIz9UOF yCSxnr0G0O6JaIIHP7qZWOEtKT6kAbP/nKjAwd17i17WSrSxFRE0xbR9PvsAw1KyPfaQ p1gw== 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=MjZ/pyBZBO4EDEwBpRQ6u4NGJabjhPzRMD0kf65cmv4=; b=IFllZ/Hl/kQMuPTpvaRKtrJGchkMoLEZu/kNHIA+JgNMZ2a9e36FVbyXrRIexWrkzF SaC9qTM/m0KscsuXo/7OxnuRoy3CI4/aYLixems7fnk+KW3dNEf63bZz91R5laq9gaJr Kq4M1aYGhKZe1HMcpb2PLvmvpOeU1oAtYkVFHbc1klRdoO/7mK5MGLiTSr8DPCp99ZqT jsLN1IRqKdv8+wATytIjEzoudPayxCblaXHTmlSp69XsO6HQSNzvx/7VXZVr952FenwV lLzkdJvHJXTVDLgIzGMz/SU0wVEhG95nsLST9rAJAvC2kNBr3H6ormvBU1h2N9+El/cW 0xmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GauBSKsf; 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 p19si15776044plq.47.2019.05.27.13.56.00; Mon, 27 May 2019 13:56: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=GauBSKsf; 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 S1727428AbfE0U4A (ORCPT + 30 others); Mon, 27 May 2019 16:56:00 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33923 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbfE0Uzw (ORCPT ); Mon, 27 May 2019 16:55:52 -0400 Received: by mail-wr1-f68.google.com with SMTP id f8so17983466wrt.1 for ; Mon, 27 May 2019 13:55: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=MjZ/pyBZBO4EDEwBpRQ6u4NGJabjhPzRMD0kf65cmv4=; b=GauBSKsfWkUC1ndbG21MewLXH8aQTbFfRtmwE0QfKWksuLdU2V1AKi/7bMLplJEzFB iY9xU9FbZht/hZvDRZy9xMUArd2o68734zpvMaqgR7NMp2JdO64lYu9Dgrq1PhGr5NdZ SvU8RmB3ilA1vCA4eVEZMCX//zKV/Y1DCLC8DKrbDPDgwCUgqnX/soDbKfneUKT4PEtI l1wCyjU9aTn5gyWosMH8wB7Uvmk4wZW9qDnGZXHe0+uoNyjs8vsdW2O/WrzgQxWLcQCV j9YBuE/dtDIavmPTLvz+k8rSg3IP+4fzrhfXKl3wvLnuURZQkb1Kr9IyEcHOxg9oCXVY jTzg== 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=MjZ/pyBZBO4EDEwBpRQ6u4NGJabjhPzRMD0kf65cmv4=; b=sMNTeibdCNOzEz73FVw7Zj2YkMuKiTckCK8R0rkGN7xb+G8Mr/qXPvV7F7IQdembcb aD69ObwQh9m4MkDeD11HRd0F8JMcRFufJH+TIJgRwKwqV5eEm3JzFbla0p6Yl6OoZ/qK fy+uuQVe67vS90RmlkY1sgeJHlgAddUYhH39h4aZGRNRcotYp4rEXAiej8hx6ZCE1Bse bzC2cmCztPZavrI95odnNxk7ukgARdCzo+sLevPIaiIA2ykLIaGxlaT2G81Z4vXNQEQs xDYBNv4yko3J7xH5QF8f0bVZzU7dnr8givTTQFt034DmNC0VHq4V6i9oC/3iUPHqCMjK vsjw== X-Gm-Message-State: APjAAAXIW9QznEVK8Y0/a/98wb+LWkU8PFktNkwd9sZQ4qS5I3Mt681d N7X09SBmtC700MW45HsOEJ9JLg== X-Received: by 2002:a5d:504f:: with SMTP id h15mr307455wrt.208.1558990549613; Mon, 27 May 2019 13:55:49 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:48 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 7/8] genirq/timings: Add selftest for irqs circular buffer Date: Mon, 27 May 2019 22:55:20 +0200 Message-Id: <20190527205521.12091-8-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 95b63bdea156..5b13c2231d4f 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -629,6 +629,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) { @@ -736,7 +871,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 Mon May 27 20:55:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 165230 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7616689ili; Mon, 27 May 2019 13:56:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7CMctgFC3hUcjRpGmbnX3a/MYSd9GQG/r3pFUl2QCc+z+LQEo05j8xc+MdqUaBV0nU7VW X-Received: by 2002:a17:90a:e17:: with SMTP id v23mr817248pje.139.1558990563435; Mon, 27 May 2019 13:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558990563; cv=none; d=google.com; s=arc-20160816; b=Xd91FpecPzGiMO8CDXsubLFWZoSx/mP7C0gaVzo2/2dTNtTYA6cl6YUc3GLaLs1fTP omdZlA24D7GZfVebJCHCeZtdQht1K4Zxw5As0t6J+NulQj3rYmkqI8eRm3h5Zpkfe2mR +uGKH+8quh0O8yxO5gTNheQPD8Dtk3bVAVI8RqTrI2VnytMVI7I5YTeP5rvUcVbxqXb9 BFe42mDOwLRHElCbmcOhmX3mxR81ZW/4PucK5QJqsBp1uAVAkqtXw2cyHNRGJjVfzXEZ 3G5B92Szm9tlnFPMb6O8iA9mBLKxu4ZKLsMt8nCdmDsBxpzYv/Gn8QrC//jwJphyVNDM njKw== 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=dfUdgBJPtbCYc/uhDOpMaPmMlc4FCxxcnSQ96C7YgX8=; b=fgX10p4bW1MKtwBt6PZj9ULhpoNeD7K89cqHfFvnw+7kO+nncoFgoblL4KABYw9OkZ lCZcibiplEPOQdMakvUSOyM0g/DckbQynNPvQqN/IVx+3EsxJeyr/uI16OiMJGvacR9L 3xWkkERhYMrvnCivaMSRBAkCJVZT0VK/qnDnTGwDwL4yuuKFlsbPkPnztJxIRlulNefC XT53aQokOJ5nT+yyBEXuj040Z8SDmhywezSjvkhwSEMCpp10H1cSG9KvFROQPm21d4i9 6xT7b5gXWfyvWgkisZmAjG9GKuB2/pjj2Dzy5Ztsdm4vsnp6lMrvm3YspXKc7NR7/+vo 3OFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pC54YjrC; 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 q14si17966816pls.327.2019.05.27.13.56.03; Mon, 27 May 2019 13:56: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=pC54YjrC; 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 S1727443AbfE0U4C (ORCPT + 30 others); Mon, 27 May 2019 16:56:02 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35834 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727377AbfE0Uzx (ORCPT ); Mon, 27 May 2019 16:55:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id m3so17972481wrv.2 for ; Mon, 27 May 2019 13:55:51 -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=dfUdgBJPtbCYc/uhDOpMaPmMlc4FCxxcnSQ96C7YgX8=; b=pC54YjrChaPbEwjQzWzOtVgI4Qfy3JE7gSPnbvirKitnpg3zXdThxMKqBnbW0zLitf jWYAtQll0nL4ZAuDMmHjmhAkzIf3BJu+eYMOe4FF/9oDdQtnjBlKRfwj12q83g+pP6Nf N0TYoOM1d12w6pdxrm/ChgZ11uOOiGKs4fWblPpQis91t42RBRyKETFU1v9rtKpEOTW+ oYKjOELW3eM9GpBHBb+kTK/vpnn197yu+CoKaQigoLQI+JJiaNSMjekcIJERuCiwG9CW kbtLh+PZXbaiooedeV2h00nqAD6L/4YJIcUHbNw+0UbWpP67iVJoMuF9MSPvHbGsPTJh u1VQ== 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=dfUdgBJPtbCYc/uhDOpMaPmMlc4FCxxcnSQ96C7YgX8=; b=fvctPqJ/fmwPbyWCEHJxrwgtye9gae44Te4NIDBS6h7v/v6R9Xh3IAQnPTDedDuHtI U4l5AnMTVpOBmNCN/yp6fnOMj1tl/koQUU3aIE/ct0glGuEXZ7FRnBvMg8uNUzpHp/jw JUdLKKKrVU761YewUO3hwL1LbnjO9tehlTvogEyagG69/QfjlfhhEWLe6+3R3KjWflmY ip7jYC8jpBIYt4U98vWtA1Q7lNPH6kqErfSTTEvxDybLiuvgKIZYE7Um/LYNU0f/MqBz iTSaRciSTrGC1+TuQgZpK4dV7sicTI5Tk7H3lurQAPDRXRdC/PWFn1o39qL2ZSPZIg4S 1gkQ== X-Gm-Message-State: APjAAAVWVghIr7U8k3ImBKw9e+j80bUVZH54wvbFET5aXUtiodYmK23Q BNhoWdTB5nwFnjlGJYUvvDfDpQ== X-Received: by 2002:a5d:694a:: with SMTP id r10mr7803842wrw.345.1558990551007; Mon, 27 May 2019 13:55:51 -0700 (PDT) Received: from clegane.local (30.94.129.77.rev.sfr.net. [77.129.94.30]) by smtp.gmail.com with ESMTPSA id a1sm388565wmj.23.2019.05.27.13.55.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 13:55:50 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com Subject: [PATCH V3 8/8] genirq/timings: Add selftest for next event computation Date: Mon, 27 May 2019 22:55:21 +0200 Message-Id: <20190527205521.12091-9-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190527205521.12091-1-daniel.lezcano@linaro.org> References: <20190527205521.12091-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 5b13c2231d4f..e960d7ce7bcc 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -704,6 +704,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; @@ -875,6 +937,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");