Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3719579pxt; Tue, 10 Aug 2021 09:45:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweH+ogwWGIpkkWnyminuxCvQ8KoTsx+c2Gh0Cqzybu9B3RKkK5RctZQcPLRy2SacyoOkba X-Received: by 2002:a17:907:1c08:: with SMTP id nc8mr29367125ejc.514.1628613948477; Tue, 10 Aug 2021 09:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628613948; cv=none; d=google.com; s=arc-20160816; b=fQ5XbUSP4MY/pZArPltUiiCWsoy2mqMlclWN70f/UBAd7uAqFpE/82sV9laq+3yf+W mRHj0p43KZ7/BgfjaxOpT8+IjDiWg9BovVx0boBVXIdL/B6e+Qi4GnTVqRu2shU4J41W R0H+oqlvx9f/fHj+xXD5WLZtMEbYbQAAycEKuN8oOlDMyBHmMAHc1camAPOiaJq6Tevv Qa+JO4b7EihEXHr8JhAzpWmtBTUK3lyKCOoLgBOK1PBpC+r+A0wioouXL2P0VO5zTI/e DgIwoYa4ZvJxi98iODhiG1oEiXVyAElFyPA9NtoFGOR7Kab00biFzHaf9M6yPLC1WZcN rC+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=XLtM8f1wACaF4P3HiDqtuQf6TysXYDwIFm7YnLmVkPY=; b=hWR3a7aXxMPCiadPx5T9E/kitE9jKKLCsF6rgd9CHIE1dWgW8bT6dUCGxiPJsTN/P8 CUd6aV0+vt/+GPoXVcw0AbA67Sp5ZjLYBhQt9ZXmgKv9CG4jtzx6NkmmiOdJUNi++NKa uNrQkKoIGb1aj5/Qd/4tMFVnsMjY7VJMLg3h5gTF9pvLG8R9wksc7MQdp0m+Z7sqlGKe NiaL2eaBKSsgwYUTAAWftAI/tAonGe520D2Fod46rCMTZ24wZpZNt385Y2rje1ZtoF8J sGTViyDog4NSXIJ5p5XKrTKqQAQm+uB2aRKaeh5qxlzO54WFto3tBXVE6eFRCiWToqk/ 9xRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rMPMjQJE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u25si22165463edq.517.2021.08.10.09.45.23; Tue, 10 Aug 2021 09:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rMPMjQJE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235999AbhHJQD0 (ORCPT + 99 others); Tue, 10 Aug 2021 12:03:26 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:44440 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235943AbhHJQCl (ORCPT ); Tue, 10 Aug 2021 12:02:41 -0400 Date: Tue, 10 Aug 2021 16:02:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628611338; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XLtM8f1wACaF4P3HiDqtuQf6TysXYDwIFm7YnLmVkPY=; b=rMPMjQJEb14tfEhwoIM4U1O3nsu8cnQsSEF/6i/78K2vnX07t5uw7j/Fkwvtzpxg90XT7L GgvaewHjXKUyCAbu/EuxULggpTWYN+Zfo32eRsu6IJkLWkdj2bjTTLsiQgx3qfoAXS/t9s lScO+1ywK5n4hzK+KgxTc9iwwCvWXxrVC6Ix3BY+2cUReTK/0fB+xNmWAZX45D418TVtNt steNrQcvvRTeF/chBcCMtuFge8WHWByW9XjBU5A5ZAeI2fHUaeYRvmKlzgWlRogCgoGNHp 4cvxbCBdmIhloa+tlEMn8mLXbQweuHZzu9YIL2Pd6AS1fB8XaoEmTvPx9QwMPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628611338; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XLtM8f1wACaF4P3HiDqtuQf6TysXYDwIFm7YnLmVkPY=; b=eQOs0BSCV8rDWLqp9+dsUPZg73heLqESCCxNdqmo13BZXBqUfmNVuf16AhbYyBf7A01xMW kfP+bVz5LLUw4SAg== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] hrtimer: Consolidate reprogramming code Cc: Peter Zijlstra , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210713135158.054424875@linutronix.de> References: <20210713135158.054424875@linutronix.de> MIME-Version: 1.0 Message-ID: <162861133759.395.7795246170325882103.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the timers/core branch of tip: Commit-ID: b14bca97c9f5c3e3f133445b01c723e95490d843 Gitweb: https://git.kernel.org/tip/b14bca97c9f5c3e3f133445b01c723e95490d843 Author: Peter Zijlstra AuthorDate: Tue, 13 Jul 2021 15:39:47 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 10 Aug 2021 17:57:22 +02:00 hrtimer: Consolidate reprogramming code This code is mostly duplicated. The redudant store in the force reprogram case does no harm and the in hrtimer interrupt condition cannot be true for the force reprogram invocations. Signed-off-by: Peter Zijlstra Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20210713135158.054424875@linutronix.de --- kernel/time/hrtimer.c | 72 ++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index ba2e0d0..5f7c465 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -652,21 +652,24 @@ static inline int hrtimer_hres_active(void) return __hrtimer_hres_active(this_cpu_ptr(&hrtimer_bases)); } -/* - * Reprogram the event source with checking both queues for the - * next event - * Called with interrupts disabled and base->lock held - */ static void -hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) +__hrtimer_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal, + struct hrtimer *next_timer, ktime_t expires_next) { - ktime_t expires_next; + /* + * If the hrtimer interrupt is running, then it will reevaluate the + * clock bases and reprogram the clock event device. + */ + if (cpu_base->in_hrtirq) + return; - expires_next = hrtimer_update_next_event(cpu_base); + if (expires_next > cpu_base->expires_next) + return; if (skip_equal && expires_next == cpu_base->expires_next) return; + cpu_base->next_timer = next_timer; cpu_base->expires_next = expires_next; /* @@ -689,7 +692,23 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected) return; - tick_program_event(cpu_base->expires_next, 1); + tick_program_event(expires_next, 1); +} + +/* + * Reprogram the event source with checking both queues for the + * next event + * Called with interrupts disabled and base->lock held + */ +static void +hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) +{ + ktime_t expires_next; + + expires_next = hrtimer_update_next_event(cpu_base); + + __hrtimer_reprogram(cpu_base, skip_equal, cpu_base->next_timer, + expires_next); } /* High resolution timer related functions */ @@ -835,40 +854,7 @@ static void hrtimer_reprogram(struct hrtimer *timer, bool reprogram) if (base->cpu_base != cpu_base) return; - /* - * If the hrtimer interrupt is running, then it will - * reevaluate the clock bases and reprogram the clock event - * device. The callbacks are always executed in hard interrupt - * context so we don't need an extra check for a running - * callback. - */ - if (cpu_base->in_hrtirq) - return; - - if (expires >= cpu_base->expires_next) - return; - - /* Update the pointer to the next expiring timer */ - cpu_base->next_timer = timer; - cpu_base->expires_next = expires; - - /* - * If hres is not active, hardware does not have to be - * programmed yet. - * - * If a hang was detected in the last timer interrupt then we - * do not schedule a timer which is earlier than the expiry - * which we enforced in the hang detection. We want the system - * to make progress. - */ - if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected) - return; - - /* - * Program the timer hardware. We enforce the expiry for - * events which are already in the past. - */ - tick_program_event(expires, 1); + __hrtimer_reprogram(cpu_base, true, timer, expires); } /*