Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1506319rwb; Mon, 7 Nov 2022 02:23:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM4xKBLCMniMkDsFSQHxgEJNAwvwluDZkNc0Tru62qCoJJvyZVh8kariSy+T+pgeQxoebhyC X-Received: by 2002:a50:9ea6:0:b0:463:c701:64de with SMTP id a35-20020a509ea6000000b00463c70164demr32947082edf.63.1667816618930; Mon, 07 Nov 2022 02:23:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667816618; cv=none; d=google.com; s=arc-20160816; b=VorqHW/kHVZYlWRQtb2CGi0Fz3yiYDLLsX3PvfHRTqgNlaIxu433Gn6bAwYdgLERba JtUuyVJf874vUWccQxq/f9trnbeM5QD4Ijxxz+S/G6k0Cg6RWmzknzc5H1WvqXhZL1jr hwL+WHtDdb8lce2jx1YIXBPsi39NGYvQf24SpklNzDAdvTiNnu/d6quq74722JmPb6cm qFuPAuBHu4bkSodhTBFTLi2qK+5oE3UcWuMZS6BRUxaqBGq5ZFqs/FMyxdd083FPv7BC x25EBM+mMRinhA8GOodz1JZiTBITbgp7wQMH0Pcc+9BZxOdJYK0XF6gqiRvgc+3DKEno 8Mjw== 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:date:dkim-signature; bh=CTtrioYXTkVXTZD+qX3bUT5AyX6rR+zh/ptjvJ/opbQ=; b=dv/2xEzoXA1hKh7onkOnniwqXZ5MEc1u8JaMpgwyINmGFPWxBcUKjiTbl0RjtcsJgj fDdILUIamCBg99ovI1k6SXgqDZrGtNEjBpilm8FD/l6AMF/XnpMU5s4XMStRxtay81uX n7UpPDMCZs8UmlnSPyNIT0mbllo1o5dlTNQcLE6+ktVpbqosGzUTwMfmsB6ENEoih7e4 7ozBp0t4RmFqDRI1mzQzC1rE3iY0A7HI1LVmYrBBPufybYKTw5GOivKOIxsUlYsxFkwl xWfolXoxHfeYWkqzwaRsh7WXiPsOErut+LKSf2PUDRjFSxI8tZpL3YQjvjigFEaYXYN2 WDww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NLp5PaJs; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs13-20020a170906dc8d00b007a8a40e6146si8808070ejc.363.2022.11.07.02.23.16; Mon, 07 Nov 2022 02:23:38 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=NLp5PaJs; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbiKGKLf (ORCPT + 94 others); Mon, 7 Nov 2022 05:11:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbiKGKLZ (ORCPT ); Mon, 7 Nov 2022 05:11:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D76F518B37 for ; Mon, 7 Nov 2022 02:11:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72E7460FB8 for ; Mon, 7 Nov 2022 10:11:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4D87C433C1; Mon, 7 Nov 2022 10:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667815880; bh=sLdgJtsgT7FBdmNyKtUpUc7S0X3GgvJlwORdilW7IN4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NLp5PaJsInoYz8sdVEPlOZuaOsmV38yvMgSnU7J3OJMwN1LYQ8ExYge1cTiSbWBvZ 6pzooYSfvMP4pCqhTOBbYKGpAJmknSX8oRzmSoTznrBR1TPcIjOv/nKMOxxBwbijyE kGSXULSHcb6dFZgkLcAgnMgo7oDuyIvzOteLlEnYvC3NZsELIzUybk8Yd0SUAsBnhX Nd2r5B0OYSX1TBylDYChC8yz9rHIvdKNaT5JpcDLACj8EeSS4glPOnVzjMd1u0USq4 66ppg/MjOXsHlx7NQ/MpeJQ0vRDVeuhZIf3LVJghcLumwyIQNUazu5vOBTBaytvAAs ejNmiFVn+Xwcw== Date: Mon, 7 Nov 2022 11:11:15 +0100 From: Frederic Weisbecker 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 , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Theodore Ts'o , "Jason A. Donenfeld" , Stephen Boyd , Tejun Heo , Lai Jiangshan Subject: Re: [PATCH v4 05/16] add_timer_on(): Make sure callers have TIMER_PINNED flag Message-ID: <20221107101115.GA3279@lothringen> References: <20221104145737.71236-1-anna-maria@linutronix.de> <20221104145737.71236-6-anna-maria@linutronix.de> <20221104164342.GA1440400@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 On Mon, Nov 07, 2022 at 09:11:11AM +0100, Anna-Maria Behnsen wrote: > On Fri, 4 Nov 2022, Frederic Weisbecker wrote: > > > On Fri, Nov 04, 2022 at 03:57:26PM +0100, Anna-Maria Behnsen wrote: > > > The implementation of the hierachical timer pull model will change the > > > timer bases per CPU. Timers, that have to expire on a specific CPU, require > > > the TIMER_PINNED flag. Otherwise they will be queued on the dedicated CPU > > > but in global timer base and those timers could also expire on other > > > CPUs. Timers with TIMER_DEFERRABLE flag end up in a separate base anyway > > > and are executed on the local CPU only. > > > > > > Therefore add the missing TIMER_PINNED flag for those callers who use > > > add_timer_on() without the flag. No functional change. > > > > You're fixing the current callers but what about the future ones? > > > > add_timer_on() should always guarantee that a timer runs on the > > right destination, which is not the case after your patchset if the > > timer hasn't been set to TIMER_PINNED. > > > > Therefore I think we should either have: > > > > * add_timer_on() enforce TIMER_PINNED (doesn't work because if the timer is > > later called with mod_timer(), we should expect it to run anywhere) > > > > or > > > > * add_timer_on() warns if !TIMER_PINNED > > This is already part of the last patch of the queue where also the > crystalball logic is removed. But the patch where I added the WARN_ONCE() > might be the wrong patch, it should be better part of the next patch where > the new timer bases are introduced. Ok. > > > or > > > > * have an internal flag TIMER_LOCAL, that is turned on when > > add_timer_on() is called or add_timer()/mod_timer() is called > > on a TIMER_PINNED. Otherwise it is turned off. > > > > The last solution should work with existing API and you don't need to > > chase the current and future users of add_timer_on(). > > With the last approach it doesn't matter how the timer is setup. Everything > is done by timer code implicitly. When a future caller uses add_timer_on() > and wants to modfiy this "implicitly pinned timer", he will call > mod_timer() and the timer is no longer pinned (if it do not end up in the > same bucket it was before). For a user this does not seems to be very > obvious, or am I wrong? That's right indeed. > > But if the caller sets up the timer correctly we do not need this extra > timer flag. With the WARN_ONCE() in place, callers need to do the timer > setup properly and it is more clear to the caller what should be done. Yeah that sounds better. > BTW, the hunk in this patch for the workqueue is also not a final fix in my > opinion. I'm preparing a cleanup queue (it's part of the deferrable cleanup > queue), where I want to set the timer flags properly when > initializing/defining the workers. I should have added a comment here... Ok, if we have some pinned initializers such as DECLARE_DELAYED_WORK_PINNED() and DECLARE_DEFERRABKE_WORK_PINNED() then I think that cleans the situation. Sounds good, thanks! > > Thanks, > > Anna-Maria >