Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp413543ybi; Fri, 21 Jun 2019 01:44:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzc4DC8LhW9wCnzQ32psWAFbJduRamqhDhhkcyAIFe4lqOthJ6fK0MTTGQEBSo4qpGQ1brm X-Received: by 2002:a17:90a:cd04:: with SMTP id d4mr5253060pju.128.1561106687024; Fri, 21 Jun 2019 01:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561106687; cv=none; d=google.com; s=arc-20160816; b=m4Uq67xEW9PrqERaRI3rgOAnZce0aZdmgvm9wkPOTy19zD40lPkCFhy9hmWx6+Iqoq NYQ+KbmV+WZV2PKnmVQCGh7C/Id/CVxX1ecfrHxGuZnLOAzWSJLic1ZOPOEw93MoVzfO dkVzaAjYCc2GQspOKKYZDm4YGImPSvz5hFvaIz7OD3rguOc0fd7qPlH2OU9hBPQWWVFr zN7VDde1yixNDsWwcs7ZU55wH07FFJ0jwM1ZZ+iJgXV0S7aDTgNLMX92jlwL1Cp6EIcO YYsz3z2levSVSXOPkv6w4ZVCTVeHLQNes8wTzLxn5A1h+JosWUAWbsZ63AUp03dlXBcy zrGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+SUebq9woY4jCotzhnYHBg3e1lnTjcQvH9kzDLCi1rE=; b=Quu6EJgWzPlqq8ixSMcB7Iq57QsL5zhrPYn8naII78lF+dYHt6H5TuslKoNhsicscQ nicEJI6KU3FApztX21M0qXH/ofmV2PeaC7Z/k5v9SSzrq+yX+J2qF7s7AjsEYHKoFE3K +ECaQwoxyIw3Qte5HBOPFXQ1OQRnK26fE01RCEh3UZMYSg5Y7cxiCIR1L9KnSi3xnbJU m1BW4n6RFNwYOm2qIjFPEi4coZM/POGfwp60Ou1/CtdIwHbI9ky3cFLQKArb9CuAPuVU hBzzTkXlXcIxVdr31V+Nmq/bYQlNOeybO70Q7Os7kP6MAZUYruo13BL+3qQFGnQ24MQo SjCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cd3si2290379plb.228.2019.06.21.01.44.31; Fri, 21 Jun 2019 01:44:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726669AbfFUIm5 (ORCPT + 99 others); Fri, 21 Jun 2019 04:42:57 -0400 Received: from foss.arm.com ([217.140.110.172]:50986 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbfFUIm4 (ORCPT ); Fri, 21 Jun 2019 04:42:56 -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 92C171516; Fri, 21 Jun 2019 01:42:55 -0700 (PDT) Received: from e110439-lin.cambridge.arm.com (e110439-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3FEFB3F246; Fri, 21 Jun 2019 01:42:53 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan , Alessio Balsini Subject: [PATCH v10 08/16] sched/core: uclamp: Set default clamps for RT tasks Date: Fri, 21 Jun 2019 09:42:09 +0100 Message-Id: <20190621084217.8167-9-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190621084217.8167-1-patrick.bellasi@arm.com> References: <20190621084217.8167-1-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By default FAIR tasks start without clamps, i.e. neither boosted nor capped, and they run at the best frequency matching their utilization demand. This default behavior does not fit RT tasks which instead are expected to run at the maximum available frequency, if not otherwise required by explicitly capping them. Enforce the correct behavior for RT tasks by setting util_min to max whenever: 1. the task is switched to the RT class and it does not already have a user-defined clamp value assigned. 2. an RT task is forked from a parent with RESET_ON_FORK set. NOTE: utilization clamp values are cross scheduling class attributes and thus they are never changed/reset once a value has been explicitly defined from user-space. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra --- kernel/sched/core.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2c49b23efc87..ab75e874fdcc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1051,6 +1051,27 @@ static int uclamp_validate(struct task_struct *p, static void __setscheduler_uclamp(struct task_struct *p, const struct sched_attr *attr) { + unsigned int clamp_id; + + /* + * On scheduling class change, reset to default clamps for tasks + * without a task-specific value. + */ + for_each_clamp_id(clamp_id) { + struct uclamp_se *uc_se = &p->uclamp_req[clamp_id]; + unsigned int clamp_value = uclamp_none(clamp_id); + + /* Keep using defined clamps across class changes */ + if (uc_se->user_defined) + continue; + + /* By default, RT tasks always get 100% boost */ + if (unlikely(rt_task(p) && clamp_id == UCLAMP_MIN)) + clamp_value = uclamp_none(UCLAMP_MAX); + + uclamp_se_set(uc_se, clamp_value, false); + } + if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP))) return; @@ -1076,8 +1097,13 @@ static void uclamp_fork(struct task_struct *p) return; for_each_clamp_id(clamp_id) { - uclamp_se_set(&p->uclamp_req[clamp_id], - uclamp_none(clamp_id), false); + unsigned int clamp_value = uclamp_none(clamp_id); + + /* By default, RT tasks always get 100% boost */ + if (unlikely(rt_task(p) && clamp_id == UCLAMP_MIN)) + clamp_value = uclamp_none(UCLAMP_MAX); + + uclamp_se_set(&p->uclamp_req[clamp_id], clamp_value, false); } } -- 2.21.0