From patchwork Wed May 24 07:06:19 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: 98331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2650432vqo; Wed, 24 May 2023 00:09:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5F/hKNVtj8qPZYYz/K+caLBBXgfIWckcSHAvddzLF7zFp7V38jDXqPR97b8LihkCdrcnmW X-Received: by 2002:a17:902:ecd2:b0:1af:dd26:4a17 with SMTP id a18-20020a170902ecd200b001afdd264a17mr1955902plh.11.1684912179460; Wed, 24 May 2023 00:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684912179; cv=none; d=google.com; s=arc-20160816; b=Fhiu8y0kr/kSjVI2tfDAGivbUnteZVruwFtRS9U6D2ZMElAqTbOHV7IdmwH81iaKFY 04nyYH2HmuPt/5wFGFH0nsgVDOASAZLL8RcjZFUssUvcpaCNyi4OjeVzhMOtNE5WtGqg cIpMrppDaGUnOUSqbD08YHSpI6aZMDUZ78T3P7TpziAADRm+xH46wI71EQpTRwgkHvoE R8rCQ9u+vA2u4QsW4kFGMe/qGUtPmOJGKij8oE5IiIBQ00wPOkoNPUEhAbCCyZ0cw6Hi BYPag9QbCjPO5VmsszJkwqg7fXIfOHlwan6t2KxJrkjNbwxRSmCeea8DSgMntWgUkgbn h99A== 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=69v6KAzJ3Kkk+I5jf4FnTJ5YhbczmyAfH/JLKYuJ49U=; b=z9gaiWekmGA92jMcpf6CQZqNgbaMQd2zWAV/iX19IMwZ4MwJmQR5piEPdOyB/+PVpe K150GuhtXyzUbgD85H0ylQDR1b0ADvHJcEbzksjPj4kmDFUmFvStaVfJYGI92IiZUdQn mPyWDvQSPJ4+jhAOW/Sjd+BfWFnpGCJ9T5C6W9mgRVZxV0OknQaTmfxkGJBfkUL2h/QT k9hqfTOElmV5iNLrf0u9cV/bfFWOOa4EGZ+k3OIbiWFOZN62icj3b/LGiFDNFHlb/LLz a6b4kJYn4pFMHvSrTL9V1RFF/9uJAgBpMwiT5jfLSxYU3ZuKwuGRdqQbhSh5AKM7Lxqa xBww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="WML/DefT"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jh19-20020a170903329300b001afb5af367csi318810plb.629.2023.05.24.00.09.27; Wed, 24 May 2023 00:09:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="WML/DefT"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239928AbjEXHHs (ORCPT + 99 others); Wed, 24 May 2023 03:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239838AbjEXHHH (ORCPT ); Wed, 24 May 2023 03:07:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B41819C for ; Wed, 24 May 2023 00:07:03 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684912021; 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=69v6KAzJ3Kkk+I5jf4FnTJ5YhbczmyAfH/JLKYuJ49U=; b=WML/DefTybhtSenrVmJjckwFy5HhArUrPp5NzIJCOlVIS+tsDYpGGz6XtAL/Tjej+iS+eX rNbbfqXomGylr1TyXGNF9C7oSeCfGOkYaCL6sd1BAOaFGieZNgZw+gx3W72RrGrsEqcGLc j41YELXuAC9lwkibcnANeJAr2yPbqNP9bpeigvcmY9yC12BVpQNQFx7PrtdJqmvtPCaA9q yZUPwZjmnH+97vj8H5kp0G1Ce7qmOae3ftU+CRjdlMHVs2P6sddNhWkRxPuKSsTu5Dd7cM UGNTTHsaFHXiDV0x82Y1FRDIPj9ryBiaIHna/DBFGClomSc/MPfLR+bRKzgpFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684912021; 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=69v6KAzJ3Kkk+I5jf4FnTJ5YhbczmyAfH/JLKYuJ49U=; b=c1N1GlFettzOJ4SoyCIpwPS+BzrT4zoXcaFKud66e1Fyr8PpCx/7gD+aeuKM8PYcvWUASH RMvesJu/2iq35MAA== 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" , Anna-Maria Behnsen , Frederic Weisbecker Subject: [PATCH v7 11/21] timers: Create helper function to forward timer base clk Date: Wed, 24 May 2023 09:06:19 +0200 Message-Id: <20230524070629.6377-12-anna-maria@linutronix.de> In-Reply-To: <20230524070629.6377-1-anna-maria@linutronix.de> References: <20230524070629.6377-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,T_SCC_BODY_TEXT_LINE 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766758473504102211?= X-GMAIL-MSGID: =?utf-8?q?1766758473504102211?= The logic for forwarding timer base clock is split into a separate function to make it accessible for other call sites. No functional change. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v6: s/splitted/split v5: New patch to simplify next patch --- kernel/time/timer.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 749b1570bdcd..fcff03757641 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1956,6 +1956,21 @@ static unsigned long next_timer_interrupt(struct timer_base *base) return base->next_expiry; } +/* + * Forward base clock is done only when @basej is past base->clk, otherwise + * base-clk might be rewind. + */ +static void forward_base_clk(struct timer_base *base, unsigned long nextevt, + unsigned long basej) +{ + if (time_after(basej, base->clk)) { + if (time_after(nextevt, basej)) + base->clk = basej; + else if (time_after(nextevt, base->clk)) + base->clk = nextevt; + } +} + /** * get_next_timer_interrupt - return the time (clock mono) of the next timer * @basej: base time jiffies @@ -1987,15 +2002,9 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) /* * We have a fresh next event. Check whether we can forward the - * base. We can only do that when @basej is past base->clk - * otherwise we might rewind base->clk. + * base. */ - if (time_after(basej, base->clk)) { - if (time_after(nextevt, basej)) - base->clk = basej; - else if (time_after(nextevt, base->clk)) - base->clk = nextevt; - } + forward_base_clk(base, nextevt, basej); /* * Base is idle if the next event is more than a tick away. Also