From patchwork Fri Jan 13 14:12:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 43325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp293902wrt; Fri, 13 Jan 2023 06:17:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXtT+Z9IFItIocV0zKWuKrUcqBvKvmfIHKGXQnBjF9De5VNeEkiuN1V8PEZPocE6/Vx9NUzH X-Received: by 2002:a17:906:7d4d:b0:862:1709:a06a with SMTP id l13-20020a1709067d4d00b008621709a06amr7492197ejp.72.1673619458591; Fri, 13 Jan 2023 06:17:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673619458; cv=none; d=google.com; s=arc-20160816; b=b4+IX5IEXkg768hvZZ1hySrtMVRKAD9OxHrRpg4R6UxhSpQOdb9ZSw/PJfA/fzy6wc hXSEVA4OArpoYdcJsXvFxHi4WyjnnlshrxAyUFkX5GqnBioJSNyqfzIEhsbndl7HLMEg c6SXc42uGmcHASPxJ/KqSc9Odl14WvlVp53E4ZzgzGQQjuKkZ1eFJWtRNIVKEHsoWvU8 wWSmpFTKkL803xx6Kn8wVHJQ/tKNvNIq/PZnovWqoDwr0xtlQqKoqnbUCN9MeKTvClz1 0JiO9UgQSc28RPPrEibLT6vgJxVhgP/QlQtmHyWt1lWk1Y0Fx3Ny8rLPllNSgFl8+ueV zeuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2Am1q/bEvRn6pheYQNrR7HS5jvhXqf4XcHEu+7BBCYA=; b=vkDHaxxaf6ui0mL/E5biImmlwv2JcCCynLuvfWT7u79bQi9FFA5pq3BhIaNYpSdhG3 mIkyqKzGl5V45usdp4Y9n7oVTeey/2/KZCNuZ08Jxjig7QOSZn2cez71ZKJz+pjpHVPe 1sDGREArvsVcod06P5RQcY+qihDGwlZsEaaMuikEA2jK88JwwSp4HGLcqcPCXjvkqg7U RN/J03wpFDZMS7YBWb+H5bVmXuvB3hW4zjDjIbYshJ/Rqa6CExvwp3PI6EYvFyWp9P0k mKQ5sorWp9Xu0Q395UiKtcUMPtWfotiPwGv48jj7iZIX/77sk40DT9QA69hcz+gzhPku 8Qag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NbVbWvwm; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc22-20020a1709078a1600b00865b943e999si6485159ejc.10.2023.01.13.06.17.13; Fri, 13 Jan 2023 06:17:38 -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=NbVbWvwm; 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 S233059AbjAMOPj (ORCPT + 99 others); Fri, 13 Jan 2023 09:15:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242026AbjAMONu (ORCPT ); Fri, 13 Jan 2023 09:13:50 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA129B12 for ; Fri, 13 Jan 2023 06:12:45 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id p3-20020a05600c1d8300b003d9ee5f125bso12372251wms.4 for ; Fri, 13 Jan 2023 06:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2Am1q/bEvRn6pheYQNrR7HS5jvhXqf4XcHEu+7BBCYA=; b=NbVbWvwm3dS9NPvSb1fzuMi3VKuQ6EhjoB3vCoplqZQl2sh2bg01jMlbprGg5xfKg/ B+4PqQkCl03dIKYokB+i6GxtDdLgzQv0k+mzoEO6cuAlF9FLmnT3LCTI6O9f6OrR+Peh kgb6gBsfsZfRVsB+gcnD2Ylh9O4eQRpMPsDv/4n7CsoPIjCup2yz3U3ZBflSbLqyOIbP ZQ2Wk3xGXJ+Ank/cocUu2n+RI44sbzx5stllUYTh1uTb7UmMDudTj6QMibXj7OFXfVd/ PSXwF+mFKr8M+92q2RlyHDx6/IoVvjxAqwyCu6G2lTs74gRz5iYi5ymBR/CWyqp8bNGk pZHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=2Am1q/bEvRn6pheYQNrR7HS5jvhXqf4XcHEu+7BBCYA=; b=nP3XFec5JZp1+89+CAmLqygnhkDB5Kks68xgvE5MGrcEJQNVcC9AP6PTar9xlYOSYh L2BjsmqKvKtigOPrgleCU30u5SvOx37VpICnjmxCGMjlG+nIa/k7yL3xz0P03z9zsiE1 7tjX/jxgc5mv7Vb538hSrhvEHhe5hHht4++/FQ0jdEkU1YxRvgF7p58j5cqGcsLyuMlW UAmHHLlM9NNfdEc4y1jE6ts7KlHIM3X5oWeeYgH7nvRCZPaST3dYL9+KFH/XSsoY6CH+ Hm97Hm2LOhG/YUSGolSt/M1k2+wjU+He/Qvfx/XdqwbrARTqPGq1pUFA8e601hSjeX+B TNyg== X-Gm-Message-State: AFqh2kp51vNf5O/954tqu93VK+xET5yfN+8oEQ6zdp6//EMYhiYgnoo9 rBGmReApf5jqikpuDPzBQZHBkA== X-Received: by 2002:a05:600c:3d91:b0:3d9:103d:9078 with SMTP id bi17-20020a05600c3d9100b003d9103d9078mr57517685wmb.22.1673619164260; Fri, 13 Jan 2023 06:12:44 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:1563:65bf:c344:661e]) by smtp.gmail.com with ESMTPSA id f7-20020a5d6647000000b002bbeb700c38sm13869919wrw.91.2023.01.13.06.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 06:12:43 -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, cgroups@vger.kernel.org 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 v10 4/9] sched: Allow sched_{get,set}attr to change latency_nice of the task Date: Fri, 13 Jan 2023 15:12:29 +0100 Message-Id: <20230113141234.260128-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230113141234.260128-1-vincent.guittot@linaro.org> References: <20230113141234.260128-1-vincent.guittot@linaro.org> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754917197406059150?= X-GMAIL-MSGID: =?utf-8?q?1754917197406059150?= 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 Tested-by: K Prateek Nayak --- 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 012a1f551f4f..981665550f8c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7392,6 +7392,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; } /* @@ -7534,6 +7542,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(); @@ -7568,6 +7583,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; @@ -7656,6 +7674,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) { @@ -7866,6 +7885,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? @@ -8103,6 +8125,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 */