From patchwork Wed Oct 4 12:34:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 148260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp98583vqb; Wed, 4 Oct 2023 05:36:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDrTeahpouM0B8JKH5DHJxTUJZA/4bV+uyW2J1hn5TSt84h9SOuODZKcFYj2ALEWCapRMj X-Received: by 2002:a05:6358:88f:b0:150:8ba9:56 with SMTP id m15-20020a056358088f00b001508ba90056mr2082742rwj.2.1696422996851; Wed, 04 Oct 2023 05:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696422996; cv=none; d=google.com; s=arc-20160816; b=B0ALNtXMf+fuV8mXWYK5FdgVPe93yeTAZVsmijBb9kCnn3jDi3E4GRruxjOn1D+1BW LjL5fCDOeh4cEbZQBkOA4zuMmtvBwqZBvREfjTOtOoctBZ+c+tb+rW7V6sRAv2lTgrDD uCR8v8Fku6Hgh+jlS6D+WwUApQhdUbF3dMrxWn75V+r7ovNbsHCutpCajHcmt2GY3k+b UQo5LAd13iTlxQoQdpstEGdRPBQrwukHWsheH6ZmS4cnq44CwY4/Y71KRWgflqLeAr7L ++OxreWHBWg9uLnatCIJ6VOdAO8wo/dCeFSqWspXKzwQqkhbi1DgWpftpfAa6ZT6GruI tOiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=JvV/GTzIlX0Cx+6nbNdm3uB0dglqhwMGFjF0Qs3Csts=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=ulBMwf3ZtucW+VNqgoVsNB6pLZ3WWQOUcyDws7FYml3kgKTjyZhloCasuom2f4V3Fm 57FnfzeWa3emuyy2W27R2lAHCHLO7SYcEnS/l7qecotbDsL/8k/gFis13qmr1WP1WEsD /u+NOSpq7LrdTykvjhZkDvYrQ8RTGjP76XWEVxtnkNFO+Oc9ozbMcvL356cXm+wDvFQX x7bCqQCCEh5y+T48IJI3q+DZMMvC8BhW2IEHImEVUcxnb+rrYbpLk+NMhYIGweGtToGM NyCMjm/rb9zz9RzU561KhG4korerppsWWws7nT88+YwRwMTE+TUf0pZUU/1RQYzw0Esq v1jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=anbpNzaF; dkim=neutral (no key) header.i=@linutronix.de header.b=N6cePmux; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b0056c2f508886si3488744pgv.423.2023.10.04.05.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:36:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=anbpNzaF; dkim=neutral (no key) header.i=@linutronix.de header.b=N6cePmux; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 35FB0801B421; Wed, 4 Oct 2023 05:36:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242403AbjJDMf6 (ORCPT + 18 others); Wed, 4 Oct 2023 08:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242376AbjJDMff (ORCPT ); Wed, 4 Oct 2023 08:35:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695AFC6 for ; Wed, 4 Oct 2023 05:35:32 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696422931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JvV/GTzIlX0Cx+6nbNdm3uB0dglqhwMGFjF0Qs3Csts=; b=anbpNzaF4gSVJYCje1CvoII4DNAP+K00Xko6363w/r9C54Ss9u48ITN+CsVTms4TpahdsJ tqXY+v2mOpyUmHytzorE+MN5OXdzM1pMN55anRLPCyT8+XviZTOU2ABl6PossHk6ybWaRi 18beY7ITHPVkMfQ5dXhnFBQClLLxWmuu4vWZF29jMC1vajgVmiwOBZwVEFwgJX2iazzGJa Z5plhNpKRuTYIZv4vceHtVZQRxrYEb2Ee8FwqOLhcfeA4r6IqBuMtqK4n7upOmqPG+plgJ +q9c86bL7B+EFiGxEkzNi0Jkn1b4K1/aCdDFIm3rhIk6f6ByVGj0fi193VtoTw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696422931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JvV/GTzIlX0Cx+6nbNdm3uB0dglqhwMGFjF0Qs3Csts=; b=N6cePmuxnggtkUWqTVBUfH7Yjf0o6ukWOKrXHR0Pj/o5cOdJIlIgadV9XxYYQdHtONDg3i +QqgcHp36b0UjsAg== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Frederic Weisbecker , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak , Anna-Maria Behnsen Subject: [PATCH v8 09/25] timer: Split out get next timer functionality Date: Wed, 4 Oct 2023 14:34:38 +0200 Message-Id: <20231004123454.15691-10-anna-maria@linutronix.de> In-Reply-To: <20231004123454.15691-1-anna-maria@linutronix.de> References: <20231004123454.15691-1-anna-maria@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 05:36:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778828440407578471 X-GMAIL-MSGID: 1778828440407578471 Split out get next timer functionality to make it reusable in other places. Thereby the order of getting the next expiry, forwarding the base clock and mark timer bases as idle, is changed. This change of order shouldn't have any impact, as nothing inside the function relies on the idle value or the updated timer base clock. Signed-off-by: Anna-Maria Behnsen --- kernel/time/timer.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 18f8aac9b19a..f443aa807fbc 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1911,6 +1911,24 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 expires) return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC; } +static inline unsigned long __get_next_timer_interrupt(unsigned long basej, + struct timer_base *base) +{ + unsigned long nextevt; + + if (base->next_expiry_recalc) + next_expiry_recalc(base); + nextevt = base->next_expiry; + + if (base->timers_pending) { + /* If we missed a tick already, force 0 delta */ + if (time_before(nextevt, basej)) + nextevt = basej; + } + + return nextevt; +} + /** * get_next_timer_interrupt - return the time (clock mono) of the next timer * @basej: base time jiffies @@ -1933,9 +1951,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) return expires; raw_spin_lock(&base->lock); - if (base->next_expiry_recalc) - next_expiry_recalc(base); - nextevt = base->next_expiry; + nextevt = __get_next_timer_interrupt(basej, base); /* * We have a fresh next event. Check whether we can forward the @@ -1952,14 +1968,10 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) */ base->is_idle = time_after(nextevt, basej + 1); - if (base->timers_pending) { - /* If we missed a tick already, force 0 delta */ - if (time_before(nextevt, basej)) - nextevt = basej; - expires = basem + (u64)(nextevt - basej) * TICK_NSEC; - } raw_spin_unlock(&base->lock); + expires = basem + (u64)(nextevt - basej) * TICK_NSEC; + return cmp_next_hrtimer_event(basem, expires); }