Lines Matching +full:smp +full:- +full:capable

1 // SPDX-License-Identifier: GPL-2.0-only
7 * Copyright (C) 1991-2002 Linus Torvalds
8 * Copyright (C) 1998-2024 Ingo Molnar, Red Hat
24 prio = MAX_DL_PRIO - 1; in __normal_prio()
26 prio = MAX_RT_PRIO - 1 - rt_prio; in __normal_prio()
35 * without taking RT-inheritance into account. Might be
42 return __normal_prio(p->policy, p->rt_priority, PRIO_TO_NICE(p->static_prio)); in normal_prio()
50 * RT-boosted. If not then it returns p->normal_prio.
54 p->normal_prio = normal_prio(p); in effective_prio()
60 if (!rt_or_dl_prio(p->prio)) in effective_prio()
61 return p->normal_prio; in effective_prio()
62 return p->prio; in effective_prio()
79 * allow the 'normal' nice value to be set - but as expected in set_user_nice()
84 p->static_prio = NICE_TO_PRIO(nice); in set_user_nice()
89 p->static_prio = NICE_TO_PRIO(nice); in set_user_nice()
91 old_prio = p->prio; in set_user_nice()
92 p->prio = effective_prio(p); in set_user_nice()
98 * is_nice_reduction - check if nice value is an actual reduction
107 /* Convert nice value [19,-20] to rlimit style value [1,40]: */ in is_nice_reduction()
114 * can_nice - check if a task can reduce its nice value
120 return is_nice_reduction(p, nice) || capable(CAP_SYS_NICE); in can_nice()
126 * sys_nice - change the priority of the current process.
141 increment = clamp(increment, -NICE_WIDTH, NICE_WIDTH); in SYSCALL_DEFINE1()
146 return -EPERM; in SYSCALL_DEFINE1()
159 * task_prio - return the priority value of a given task.
166 * normal, batch, idle [0 ... 39] [100 ... 139] 0/[-20 ... 19]
167 * fifo, rr [-2 ... -100] [98 ... 0] [1 ... 99]
168 * deadline -101 -1 0
172 return p->prio - MAX_RT_PRIO; in task_prio()
176 * idle_cpu - is a given CPU idle currently?
187 * idle_task - return the idle task for a given CPU.
194 return cpu_rq(cpu)->idle; in idle_task()
202 if (sched_core_enabled(rq) && rq->curr == rq->idle) in sched_core_idle_cpu()
210 * find_process_by_pid - find a process with a matching PID value.
236 * sched_setparam() passes in -1 for its policy, to let the functions in DEFINE_CLASS()
239 #define SETPARAM_POLICY -1 in DEFINE_CLASS()
244 int policy = attr->sched_policy; in DEFINE_CLASS()
247 policy = p->policy; in DEFINE_CLASS()
249 p->policy = policy; in DEFINE_CLASS()
256 /* rt-policy tasks do not have a timerslack */ in DEFINE_CLASS()
258 p->timer_slack_ns = 0; in DEFINE_CLASS()
259 } else if (p->timer_slack_ns == 0) { in DEFINE_CLASS()
260 /* when switching back to non-rt policy, restore timerslack */ in DEFINE_CLASS()
261 p->timer_slack_ns = p->default_timer_slack_ns; in DEFINE_CLASS()
265 * __sched_setscheduler() ensures attr->sched_priority == 0 when in DEFINE_CLASS()
269 p->rt_priority = attr->sched_priority; in DEFINE_CLASS()
270 p->normal_prio = normal_prio(p); in DEFINE_CLASS()
283 return (uid_eq(cred->euid, pcred->euid) || in check_same_owner()
284 uid_eq(cred->euid, pcred->uid)); in check_same_owner()
303 p->dl.pi_se = pi_task->dl.pi_se; in __setscheduler_dl_pi()
304 scope->flags |= ENQUEUE_REPLENISH; in __setscheduler_dl_pi()
321 int util_min = p->uclamp_req[UCLAMP_MIN].value; in uclamp_validate()
322 int util_max = p->uclamp_req[UCLAMP_MAX].value; in uclamp_validate()
324 if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { in uclamp_validate()
325 util_min = attr->sched_util_min; in uclamp_validate()
328 return -EINVAL; in uclamp_validate()
331 if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) { in uclamp_validate()
332 util_max = attr->sched_util_max; in uclamp_validate()
335 return -EINVAL; in uclamp_validate()
338 if (util_min != -1 && util_max != -1 && util_min > util_max) in uclamp_validate()
339 return -EINVAL; in uclamp_validate()
357 /* Reset on sched class change for a non user-defined clamp value. */ in uclamp_reset()
358 if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP)) && in uclamp_reset()
359 !uc_se->user_defined) in uclamp_reset()
362 /* Reset on sched_util_{min,max} == -1. */ in uclamp_reset()
364 attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN && in uclamp_reset()
365 attr->sched_util_min == -1) { in uclamp_reset()
370 attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX && in uclamp_reset()
371 attr->sched_util_max == -1) { in uclamp_reset()
384 struct uclamp_se *uc_se = &p->uclamp_req[clamp_id]; in __setscheduler_uclamp()
403 if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP))) in __setscheduler_uclamp()
406 if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN && in __setscheduler_uclamp()
407 attr->sched_util_min != -1) { in __setscheduler_uclamp()
408 uclamp_se_set(&p->uclamp_req[UCLAMP_MIN], in __setscheduler_uclamp()
409 attr->sched_util_min, true); in __setscheduler_uclamp()
412 if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX && in __setscheduler_uclamp()
413 attr->sched_util_max != -1) { in __setscheduler_uclamp()
414 uclamp_se_set(&p->uclamp_req[UCLAMP_MAX], in __setscheduler_uclamp()
415 attr->sched_util_max, true); in __setscheduler_uclamp()
424 return -EOPNOTSUPP; in uclamp_validate()
432 * Only issue a capable test if needed and only once to avoid an audit
433 * event on permitted non-privileged operations:
440 if (attr->sched_nice < task_nice(p) && in user_check_sched_setscheduler()
441 !is_nice_reduction(p, attr->sched_nice)) in user_check_sched_setscheduler()
449 if (policy != p->policy && !rlim_rtprio) in user_check_sched_setscheduler()
453 if (attr->sched_priority > p->rt_priority && in user_check_sched_setscheduler()
454 attr->sched_priority > rlim_rtprio) in user_check_sched_setscheduler()
481 if (p->sched_reset_on_fork && !reset_on_fork) in user_check_sched_setscheduler()
487 if (!capable(CAP_SYS_NICE)) in user_check_sched_setscheduler()
488 return -EPERM; in user_check_sched_setscheduler()
497 int oldpolicy = -1, policy = attr->sched_policy; in __sched_setscheduler()
512 reset_on_fork = p->sched_reset_on_fork; in __sched_setscheduler()
513 policy = oldpolicy = p->policy; in __sched_setscheduler()
515 reset_on_fork = !!(attr->sched_flags & SCHED_FLAG_RESET_ON_FORK); in __sched_setscheduler()
518 return -EINVAL; in __sched_setscheduler()
521 if (attr->sched_flags & ~(SCHED_FLAG_ALL | SCHED_FLAG_SUGOV)) in __sched_setscheduler()
522 return -EINVAL; in __sched_setscheduler()
526 * 1..MAX_RT_PRIO-1, valid priority for SCHED_NORMAL, in __sched_setscheduler()
529 if (attr->sched_priority > MAX_RT_PRIO-1) in __sched_setscheduler()
530 return -EINVAL; in __sched_setscheduler()
532 (rt_policy(policy) != (attr->sched_priority != 0))) in __sched_setscheduler()
533 return -EINVAL; in __sched_setscheduler()
540 if (attr->sched_flags & SCHED_FLAG_SUGOV) in __sched_setscheduler()
541 return -EINVAL; in __sched_setscheduler()
549 if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) { in __sched_setscheduler()
559 if (dl_policy(policy) || dl_policy(p->policy)) { in __sched_setscheduler()
565 * Make sure no PI-waiters arrive (or leave) while we are in __sched_setscheduler()
568 * To be able to change p->policy safely, the appropriate in __sched_setscheduler()
577 if (p == rq->stop) { in __sched_setscheduler()
578 retval = -EINVAL; in __sched_setscheduler()
590 if (unlikely(policy == p->policy)) { in __sched_setscheduler()
592 (attr->sched_nice != task_nice(p) || in __sched_setscheduler()
593 (attr->sched_runtime != p->se.slice))) in __sched_setscheduler()
595 if (rt_policy(policy) && attr->sched_priority != p->rt_priority) in __sched_setscheduler()
599 if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) in __sched_setscheduler()
602 p->sched_reset_on_fork = reset_on_fork; in __sched_setscheduler()
611 * Do not allow real-time tasks into groups that have no runtime in __sched_setscheduler()
616 task_group(p)->rt_bandwidth.rt_runtime == 0 && in __sched_setscheduler()
618 retval = -EPERM; in __sched_setscheduler()
623 !(attr->sched_flags & SCHED_FLAG_SUGOV)) { in __sched_setscheduler()
624 cpumask_t *span = rq->rd->span; in __sched_setscheduler()
631 if (!cpumask_subset(span, p->cpus_ptr) || in __sched_setscheduler()
632 rq->rd->dl_bw.bw == 0) { in __sched_setscheduler()
633 retval = -EPERM; in __sched_setscheduler()
639 /* Re-check policy now with rq lock held: */ in __sched_setscheduler()
640 if (unlikely(oldpolicy != -1 && oldpolicy != p->policy)) { in __sched_setscheduler()
641 policy = oldpolicy = -1; in __sched_setscheduler()
654 retval = -EBUSY; in __sched_setscheduler()
658 p->sched_reset_on_fork = reset_on_fork; in __sched_setscheduler()
659 oldprio = p->prio; in __sched_setscheduler()
661 newprio = __normal_prio(policy, attr->sched_priority, attr->sched_nice); in __sched_setscheduler()
675 prev_class = p->sched_class; in __sched_setscheduler()
683 if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) { in __sched_setscheduler()
685 p->sched_class = next_class; in __sched_setscheduler()
686 p->prio = newprio; in __sched_setscheduler()
691 if (scope->queued) { in __sched_setscheduler()
696 if (oldprio < p->prio) in __sched_setscheduler()
697 scope->flags |= ENQUEUE_HEAD; in __sched_setscheduler()
730 .sched_priority = param->sched_priority, in _sched_setscheduler()
731 .sched_nice = PRIO_TO_NICE(p->static_prio), in _sched_setscheduler()
734 if (p->se.custom_slice) in _sched_setscheduler()
735 attr.sched_runtime = p->se.slice; in _sched_setscheduler()
747 * sched_setscheduler - change the scheduling policy and/or RT priority of a thread.
776 …* sched_setscheduler_nocheck - change the scheduling policy and/or RT priority of a thread from ke…
833 * emulating the behavior of a non-PREEMPT_RT system where the primary handler
838 struct sched_param sp = { .sched_priority = MAX_RT_PRIO / 2 - 1 }; in sched_set_fifo_secondary()
858 return -EINVAL; in do_sched_setscheduler()
860 return -EFAULT; in do_sched_setscheduler()
864 return -ESRCH; in do_sched_setscheduler()
880 ret = get_user(size, &uattr->size); in sched_copy_attr()
892 if (ret == -E2BIG) in sched_copy_attr()
897 if ((attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) && in sched_copy_attr()
899 return -EINVAL; in sched_copy_attr()
903 * to be strict and return an error on out-of-bounds values? in sched_copy_attr()
905 attr->sched_nice = clamp(attr->sched_nice, MIN_NICE, MAX_NICE); in sched_copy_attr()
910 put_user(sizeof(*attr), &uattr->size); in sched_copy_attr()
911 return -E2BIG; in sched_copy_attr()
919 attr->sched_priority = p->rt_priority; in get_params()
921 attr->sched_nice = task_nice(p); in get_params()
922 attr->sched_runtime = p->se.slice; in get_params()
927 * sys_sched_setscheduler - set/change the scheduler policy and RT priority
937 return -EINVAL; in SYSCALL_DEFINE3()
943 * sys_sched_setparam - set/change the RT priority of a thread
955 * sys_sched_setattr - same as above, but with extended sched_attr
967 return -EINVAL; in SYSCALL_DEFINE3()
974 return -EINVAL; in SYSCALL_DEFINE3()
980 return -ESRCH; in SYSCALL_DEFINE3()
989 * sys_sched_getscheduler - get the policy (scheduling class) of a thread
1001 return -EINVAL; in SYSCALL_DEFINE1()
1006 return -ESRCH; in SYSCALL_DEFINE1()
1010 retval = p->policy; in SYSCALL_DEFINE1()
1011 if (p->sched_reset_on_fork) in SYSCALL_DEFINE1()
1018 * sys_sched_getparam - get the RT priority of a thread
1032 return -EINVAL; in SYSCALL_DEFINE2()
1037 return -ESRCH; in SYSCALL_DEFINE2()
1044 lp.sched_priority = p->rt_priority; in SYSCALL_DEFINE2()
1050 return copy_to_user(param, &lp, sizeof(*param)) ? -EFAULT : 0; in SYSCALL_DEFINE2()
1054 * sys_sched_getattr - similar to sched_getparam, but with sched_attr
1069 return -EINVAL; in SYSCALL_DEFINE4()
1074 return -ESRCH; in SYSCALL_DEFINE4()
1079 return -EINVAL; in SYSCALL_DEFINE4()
1086 kattr.sched_policy = p->policy; in SYSCALL_DEFINE4()
1087 if (p->sched_reset_on_fork) in SYSCALL_DEFINE4()
1098 kattr.sched_util_min = p->uclamp_req[UCLAMP_MIN].value; in SYSCALL_DEFINE4()
1099 kattr.sched_util_max = p->uclamp_req[UCLAMP_MAX].value; in SYSCALL_DEFINE4()
1120 if (dl_entity_is_special(&p->dl)) in dl_task_check_affinity()
1125 * if admission test is enabled, we only admit -deadline in dl_task_check_affinity()
1130 if (!cpumask_subset(task_rq(p)->rd->span, mask)) in dl_task_check_affinity()
1131 return -EBUSY; in dl_task_check_affinity()
1142 return -ENOMEM; in __sched_setaffinity()
1145 retval = -ENOMEM; in __sched_setaffinity()
1150 cpumask_and(new_mask, ctx->new_mask, cpus_allowed); in __sched_setaffinity()
1152 ctx->new_mask = new_mask; in __sched_setaffinity()
1153 ctx->flags |= SCA_CHECK; in __sched_setaffinity()
1179 if (unlikely((ctx->flags & SCA_USER) && ctx->user_mask)) { in __sched_setaffinity()
1181 ctx->user_mask); in __sched_setaffinity()
1187 retval = -EINVAL; in __sched_setaffinity()
1205 return -ESRCH; in sched_setaffinity()
1207 if (p->flags & PF_NO_SETAFFINITY) in sched_setaffinity()
1208 return -EINVAL; in sched_setaffinity()
1212 if (!ns_capable(__task_cred(p)->user_ns, CAP_SYS_NICE)) in sched_setaffinity()
1213 return -EPERM; in sched_setaffinity()
1221 * With non-SMP configs, user_cpus_ptr/user_mask isn't used and in sched_setaffinity()
1228 return -ENOMEM; in sched_setaffinity()
1251 return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; in get_user_cpu_mask()
1255 * sys_sched_setaffinity - set the CPU affinity of a process
1258 * @user_mask_ptr: user-space pointer to the new CPU mask
1269 return -ENOMEM; in SYSCALL_DEFINE3()
1286 return -ESRCH; in sched_getaffinity()
1292 guard(raw_spinlock_irqsave)(&p->pi_lock); in sched_getaffinity()
1293 cpumask_and(mask, &p->cpus_mask, cpu_active_mask); in sched_getaffinity()
1299 * sys_sched_getaffinity - get the CPU affinity of a process
1302 * @user_mask_ptr: user-space pointer to hold the current CPU mask
1314 return -EINVAL; in SYSCALL_DEFINE3()
1315 if (len & (sizeof(unsigned long)-1)) in SYSCALL_DEFINE3()
1316 return -EINVAL; in SYSCALL_DEFINE3()
1319 return -ENOMEM; in SYSCALL_DEFINE3()
1326 ret = -EFAULT; in SYSCALL_DEFINE3()
1342 schedstat_inc(rq->yld_count); in do_sched_yield()
1343 rq->donor->sched_class->yield_task(rq); in do_sched_yield()
1353 * sys_sched_yield - yield the current processor to other threads.
1367 * yield - yield the current processor to other threads.
1396 * yield_to - yield the current processor to another thread in
1408 * -ESRCH if there's no task to yield to.
1416 scoped_guard (raw_spinlock_irqsave, &p->pi_lock) { in yield_to()
1418 curr = rq->donor; in yield_to()
1426 if (rq->nr_running == 1 && p_rq->nr_running == 1) in yield_to()
1427 return -ESRCH; in yield_to()
1433 if (!curr->sched_class->yield_to_task) in yield_to()
1436 if (curr->sched_class != p->sched_class) in yield_to()
1442 yielded = curr->sched_class->yield_to_task(rq, p); in yield_to()
1444 schedstat_inc(rq->yld_count); in yield_to()
1462 * sys_sched_get_priority_max - return maximum RT priority.
1471 int ret = -EINVAL; in SYSCALL_DEFINE1()
1476 ret = MAX_RT_PRIO-1; in SYSCALL_DEFINE1()
1490 * sys_sched_get_priority_min - return minimum RT priority.
1499 int ret = -EINVAL; in SYSCALL_DEFINE1()
1522 return -EINVAL; in sched_rr_get_interval()
1527 return -ESRCH; in sched_rr_get_interval()
1535 if (p->sched_class->get_rr_interval) in sched_rr_get_interval()
1536 time_slice = p->sched_class->get_rr_interval(rq, p); in sched_rr_get_interval()
1545 * sys_sched_rr_get_interval - return the default time-slice of a process.
1547 * @interval: userspace pointer to the time-slice value.
1549 * this syscall writes the default time-slice value of a given process
1550 * into the user-space timespec buffer. A value of '0' means infinity.
1552 * Return: On success, 0 and the time-slice is in @interval. Otherwise,