Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1365473ybt; Thu, 25 Jun 2020 04:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNwMbz8d5AZxGI/u5yX2UNtoLOPNE7lm/WLXypSixjBZgCz55tuyFaHkG1ZUZK0+XIS19o X-Received: by 2002:a17:907:435f:: with SMTP id oc23mr29890091ejb.426.1593084434498; Thu, 25 Jun 2020 04:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593084434; cv=none; d=google.com; s=arc-20160816; b=n90/Z3rxiFQv9ZSlQpJ3JBbDJbrOq0tznoBFOhFcABlxwGdXQH8GJr0vrN7ZoWO2Bu KFkYhsnzQCdHkPl86qGeUf/JWGW2JmMa4F4twDACwAIw+77BSJkXcd9AARbr4ixIH2JL 1+mjS0ZLJhhYKJQFI5Ow/e5R0YkHOHyPI4S8Ih5Wt/hCa2ZnFKwCmTtO6mtfvR3qstEa pjRMmtZd3wOKnCi2Rqee6mdp8dOEBPPMshZOYUC4YGvQFAe063iWzvAuzviEZfIX41VB V55YJg/zesEUFD3cgz8GybrD8TLPJrHj0aDKEzLEBNzLTpO//OzlLNoQ+ooNmqsLWFGJ h9Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:date:in-reply-to:message-id :subject:cc:to:from:user-agent:references; bh=uiUno+LBEImn1oEm+lH6+VlcBPLS57T76lM8k7gSftQ=; b=x6n2LGI87iSn0lC+YKkZJOOX2vfQkYzIZJeTHn/PGU1d2JLJC1wLnjqHy0QUPJqiec nt1MjK+ExBziqhHV9RCKWULB2dR//LcYSMxV4Uy38+dPi8c1kFPRB0p04SVodT25BY1j d6arEUiNnxAZKZjeekwi8+X0sceFbzPrjzEWRVv3pS71uWbk9L3JFbA7h7rad1yCiv1C jk5F2I6WIAUFbJYcKJ5eqh6kviq8nYKhK6g0SC1cHLVGJm5kzNeu4vXenx8VuhmB1J+g aJvMW4Wg3dUNsIejyBkii+9/TOTDJXYxTSIfa31n/bDX7V9snnVIyDp4lVInPNiw8zsf u77A== 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 ot25si9530686ejb.647.2020.06.25.04.26.50; Thu, 25 Jun 2020 04:27:14 -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 S2404214AbgFYL0L (ORCPT + 99 others); Thu, 25 Jun 2020 07:26:11 -0400 Received: from foss.arm.com ([217.140.110.172]:35202 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404042AbgFYL0L (ORCPT ); Thu, 25 Jun 2020 07:26:11 -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 A17521FB; Thu, 25 Jun 2020 04:26:10 -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 01D683F73C; Thu, 25 Jun 2020 04:26:08 -0700 (PDT) References: <20200624172605.26715-1-qais.yousef@arm.com> <20200624172605.26715-3-qais.yousef@arm.com> <20200625110006.q3iepcrh2uh4oizv@e107158-lin.cambridge.arm.com> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Qais Yousef Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Patrick Bellasi , Chris Redpath , Lukasz Luba , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] sched/uclamp: Protect uclamp fast path code with static key Message-ID: In-reply-to: <20200625110006.q3iepcrh2uh4oizv@e107158-lin.cambridge.arm.com> Date: Thu, 25 Jun 2020 12:26:04 +0100 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 25/06/20 12:00, Qais Yousef wrote: > Hi Valentin > > On 06/25/20 01:16, Valentin Schneider wrote: >> In schedutil_cpu_util(), when uclamp isn't compiled it, we have an explicit >> 'goto max'. When uclamp *is* compiled in, that's taken care of by the >> "natural" RT uclamp aggregation... Which doesn't happen until we flip the >> static key. >> >> It's yucky, but if you declare the key in the internal sched header, you >> could reuse it in the existing 'goto max' (or sysctl value, when we make >> that tweakable) path. > > Not sure if this is the best way forward. I need to think about it. > While I am not keen on enabling in kernel users of util clamp, but there was > already an attempt to do so. This approach will not allow us to implement > something in the future for that. Which maybe is what we want.. > Just to be clear, I'm not suggesting to add any in-kernel toggling of uclamp outside of the scheduler: by keeping that to the internal sched header & schedutil, we're keeping it contained to internal scheduler land. Since a diff is worth a thousand words, here's what I was thinking of (not even compiled): --- diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 7fbaee24c824..68731c3316ef 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -210,7 +210,7 @@ unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs, unsigned long dl_util, util, irq; struct rq *rq = cpu_rq(cpu); - if (!IS_BUILTIN(CONFIG_UCLAMP_TASK) && + if ((!IS_BUILTIN(CONFIG_UCLAMP_TASK) || !static_branch_likely(&sched_uclamp_used)) && type == FREQUENCY_UTIL && rt_rq_is_runnable(&rq->rt)) { return max; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 1d4e94c1e5fe..3fd5c792f247 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1638,6 +1638,7 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features = extern struct static_key_false sched_numa_balancing; extern struct static_key_false sched_schedstats; +extern struct static_key_false sched_uclamp_used; static inline u64 global_rt_period(void) { --- >> > + * As soon as userspace modifies any of the uclamp knobs, the static key is >> > + * enabled, since we have an actual users that make use of uclamp >> > + * functionality. >> > + * >> > + * The knobs that would enable this static key are: >> > + * >> > + * * A task modifying its uclamp value with sched_setattr(). >> >> That one makes it not just userspace, right? While the sched_setattr() >> stuff is expected to be unexported, it isn't ATM and we may expect some >> modules to ask for a uclamp API eventually. > > This has already come up with another thread [1]. I think in-kernel users > shouldn't go through this path. I will propose something to give stronger > guarantees in this regard. > True; and they'll have to go through another path anyway once the unexport thing happens. >> > - if (update_root_tg) >> > + if (update_root_tg) { >> > uclamp_update_root_tg(); >> > + static_branch_enable(&sched_uclamp_used); >> >> I don't think it matters ATM, but shouldn't we flip that *before* updating >> the TG's to avoid any future surprises? > > What sort of surprises are you thinking of? > Say if we end up adding static key checks in some other uclamp functions (which are called in the TG update) and don't change this here, someone will have to scratch their heads to figure out the key enablement needs to be moved one line higher. It's harmless future-proofing, I think. > Thanks