Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp365593yba; Wed, 15 May 2019 02:47:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1FrJlvIFECqElOuOxoKm/NdzfQnkvswLBoSDoLyjl3sRQVJoaO8Y+8IUUJ7NJOrMTUrq3 X-Received: by 2002:a62:53:: with SMTP id 80mr18169169pfa.183.1557913660403; Wed, 15 May 2019 02:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557913660; cv=none; d=google.com; s=arc-20160816; b=hYmI6+E0K3wE3LSAlavgsVL907e8Mt0cuX9F+FziS23sLtLZjyZSgVnk3vWUPvNCJ5 2XKmUnt0A4mvGq0NandLVlZVB5MPF+Q++RffQK0Kg9DvakHnOjb7Jw1XPRMhnPPNen3J VPrDLT/ptjsKcmVSDrQza/GQrTJ9WBe1ahyBGi60Uy2tzDCEr1jhGVvPEKI6ECEEjup/ hDUAInHUc5HF2G4hVI6HJ8j3BU4Rch0JBaMYdiT6EXyq+EThzIMMCiGcUhz4x1JfLjot qo5yXCn491y/X2yoO3cGAE3z11L/LiC8MxGjLeKO0blR6P7KSklGuvxY85epxjOhqC2C +weQ== 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=JpbFmdLrayyg3fUNMKFYcrycOBOMD9kMXfGLkhmfIEc=; b=KdQcqLk43jLe2qonWL+OvJxpe1EKvBcwMBF5q8lRQl2qb+tszew4Otf4ASIJyz3P45 0xwfwKzO2iVK8Wlh/SUkR+1RQWlJFUXFjHqmhCil+hPfhUD7eqlTQFjdPjwdP64BUwmZ tiY3FwODjFCGAO2yNlzV4nR/kQyWW518MIzCOcl2YuxAKk93zlhfsk9IxepdKA799H9N U2HK7YFyB9TpReb1y6FZ3ZSX5mAgaZYdj4CVeXC949VGGA0QCK98BC1ONLs3rrOiurPG CjAJ6Oy5n7P7D1KCTyZ2gKy/y+aMhL8/a6z9+JpMm23ZU3VMbhSqtd4ihoOgkh9kO0ke rfxA== 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 m1si1388094pgg.380.2019.05.15.02.47.26; Wed, 15 May 2019 02:47:40 -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 S1726699AbfEOJqB (ORCPT + 99 others); Wed, 15 May 2019 05:46:01 -0400 Received: from foss.arm.com ([217.140.101.70]:39354 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726651AbfEOJp7 (ORCPT ); Wed, 15 May 2019 05:45:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 992E780D; Wed, 15 May 2019 02:45:58 -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 81E723F703; Wed, 15 May 2019 02:45:55 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@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 Subject: [PATCH v9 08/16] sched/core: uclamp: Set default clamps for RT tasks Date: Wed, 15 May 2019 10:44:51 +0100 Message-Id: <20190515094459.10317-9-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515094459.10317-1-patrick.bellasi@arm.com> References: <20190515094459.10317-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 03b1cd82bc48..f0e04298b1d7 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1050,6 +1050,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; @@ -1075,8 +1096,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