Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp266924ybt; Mon, 6 Jul 2020 08:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZn4ImZGVDuA+WswoxjuSH97UwK57JqW+cEnOS71HKBBxQv7URjkh3IBTsw3w4OF9emHvL X-Received: by 2002:a05:6402:b10:: with SMTP id bm16mr10083037edb.92.1594050660952; Mon, 06 Jul 2020 08:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594050660; cv=none; d=google.com; s=arc-20160816; b=kdi+A+4GPk+acV4Ngwc729W0075DL6Brtad07XvO4vLiFYmMlwS5e7hWwaBf/4tqVw RjV3f2KUX/QsohVitgDVlg9lvnGds6pIUTP9iF9+jVEhNRCeIeGjIoEx/D9ULHr8r0s+ aqE9US+P1n+1ylSnAebDFfVRJEZNGM7f9Ud564HNKnU8R+d0JfRQyvxZo163xmrS49cJ D8P6Y78FEaTPH9qyA32L2CnDFKcHHMgY0aGr5RGll1HuF2FK3ZZZFJbmxslp/Rv7e1wZ sbiSvA9+a7EjpFcpB0czm12BFBz7MYgRyo2jf2QqRCSTUXc3Qk7M+e83nfJKi0zzPTjj mCOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references; bh=LkPAVDaV5fhGcwmN2xiBHCKYuWDXqb/WhD07reyreUc=; b=EfR2gLZK3X2WEauM1FFGrmDe4H2J274Iuro8sM3D2k4ZKLvzbwxvAWmuExdjDsUiE4 QvC1PqNkaomBlqZBbzc/0YzWfdy3DhQt/S3XUjU+HB36wE7gxub2a4KMBH9Ppw37f5U/ D3CBfSiZI5po5YtnuiittFP0AHDybUcbdKgDbrwQ8WYFR8dPBe+Go0ODJoyxgYVbnXjm lvduHo8vdw9IeDbVBWbo4kepWAegh2CUkzPLWvoFD2cZWQ+X8pfUlTYe326xbnX0EwDC IYduURTJcIwOEfQ4HlUVGuMABLN8X2/umi68XiSd/2gUbVqK2GNS6bb7nps2x/dJbl7r il5g== ARC-Authentication-Results: i=1; mx.google.com; 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 v20si13368951ejx.754.2020.07.06.08.50.38; Mon, 06 Jul 2020 08:51:00 -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; 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 S1729560AbgGFPtb (ORCPT + 99 others); Mon, 6 Jul 2020 11:49:31 -0400 Received: from foss.arm.com ([217.140.110.172]:51122 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729476AbgGFPta (ORCPT ); Mon, 6 Jul 2020 11:49:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F09DCC0A; Mon, 6 Jul 2020 08:49:29 -0700 (PDT) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 872893F68F; Mon, 6 Jul 2020 08:49:27 -0700 (PDT) References: <20200706142839.26629-1-qais.yousef@arm.com> <20200706142839.26629-2-qais.yousef@arm.com> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Qais Yousef Cc: Ingo Molnar , Peter Zijlstra , Doug Anderson , Jonathan Corbet , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Luis Chamberlain , Kees Cook , Iurii Zaikin , Quentin Perret , 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 In-reply-to: <20200706142839.26629-2-qais.yousef@arm.com> Date: Mon, 06 Jul 2020 16:49:19 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/07/20 15:28, Qais Yousef wrote: > CC: linux-fsdevel@vger.kernel.org > --- > > Peter > > I didn't do the > > read_lock(&taslist_lock); > smp_mb__after_spinlock(); > read_unlock(&tasklist_lock); > > dance you suggested on IRC as it didn't seem necessary. But maybe I missed > something. > So the annoying bit with just uclamp_fork() is that it happens *before* the task is appended to the tasklist. This means without too much care we would have (if we'd do a sync at uclamp_fork()): CPU0 (sysctl write) CPU1 (concurrent forker) copy_process() uclamp_fork() p.uclamp_min = state state = foo for_each_process_thread(p, t) update_state(t); list_add(p) i.e. that newly forked process would entirely sidestep the update. Now, with Peter's suggested approach we can be in a much better situation. If we have this in the sysctl update: state = foo; read_lock(&taslist_lock); smp_mb__after_spinlock(); read_unlock(&tasklist_lock); for_each_process_thread(p, t) update_state(t); While having this in the fork: write_lock(&tasklist_lock); list_add(p); write_unlock(&tasklist_lock); sched_post_fork(p); // state re-read here; probably wants an mb first Then we can no longer miss an update. If the forked p doesn't see the new value, it *must* have been added to the tasklist before the updater loops over it, so the loop will catch it. If it sees the new value, we're done. AIUI, the above strategy doesn't require any use of RCU. The update_state() and sched_post_fork() can race, but as per the above they should both be writing the same value.