Commit d0ea0268 authored by Dongsheng Yang's avatar Dongsheng Yang Committed by Ingo Molnar
Browse files

sched: Implement task_nice() as static inline function



As patch "sched: Move the priority specific bits into a new header file" exposes
the priority related macros in linux/sched/prio.h, we don't have to implement
task_nice() in kernel/sched/core.c any more.

This patch implements it in linux/sched/sched.h as static inline function,
saving the kernel stack and enhancing performance a bit.
Signed-off-by: default avatarDongsheng Yang <yangds.fnst@cn.fujitsu.com>
Cc: clark.williams@gmail.com
Cc: rostedt@goodmis.org
Cc: raistlin@linux.it
Cc: juri.lelli@gmail.com
Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1390878045-7096-1-git-send-email-yangds.fnst@cn.fujitsu.com

Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 6b6350f1
...@@ -2094,7 +2094,16 @@ static inline void sched_autogroup_exit(struct signal_struct *sig) { } ...@@ -2094,7 +2094,16 @@ static inline void sched_autogroup_exit(struct signal_struct *sig) { }
extern bool yield_to(struct task_struct *p, bool preempt); extern bool yield_to(struct task_struct *p, bool preempt);
extern void set_user_nice(struct task_struct *p, long nice); extern void set_user_nice(struct task_struct *p, long nice);
extern int task_prio(const struct task_struct *p); extern int task_prio(const struct task_struct *p);
extern int task_nice(const struct task_struct *p); /**
* task_nice - return the nice value of a given task.
* @p: the task in question.
*
* Return: The nice value [ -20 ... 0 ... 19 ].
*/
static inline int task_nice(const struct task_struct *p)
{
return PRIO_TO_NICE((p)->static_prio);
}
extern int can_nice(const struct task_struct *p, const int nice); extern int can_nice(const struct task_struct *p, const int nice);
extern int task_curr(const struct task_struct *p); extern int task_curr(const struct task_struct *p);
extern int idle_cpu(int cpu); extern int idle_cpu(int cpu);
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
*/ */
#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
#define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)
/* /*
* 'User priority' is the nice value converted to something we * 'User priority' is the nice value converted to something we
......
...@@ -3000,7 +3000,7 @@ void set_user_nice(struct task_struct *p, long nice) ...@@ -3000,7 +3000,7 @@ void set_user_nice(struct task_struct *p, long nice)
unsigned long flags; unsigned long flags;
struct rq *rq; struct rq *rq;
if (TASK_NICE(p) == nice || nice < -20 || nice > 19) if (task_nice(p) == nice || nice < -20 || nice > 19)
return; return;
/* /*
* We have to be careful, if called from sys_setpriority(), * We have to be careful, if called from sys_setpriority(),
...@@ -3078,7 +3078,7 @@ SYSCALL_DEFINE1(nice, int, increment) ...@@ -3078,7 +3078,7 @@ SYSCALL_DEFINE1(nice, int, increment)
if (increment > 40) if (increment > 40)
increment = 40; increment = 40;
nice = TASK_NICE(current) + increment; nice = task_nice(current) + increment;
if (nice < -20) if (nice < -20)
nice = -20; nice = -20;
if (nice > 19) if (nice > 19)
...@@ -3110,18 +3110,6 @@ int task_prio(const struct task_struct *p) ...@@ -3110,18 +3110,6 @@ int task_prio(const struct task_struct *p)
return p->prio - MAX_RT_PRIO; return p->prio - MAX_RT_PRIO;
} }
/**
* task_nice - return the nice value of a given task.
* @p: the task in question.
*
* Return: The nice value [ -20 ... 0 ... 19 ].
*/
int task_nice(const struct task_struct *p)
{
return TASK_NICE(p);
}
EXPORT_SYMBOL(task_nice);
/** /**
* idle_cpu - is a given cpu idle currently? * idle_cpu - is a given cpu idle currently?
* @cpu: the processor in question. * @cpu: the processor in question.
...@@ -3321,7 +3309,7 @@ static int __sched_setscheduler(struct task_struct *p, ...@@ -3321,7 +3309,7 @@ static int __sched_setscheduler(struct task_struct *p,
*/ */
if (user && !capable(CAP_SYS_NICE)) { if (user && !capable(CAP_SYS_NICE)) {
if (fair_policy(policy)) { if (fair_policy(policy)) {
if (attr->sched_nice < TASK_NICE(p) && if (attr->sched_nice < task_nice(p) &&
!can_nice(p, attr->sched_nice)) !can_nice(p, attr->sched_nice))
return -EPERM; return -EPERM;
} }
...@@ -3345,7 +3333,7 @@ static int __sched_setscheduler(struct task_struct *p, ...@@ -3345,7 +3333,7 @@ static int __sched_setscheduler(struct task_struct *p,
* SCHED_NORMAL if the RLIMIT_NICE would normally permit it. * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
*/ */
if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) { if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
if (!can_nice(p, TASK_NICE(p))) if (!can_nice(p, task_nice(p)))
return -EPERM; return -EPERM;
} }
...@@ -3385,7 +3373,7 @@ static int __sched_setscheduler(struct task_struct *p, ...@@ -3385,7 +3373,7 @@ static int __sched_setscheduler(struct task_struct *p,
* If not changing anything there's no need to proceed further: * If not changing anything there's no need to proceed further:
*/ */
if (unlikely(policy == p->policy)) { if (unlikely(policy == p->policy)) {
if (fair_policy(policy) && attr->sched_nice != TASK_NICE(p)) if (fair_policy(policy) && attr->sched_nice != task_nice(p))
goto change; goto change;
if (rt_policy(policy) && attr->sched_priority != p->rt_priority) if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
goto change; goto change;
...@@ -3837,7 +3825,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, ...@@ -3837,7 +3825,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
else if (task_has_rt_policy(p)) else if (task_has_rt_policy(p))
attr.sched_priority = p->rt_priority; attr.sched_priority = p->rt_priority;
else else
attr.sched_nice = TASK_NICE(p); attr.sched_nice = task_nice(p);
rcu_read_unlock(); rcu_read_unlock();
...@@ -7010,7 +6998,7 @@ void normalize_rt_tasks(void) ...@@ -7010,7 +6998,7 @@ void normalize_rt_tasks(void)
* Renice negative nice level userspace * Renice negative nice level userspace
* tasks back to 0: * tasks back to 0:
*/ */
if (TASK_NICE(p) < 0 && p->mm) if (task_nice(p) < 0 && p->mm)
set_user_nice(p, 0); set_user_nice(p, 0);
continue; continue;
} }
......
...@@ -142,7 +142,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime, ...@@ -142,7 +142,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
p->utimescaled += cputime_scaled; p->utimescaled += cputime_scaled;
account_group_user_time(p, cputime); account_group_user_time(p, cputime);
index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER; index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
/* Add user time to cpustat. */ /* Add user time to cpustat. */
task_group_account_field(p, index, (__force u64) cputime); task_group_account_field(p, index, (__force u64) cputime);
...@@ -169,7 +169,7 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime, ...@@ -169,7 +169,7 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime,
p->gtime += cputime; p->gtime += cputime;
/* Add guest time to cpustat. */ /* Add guest time to cpustat. */
if (TASK_NICE(p) > 0) { if (task_nice(p) > 0) {
cpustat[CPUTIME_NICE] += (__force u64) cputime; cpustat[CPUTIME_NICE] += (__force u64) cputime;
cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime; cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime;
} else { } else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment