Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp568869rdb; Tue, 5 Dec 2023 13:11:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeFZTSA/gSif4WOIDtkKi1IfFtXBI6QxzkZWO3vAl3zmSoc1rZKA3tcahoyfSMd6baD8aN X-Received: by 2002:a17:902:ec90:b0:1d0:ad0e:bef4 with SMTP id x16-20020a170902ec9000b001d0ad0ebef4mr2779934plg.63.1701810685494; Tue, 05 Dec 2023 13:11:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701810685; cv=none; d=google.com; s=arc-20160816; b=HMqxq+9Sbhlhghte0rFQJX3Lxrj5eUuwdR1FpWo0YGzXgDIjRNcLWYkkP9YFBkGJLG tOQlu20w760IptNnZetmjHpZv0f7XSEub8K8REhzXh9YeCr6z6zFgDnP3SBmqVp3jg6s qYITFCio4bf5z0/BjMy92mdMvgaIV7ZUiFQqGhNSOpf9mR6/fTfkHt7wW10SEpZAvU0Z lTmWSf489gTMXjEDWpLJS44szxXIW4+lL0N7atZ5GGJmbQx3xwEVmQJraFDiLXXqXJsE BW0LIVYXt4+V5aVqaUAP6hFuVJFqXLwRwn+m0GynOkpoLiuK1QMrcK2wZ/vZBSTPaXix jzQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=lRnyi7RUD3uat7xocE2sCs3Fi4FAPkAA/cTsvLupByc=; fh=4LKILmejfgmojncqcPqQssQ1OafpGCkuCUM9riGOaE4=; b=D2u8FMZFb01aAElQJaJ7zOCaHaI/KBvDwODM+Z51XHRGQD9QMOD/tmdISjJA/EwIWA msBtJQ5VrngK1zkZf7T83XNhkD91zqu6+oplbbr3Ce5S5DuNilE9Y4JGpzRJ5HA4lQyV 9sAsIJQYhO4Wa5itBa9XseL+sInMs+k59jHQ9LyBaMyvfN514cv7STfowilno8tnV60n gy0tpcpta158IVpQA397v99k9uc7Xsi9UVwumRezusEO2hEXk2sIyjEFCgDa20waMuYV vojYIeC2ii8WCKKi3NGVrhY733kIERG6Mtaw/UP88nojIV023WYyGYAwTOXhYyuOyKFx Evzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lrueSzkx; dkim=neutral (no key) header.i=@linutronix.de header.b=3Wfu6fJf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b15-20020a170902650f00b001cfb4bd0e36si7939498plk.341.2023.12.05.13.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 13:11:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lrueSzkx; dkim=neutral (no key) header.i=@linutronix.de header.b=3Wfu6fJf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id D100E804755F; Tue, 5 Dec 2023 13:11:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346387AbjLEVLG (ORCPT + 99 others); Tue, 5 Dec 2023 16:11:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjLEVLF (ORCPT ); Tue, 5 Dec 2023 16:11:05 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56E2B18B for ; Tue, 5 Dec 2023 13:11:10 -0800 (PST) Date: Tue, 5 Dec 2023 22:11:06 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701810668; 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=lRnyi7RUD3uat7xocE2sCs3Fi4FAPkAA/cTsvLupByc=; b=lrueSzkx6AaDlJdqyVKMhPq5+JiUPsN37iQM14iYQZqKZSCKh/3IC0uEfhwkstVITpy2Nm zvlwLELgxdz7Fe9o4lYoulgmYQ2JTTGr25HAVJ+jH//FawuRjd3SIp+Uo2kthFu2W89Rba EYdQ9bIT93EdIG9mW99KE99bykosVSY7mDgsoMQwFhjccJ8ZHM1OF11vNmz2Saa94ywFJl oSatNy1yijPmbnNv33iz/xkSy+lw5wa/3OpqXcM5+5g1/2qqsmuimQaSlIHlCBtIDgSlQL aGBmXdgM9n7oC/0rkgh7WJbjNqoH/HWdC9npHR++PpsPLwsHKaaNkhz1S5Qylw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701810668; 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=lRnyi7RUD3uat7xocE2sCs3Fi4FAPkAA/cTsvLupByc=; b=3Wfu6fJf8M4C7yvH9N1d/YOEjMEVXDhiRM4HNXxza2/eeUzwJSc1etAIXybj5Sx2tK80YQ 6x38yeUWy6IdF1Dg== From: Sebastian Siewior To: Anna-Maria Behnsen 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 Message-ID: <20231205211106.ykKsi921@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> <20231201092654.34614-23-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231201092654.34614-23-anna-maria@linutronix.de> 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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 05 Dec 2023 13:11:23 -0800 (PST) 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 looks good. I just don't understand the (above) comment. Sebastian