Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2202221ybv; Mon, 24 Feb 2020 01:00:08 -0800 (PST) X-Google-Smtp-Source: APXvYqyX71Bx9clizRyymGUvQnV1F2mdh1U+kTcvdiXP//Dnj+5MEWQmzCP4r3uFMKapZp47Gytj X-Received: by 2002:a05:6830:10d7:: with SMTP id z23mr39083660oto.114.1582534808498; Mon, 24 Feb 2020 01:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582534808; cv=none; d=google.com; s=arc-20160816; b=LP7HFa58308jTzLewR4hKtdMKaWv5wVzPr+ovFDDhBcfwbOfXziUEXyP7IKVIaP0wa LSECX9+0j0S+PMaVcWLo5FA/Qu0rpH/rChbvRgM5QSA7hPcvvwXvb708d0jjYNCTjdqs XhDhwrTbG/GHmSem8gkjWhcVM+AC2P7xs5fp4VB0P5gYi7CaL3BnuzJqic9yuO/ykizF K5e0WpjIjga9AEs9ntFhAKwD2dwCny23ZYKUFvfRzIFFut7cmNG8o7cmJ8vhVq22bAet gO6ucLl/rb7KTq2uk5F2zkSZmKaC2OjKZgnGW+FAVVqbPQYi+kdSXbKHorG++JkS9Qo5 43IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=euBCE58kMeomWWb8D6ecezHOxJg/0v8M9r5JRYMxHTQ=; b=h1B9AaX3y6jSu5k9n80m3MgJc0wPL0XcIefUnKC6OiUTsUIdT8Y2rxRZthQkrxZthT NRrxXyldAB7s1IWAL/WsweP7Dk1rbshszYeYhz80v8mV8HzIxfO4Rrns9TQRfg/cS0/3 Mxjit6Oai4fxK+Pw0PyTxa3QDGPiIsULrX2Qp631wB+MZm9F/qjEppWlMfTSZQ4aHFS4 rdBKzY11ngiwsKWQbZLayFwePcH6jakr0DLLg7AyBELpn5RnC+IF8h/wTsTA3W8e0aFv Swn+VeoLaySNXi64TdswSOqetOb5PQi9FDYJV+Gxb/EOWu/8PrhO+P9TuCIOvfW284Ly MUHQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si6001382otl.82.2020.02.24.00.59.56; Mon, 24 Feb 2020 01:00:08 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727378AbgBXI7l (ORCPT + 99 others); Mon, 24 Feb 2020 03:59:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32704 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbgBXI7i (ORCPT ); Mon, 24 Feb 2020 03:59:38 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01O8wo9a088332 for ; Mon, 24 Feb 2020 03:59:38 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yaygnhgee-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 24 Feb 2020 03:59:38 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Feb 2020 08:59:35 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 24 Feb 2020 08:59:31 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01O8wX9k30212502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 08:58:33 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF06C4203F; Mon, 24 Feb 2020 08:59:29 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6CCBE42041; Mon, 24 Feb 2020 08:59:27 +0000 (GMT) Received: from localhost.in.ibm.com (unknown [9.124.35.160]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 24 Feb 2020 08:59:27 +0000 (GMT) From: Parth Shah To: linux-kernel@vger.kernel.org Cc: peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, qais.yousef@arm.com, chris.hyser@oracle.com, patrick.bellasi@matbug.net, valentin.schneider@arm.com, David.Laight@ACULAB.COM, pjt@google.com, pavel@ucw.cz, tj@kernel.org, dhaval.giani@oracle.com, qperret@google.com, tim.c.chen@linux.intel.com Subject: [PATCH v4 3/4] sched: Allow sched_{get,set}attr to change latency_nice of the task Date: Mon, 24 Feb 2020 14:29:17 +0530 X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200224085918.16955-1-parth@linux.ibm.com> References: <20200224085918.16955-1-parth@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 20022408-0012-0000-0000-00000389B4C4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022408-0013-0000-0000-000021C6534F Message-Id: <20200224085918.16955-4-parth@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-24_02:2020-02-21,2020-02-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=1 bulkscore=0 malwarescore=0 adultscore=0 priorityscore=1501 spamscore=0 phishscore=0 clxscore=1015 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240079 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce the latency_nice attribute to sched_attr and provide a mechanism to change the value with the use of sched_setattr/sched_getattr syscall. Also add new flag "SCHED_FLAG_LATENCY_NICE" to hint the change in latency_nice of the task on every sched_setattr syscall. Signed-off-by: Parth Shah Reviewed-by: Qais Yousef --- include/uapi/linux/sched.h | 4 +++- include/uapi/linux/sched/types.h | 19 +++++++++++++++++++ kernel/sched/core.c | 17 +++++++++++++++++ tools/include/uapi/linux/sched.h | 4 +++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index 4a0217832464..88ce1e8d7553 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -121,6 +121,7 @@ struct clone_args { #define SCHED_FLAG_KEEP_PARAMS 0x10 #define SCHED_FLAG_UTIL_CLAMP_MIN 0x20 #define SCHED_FLAG_UTIL_CLAMP_MAX 0x40 +#define SCHED_FLAG_LATENCY_NICE 0x80 #define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \ SCHED_FLAG_KEEP_PARAMS) @@ -132,6 +133,7 @@ struct clone_args { SCHED_FLAG_RECLAIM | \ SCHED_FLAG_DL_OVERRUN | \ SCHED_FLAG_KEEP_ALL | \ - SCHED_FLAG_UTIL_CLAMP) + SCHED_FLAG_UTIL_CLAMP | \ + SCHED_FLAG_LATENCY_NICE) #endif /* _UAPI_LINUX_SCHED_H */ diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h index c852153ddb0d..626ab61c1145 100644 --- a/include/uapi/linux/sched/types.h +++ b/include/uapi/linux/sched/types.h @@ -10,6 +10,7 @@ struct sched_param { #define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */ #define SCHED_ATTR_SIZE_VER1 56 /* add: util_{min,max} */ +#define SCHED_ATTR_SIZE_VER2 60 /* add: latency_nice */ /* * Extended scheduling parameters data structure. @@ -96,6 +97,22 @@ struct sched_param { * on a CPU with a capacity big enough to fit the specified value. * A task with a max utilization value smaller than 1024 is more likely * scheduled on a CPU with no more capacity than the specified value. + * + * Latency Tolerance Attributes + * =========================== + * + * A subset of sched_attr attributes allows to specify the relative latency + * requirements of a task with respect to the other tasks running/queued in the + * system. + * + * @ sched_latency_nice task's latency_nice value + * + * The latency_nice of a task can have any value in a range of + * [LATENCY_NICE_MIN..LATENCY_NICE_MAX]. + * + * A task with latency_nice with the value of LATENCY_NICE_MIN can be + * taken for a task with lower latency requirements as opposed to the task with + * higher latency_nice. */ struct sched_attr { __u32 size; @@ -118,6 +135,8 @@ struct sched_attr { __u32 sched_util_min; __u32 sched_util_max; + /* latency requirement hints */ + __s32 sched_latency_nice; }; #endif /* _UAPI_LINUX_SCHED_TYPES_H */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 65b6c00d6dac..e1dc536d4ca3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4723,6 +4723,8 @@ static void __setscheduler_params(struct task_struct *p, p->rt_priority = attr->sched_priority; p->normal_prio = normal_prio(p); set_load_weight(p, true); + + p->latency_nice = attr->sched_latency_nice; } /* Actually do priority change: must hold pi & rq lock. */ @@ -4880,6 +4882,13 @@ static int __sched_setscheduler(struct task_struct *p, return retval; } + if (attr->sched_flags & SCHED_FLAG_LATENCY_NICE) { + if (attr->sched_latency_nice > MAX_LATENCY_NICE) + return -EINVAL; + if (attr->sched_latency_nice < MIN_LATENCY_NICE) + return -EINVAL; + } + if (pi) cpuset_read_lock(); @@ -4914,6 +4923,9 @@ static int __sched_setscheduler(struct task_struct *p, goto change; if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) goto change; + if (attr->sched_flags & SCHED_FLAG_LATENCY_NICE && + attr->sched_latency_nice != p->latency_nice) + goto change; p->sched_reset_on_fork = reset_on_fork; retval = 0; @@ -5162,6 +5174,9 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a size < SCHED_ATTR_SIZE_VER1) return -EINVAL; + if ((attr->sched_flags & SCHED_FLAG_LATENCY_NICE) && + size < SCHED_ATTR_SIZE_VER2) + return -EINVAL; /* * XXX: Do we want to be lenient like existing syscalls; or do we want * to be strict and return an error on out-of-bounds values? @@ -5391,6 +5406,8 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, else kattr.sched_nice = task_nice(p); + kattr.sched_latency_nice = p->latency_nice; + #ifdef CONFIG_UCLAMP_TASK kattr.sched_util_min = p->uclamp_req[UCLAMP_MIN].value; kattr.sched_util_max = p->uclamp_req[UCLAMP_MAX].value; diff --git a/tools/include/uapi/linux/sched.h b/tools/include/uapi/linux/sched.h index 4a0217832464..fa67e2527169 100644 --- a/tools/include/uapi/linux/sched.h +++ b/tools/include/uapi/linux/sched.h @@ -121,6 +121,7 @@ struct clone_args { #define SCHED_FLAG_KEEP_PARAMS 0x10 #define SCHED_FLAG_UTIL_CLAMP_MIN 0x20 #define SCHED_FLAG_UTIL_CLAMP_MAX 0x40 +#define SCHED_FLAG_LATENCY_NICE 0X80 #define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \ SCHED_FLAG_KEEP_PARAMS) @@ -132,6 +133,7 @@ struct clone_args { SCHED_FLAG_RECLAIM | \ SCHED_FLAG_DL_OVERRUN | \ SCHED_FLAG_KEEP_ALL | \ - SCHED_FLAG_UTIL_CLAMP) + SCHED_FLAG_UTIL_CLAMP | \ + SCHED_FLAG_LATENCY_NICE) #endif /* _UAPI_LINUX_SCHED_H */ -- 2.17.2