Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp875309rdb; Wed, 6 Dec 2023 02:23:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFikMAQQjo8VbSLx2eHUkvLZj3W7sGZQ6H4TuMPFsfYC8KilAsqUUw9sy00451U29rv0y+R X-Received: by 2002:a05:6a00:1945:b0:6cd:dc48:1fff with SMTP id s5-20020a056a00194500b006cddc481fffmr3347821pfk.0.1701858234587; Wed, 06 Dec 2023 02:23:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701858234; cv=none; d=google.com; s=arc-20160816; b=T2twopcI1X9651zag+9Bx2hbRtb7Kyzl77B09ozkn69LO6tkIqm0xbKulRP3/LB6cC AA5NdGRoFL5UGnTtiIgT/b1uvxqZUZxUxm1ViBntB1jRGR5CnXvfNgWa5Yv+m2XW2nQt HJcrV9hoT4eLZm+qo456ieGdbRedihV1hin11wNSsw1CkH/2Kmx+uvep4P8evYZk3nW8 Z8wgXlpGQd3geCAnvmeTpzq6WfpL54kstha7xODTiQ54RtZ2tScPIn795JgxOo71hIVB 6HZjEoJp3iHqJu7I7btrA9Xrh+ufGgnbrBtlOaV9NTycGoAYtKCgAt3LnUO8YVYXGVnn J2Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=GsNdpIFc09s1gqwIZ71ov1AFzBRmEFB6zZkx3fRFd5g=; fh=YKn3uPfaA5nN+8pZY/jw/HyZrSnvWg60+MCe46F6YDQ=; b=dB35bKRhWimf/mPpJrm95yM+466dRKh+jYobHnUH1rtScM1I+OTzKjpO7BmcXf0cdR W+IYY9LJ70sdX+jdHr5bI6lcdkbCvlEzPG6DMcY1w87Zv+2X1ojKa5MKY5HQSyuqpBHz B0nzY6/ZkaootuEluJx7/mjWdEk1z4dXgqAV9CqozKh46uTeKsLfhZBLrEvefU285xTk N6tm1t+5eKRL5O8Rt4HrhI+dXXhZjQ64CWrGLPydV3ZOAzweumjTARUNEsTqFRS1dQzP 2X/Qg0lccq/ePrBSGfYs/jJ9/8jjRbVcK8ohXAwoOwq+9UyJRBJmkYFIFJvheo/wDrCt 7OUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iglMCXYy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+dJEwX6Y; 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 Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id 29-20020a63185d000000b00563de199314si11410247pgy.896.2023.12.06.02.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:23:54 -0800 (PST) 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=iglMCXYy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+dJEwX6Y; 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 A49C382EC547; Wed, 6 Dec 2023 02:23:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377278AbjLFKXf (ORCPT + 99 others); Wed, 6 Dec 2023 05:23:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377339AbjLFKXc (ORCPT ); Wed, 6 Dec 2023 05:23:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC28012F for ; Wed, 6 Dec 2023 02:23:38 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701858217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GsNdpIFc09s1gqwIZ71ov1AFzBRmEFB6zZkx3fRFd5g=; b=iglMCXYyWWOMX7ot3k5OXm8pLuBqWxuDAP2bHQUssr5GOCjJq8hVEADDYLcqHtp4Ep5wfm xe1r8/kqj0JZLEttatjOUyZzkMPt+MMZ/qgy18cSVxvFaycfumYY/nNn0+BqKQSBqr0fz1 +e7IXR5KdNmVMYFSjvI4Q4k0bAVkzjUwOdoDriacIToGLT7pu5cHrg+I0zFpG6KvxHCdSM 9Jd2aOsz1U4YmnlJSzIy6oQZ6KNsWAYmg0rT0Il4k5WpP0yElDKxnuWNNJQJMBK5YFAKG1 yeTKPTcFxyanC0FgHsQZI4SuLhj7lfnTsXf98YM+bsaTrFkGezWeSJ+mt+rSXg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701858217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GsNdpIFc09s1gqwIZ71ov1AFzBRmEFB6zZkx3fRFd5g=; b=+dJEwX6YqeEwRrSRllj+nGgCh/Z4usBpBzPJUCNUqgV9ao2PWcoaKgLJuW9K661xfUH2qu JIR1wSI6bAPhsDCA== To: Sebastian Siewior Cc: linux-kernel@vger.kernel.org, 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 , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak , Richard Cochran Subject: Re: [PATCH v9 22/32] timers: Keep the pinned timers separate from the others In-Reply-To: <20231205211106.ykKsi921@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> <20231201092654.34614-23-anna-maria@linutronix.de> <20231205211106.ykKsi921@linutronix.de> Date: Wed, 06 Dec 2023 11:23:36 +0100 Message-ID: <87fs0feijb.fsf@somnus> MIME-Version: 1.0 Content-Type: text/plain 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:23:51 -0800 (PST) Sebastian Siewior writes: > On 2023-12-01 10:26:44 [+0100], Anna-Maria Behnsen wrote: >> --- a/kernel/time/timer.c >> +++ b/kernel/time/timer.c >> @@ -1985,10 +1998,31 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem, >> return expires; >> } >> >> - raw_spin_lock(&base->lock); >> - nextevt = next_timer_interrupt(base, basej); >> + base_local = this_cpu_ptr(&timer_bases[BASE_LOCAL]); >> + base_global = this_cpu_ptr(&timer_bases[BASE_GLOBAL]); >> + >> + raw_spin_lock(&base_local->lock); >> + raw_spin_lock_nested(&base_global->lock, SINGLE_DEPTH_NESTING); >> + >> + nextevt_local = next_timer_interrupt(base_local, basej); >> + nextevt_global = next_timer_interrupt(base_global, basej); >> >> - if (base->timers_pending) { >> + /* >> + * Check whether the local event is expiring before or at the same >> + * time as the global event. >> + * >> + * Note, that nextevt_global and nextevt_local might be based on >> + * different base->clk values. So it's not guaranteed that >> + * comparing with empty bases results in a correct local_first. > > This ends like an unsolved mystery case. Could you add why one should > not worry about an incorrect local_first? > > But seriously, how far apart can they get and what difference does it > make? At timer enqueue time clk equals jiffies. At this point one clk > base could be at jiffies and the other might be a few jiffies before > that. > The next event (as in next_expiry) should be valid for both compare > wise. Both must be larger than jiffies. The delta between jiffies and > next event has to be less than NEXT_TIMER_MAX_DELTA for each base. > >> + */ >> + if (base_local->timers_pending && base_global->timers_pending) >> + local_first = time_before_eq(nextevt_local, nextevt_global); >> + else >> + local_first = base_local->timers_pending; >> + >> + nextevt = local_first ? nextevt_local : nextevt_global; >> + >> + if (base_local->timers_pending || base_global->timers_pending) { >> /* If we missed a tick already, force 0 delta */ >> if (time_before(nextevt, basej)) >> nextevt = basej; > > So if nextevt_local missed a tick and nextevt_global is > NEXT_TIMER_MAX_DELTA-1 (so we get the largest difference possible > between those two) then the time_before_eq() should still come out > right. We could still miss more than one tick. > This problem was only there when comparing _empty_ bases (!timer_base::timers_pending) because of the different base clocks and the stale next_expiry. But I didn't update the check and the comment after introducing the forward of the next_expiry when !timer_base::timers_pending in next_timer_interrupt(). So now it is sufficient to replace the local_first detection by simply doing: local_first = time_before_eq(nextevt_local, nextevt_global); Will fix it and will also add a comment to next_timer_interrupt() where the next_expiry is updated when !timer_base::timers_pending. Thanks, Anna-Maria