Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp988823ybh; Mon, 13 Jul 2020 06:39:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXMmkadu4i2u3W1cclHxPsA/YChEV5nkaV8DcHJv0hpHNCWaRqjD6F1koUPuOChOYmJ9jk X-Received: by 2002:a17:906:364a:: with SMTP id r10mr72452791ejb.122.1594647552384; Mon, 13 Jul 2020 06:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594647552; cv=none; d=google.com; s=arc-20160816; b=RbDFqscECUNBi3+0rPkAhjnml0PQfvPjHpqEYl4MtMGy+VzOadcidGLrLWkCOfmn31 a1fjVOtzPEtFgaU/lHLRx1lZ58mWKkvkNqlGYKd/3XmFLIIObVNtK/g2MbZiye551gJ3 Gw4JV5G7b5rpChTe6cnyA2LjQL+TcgI/Znor6IIu+ItCZrdQ+Kf5DwoinHG4mG/ajzYv DH+l7yQsshP7QHypE8F+cLJUtTGkx5vQFmGl8/dZ1n2n1G6Hb55OkvPrwgmUMEDa4fDi V7oLPXpTESSzJ8yDQbsw5KAYoy730zWqxykIKgwcqHsVeFDgufrVPv9i5vwcXAJMq8No V0RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9EMK+UYrL6jQjzlvQppNu91JO3Sh4jNLd4V1M4+eiGU=; b=k5CcSZjvLeECP8XY7dN5+jubeWBPeSpN7/WuCmx861eoK6lYcjetbDg2czXfkSUQfm pJm0t1gRQ7ZAwy2Vj5TTdeMBuRE1RzOQsEuAFbxF0ioHq+DKX9uDybxn1IKMo+YH8XRW SzLeq3jMcY/eJ3FX7j8CxgqY54JGH9go/kbuKqK6Ex2OazBavLEgSQwsjOFBWu3GppQF 8hgrIXtGKGFOKtyxomYY1TLaBS6DBfBIYSo6k1RL+bkLccqGaXRRozGRJxg9fHDggB1A b18JhrJbDidNc+e9cEgr3+dul28DV/u9x4LVql1/HtV+E0cNqo8bf20WdYkE5bmf2lfw zXLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=dTUuatlg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s3si9533259edy.157.2020.07.13.06.38.48; Mon, 13 Jul 2020 06:39:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=dTUuatlg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729846AbgGMNgV (ORCPT + 99 others); Mon, 13 Jul 2020 09:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729747AbgGMNgU (ORCPT ); Mon, 13 Jul 2020 09:36:20 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE84C061755; Mon, 13 Jul 2020 06:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9EMK+UYrL6jQjzlvQppNu91JO3Sh4jNLd4V1M4+eiGU=; b=dTUuatlg0KVwBCRqwtaZ2s9TzC 1S/HjNyZfYj0F/RACCE/EfF8yeNRRyX3JpVsCeOkBljoXS5FXUnkL/FIjBK9E3s4X1QURF42QlC7p NGr+4XNrY5lYFQCUci4QxnnwIhzXqvMwNIVSXsERBSscAex+gjl2AKhs/ioLo6wxTZZW/kpW8Fgg5 I6k9W19UFGSMyqxEGoaiRs2H4D/UEDYi79TrTIegUYGyJegtVlwPlSw4Np5fDb1jDyS++RYAiR1rm YGuXazd/Yx3LRTgX950c4nQkTEpXCb+BII+dwqc3+LOG1OMcOs5oIhIq1zBKP+yY+ZwMu2f7iuE/V c8ufUVgQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1juych-0002Nc-Oz; Mon, 13 Jul 2020 13:36:00 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8AD2D300F7A; Mon, 13 Jul 2020 15:35:58 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 70EF820D27C6B; Mon, 13 Jul 2020 15:35:58 +0200 (CEST) Date: Mon, 13 Jul 2020 15:35:58 +0200 From: Peter Zijlstra To: Qais Yousef Cc: Ingo Molnar , Doug Anderson , Jonathan Corbet , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Luis Chamberlain , Kees Cook , Iurii Zaikin , Quentin Perret , Valentin Schneider , Patrick Bellasi , Pavan Kondeti , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v6 1/2] sched/uclamp: Add a new sysctl to control RT default boost value Message-ID: <20200713133558.GK10769@hirez.programming.kicks-ass.net> References: <20200706142839.26629-1-qais.yousef@arm.com> <20200706142839.26629-2-qais.yousef@arm.com> <20200713112125.GG10769@hirez.programming.kicks-ass.net> <20200713121246.xjif3g4zpja25o5r@e107158-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200713121246.xjif3g4zpja25o5r@e107158-lin.cambridge.arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 13, 2020 at 01:12:46PM +0100, Qais Yousef wrote: > On 07/13/20 13:21, Peter Zijlstra wrote: > > It's monday, and I cannot get my brain working.. I cannot decipher the > > comments you have with the smp_[rw]mb(), what actual ordering do they > > enforce? > > It was a bit of a paranoia to ensure that readers on other cpus see the new > value after this point. IIUC that's not something any barrier can provide. Barriers can only order between (at least) two memory operations: X = 1; y = Y; smp_wmb(); smp_rmb(); Y = 1; x = X; guarantees that if y == 1, then x must also be 1. Because the left hand side orders the store of Y after the store of X, while the right hand side order the load of X after the load of Y. Therefore, if the first load observes the last store, the second load must observe the first store. Without a second variable, barriers can't guarantee _anything_. Which is why any barrier comment should refer to at least two variables. > > Also, your synchronize_rcu() relies on write_lock() beeing > > non-preemptible, which isn't true on PREEMPT_RT. > > > > The below seems simpler... > Hmm maybe I am missing something obvious, but beside the race with fork; I was > worried about another race and that's what the synchronize_rcu() is trying to > handle. > > It's the classic preemption in the middle of RMW operation race. > > copy_process() sysctl_uclamp > > sched_post_fork() > __uclamp_sync_rt() > // read sysctl > // PREEMPT > for_each_process_thread() > // RESUME > // write syctl to p > > 2. sysctl_uclamp happens *during* sched_post_fork() > > There's the risk of the classic preemption in the middle of RMW where another > CPU could have changed the shared variable after the current CPU has already > read it, but before writing it back. Aah.. I see. > I protect this with rcu_read_lock() which as far as I know synchronize_rcu() > will ensure if we do the update during this section; we'll wait for it to > finish. New forkees entering the rcu_read_lock() section will be okay because > they should see the new value. > > spinlocks() and mutexes seemed inferior to this approach. Well, didn't we just write in another patch that p->uclamp_* was protected by both rq->lock and p->pi_lock?