Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7256890rwb; Tue, 15 Nov 2022 09:36:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Ob5HJv20PE3YI11FXpHwjAVO4Ihx5JY6I1BYpB7SEDUHJZa+KQCd3kvMmHpz/rZaQ/nFo X-Received: by 2002:a17:907:1010:b0:78d:cd84:9a40 with SMTP id ox16-20020a170907101000b0078dcd849a40mr15099002ejb.167.1668533766820; Tue, 15 Nov 2022 09:36:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668533766; cv=none; d=google.com; s=arc-20160816; b=USre8sSGuxfm8QWJIQfmKsYz6QD5/ljMpeTcD18ZnnGIChR5gFjD9Hqumltv6MUd1g wJvRSJslK9iAP5oAzSlDSETeMWSZjHesu2fKP+Wu888FPyfZcXN1ctVYzjYwHXTaRTYW 9zAKKtac1NLI8Ebq/4r90QjAGJlrD1MMMFVRsML6Vb722s8CufbWpWv7Lnq9qhtYiinP NPvxepSqPUGyUfveMcYbxdKh9kyt4h/+Ka86R0zXLTohutQWZpcldn+nXRfWk943vXO4 lMefbVF/ilZ6HF1j+3pOfFWzr0r6fhGzGxoESA2T/QRJLJEF6YK5bi8p8iA+ZB7J+pOf R66Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=VNnqFiK+Z/ErdMBjKPrnbW5+yw7a25XFT+5NgGkgZIQ=; b=XcPbdQfwqdnlS1DYgHY7QrqtEc6YId6JYIwNbmlJlYTIm/RufFDZZv0F4E9RDlhJ26 NA/EfNvCsLAL7GYl61WvszAllEuTU5g/2gHlRXI7DWQ/pcmlGVevgUD3YvyP5bzdIBnh jT1+Yyamq3/o4L0CJ8HPvUICVrpgrN+ABOminhdlzdXIdtSUFoZahjfqOQsI6qQr26wX qVWRnas3F2+CEfyvoGVZoPiJov8vdGAG1q06YhJVdf2P/HihzPGHDc6RpXtUDcTfhsJq WPSCW/nJ9PyxxLYMwhtNAhQ2ZDnJ+eaCRI8hJrR8ATlpRH9GmitvXLM87vy8tex4D4GF C2tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="md9Ac/r9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a170906bc4600b007af0bc6e10asi3154682ejv.213.2022.11.15.09.35.44; Tue, 15 Nov 2022 09:36:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="md9Ac/r9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238401AbiKORTw (ORCPT + 90 others); Tue, 15 Nov 2022 12:19:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232178AbiKORTP (ORCPT ); Tue, 15 Nov 2022 12:19:15 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D2618378 for ; Tue, 15 Nov 2022 09:19:08 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id y16so25428769wrt.12 for ; Tue, 15 Nov 2022 09:19:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=VNnqFiK+Z/ErdMBjKPrnbW5+yw7a25XFT+5NgGkgZIQ=; b=md9Ac/r9a1O7toIV1WqvkpWh900j2oJvSBER4ZWontIVPXXy74b6ydOINhOSY9kP3i Jsy2KEzqaxEgbDoP5y6Loq1bBLxEmalgLk0n31iBIK9MWaY5SM98tVlqJtfONvMmUTqq PRxMsohBM2CBAc+Z3CEN6Lispq/JG0KfNRAKFB3WF3b4qMEx1iQxaiswOvbvaYE0QhZA bEsdmQ0wxYVtdKWYrHwpwkSALue7qNEVMWv+m45qWvgasraQP/Ish4TjacR8o8hptR9R 3+M+4T5s3jaY+6oTd1/vrDEEU/vOLpXVA0NRthwF5dRwkjz9swJw0m2ek/MnFeSE/VYo 86vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VNnqFiK+Z/ErdMBjKPrnbW5+yw7a25XFT+5NgGkgZIQ=; b=IflpUGPHAfI1XEb32WJBZFGR7vyIkpFDTtDK9W4yLbgt4F1POM+0AJUqqvxEqjHXRL nSJs6RWXGuKaK9vA1bW6GiNI8Ddw73EGYc83gNw2kk/z7QwTr+aMkbc96jMckWByBm08 mtGLZXB7L45duDJrWR4UEY37rUKOBq0JBvXJM7fUWaqMny+CGhNjD9dZFmxwSgrLouJ5 rd8BQKFfw8fsJhpUeMwwgWBuxsYYbSWB7kBLVVXi+OqyHqgID7DKnDTuvi79kdTrreI2 j4qX9jTFWRuvgkg/cnZ3ovUBBJN/zqTMoIXLbuTsjSC4iaCukRJudCBT3Iz725ssYJAS Lhgg== X-Gm-Message-State: ANoB5pk02h1EE85CBACsFclupz/fMDcSqKLsNUzG6IhnHkwV8+tevIBG RAahMN+4pKwFAoInOoDkaeRvWw== X-Received: by 2002:adf:f0d2:0:b0:236:8ef4:6eea with SMTP id x18-20020adff0d2000000b002368ef46eeamr11946943wro.716.1668532746500; Tue, 15 Nov 2022 09:19:06 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:91c8:7496:8b73:811f]) by smtp.gmail.com with ESMTPSA id bg40-20020a05600c3ca800b003cf78aafdd7sm16846461wmb.39.2022.11.15.09.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 09:19:05 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, parth@linux.ibm.com Cc: qyousef@layalina.io, chris.hyser@oracle.com, patrick.bellasi@matbug.net, David.Laight@aculab.com, pjt@google.com, pavel@ucw.cz, tj@kernel.org, qperret@google.com, tim.c.chen@linux.intel.com, joshdon@google.com, timj@gnu.org, kprateek.nayak@amd.com, yu.c.chen@intel.com, youssefesmat@chromium.org, joel@joelfernandes.org, Vincent Guittot Subject: [PATCH v9 4/9] sched: Allow sched_{get,set}attr to change latency_nice of the task Date: Tue, 15 Nov 2022 18:18:46 +0100 Message-Id: <20221115171851.835-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221115171851.835-1-vincent.guittot@linaro.org> References: <20221115171851.835-1-vincent.guittot@linaro.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Parth Shah 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 [rebase and add a dedicated __setscheduler_latency ] Signed-off-by: Vincent Guittot --- include/uapi/linux/sched.h | 4 +++- include/uapi/linux/sched/types.h | 19 +++++++++++++++++++ kernel/sched/core.c | 24 ++++++++++++++++++++++++ tools/include/uapi/linux/sched.h | 4 +++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index 3bac0a8ceab2..b2e932c25be6 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -132,6 +132,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) @@ -143,6 +144,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 f2c4589d4dbf..db1e8199e8c8 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. @@ -98,6 +99,22 @@ struct sched_param { * scheduled on a CPU with no more capacity than the specified value. * * A task utilization boundary can be reset by setting the attribute to -1. + * + * 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 + * [MIN_LATENCY_NICE..MAX_LATENCY_NICE]. + * + * A task with latency_nice with the value of LATENCY_NICE_MIN can be + * taken for a task requiring a lower latency as opposed to the task with + * higher latency_nice. */ struct sched_attr { __u32 size; @@ -120,6 +137,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 8c84c652853b..18c31a68eb18 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7352,6 +7352,14 @@ 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); + +} + +static void __setscheduler_latency(struct task_struct *p, + const struct sched_attr *attr) +{ + if (attr->sched_flags & SCHED_FLAG_LATENCY_NICE) + p->latency_nice = attr->sched_latency_nice; } /* @@ -7494,6 +7502,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(); @@ -7528,6 +7543,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; @@ -7616,6 +7634,7 @@ static int __sched_setscheduler(struct task_struct *p, __setscheduler_params(p, attr); __setscheduler_prio(p, newprio); } + __setscheduler_latency(p, attr); __setscheduler_uclamp(p, attr); if (queued) { @@ -7826,6 +7845,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? @@ -8063,6 +8085,8 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, get_params(p, &kattr); kattr.sched_flags &= SCHED_FLAG_ALL; + kattr.sched_latency_nice = p->latency_nice; + #ifdef CONFIG_UCLAMP_TASK /* * This could race with another potential updater, but this is fine diff --git a/tools/include/uapi/linux/sched.h b/tools/include/uapi/linux/sched.h index 3bac0a8ceab2..b2e932c25be6 100644 --- a/tools/include/uapi/linux/sched.h +++ b/tools/include/uapi/linux/sched.h @@ -132,6 +132,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) @@ -143,6 +144,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.1