From patchwork Fri Dec 1 09:26:25 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: 172341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp991486vqy; Fri, 1 Dec 2023 01:27:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPNo0yajOiJNbffPZGtLueaGUn1lMZrf7EOQXDkQ8/YlrHihA72moFH1VzvfnwPySzjL/2 X-Received: by 2002:a9d:67cd:0:b0:6bd:603:797f with SMTP id c13-20020a9d67cd000000b006bd0603797fmr2643080otn.37.1701422845114; Fri, 01 Dec 2023 01:27:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701422845; cv=none; d=google.com; s=arc-20160816; b=MjLwj56eSagzaQOAFoi5oMa3B/ADj0wnwJ4EOeKU3vkQFwLhUD5mDpJ+NyZZlgYAV9 yCScJiYCWYb5ZucO8ws/gQxR8FNggekcou4LqUjNMVDhmQq1vD8aGdewvigRGsVMBbby vmEdWfhv6UzazmR+MNQCwuC+HNfEFvwRBD+nFseIg2dBp8UngaZxQfeQ1A4xveIUyxuC dqkAursMd9eNRG/GoTn2Q0cm2oWTxLWcbChiiYec6qLfZ3m8fJDXsnCdHc0wolMlmnuB k1jcos0BnhiXthyDeLuBPx9BNFyBGq405GFMee9AwpKyoVMSk9KvfvkSt8aEfJiY+0Ra +c+g== 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=TpL4QHNJmRbyjNaiO3+z9ClPjQHijZRgI0ccvQpegrw=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=b5pp/ZaiqpXaHqgVA+E2j86r8y96veyaFnhTsW2Sbwywd/xqZofG+gdwJvOKZALDvC UnC5/+10oUP0qFMOISEpvgCUZG1Z2MmfST1W3XfKaSYqhCiQ73CJxSR4YeL8txHfIH/b nrCtfS61NBzA4TH0W5MeA8MFJ/PbZo5K+hlREmYYcuvmfYA/OwOrIj2uSTytQj/SfE/h Nz/HqW2q3pGd24WGya859Fd6SKBdAs/NWHqG1PgFK/dn6MJ0JHeH495B8M1jzaZCxYFb ELQvINg0Re9b+/rsij2nH0rnfxXi6D/L3JVR+fhDLuGh28dxz6JMlc7UYHq41/Q2rPgU aq/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UJJq6noc; dkim=neutral (no key) header.i=@linutronix.de header.b="iUF3pD/b"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id q78-20020a632a51000000b005bd3da15474si3034582pgq.839.2023.12.01.01.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UJJq6noc; dkim=neutral (no key) header.i=@linutronix.de header.b="iUF3pD/b"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 222DE8339399; Fri, 1 Dec 2023 01:27:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378038AbjLAJ1I (ORCPT + 99 others); Fri, 1 Dec 2023 04:27:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378020AbjLAJ1D (ORCPT ); Fri, 1 Dec 2023 04:27:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A980E194 for ; Fri, 1 Dec 2023 01:27:09 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422828; 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=TpL4QHNJmRbyjNaiO3+z9ClPjQHijZRgI0ccvQpegrw=; b=UJJq6nocAW/HiAnWK8GyTPEfN1oOPO+9lXJFr9C7HGZTAE0APcdz0FcSis+Nc63mNgmw7f DQPc5vLiU1FzKvIj7a/2povI1jdnoqtwEcyQ4eoRRnp+/slR/Hg9n99bO/DdzE97DLkd42 hzRcSz+mTyBFBysF7BFmGGc2ExkPoKocraYbLNw8ngI0NZCg+akvnglvPjX9CmYUNTqa0i Z+SVu3HynyVTQZWf/Bm6/K2wD5JvHi04S7bTy8ANUEXKTMjAfXPp71O+NVOGHyTBwtWZ62 Jt2ZkJr4otEraNlGF8lGS4zufaLNY/yoA57SyGoui/zyn0ZZgM4oNgQ8y6fvlQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422828; 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=TpL4QHNJmRbyjNaiO3+z9ClPjQHijZRgI0ccvQpegrw=; b=iUF3pD/b/ZHxN9ryp4qCxj+pHqQ1FCpLeP6M2yWc0rOxGEeo31fEwzQLExz/7zDZSZEI2g JFxHUEpcXyBZvzCA== 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 v9 03/32] tick-sched: Warn when next tick seems to be in the past Date: Fri, 1 Dec 2023 10:26:25 +0100 Message-Id: <20231201092654.34614-4-anna-maria@linutronix.de> In-Reply-To: <20231201092654.34614-1-anna-maria@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:27:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784071161290723538 X-GMAIL-MSGID: 1784071161290723538 When the next tick is in the past, the delta between basemono and the next tick gets negativ. But the next tick should never be in the past. The negative effect of a wrong next tick might be a stop of the tick and timers might expire late. To prevent expensive debugging when changing underlying code, add a WARN_ON_ONCE into this code path. To prevent complete misbehaviour, also reset next_tick to basemono in this case. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v9: Add reset of next_tick to basemono --- kernel/time/tick-sched.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 89517cfb6510..b1b591de781e 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -839,6 +839,10 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu) ts->next_timer = next_tick; } + /* Make sure next_tick is never before basemono! */ + if (WARN_ON_ONCE(basemono > next_tick)) + next_tick = basemono; + /* * If the tick is due in the next period, keep it ticking or * force prod the timer.