From patchwork Mon May 13 10:29:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164015 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141169ili; Mon, 13 May 2019 03:30:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKPtVKKqqIf7zwUz3TqRIUWbV8YvImxdQ5SN2fEhsDAcA7m4Xfp8mUNLXbAgX2N055p2X3 X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr30471427plb.202.1557743408718; Mon, 13 May 2019 03:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743408; cv=none; d=google.com; s=arc-20160816; b=fyJODnQHGbUnRea/jjgcjCTlifI6sYgKD0QbPVxu6sexPIFDqDwjsHg+GyYb9Di2jz 6UExmKAsFCtN+z1WYQp48H8CGhnYJy290CmYk/r+vQia4uYZZRCN24hy3OfvqVeI+8tQ eyWwcVcK41kPmWSK3TssHLfzhTE63Lo4DXCQ18VsqKAD/AS8blirpVTahSx786RhY02R Lik2K75+Hyym8QMlWaYeUO2fuTzBJTypzn66X/Fh85YD8pGicvbpKrANUbgZAF1v8GwX TA1dt7GhVtlhNlbZMZnowazrCW+HwQrVAWV27dIu7aEofiy1sXW9OcsTdHEByaLvG0OV QFOQ== 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=SngP4ezi5dpOCFE2Gari8yDJT7CulzqHpnWvuHtHJU2ViMrLijnYkjKgPpgvQ3oJvP 6F0kc84XzdFjgXcA8MuKDVIYIeAmUxT3MCNA/Yasu5GDmtd6FSFqrAo99ofIumX4Et7Q 5PeGTRzHGopqJknTf6vEVLgcHmbe5kG4WALArfidGcpKa8IG7ugC6Q+uxhlSONqqXs+9 to3vIbyC7Amh04G7tUFJlir9n56S37T+ScVSA+2JY/D/a5lHF8DzJMKQ3/gR+R1W2W4B Ws9oopABdehHwBp0915kPE4yFS93MRc65NXiHm7UQ1a4tOwsAGmBYk2V94VJ61tK3cz/ XbWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hlw7JzBt; 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 a9si15649572pgw.14.2019.05.13.03.30.08; Mon, 13 May 2019 03:30:08 -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=hlw7JzBt; 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 S1728563AbfEMKaH (ORCPT + 30 others); Mon, 13 May 2019 06:30:07 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33078 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728118AbfEMKaG (ORCPT ); Mon, 13 May 2019 06:30:06 -0400 Received: by mail-wm1-f66.google.com with SMTP id c66so5806496wme.0 for ; Mon, 13 May 2019 03:30:05 -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=hlw7JzBtrgh3/XIvBJP98kqEUKf77GmYZoHuNHj9UWkdTEP3+5ukxMxY/xE0wdVrpS ij1IC/WHsr1VhutVOAyaZLEhE7uH1Ur+DlCo67iG8hS8kCmdyOWRMw5p0Sgn9lE4KE3C CNRgx6KuK70TofcGPFp8eRCWjAGq0zZsLbx3Fmwm8QDNeUExNphDlWd0bcufY1J7oVW3 AW6xhVHbCraw/hUqjytBmMma0XUgWf4EfovjJwNAL8Ii6+NgjMsCPBB41YCc9LtcQutK W9NCvRhBZH1xxMuyTOPm2EAu5SiPHqCiuOLR4uIZ/UlczNskIJ9KNfRD3R5Hq0W+e30y JFwA== 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=SsBEdjF0db/mcRt64PdW1p6HBLFS+77fXJTgKHAQSdJKNUb/vmBj2dayIVqYjASICS HIHZUUbbFXuj8ViWQUrf8N8mf6liQDFDYPD8itsyo4ZpBftulFBM8JH52e5LLwecndpV 302UbihkrUPtcsGR3x8mAITTe4cTsyZBmRVLGTwfPYadqv81Msx9ySqyb1CIAvg0ZxZc SVqMtC3SqrW7dGkzh3gxmZo6W/ofeYM2LWPaRtJNYFLbtZsuOK0y0GlykowXgFGYUNl+ 8xfqU4lWyoaA5Qf0Cr1Brh2BAhM1kw69KihA8AawQDIpcuyAqe0ynmoCFr0EFevTY2XZ NjhA== X-Gm-Message-State: APjAAAUwV5Au39whzehMjRpWCmwgWGfc4zBGTMGt3C4G+AZf0q/RZ+oZ JOyhaedoXscEFyCwv2NsD86MA2SleCo= X-Received: by 2002:a1c:3dd6:: with SMTP id k205mr10369340wma.109.1557743404664; Mon, 13 May 2019 03:30:04 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:04 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/9] genirq/timings: Fix next event index function Date: Mon, 13 May 2019 12:29:45 +0200 Message-Id: <20190513102953.16424-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Mon May 13 10:29:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164017 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141265ili; Mon, 13 May 2019 03:30:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqy56qLMMwNM+CsctNkG3FWAV2siD11jhFpRQkQtMOkuq4FN2SuRB414FNdf+3IqYvfe45uG X-Received: by 2002:a17:902:8343:: with SMTP id z3mr29674309pln.240.1557743414289; Mon, 13 May 2019 03:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743414; cv=none; d=google.com; s=arc-20160816; b=bIzw6xhIlPryouzrVq6GIP/0nnrsvckNo/gAjMYgGlAvxiVCgyncrGI9IQS3aeHnqf /xsM4dFE13XsWaf4VLFQUrDrVmBLAKRrOfRUm96Kr/01Y0zAgNED7Yl52sfOyK+7o2zr K2srAu25dPVxirju0ppbBkh8j1Z+tj9r9KA0VlvtwoD8XPjLwjW24lbyGINR8C9Wcbvb 9JJZJw8Wvhl/nNI9horN3PXd7U/FGOXbe/gfIzJtYGtIHJk13zxJ+eGPsvn7q6JtjCOr E6Lj04rlGFkKFF13i+GusBwLUnnWqbz+C41/CihiU04qShrgZob3/Bwlmx0CR1GbgSJ/ hi7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=OVCnRskmJCeqZXRUtBHTU3a0dRFZnt0B8APXmqZl1PE=; b=0i+yL6r1DnJFCKFTFHm4nBRcGiBFJBwla8prtPzNS83i8vRDhhZekGTHjAdDDb8p5V EH7jfK61Cb3yZWaNU2mhEQ+pj8Y5F5jOVYfJ5H5KI6RPaDuEvGhR5xsyHBclPVDycnHD MBt40GGIWULPdJltEyQZJJxSBJNrIiFcvC5CRs/vRX2CJ9f0W9UT2V7HADCUi+UJMLHH ljbCIhD5jJrX4s43s/opwskGRj7EYxNggxTGgfAmk/8YTFREGRZzcSMgr8do06FQ5z9r Flqz9tgi+13nUKd2scqMoW5UhfZn9BygDyiMbthIJljtWhBJw0KwqDPXJMqoUF50gA8S mWAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dCjmqheu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si14997508plk.108.2019.05.13.03.30.14; Mon, 13 May 2019 03:30:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dCjmqheu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728633AbfEMKaM (ORCPT + 30 others); Mon, 13 May 2019 06:30:12 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36959 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbfEMKaH (ORCPT ); Mon, 13 May 2019 06:30:07 -0400 Received: by mail-wr1-f66.google.com with SMTP id e15so2219254wrs.4 for ; Mon, 13 May 2019 03:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OVCnRskmJCeqZXRUtBHTU3a0dRFZnt0B8APXmqZl1PE=; b=dCjmqheu9OCwBZAEeNAV56ihyvGOc9X0p3J9Kl5gUc+31+Qi6NFQAoJhzZuU1zIOfa 2e59iMszAI3DOIwYF6e1EeLWiL1gGSMifaEib95F80Q6lIJ8vj09T/ZRby7HdJbYVrbX dUwrVAKH9wIQjAQeIfw/TULMWkAEm2mUb+ABsfQcp5SQpTSyJjU7KlOhQIGwLyqui1a1 /iW2Zqtydfj05piNB/nUJyOJYPq549bCbF1irA9Q9WwEAuOI9HFZ0xtK2qpb/7vhap0A T7dyeMNhrPzV4WvDwDFaUIB6Q9oFVQYSVtzTBpTq41FR4lVB+9tMy0c4AySmz+L6Q1Fs ejAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OVCnRskmJCeqZXRUtBHTU3a0dRFZnt0B8APXmqZl1PE=; b=oZ0V64V94dZk5oPPAeumoakd37BcmLtjlzEsHECupnRAIk5PMgZcH51AcjI72FaZhZ 7C+EhaC0uDxF1PgtBevKmm3BeJI2uxNuaSLOvH7+T2YLjNk9UPXqTsCa6S4ycQNwku3v YPwkjubhOAGUH+Bb6+lFtwbkB3T+RaTxlYydJ/GmiVfAJ+qTLWvAWHLa3OIQe8DdeEle njXiX6+boCw7x1GJ6ukb1t6DrFEidEF/KeQQap1GLB7CusJwtmzFkBr4Gv46eZtgHNy3 Dg3MIgS7mVC8fsE88TBAxNcDawTQogn+z1Lmiy/W6NfrDr+nNHCkKN9WlwNgBSXyuKDr C4Ag== X-Gm-Message-State: APjAAAUs96uIm2scT35I71u1JxlJN0/DNOyE+yE00hbgY3JKcm2QTtam ZtCrrNQeJF5bXXiBb80AU2pdpg== X-Received: by 2002:a5d:6703:: with SMTP id o3mr3610617wru.183.1557743405941; Mon, 13 May 2019 03:30:05 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:05 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/9] genirq/timings: Fix timings buffer inspection Date: Mon, 13 May 2019 12:29:46 +0200 Message-Id: <20190513102953.16424-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It appears the index beginning computation is not correct, the current code does: i = (irqts->count & IRQ_TIMINGS_MASK) - 1 If irqts->count is equal to zero, we end up with an index equal to -1, but that does not happen because the function checks against zero before and returns in such case. However, if irqts->count is a multiple of IRQ_TIMINGS_SIZE, the resulting & bit op will be zero and leads also to a -1 index. Re-introduce the iteration loop belonging to the previous variance code which was correct. Fixes: bbba0e7c5cda "genirq/timings: Add array suffix computation code" Signed-off-by: Daniel Lezcano --- kernel/irq/timings.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/kernel/irq/timings.c b/kernel/irq/timings.c index 60362aca4ca4..250bb00ccd85 100644 --- a/kernel/irq/timings.c +++ b/kernel/irq/timings.c @@ -267,6 +267,23 @@ void irq_timings_disable(void) #define PREDICTION_MAX 10 /* 2 ^ PREDICTION_MAX useconds */ #define PREDICTION_BUFFER_SIZE 16 /* slots for EMAs, hardly more than 16 */ +/* + * Number of elements in the circular buffer: If it happens it was + * flushed before, then the number of elements could be smaller than + * IRQ_TIMINGS_SIZE, so the count is used, otherwise the array size is + * used as we wrapped. The index begins from zero when we did not + * wrap. That could be done in a nicer way with the proper circular + * array structure type but with the cost of extra computation in the + * interrupt handler hot path. We choose efficiency. + */ +#define for_each_irqts(i, irqts) \ + for (i = irqts->count < IRQ_TIMINGS_SIZE ? \ + 0 : irqts->count & IRQ_TIMINGS_MASK, \ + irqts->count = min(IRQ_TIMINGS_SIZE, \ + irqts->count); \ + irqts->count > 0; irqts->count--, \ + i = (i + 1) & IRQ_TIMINGS_MASK) + struct irqt_stat { u64 last_ts; u64 ema_time[PREDICTION_BUFFER_SIZE]; @@ -528,11 +545,7 @@ u64 irq_timings_next_event(u64 now) * model while decrementing the counter because we consume the * data from our circular buffer. */ - - i = (irqts->count & IRQ_TIMINGS_MASK) - 1; - irqts->count = min(IRQ_TIMINGS_SIZE, irqts->count); - - for (; irqts->count > 0; irqts->count--, i = (i + 1) & IRQ_TIMINGS_MASK) { + for_each_irqts(i, irqts) { irq = irq_timing_decode(irqts->values[i], &ts); s = idr_find(&irqt_stats, irq); if (s) From patchwork Mon May 13 10:29:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164016 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141242ili; Mon, 13 May 2019 03:30:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZEDal5C67h2v7LLf/SL9hjOH4ewJ1UbipUstUKcqcDwlkZNTa9jSFhxaSb7qQ4bM0rkk5 X-Received: by 2002:a62:7d8e:: with SMTP id y136mr9817363pfc.224.1557743412811; Mon, 13 May 2019 03:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743412; cv=none; d=google.com; s=arc-20160816; b=aVBhtogi646UyuIZwBS2rucNQ0yk0MgSrDMAz2FOFJV8tOaHbfqO71yhMwNf8q/KrY XVP/zglVZJaF5rpM8GDstH0oLNgyGK03w/mEe+KsZu1P5Wey0zv1abQhPWdpxg1dBfSs 2xIXT8ZlmsDw9U7Kr20odylLYT425t/KxvX6Wwg2bN2026QLfTF4Gr76dYpIznhq/mT8 gXNdravxDwy56md1r6AyRz+f1tmq2FGjWrUalqcGE6X3mkg6a7XUQJ0kML1PoapDb8sJ Gtim9yeaejXxpvyAleMeSbztLIAPuS00V3m+Yyh4Yk4zsQGLsvppZtB/MhLkHqQ8vO5/ Q5ig== 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=XJW+KCw+u+y5fooHMs2rYEkM1Z7zEzqsWbPB4WWdBiD6TrdXNkGY8dMXZ+5wHzLrjh vTb7sZh+N7Ktc4a1aoaKKJKrKbMu9Lr2+UgbCIYyoptSnkbLHzR94OdA+mLGx6Ek+sRX RKicAWbKHvuJ+ZckD9wsKrFdSrE59JGQ0j5ZxggLNP3a55h7R6T8yf4gPW9y5k4iIrWT TnY2ZATjC9EUF+UHw+K3uItPpWOu1/1K52Oc1vmo2s7WgQg8qj0PVfagefOoLAmposfR MxkGFKvvXaf/i+8GlRMBFsOsaOfG31S6C8dwnxZDuOei9LBkRiZtvJpHCSyoVZgckQhx D6Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KaMLGxq5; 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 a9si15649572pgw.14.2019.05.13.03.30.12; Mon, 13 May 2019 03:30:12 -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=KaMLGxq5; 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 S1728607AbfEMKaL (ORCPT + 30 others); Mon, 13 May 2019 06:30:11 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43619 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728118AbfEMKaJ (ORCPT ); Mon, 13 May 2019 06:30:09 -0400 Received: by mail-wr1-f66.google.com with SMTP id r4so14588532wro.10 for ; Mon, 13 May 2019 03:30:08 -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=KaMLGxq5Wb940wNjeO7BJOduBqFwHX0vgpSfCZ+93hfjbyg7qWJg271Pn/VKXyd39w bQCBsUYg1VvXJegV31qG8hLePpv0czgoGzUEMs4phtmeD/zmUC1nfEQJC8ogw28eG2bk +An7yw8256pDJcinE/m0XLNIcmUeUAE4y2m9c4gUA0k5QBEPJpb+AkdYJlChJ+5gw1t3 tSRK6T23ZWmmujbo1eRKJF1zxUdU34dcaU/iPR3nEkUY5wwIkPRxWuJTrBBYsQt6fL3P gSTqWb24e4RuKL5Jy3Dqu9SzUr4XxOABGUldg3IeYOApTUZlwsQTBHDdGq6GsTBGut5c 4IrQ== 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=NcpAtH/VZizNdO8a7DFvFEvnwlSa3C70cS/jXBfiTn/U0drxwA18U6rJbb9jMDMrVq 5xRLSnZ8raN8vF/fTlnd83X8vxgjfHtTJGx3pItWJKatTSAP18Hxe8Uj6/wzEUogmidk xVn5diRwfMpkJjwormgZT1zumsJVoG8/HodDzO6+wyrMb9GacadJDdsHJbtIXmz770z8 PWa3hTp+MxVJt937WjvQnUTeatjXBQ41CqPT9y73gwttv5hahtzbOw1pVkBM3DvoPArk WbCUnwTfYL4YDahPyrURcAGkX/KbhVmEsrmTT30ZZlRbENhQoh/g80KDm99LTEV/e/Gx D0dg== X-Gm-Message-State: APjAAAUdIqXNF8q6mAAdQwCY0XRzoIjCvaSePquo9GPrUz9HbnG7MK9h f1VZxvqBDdKee1yAskBv3rLO2g== X-Received: by 2002:a05:6000:1209:: with SMTP id e9mr16196807wrx.205.1557743407366; Mon, 13 May 2019 03:30:07 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:06 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/9] genirq/timings: Optimize the period detection speed Date: Mon, 13 May 2019 12:29:47 +0200 Message-Id: <20190513102953.16424-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Mon May 13 10:29:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164023 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141804ili; Mon, 13 May 2019 03:30:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3CrwdbGd7vbuWjQQ+PdBSHcafBr5gujXMviEJpYeusuBF+urggIR6Tm67Cu70kqfuX4kY X-Received: by 2002:a63:5ec5:: with SMTP id s188mr14286652pgb.418.1557743446396; Mon, 13 May 2019 03:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743446; cv=none; d=google.com; s=arc-20160816; b=V043xXNKF35tP175ZLCr9Ndruo4W4rE4dWg/LoRj8QWtvt3K/HteznVvrOzQ/+rT5c wWSTu5Np7xeyRZTbRvH0E4zjcMobPx8KiaxeFydvfs/HmokdDoaDXa1bJ7vFV4f11Wjp 1WPanBYQ+Uz9ZLlVC0VJlNysuJKVoIYUka8MY6+8R9WdZ5ap61HLggBpXqQ6VvARS7eu vQ9Eh+i+tIJtcuKH1VsiXDJZBh60fj5XtXeUTg0KYzDul7hXbALD4n7Qr6ZcUHLLw1Xu TNOFd7DoLGF50daOgR+UV/q3RhGPWWP0JF6RTzwbfDVEwwT5A5CoaMaxu/7t3pd3Serw RAvw== 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=QuFEVfgYyBmuGbwNsYonMvKu9+V/7BvHFy3pKjpoGUCcsH/5tD111WNJ3jeV9eGsFm VuLExKHaroWzkksnb/aG+0P+zoSPFQ8LCXvOeQzvWjwb1Kt0CQN7aTHoDB9c45epM1Sb MgAdU0s/ZndTqCrtoOtm9mz1EjDQbgOoIi7dW1be3fM3/YX878JUL4K9jy1FC4zJ0MZ+ WeGrSPMza2i+Xd9vYYA0NCKZ9wKhzsj4qx001oIge+OeT3eXIVQeh9U3f/1Y0vqTdDdR uSoqzw9l9H0uPrt1JbAfe7FjVukhY9ICzEFZXAvj6z+bGL0RDXZkqr6QzPVOjdNpTxt7 XbkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xtpCY5Ls; 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 101si16141471plb.31.2019.05.13.03.30.46; Mon, 13 May 2019 03:30: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=xtpCY5Ls; 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 S1729021AbfEMKap (ORCPT + 30 others); Mon, 13 May 2019 06:30:45 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33082 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbfEMKaL (ORCPT ); Mon, 13 May 2019 06:30:11 -0400 Received: by mail-wm1-f65.google.com with SMTP id c66so5806666wme.0 for ; Mon, 13 May 2019 03:30:09 -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=xtpCY5LsYPDsHS0aQCf3Xs367A7e/JZ4MUxHD3yChdm5d5/d6cWgO0DgGd0Am/gJg9 tdqFHUW/+rdS2nzakkntj61aw8YL31HhsFeekfYFEbXiomu+/h0A/lmkMCuUzA5AXtIT YUr//hEHu6lVOI8OCOoxYWiQGYhitb9o95p22sGpZmJ7vWNLEvDx+U7SLXNm/ekwDR9U HsJPZRh+4YzjMhGb1aoJznB2VHK4XrVuYuURPlWBbyWxt/7j9o0qNxNp54nMFkezKnYN 2MZYU0L+RAYvIxscoVd5Pi9VQGLw0yTluQ60aX3zY9Qxpydj/1W3KMVfT0mPHd8VRI0x 4QJg== 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=ItlHAjCvv7D0L+NUn3hEAGWIos4qlnyI7TpeqGoEto3x0vtTwGpn9jmaZbKFZU4UlZ vv0CQkT53H1oAG5KQ+uRifkTkHKMASuFzN+IhSV4GU5XugL/GHEh8BjMNmlt0tZesaMp a7fs3XWfh2ZhMyHCN1GjXjl3hNZj+LLEMXePceU6etut5d2c4yuxGMByVM7GVYc91lSv DPFacJhPxtxOW08dol33WDKCfhmiqIRd1m1R6uitUNF4hU96BWjBo5aXoPYTb12T4ht6 8/9c1Nju3TP5xSlaL2rf7tHaJilMJ+tFBesxUl8hAzzPSvTXdPi6tC9D7Z0VzyoHksj6 cnTg== X-Gm-Message-State: APjAAAWf66p7x1509Y8t8R/jfhD7xrJQnP4C2yy4cMkV8mUr4hSH7Ag9 0saWaAomeUvEGj2azRWELS1ylg== X-Received: by 2002:a1c:a684:: with SMTP id p126mr10382552wme.101.1557743408653; Mon, 13 May 2019 03:30:08 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:08 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/9] genirq/timings: Use the min kernel macro Date: Mon, 13 May 2019 12:29:48 +0200 Message-Id: <20190513102953.16424-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Mon May 13 10:29:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164022 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141700ili; Mon, 13 May 2019 03:30:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/91PlYfR3K5snZmrd1T74o1NAbV8iGORP9AlOwrbHzXMYUJZ+q2EU5FDjcjw7XXGLRZCR X-Received: by 2002:a17:902:46a:: with SMTP id 97mr1317100ple.66.1557743439507; Mon, 13 May 2019 03:30:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743439; cv=none; d=google.com; s=arc-20160816; b=PDpjXjB+18vHCjjxrvuSt1RQslQDlwG50CdVGkTH28Uo/uRmPko+Rmv+tIOEExV4/A dhs7/Bv8g9KU3Md86+/w8+sqdojpH1uOdQYcMC9+QBxUpaFqsk84MywIZ3AhH+gNwZtk 1kSVSg60pExW4wmMB2HOckdc18vr5O2y8Dc62lZCxv1h4MVKWOkOcDZJ0wTfkPIczzTO AzIDMq+9Z0o4UbZYCIQlbCnB4quV2mXlgbdWB1P6Wjd5o3WL1TFldV/F1w8/7xhBqlpf CLkLo5/ynluEdxh7xPw9zgAYkadVVj7B8KcK6jurDNsYkUBcXlPbF2+38P2c2o6huPu0 URSA== 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=ZphBE3mcQQgIg3Jps29GQcPcbyd7Y2KaCi2cm4mtUneIokYVZKOxqzQWqb+Rz9CzWW g7k5jawC67oWEIPYKJE/EP/Vmx92bs4OR1zVyYJHWEb4+jYiopZzUdkszq7XtihuBkTj 6QvJjOc9PLYLimzO24S9kt+l3B64mkoJvZVL3IOImAygTarB9oQJkuXBt92wvLJ866ZO ajb/O82tnLUlOZnHlTKtji21pdu7QcigBNVBYUBq8az19NXYa9/WZXe0DjUfSymF6gbn 4MtIXS0dl9XfAykzWNJwRL0HWrAKpthd10IgJDiGa7E7uL9nAGRMrwIdAp1zDT7dlnhn 5P2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=awxf1rKt; 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 101si16141471plb.31.2019.05.13.03.30.39; Mon, 13 May 2019 03:30:39 -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=awxf1rKt; 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 S1728958AbfEMKah (ORCPT + 30 others); Mon, 13 May 2019 06:30:37 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35524 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728577AbfEMKaM (ORCPT ); Mon, 13 May 2019 06:30:12 -0400 Received: by mail-wm1-f68.google.com with SMTP id q15so9123031wmj.0 for ; Mon, 13 May 2019 03:30:10 -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=awxf1rKt8shPIXHZraJS5fZLFnvTaFd4ypRimyn0+syJg+6YCdK0vkQQlGZQihWiQy dqfVHq4IkzUVyycEPEa4ZBl6vbWhscuLOoDnGbLvYXjeFB8Fd9sHi7YyKQvZyNfiQuCA nM7B6V7jiHiTwCNjbFrIOmt4Tp/yfW9HmHIftGpSL0dsqmOioOjr1fOdIde3cfNaUlU6 C9DIsFk3CeRtIlH42aMxIyIf52SwHnR7GhNm8ewuStu+WPnDRleG+PDhyWER297fLOOQ Vn2X4zTxbPOi20sbh6657KOHQOoux9sogvJ86Bi+v3Vv6jY74nN9I9BIV7wEVi/eRlCk qU3g== 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=fZHcHOqdBL4DvmwACh80J6zfs1vVrYmJD2SgEPv9KCuy/R3VFy+GrG2AKB8y/c1LJl itLUDx5T6lL/7B0rjOvIGAYkJtoPfi5MJZi4PQELVuQT0XZQPQTs+F5wmi9Yo89SWHmd Lon8G75B1iFByMxACOZRF9UAwyOzqaTNsQAct48ei4CjdHsjNmJkaw+w2xDS8/tF1IcE yQQA2M/QhFkEQINCDWuefQdAs8uSFIcIc3ZMSPFALJWdRnkVSoAQZliHooI6L1BkYQLj LhjcUn/f4P5goMUPu2PcqJu55gpukbPh04XyrlADyeXi0qlpeQo5TQckxzS5M9Oo3q4R YULQ== X-Gm-Message-State: APjAAAWfv2nfNdeBR0AciwD0CfWfQ166wDHlxsOdlfPJhyr2gKX2RKe6 xr3roNI6iiVpcKcUrcuyxUDrRTbAe9Q= X-Received: by 2002:a05:600c:230a:: with SMTP id 10mr2020296wmo.13.1557743409981; Mon, 13 May 2019 03:30:09 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:09 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/9] genirq/timings: Encapsulate timings push Date: Mon, 13 May 2019 12:29:49 +0200 Message-Id: <20190513102953.16424-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 13 10:29:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164018 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141320ili; Mon, 13 May 2019 03:30:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyt34fG12Dj21OoeKFMILJrUr/3OHZYGsjg44ZLcXth6MwleJHwtoxDw/viywdcCdLhWxw6 X-Received: by 2002:a63:4820:: with SMTP id v32mr29599314pga.89.1557743416899; Mon, 13 May 2019 03:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743416; cv=none; d=google.com; s=arc-20160816; b=ttpNVpKYA12W+ftpv8d4MomZdO4ziQPZN36Jun/aS4PewiR1/O5vuTc/su0bcc5sGu syq8GZ1ynECK49x9UlcS+zyp4f9CXDWAapvUVXT6iZnWKd1+qbq6eW0Q61ErrDotm2qS WqKafzKaV696FPi7ZM1S5YcX5I8etQxD23q18V43IqN4MjgBpp6xAevQHnaElj+Ir5GG /iBS4fmylnNYPJWh7LEj0nVMYpQWwXH+NSXP0hvm/8hZQvMuNa110vymZ/69TOGzUn8K UVslt2qyDwul6MjXwqMb+CMrFFsKbUXPmd8qECKKz/su0+U887xaiWK517vu5DsRAO7X zqqQ== 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=zRyCcd00gp1YDQuQa/LOZGz36D/KphA/uBGc0IefzaMMgGFAk/uyWsPj5M/81nmvwb DJ0dQ4jWaWauNYKOKKviTjjVldEFRM4aF28aTpv2cXkWvQnn3TOCN9zA5Y4vx8NDbx+E /zWzEjHcDIS56leySS00l55h9CBH8ZcvWNim9ftHEfl61FyMdpK7g44wfx/k8mHzs4JL NBkmzzBXQ0VYD4STcuuaO9/wdPDyJHK+d33wQaRgY9vCpnVgov0aiaEfu9kXEad8RmA5 mBlcOOrzWWbCCkpnnAUq1ENElOEgRlvGtkt8wfQ1kC2XZustRd3IvF1XY6nxPTWONTDo X39g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dSHCuoqo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si14997508plk.108.2019.05.13.03.30.16; Mon, 13 May 2019 03:30: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=dSHCuoqo; 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 S1728650AbfEMKaP (ORCPT + 30 others); Mon, 13 May 2019 06:30:15 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52274 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728613AbfEMKaN (ORCPT ); Mon, 13 May 2019 06:30:13 -0400 Received: by mail-wm1-f65.google.com with SMTP id y3so3881738wmm.2 for ; Mon, 13 May 2019 03:30:12 -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=dSHCuoqojnoQnhQPXQz7BOVR+dK7em4UWq9W9rNbeZ12DzLkg6+CSMkUVF3RJoH8J9 3vwrdsnfCIYmRc69SgZPhD1rK9ulkby2MgOFR/87kjRSScR3JLGSzjEfJ0uPDXpVN0q+ Bh6wnWmJfVs2UvMmrwleiJq8wtf8GMI3Jr55Gea3Ooec/6xHIj7t3WENxc0iopWgbhz1 a/dgI5WH/UCZej5n3L9XHCoseNge88nTv9znxrHgM7ZFwJAMHYqeUOmyE7UGhCE/I7zI 8P1EqmHWjKo3UBzbTpjmKGK5uB8U6nqufkFVdg8QY1gvQcjYk9OqOtOadY3pFUvwNC7r Iuxw== 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=ER6m2I3ThIzqWFkdGokY60B9JsyXEfE/ZPrpaB8lO4SB0urCPDPqYXWMTt0q3q7JSJ u7Q983f6nuMXcKlDTHTXKnLbg9XfGOunxBHDM8BMcUQUnVauUI9BBTDAKM9APGJh88NF lBtK0HKIA1JCdC4MuIfEZv8vONCB35tlic376Ych7Sp4DRPW6A6mfRYOpaUnCTRuiT34 uqwv+iE7m9We1zRwdUbom9bbljXZDoNhqjahfWLLc27W5GOB2w3podZJApGptwlZ6N0l M6j13BKEIi0HHyyJ9vTPsBDag+AUqNnHNUM/uN3rSJJhBKG0pnDSvWvRWZ4eNxyMITey kobw== X-Gm-Message-State: APjAAAWCyZw95Y/hMeztXwMMa5p6VCMdzpI5vBc9GOdwtjrSnONO7YZo tKccAQjwrKobvC90Sr4RGhWYzCYpT60= X-Received: by 2002:a1c:b782:: with SMTP id h124mr15844451wmf.5.1557743411330; Mon, 13 May 2019 03:30:11 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:10 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 6/9] genirq/timings: Encapsulate storing function Date: Mon, 13 May 2019 12:29:50 +0200 Message-Id: <20190513102953.16424-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Mon May 13 10:29:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164019 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141407ili; Mon, 13 May 2019 03:30:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxasdwqBMORzj3De0jKu7CFSv3xgL+yjckjyf0gOFxDVexfRg1lsJH4V8FBKyVw6gluIRUa X-Received: by 2002:aa7:8157:: with SMTP id d23mr4752112pfn.92.1557743422905; Mon, 13 May 2019 03:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743422; cv=none; d=google.com; s=arc-20160816; b=MgK7P2rdakNl61pvz8nwmIekOlB3DCOyAiRgW5pD3Rn+7O9vdoh2QbnynzIzaZciB2 jmowLOamv8LjYH9g+OJamZY3hEWFglv00kKorflVsQ0XB8o9rJ0YWwoTbxdb06RfLvtM ziouRSgFwKlV2INX0tHMEmAPsq3eZr0/E6Bfw+32uNWFjUiKM+pd4xtbPNNVSoCCM8q+ RVi7Aip28k6RGjU5nF9tQ4jG0Is+eLJKixqPlNdpwPFJxi+OV3S53vYVtSqiJcKiL41r OCt9K35ZA2O86s+SGbRiFcLGfl+PXG6kjVIcQdq+SzmhuJPLAhauVgG+U3QLjs7WJ8G9 OkMg== 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=mR7EEZ3aUUw52vrsHVUGLaXGM2W4darF/cVAQlTAvMk=; b=ZL8CvvV/PkfvamY6sDj+EShqtZcbhKIT9oBe1enjDdIDs4Hl3PXBtP4tm9Q9giXptL gzEZZO+wx9+w9agwlXn0YzoSSLi3xeoMeaNbVwRsdoKTMhI21dBSY7RjrS19xIe573w6 QmN/m+RQsVvPE5QFaZ989r9UCHJyUn12xAD4nqH7mLQ2h1JksTtK0rqha//FEn/Q7C1E OpcbpGLU3AVxy7j9vZDCriyEM1MbvtLom6pp1EAeNaUKp28pRP4rjJEMnY6I5MzSpa26 1+qxpn9WAwwKiwJwW0HU3wAvkfdCiCOj5GQGSoj9fwRJDrUCHyeb8TZcl16cVKA42UUU t0dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kKIiE2T7; 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 j190si16333590pgd.394.2019.05.13.03.30.22; Mon, 13 May 2019 03:30:22 -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=kKIiE2T7; 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 S1728690AbfEMKaV (ORCPT + 30 others); Mon, 13 May 2019 06:30:21 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40667 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728613AbfEMKaT (ORCPT ); Mon, 13 May 2019 06:30:19 -0400 Received: by mail-wm1-f65.google.com with SMTP id h11so13074198wmb.5 for ; Mon, 13 May 2019 03:30:17 -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=mR7EEZ3aUUw52vrsHVUGLaXGM2W4darF/cVAQlTAvMk=; b=kKIiE2T73q92wZkdJaz59Ou5mIDun42zy5V6pPnKEOEGSnQxfMDbcbjysw/3jRhlEv RsZOw2EGYFkZQjh6rf8KA/Gvl728v1s2wexOmRboRdzcAUK5NJdRYU/YfcDfay6uDxBA VUdiZlInqKY+ho5wblgw0a+gI4wp/U9Jsm80OOgtTr0wrScZuukLRKQOVH7yvZSMwvUy i0vMbsP67tW9bdmxS1NlmFu31iy4d+mlj6uDSy0xvaQDVC3slg3dKwhjCHmaA5R/YO55 dwrrMl/oKCNqnmabufJSP0v/RhELonzzxhYxluosvhx3v0jtY3knPIoVHEm7pfSe8tDa U2tw== 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=mR7EEZ3aUUw52vrsHVUGLaXGM2W4darF/cVAQlTAvMk=; b=hcNW9IIKwOkz6ds1X1ZMb8vrhtq9yLF6A0tLxjx6ogIitoZkhUp3Obv3DTnGLk4w04 Kx9C3THRlrHVzk6HBaibowmCdRlEKDW+hu+j+BPGtpTqgqEb3AP8U46qMP5aW6atCaXE bfwk/FH9W6YgYTqwDixV1KyMuGlcxaxsqZ9cUNMvvqaDPW/m8gzK2+eMIceA3WNVWxrw HOgKMI1qo+jg6VTa8aZ0OcZRNPOOHlUUE2060lyuunJVmRwVhM1i9NBVRaZ1GU9VOlZ7 HjTKmq9tDMOAeZpMn3yFa7wbt3hSXuKNsqe82Ve09h+56yoEOUPsOO5N9UXJNz5TRpoG sjAw== X-Gm-Message-State: APjAAAXVXBDdjhilul2F9sVHbwAlYEFPJGXsTO+ZkzHzacZs1EgzsflN GTtW+nfasDkZcGAWyOKyyRmltw== X-Received: by 2002:a1c:9a14:: with SMTP id c20mr14336565wme.61.1557743416890; Mon, 13 May 2019 03:30:16 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:16 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Andrew Morton , Masahiro Yamada , Kees Cook , Andy Shevchenko , Petr Mladek , Matthew Wilcox , Joe Lawrence , Mikulas Patocka , Tetsuo Handa , Robin Murphy , Sri Krishna chowdary , Changbin Du Subject: [PATCH 7/9] genirq/timings: Add selftest for circular array Date: Mon, 13 May 2019 12:29:51 +0200 Message-Id: <20190513102953.16424-8-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 9 ++++ 3 files changed, 131 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..a05c6695f6f9 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1827,6 +1827,15 @@ config TEST_PARMAN If unsure, say N. +config TEST_IRQ_TIMINGS + bool "IRQ timings selftest" + default n + 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 13 10:29:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164021 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141518ili; Mon, 13 May 2019 03:30:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqww1o81AkbsxWOE5rt8GsczSXoDRIEEHxDlR3piezZbKRwei1XaiqE1HjkJR6NtTnewc7AP X-Received: by 2002:a62:117:: with SMTP id 23mr3499983pfb.156.1557743429224; Mon, 13 May 2019 03:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743429; cv=none; d=google.com; s=arc-20160816; b=P8TOlgjHWGpb4hRrP7y7wpAT8G+haJQpcgXDhSHxXXHXo/E+QlKZpuARSpWX/pfMZi Vm3dRyFF7IublcAov9tNZq5polG5H8TjdoZbpIFxuI/RCHvTzvsYa3H7XPMnpOL6PnQz qkZ9L/xNymRtwb8LzCVuqgnIP734sVlgdORf1vInmEJkK79zqDT1GsGyV9E2AVZw01iu nXD81GWNIFy4K4lZMYM/x7idUQ3DMllEJzaAbYBUAlc4ntY4V5lCYgf0yQIOHeN8dAQm MgkbwOc17j2eO2riiytNcZ0RdPG6TGopsddeOPn6/OeIDOiVKRs6CDi+j1Qo/mnUzQQD 6Y/w== 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=l+UT9rs3aaywy5hwb22wGgtUDACKthUYGflj1cLFFmtDqALYf6xNUeEcID9mSrrWts YvKt91Rmp4dtN42miiz+6bITzfN4PdT8cBgRFMS1pcCkuj3h7hKQVYHuVmAPEiVBrcLv U6ZY200MYSwqtas3ZKwtezCgAC3BA3mslZtuht8bWtyOi9hglH0epLa5MO2GhEnzuy5X AI+vBn3ZprZXTY+npaEey0sc1kmk5kN+kMJE1smcsmoJW87n2KGMzBsfeSXbbM72ruQJ aaj2cPxPr8TWrikkpdOyt1Z5HM98+l1HCeIGqx6WkSL47KALER7f0UV5Fb44Uo7Oj+O5 sjZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xZH5BEx4; 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 101si16141471plb.31.2019.05.13.03.30.28; Mon, 13 May 2019 03:30:29 -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=xZH5BEx4; 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 S1728749AbfEMKaX (ORCPT + 30 others); Mon, 13 May 2019 06:30:23 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52289 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728239AbfEMKaV (ORCPT ); Mon, 13 May 2019 06:30:21 -0400 Received: by mail-wm1-f67.google.com with SMTP id y3so3882194wmm.2 for ; Mon, 13 May 2019 03:30:19 -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=xZH5BEx4DVqhI/yCyJ/9//mDG0TBL56xfES6Hh+yGgzJpmiCY/zM7Qc3RqlFAZGs34 zVZTewhKISZTL7KtBNzxq2sG9+SDZZkVwp+mretiIOKougb51b9OJucvlMB5ON5VjwvY EOs/y5dnkTsbNcDMFFNV0lpkrPOtJrqj/Umn6K5+GfBBRFLkdxWk1LAPxiiiaJy9t8p2 Ij1zd1SdZRGcMHcUgZvcy9Pz+/5DT4qrcC1FQC3v5YoN5Gmtq3mjBo2djFtJPLdIhroS ziLuB+3ODowvBXvumXaT4oU9b1fZ+QXCd3F+YMP1Q4clWFTcvNMtt/XGQk4coDli9gmQ PRLw== 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=kO09bmvqtniQdC7eAvXkz+DKvlyAL/R6cWJV6inWV1YV6DbaL5PTg2nMf1ZxlLJrrX NLkZI2YQZfFKC17imwIk0VpnfCfU0jG81LX8tmAaiET5oCbd0nBgoXWVD1qVkzr92TNy vYM18X+4F3jfQ0xn2RAPak5Bn/UE9v3+zYcRYxNzHJ1zMgII+yjeHc34Rq0xvmqtFrvN UDFJm7xsb3mkGZhNGbhVep8KV9EkPBW4ebOc/oqBZVgpA5lTOYuM/fOVxF0wuRRzexMU uU3EyLAFyx34L0QTgvc4yV3n6LB8WQd0r8x0SOTWNEstclkcjIXkeHlfeBmSVI/Zj4Gu xEew== X-Gm-Message-State: APjAAAW2XphvaAUbcqzdh/1LfhZmLqJHodGnsy+2JK8HWZ4ZWCElejwE TAoy2Bdq5Gm9PgdQnT/1EQ0NIQ== X-Received: by 2002:a1c:14e:: with SMTP id 75mr16071820wmb.100.1557743418190; Mon, 13 May 2019 03:30:18 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:17 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 8/9] genirq/timings: Add selftest for irqs circular buffer Date: Mon, 13 May 2019 12:29:52 +0200 Message-Id: <20190513102953.16424-9-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Mon May 13 10:29:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 164020 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1141454ili; Mon, 13 May 2019 03:30:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7cxLWZKwS0Xnd3FrAu7ioMN04g+2s5LMlGXTjBZGz5oxDyUYrqnAZV1XJ6c+wD6MjQwvF X-Received: by 2002:a63:d343:: with SMTP id u3mr30027572pgi.285.1557743425704; Mon, 13 May 2019 03:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743425; cv=none; d=google.com; s=arc-20160816; b=UlcTz4OVciRPRSmU1OmVfmTPZ5I58Sn56SsXtbEJjogbNJF4EOOwBC5LXW068BpBVp Yb6tjvih3gNE/S0VqM9G805zQDzxgpawYvRqV88wLyusXZjCwNItxypLi9hoeBZZQjs2 kblk+M03ixTm4UKoo9N61KdCgEkRAigfXWN+WpjnL7x2u0UJBv48k5+5LJ1gyA3BJI23 3VvxTnHQJyUO8NPXUrU8W8CGB+AUA7nw4XIZiKcjtsn1R/X+KjKF+OywpjdMieA5VML4 EBgxjapTCWsanibe1F+XqiVvweB5bd3w1JUw8jRQkxakYngEygMcjiumoSIBLglS9toq v7KQ== 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=PDS2rlsAbwSffDy0nnr7OLddzyVLSCnqmXsR7k4O0Rt4osxyMMPpSHgT+HVcJqwOQO rGHIjODXUazWeQy+OsirtSXVykejzondDVwtA+dx9wXlXwH/+yQSc7gvIntGcC3s8giP haLvrz9VmqIdE5Ue7Hobd10lewXXuhnqtkfr/07DZjYNvcokvF6KFwnbyDHlbwMEqRRM Z2EjTzb0X7xuC+IBQ9q5nRENKc+3laFwULU39tdef9XJS3A/Di7+R36oCbI0/hke8RmA DkNYib0lRjwSkg+dx9qNC6ukpIeikN643u49ZfQ8ULLjT/lk9lfWu0biS0xlCTRpJFWM TU3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UmBOW939; 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 j190si16333590pgd.394.2019.05.13.03.30.25; Mon, 13 May 2019 03:30:25 -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=UmBOW939; 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 S1728816AbfEMKaY (ORCPT + 30 others); Mon, 13 May 2019 06:30:24 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52112 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728653AbfEMKaV (ORCPT ); Mon, 13 May 2019 06:30:21 -0400 Received: by mail-wm1-f65.google.com with SMTP id o189so13314197wmb.1 for ; Mon, 13 May 2019 03:30:20 -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=UmBOW939gLTq232p+iwK3f8nCudEncfvXezxIaacngiWvHR8NtB7S5O7nxFq1G9SKz ssd8Zi5tDEqiCdHVFS51Gw4UZYFqp+S7fqqHcqiaXYKet2KtrLRD4PD2VZE59dgrsvkj 3R4liWCFsEBSbG2sUJaHoZ0Uxw3sbivwcwRMp+bY0Xm1ayPdP+ZN8KhMJETc4zqYoZ8o wt2DLh1MiZuUNBhKsYrmewM0i3WxsFP7W4pU5/eGIF0G7ZOQ+c50PZFxrz8wIz4DAg6c zUeryUgBE5tPYqmhPjZvjMcCmCUFy9WkLnU2Mc4tn0/cHh9dF3Sr28aGM8yAVsYnP8x7 r4TQ== 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=VOGuMlew3N0vfOTc4bJcwazVoROoZnyvR0f/PrlobpRVzWcN28Mj+2w6wwBJWewUFR OhYyBd+HiTwXCZbEXXRfS6FJyE5DyfxHQ/CVpzMwDZ/16+zK9lVisYyaOdyH2S4uv+7c tWBzPUpNTjiJ9If82jZUeQLC2S5ORo3uAJlIZmIPOSoVmR5ZZGgC332EfLpBc3s8ZOAe 8q/IVef8RLQZsLuonyGpx+e2i/EqjXB+TAOL0Mu8BMbZQlcYLRVm7OHL6NTOUo0yy5Th bAfaDoEW7yGAEpTomJDS/AtWMFEXX/kOVha+/dIFVG01QgF+2mR05qAQcRXmUHUyBF2Z hLyg== X-Gm-Message-State: APjAAAVxo5D98w9+S0vIEl/b6qI80EAoq3hTKXVzLJeMLrnMsEHTXEvD BHP/Ka4AYaZUaattKcPgyp6Fi6mjExo= X-Received: by 2002:a1c:ca08:: with SMTP id a8mr14602038wmg.5.1557743419532; Mon, 13 May 2019 03:30:19 -0700 (PDT) Received: from clegane.local (205.29.129.77.rev.sfr.net. [77.129.29.205]) by smtp.gmail.com with ESMTPSA id v192sm13645238wme.24.2019.05.13.03.30.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:30:19 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH 9/9] genirq/timings: Add selftest for next event computation Date: Mon, 13 May 2019 12:29:53 +0200 Message-Id: <20190513102953.16424-10-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513102953.16424-1-daniel.lezcano@linaro.org> References: <20190513102953.16424-1-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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");