Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1435271rdh; Fri, 27 Oct 2023 14:24:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/T3IKFyzFoGSBdLaCcnep0WbL9NQtPXg0veBvBCsy+hfi1zoO6SiNqpplJYp7Hop4Pzr6 X-Received: by 2002:a05:6a20:9146:b0:163:a041:336c with SMTP id x6-20020a056a20914600b00163a041336cmr3934730pzc.48.1698441849788; Fri, 27 Oct 2023 14:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698441849; cv=none; d=google.com; s=arc-20160816; b=ZC93rGWgFzCDRbf6RUo6J8w0XaFKKJJgdoqet0923vUV2QPE5AkWWcMbJIFRBVZwH2 OfqeV8YWTlsY1k5Xora0GA/hq9e0xopM41GLn20JJdiif2rvVTNW/eY4hH7Hb6v3mC+K DwT/VPHxP07ix7aRxic5Vr+yblZITjS4PAHxpi1ilRtaK/AzifU35e5IjA4TUa2kAIu6 RyaSEH23ohkIA88CdzWDd7i3tCRogoA8K8B9eudYw2rIQ+v6RRvGgFwnG1KfLjB1Tj2t Al/oPbTahvGcAZDwSu8ymC3PmYeY+LJhVwh1gt7G+n0EYSz1/SG/h0oG6tcsaFqr2Ei2 ZheA== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ISAcKwTlCjWt50Wtp1FMo2iKxFSn4VTjAXi6VpEQfww=; fh=otInkNaWWxGa9jTskILH8UfKagcq7+MvPSlbUHMhSNU=; b=VIX21ZyzIGzvHvqkpWKwXqRuTKQFg2WRi2d6zfmjYrIv5mocUB+G12i9TUz0qpWEwh P+vjuNeeV6GvdO84yLIV0KH+6nYKsTCEe+gND195nGY38l0IdpyNRs7v5LxnF+adFC3t b059HdJAJF5OVOAZSdpYfSIsK6ZYF02eUMEsPOh+T4HqmKjY/J4L7AUMSsF/4Yy0t00u 5EwvfYK8IoJuY7EUmZKY7WgZk8DglfNh9HvFYDBV34anfhhtSxnoyYGz0Ie81p3Nu+Ie 5vgN+4c5IpmljAJOdMotf09997HiVD2Vg5Pt94iNxunEzsdk2rB/u9PqEONPN7hmDLyc Vl4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=INtumRR2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x4-20020aa79a44000000b0068fba6a7375si1489554pfj.321.2023.10.27.14.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 14:24:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=INtumRR2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 60FEB82976BB; Fri, 27 Oct 2023 14:24:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235075AbjJ0VYA (ORCPT + 99 others); Fri, 27 Oct 2023 17:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232830AbjJ0VX7 (ORCPT ); Fri, 27 Oct 2023 17:23:59 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F7C21B9; Fri, 27 Oct 2023 14:23:57 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0391C433C7; Fri, 27 Oct 2023 21:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698441836; bh=cxrXMW55znlA8hWbjAzUa2LtKvbRRjs8G08OyY3NX8s=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=INtumRR2+PR0Kk5NjK85B8O64CB+AnxneOeE8PCZjvBo1cUQwPowe9Y5mCaC4ThV8 zYCUEGAeH1jD7Yk8uzdjfeifdLsX+EnmlCgW75IxNa9PFaxa2c2sFFw736EGE8mxBA 6Xb7W2uhCU/gAPC8YOgdWGUb6Ktk2xdvqme6V/6M/4hg2rcu1XBf92wf4dJwMDKAGC ISNhYVXOx4M3ex0xIKBO+mHdkTGz1RVyqFCjsqY5oUUazVStNGu25V/MG5oHl0SpWK Vxccc17Z8msJKNfRsNvbFryPehKaTwox+L4+FspkuVSNrEIYdB39s5rokrrTDVO185 Y7OygeUPPlaAQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 71BE8CE0F11; Fri, 27 Oct 2023 14:23:56 -0700 (PDT) Date: Fri, 27 Oct 2023 14:23:56 -0700 From: "Paul E. McKenney" To: Peter Zijlstra Cc: Frederic Weisbecker , LKML , Boqun Feng , Joel Fernandes , Josh Triplett , Mathieu Desnoyers , Neeraj Upadhyay , Steven Rostedt , Uladzislau Rezki , rcu , Zqiang , "Liam R . Howlett" Subject: Re: [PATCH 2/4] rcu/tasks: Handle new PF_IDLE semantics Message-ID: <2a0d52a5-5c28-498a-8df7-789f020e36ed@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20231027144050.110601-1-frederic@kernel.org> <20231027144050.110601-3-frederic@kernel.org> <20231027192026.GG26550@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231027192026.GG26550@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 27 Oct 2023 14:24:07 -0700 (PDT) On Fri, Oct 27, 2023 at 09:20:26PM +0200, Peter Zijlstra wrote: > On Fri, Oct 27, 2023 at 04:40:48PM +0200, Frederic Weisbecker wrote: > > > + /* Has the task been seen voluntarily sleeping? */ > > + if (!READ_ONCE(t->on_rq)) > > + return false; > > > - if (t != current && READ_ONCE(t->on_rq) && !is_idle_task(t)) { > > AFAICT this ->on_rq usage is outside of scheduler locks and that > READ_ONCE isn't going to help much. > > Obviously a pre-existing issue, and I suppose all it cares about is > seeing a 0 or not, irrespective of the races, but urgh.. The trick is that RCU Tasks only needs to spot a task voluntarily blocked once at any point in the grace period. The beginning and end of the grace-period process have full barriers, so if this code sees t->on_rq equal to zero, we know that the task was voluntarily blocked at some point during the grace period, as required. In theory, we could acquire a scheduler lock, but in practice this would cause CPU-latency problems at a certain set of large datacenters, and for once, not the datacenters operated by my employer. In theory, we could make separate lists of tasks that we need to wait on, thus avoiding the need to scan the full task list, but in practice this would require a synchronized linked-list operation on every voluntary context switch, both in and out. In theory, the task list could sharded, so that it could be scanned incrementally, but in practice, this is a bit non-trivial. Though this particular use case doesn't care about new tasks, so it could live with something simpler than would be required for certain types of signal delivery. In theory, we could place rcu_segcblist-like mid pointers into the task list, so that scans could restart from any mid pointer. Care is required because the mid pointers would likely need to be recycled as new tasks are added. Plus care is needed because it has been a good long time since I have looked at the code managing the tasks list, and I am probably woefully out of date on how it all works. So, is there a better way? Thanx, Paul