Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3739632imd; Mon, 29 Oct 2018 11:34:43 -0700 (PDT) X-Google-Smtp-Source: AJdET5eVd25oqKlGE8c4chNNiHyW19sd6vXF4qC9SGACj5nMSleTx2WKNtCSHYXNDVCQulbJjAQm X-Received: by 2002:a63:1a41:: with SMTP id a1-v6mr15198575pgm.9.1540838083420; Mon, 29 Oct 2018 11:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540838083; cv=none; d=google.com; s=arc-20160816; b=iJquOgIexZ2OXrkdTP7diQz/M31daqAbRLRRyyqE6TpNGiM2ERU46rxzVOqMJZr1yJ TWT9SOzC71pM1BDfbCVbWl6Pn6JZ1C9uYHoIz353dU+nUKeZjE9eW4rVpOU7Dg9R0d/k Oo7aAgkaN4PgvLhxMxKz3OhKyvArNLySESpjY91d13lYp1w646M5+LOshBq/amJkDDkv 6G/G4pLOJz1dhVjxy3dpcKLcNQsQCFNfBN7jcOWNo4x72FtOxrnrutB/x/FTa8Kw2QhO MCcxdyac45RBlT6d9A5/Hml00wI9dp5KPEqh5Jkerjdynk5skd83NEk5aR3OSegzPTIS 5mEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=woDtnwvwdcn4CM3vSC+fzqlGvY154oZ+3uMwJCld1Lk=; b=hn2M3w/cSdWrlR+7dK1IH4HSRgZ/3x3aefkqVC7qpQyt083TcAmq5uHUfYWBILmzgz bMH9TzP/lhza7YLv1n+suvz0MANeoepl2nLDVKJTeL6cdY6cpT7wj5hHKIRE1DARrVCO IV7C7X4dwrBV/47wU/FKgPv5jignXZHlPnXAAXilbfu1VE0mFRvp5wmgE3UeCWhyvntA VlWjH05m39UGYzZ/EHgi2v3mpbWfG8QeKRCH/UtH9o9zF/8D4RN7sG62BaE30H4FAzT/ dIgmcK8oxpxFA92BE3LW95KRdGqBvE7wrhXzQC7VnO1atGBc3YyvlRcZ1KF23SKiFbZ4 PO9A== 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 y18-v6si19681950plp.61.2018.10.29.11.34.27; Mon, 29 Oct 2018 11:34:43 -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 S1729448AbeJ3DX0 (ORCPT + 99 others); Mon, 29 Oct 2018 23:23:26 -0400 Received: from foss.arm.com ([217.140.101.70]:44530 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728221AbeJ3DX0 (ORCPT ); Mon, 29 Oct 2018 23:23:26 -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 7CCE7165C; Mon, 29 Oct 2018 11:33:35 -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 687A73F6A8; Mon, 29 Oct 2018 11:33:32 -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 , linux-api@vger.kernel.org Subject: [PATCH v5 02/15] sched/core: make sched_setattr able to tune the current policy Date: Mon, 29 Oct 2018 18:32:56 +0000 Message-Id: <20181029183311.29175-3-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181029183311.29175-1-patrick.bellasi@arm.com> References: <20181029183311.29175-1-patrick.bellasi@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, sched_setattr mandates that a policy is always specified. Since utilization clamp attributes could apply across different scheduling policies (i.e. all but SCHED_DEADLINE), this requires also to always know which policy a task has before changing its clamp values. This is not just cumbersome but it's also racy, indeed we cannot be sure that a task policy has been changed in between its policy read and the actual clamp value change. Sometimes however, this could be the actual use-case, we wanna change the clamps without affecting the policy. Let's fix this adding an additional attribute flag (SCHED_FLAG_TUNE_POLICY) which, when specified, will ensure to always force the usage of the current policy. This is done by re-using the SETPARAM_POLICY thing we already have for the sched_setparam syscall, thus extending its usage to the non-POSIX sched_setattr while not exposing that internal concept to user-space. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Suren Baghdasaryan Cc: Todd Kjos Cc: Joel Fernandes Cc: Steve Muckle Cc: Juri Lelli Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org Cc: linux-api@vger.kernel.org --- Changes in v5: Message-ID: <20180905110108.GC20267@localhost.localdomain> - allow to change clamp values without affecting current policy --- include/uapi/linux/sched.h | 6 +++++- kernel/sched/core.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index c27d6e81517b..62498d749bec 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -40,6 +40,8 @@ /* SCHED_ISO: reserved but not implemented yet */ #define SCHED_IDLE 5 #define SCHED_DEADLINE 6 +/* Must be the last entry: used check attr.policy values */ +#define SCHED_POLICY_MAX 7 /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */ #define SCHED_RESET_ON_FORK 0x40000000 @@ -50,11 +52,13 @@ #define SCHED_FLAG_RESET_ON_FORK 0x01 #define SCHED_FLAG_RECLAIM 0x02 #define SCHED_FLAG_DL_OVERRUN 0x04 -#define SCHED_FLAG_UTIL_CLAMP 0x08 +#define SCHED_FLAG_TUNE_POLICY 0x08 +#define SCHED_FLAG_UTIL_CLAMP 0x10 #define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \ SCHED_FLAG_RECLAIM | \ SCHED_FLAG_DL_OVERRUN | \ + SCHED_FLAG_TUNE_POLICY | \ SCHED_FLAG_UTIL_CLAMP) #endif /* _UAPI_LINUX_SCHED_H */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 3701bb1e6698..9a2e12eaa377 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4595,8 +4595,17 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, if (retval) return retval; - if ((int)attr.sched_policy < 0) + /* + * A valid policy has always to be required from userspace. Unless + * the SCHED_FLAG_TUNE_POLICY is set, in which case, the current + * policy will be enforced for this call. + */ + if (attr.sched_policy >= SCHED_POLICY_MAX && + !(attr.sched_flags & SCHED_FLAG_TUNE_POLICY)) { return -EINVAL; + } + if (attr.sched_flags & SCHED_FLAG_TUNE_POLICY) + attr.sched_policy = SETPARAM_POLICY; rcu_read_lock(); retval = -ESRCH; -- 2.18.0