Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1988738rwr; Fri, 28 Apr 2023 04:51:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mxu8zgtde5YuYxE4aUtPTLzy/lSMXdgtSJKgxoRNB5O40udkkl9KuNL38b/1PneCMnL64 X-Received: by 2002:a17:902:ce09:b0:1a0:76e8:a4d with SMTP id k9-20020a170902ce0900b001a076e80a4dmr8929495plg.14.1682682698697; Fri, 28 Apr 2023 04:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682682698; cv=none; d=google.com; s=arc-20160816; b=pORm+4DE9CXwr6Km5k2Xghm45CPI7yE3dWX0VJc3FSG6DHoWuAFjpJjo/OHVot6pXO TZSqZa/EGRJGuhNgaAZoNHzRxT7b15ZPlcSlDJ5bIW7I6r5Kh+ssT8ecl6Od9MrFdcdy 40s7ULAzyU0pvvZfLnGNJIcinirY4R5L029l2bUzWJDkCXEuD9oFrnjMcO19XQ7zPvOl z/FHMRpbJq45VIOEosSketxJwbjGDaTgRCcFzjtaU6qZOnHHJ2UxOwuhzgfjMdwLEBuv 1N0TcKpvC+9PJz1mXz285SabrNU2U3ownSKYCdvhwSojmNQ2c26mmwAG5dLAILkQOncS q2kQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=P6/aX0pjGA8oLPAxpT7Bqo52a3vTQjbKWU5jNN+quzY=; b=mzwqu7qFJap8YBcGz8TDC2YLWXRVGZDLaQf797jw6KH6wOJNMOSbukb2GmudPY/igo 2TFbr9/N7rS0YnA15eSenux90pb36q0uFgdg5kEQD9e80vEuexrKJlRLjRuj+i7MEEUs Dh5BTYhtPnvwRWo/c1HKJDukPDupnoWZ4z3rijDTwiDuAc41hguG6dC84RsoqaIQW4Uj b+hloiHxpicpJMKchgUkwRrPfUblz/oHg2RMYsORY0ZB17iSBO7rnjujJ1ZENXFvrM6v fvKgjSJAivTj43gQvWF7UROhXXIKrNRJTRrZpIIIjtbhxE7zovRMJElaeenG61w8Wmgd 8Yhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@layalina-io.20221208.gappssmtp.com header.s=20221208 header.b="W6ekVWa/"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a630004000000b0050beec91e30si21179038pga.768.2023.04.28.04.51.19; Fri, 28 Apr 2023 04:51:38 -0700 (PDT) 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=@layalina-io.20221208.gappssmtp.com header.s=20221208 header.b="W6ekVWa/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232045AbjD1LpC (ORCPT + 99 others); Fri, 28 Apr 2023 07:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345945AbjD1Lo6 (ORCPT ); Fri, 28 Apr 2023 07:44:58 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A315BB9 for ; Fri, 28 Apr 2023 04:44:48 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-2f58125b957so8913077f8f.3 for ; Fri, 28 Apr 2023 04:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=layalina-io.20221208.gappssmtp.com; s=20221208; t=1682682287; x=1685274287; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=P6/aX0pjGA8oLPAxpT7Bqo52a3vTQjbKWU5jNN+quzY=; b=W6ekVWa/voyYFiTISBGqQaPat0XKYjXTPt7fq//3DlKxX7yzojKMe8fo2PEQR2pTmu JWSx14Yc0QwPOll3HgWyrh3IGdhdfg2vSJg4dUW2VAZIJeD11vQs+mCX5kLvUOsEJZGL ZFdmfSNyMobPiBnHfM9HOTXEoNUSo+wbqB+2+QCx1zXLh+80D5fyYKrHgYbPf/1+57yL wuSojJ98wVyNGLZPbfuCrXv9CqPxiP2jLC0bzlRTvSZEn5ODnWADsgk1sYq44AG175tq n2tWFXWxp3/qfY/s4qP/YuaN57H2fZfvvTZHhsfZRqhd8QARrTOpfsW5x6K150uebBEo P5ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682682287; x=1685274287; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P6/aX0pjGA8oLPAxpT7Bqo52a3vTQjbKWU5jNN+quzY=; b=RVneAWd35rWjNnPkCDpvvuazqveFh45w7JcqrJFDgcLhLEqnR/8ozKqMmmtW8j9Fz9 tdfD4kKkfdnRKe4AG2vaB5grMietb92nbUtNMy3dsyLJFd8d+GrlzCZB0/M1Zt6JOUOz FK4sCPUSA+ie8HtZVlBZZ3iI4wgkstm8LJNuQ4jRs53HH3J41KfRRtSFaywvcyMg6Mn6 s8G00cGEDENXr2TVSybGiubNAQYiRKto0MMZGNFpYNDxWXDGO2KiimxImULehWpDcHMf oE+gNdPmRGxVWfnuhUMIC1gA8vPmornJUOZimFYHYOwVeoaprGttLwz1TTCHWsBoV+yN Qo5g== X-Gm-Message-State: AC+VfDyEvofaPAN1e28smouiGEQA7+D6vG1bKrfPJEaENNor1a2jEjOU jyNH52GaxUwwJZwCrwp7yrmU/w== X-Received: by 2002:a5d:4444:0:b0:2ef:b3e6:8293 with SMTP id x4-20020a5d4444000000b002efb3e68293mr3574166wrr.9.1682682287202; Fri, 28 Apr 2023 04:44:47 -0700 (PDT) Received: from airbuntu ([104.132.45.110]) by smtp.gmail.com with ESMTPSA id p10-20020a5d48ca000000b003047dc162f7sm11622477wrs.67.2023.04.28.04.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 04:44:46 -0700 (PDT) Date: Fri, 28 Apr 2023 12:44:42 +0100 From: Qais Yousef To: Vincent Guittot Cc: Saravana Kannan , Dietmar Eggemann , David Dai , Ingo Molnar , Peter Zijlstra , Juri Lelli , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Qais Yousef , Quentin Perret , kernel-team@android.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v1] sched/uclamp: Introduce SCHED_FLAG_RESET_UCLAMP_ON_FORK flag Message-ID: <20230428114442.t2blsllmgntooayy@airbuntu> References: <20230416213406.2966521-1-davidai@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Hi Vincent Sorry for the late response. On 04/21/23 17:10, Vincent Guittot wrote: > On Thu, 20 Apr 2023 at 18:26, Saravana Kannan wrote: > > > > On Thu, Apr 20, 2023 at 6:44 AM Vincent Guittot > > wrote: > > > > > > On Thu, 20 Apr 2023 at 11:37, Dietmar Eggemann wrote: > > > > > > > > On 20/04/2023 03:11, David Dai wrote: > > > > > On Tue, Apr 18, 2023 at 10:18 PM Dietmar Eggemann > > > > > wrote: > > > > >> > > > > > > > > > > Hi Dietmar, thanks for your time, > > > > > > > > > >> On 16/04/2023 23:34, David Dai wrote: > > > > >>> A userspace service may manage uclamp dynamically for individual tasks and > > > > >>> a child task will unintentionally inherit a pesudo-random uclamp setting. > > > > >>> This could result in the child task being stuck with a static uclamp value > > > > >> > > > > >> Could you explain this with a little bit more detail? Why isn't the > > > > >> child task also managed by the userspace service? > > > > > > > > > > See Qais’ reply that contains more detail on how it’s being used in > > > > > Android. In general, if a dynamic userspace service will adjust uclamp > > > > > on the fly for a given task, but has no knowledge or control over if > > > > > or when a task forks. Depending on the timing of the fork, a child > > > > > task may inherit a very large or a small uclamp_min or uclamp_max > > > > > value. The intent of this patch is to provide more flexibility to the > > > > > uclamp APIs such that child tasks do not get stuck with a poor uclamp > > > > > value when spawned while retaining other sched attributes. When > > > > > RESET_ON_FORK is set on the parent task, it will reset uclamp values > > > > > for the child but also reset other sched attributes as well. > > > > > > > > OK, in this case, why not just change behavior and always reset the > > > > uclamp values at fork? > > > > > > > > Do we anticipate a use-case in which uclamp inheritance would be required? > > > > > > > > Let's not over-complicate the sched_[sg]etattr() unnecessarily. > > > > > > I was about to ask the same question and I'm aligned with Dietmar. > > > Use RESET_ON_FORK and set all attributes > > > > That's racy though. If we have an external service (that's only > > responsible for setting uclamp) setting all the attributes, the forked > > thread could also be trying to set some of the attributes. Also, how > > is this external service going to keep track of all the threads being > > forked and set the right attributes for all of them? > > My assumption was that you didn't use RESET_ON_FORK because there were > other attributes that you wanted to keep from parent but it doesn't Correct. > seem to be the case so use RESET_ON_FORK and if needed the forked > thread will set its other attributes Hmm, it seems you think it's the parent who's trying to control the fork for the child. But the situation we're in is different. ADPF is a shared library/middleware/system service that provides higher level API to manage the performance requirements for a group of tasks. They provide a set of PIDs and a deadline, then continuously tell it how long they took to finish their work. ADPF uses this info to manipulate uclamp_min dynamically on their behalf so they finish their work in time. Explaining it very simply and briefly here. It should make using uclamp_max easier too (though we are not there yet) since the most efficient point is platform specific and the middleware can help abstract this better in a portable way. The problem is these tasks can be RT and/or can have their priorities/nice values set by something else. But what we want is to make sure that we control uclamp values only for the PIDs we were asked to manage, and anything forked must have their uclamp values reset, but not the rest as this is outside of this service available context. It gets delegated to handle performance hints only and make using uclamp easier and generic. But this should not interfere with policy and priority management done outside of its scope. Apps that manage their own uclamp values wouldn't need this. But if we are to build a smart middleware that provides a consistent and easier to use higher level APIs, which is what we have here, we need this selective reset on fork. Does this explain the problem better? Note we noticed because we saw problems here. So we are not trying to be theoretically cautious. Thanks! -- Qais Yousef