aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDongsheng Yang <yangds.fnst@cn.fujitsu.com>2014-01-27 22:00:45 -0500
committerIngo Molnar <mingo@kernel.org>2014-02-09 09:28:23 -0500
commitd0ea026808ad81de2af14938448419a95211b938 (patch)
tree217b1467d99ea3b5dbffe9754979ff4d033ef44c
parent6b6350f155afdfdf888e18c7bf26950a6d10b0c2 (diff)
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: Dongsheng 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: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1390878045-7096-1-git-send-email-yangds.fnst@cn.fujitsu.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--include/linux/sched.h11
-rw-r--r--include/linux/sched/prio.h1
-rw-r--r--kernel/sched/core.c26
-rw-r--r--kernel/sched/cputime.c4
4 files changed, 19 insertions, 23 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index d97d0a8e87dc..e3d556427b2e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2094,7 +2094,16 @@ static inline void sched_autogroup_exit(struct signal_struct *sig) { }
2094extern bool yield_to(struct task_struct *p, bool preempt); 2094extern bool yield_to(struct task_struct *p, bool preempt);
2095extern void set_user_nice(struct task_struct *p, long nice); 2095extern void set_user_nice(struct task_struct *p, long nice);
2096extern int task_prio(const struct task_struct *p); 2096extern int task_prio(const struct task_struct *p);
2097extern int task_nice(const struct task_struct *p); 2097/**
2098 * task_nice - return the nice value of a given task.
2099 * @p: the task in question.
2100 *
2101 * Return: The nice value [ -20 ... 0 ... 19 ].
2102 */
2103static inline int task_nice(const struct task_struct *p)
2104{
2105 return PRIO_TO_NICE((p)->static_prio);
2106}
2098extern int can_nice(const struct task_struct *p, const int nice); 2107extern int can_nice(const struct task_struct *p, const int nice);
2099extern int task_curr(const struct task_struct *p); 2108extern int task_curr(const struct task_struct *p);
2100extern int idle_cpu(int cpu); 2109extern int idle_cpu(int cpu);
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 13216f16762e..410ccb74c9e6 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -27,7 +27,6 @@
27 */ 27 */
28#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) 28#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
29#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) 29#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
30#define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)
31 30
32/* 31/*
33 * 'User priority' is the nice value converted to something we 32 * 'User priority' is the nice value converted to something we
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 210a12acf2cd..104c8164e04f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3000,7 +3000,7 @@ void set_user_nice(struct task_struct *p, long nice)
3000 unsigned long flags; 3000 unsigned long flags;
3001 struct rq *rq; 3001 struct rq *rq;
3002 3002
3003 if (TASK_NICE(p) == nice || nice < -20 || nice > 19) 3003 if (task_nice(p) == nice || nice < -20 || nice > 19)
3004 return; 3004 return;
3005 /* 3005 /*
3006 * We have to be careful, if called from sys_setpriority(), 3006 * We have to be careful, if called from sys_setpriority(),
@@ -3078,7 +3078,7 @@ SYSCALL_DEFINE1(nice, int, increment)
3078 if (increment > 40) 3078 if (increment > 40)
3079 increment = 40; 3079 increment = 40;
3080 3080
3081 nice = TASK_NICE(current) + increment; 3081 nice = task_nice(current) + increment;
3082 if (nice < -20) 3082 if (nice < -20)
3083 nice = -20; 3083 nice = -20;
3084 if (nice > 19) 3084 if (nice > 19)
@@ -3111,18 +3111,6 @@ int task_prio(const struct task_struct *p)
3111} 3111}
3112 3112
3113/** 3113/**
3114 * task_nice - return the nice value of a given task.
3115 * @p: the task in question.
3116 *
3117 * Return: The nice value [ -20 ... 0 ... 19 ].
3118 */
3119int task_nice(const struct task_struct *p)
3120{
3121 return TASK_NICE(p);
3122}
3123EXPORT_SYMBOL(task_nice);
3124
3125/**
3126 * idle_cpu - is a given cpu idle currently? 3114 * idle_cpu - is a given cpu idle currently?
3127 * @cpu: the processor in question. 3115 * @cpu: the processor in question.
3128 * 3116 *
@@ -3321,7 +3309,7 @@ recheck:
3321 */ 3309 */
3322 if (user && !capable(CAP_SYS_NICE)) { 3310 if (user && !capable(CAP_SYS_NICE)) {
3323 if (fair_policy(policy)) { 3311 if (fair_policy(policy)) {
3324 if (attr->sched_nice < TASK_NICE(p) && 3312 if (attr->sched_nice < task_nice(p) &&
3325 !can_nice(p, attr->sched_nice)) 3313 !can_nice(p, attr->sched_nice))
3326 return -EPERM; 3314 return -EPERM;
3327 } 3315 }
@@ -3345,7 +3333,7 @@ recheck:
3345 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. 3333 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
3346 */ 3334 */
3347 if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) { 3335 if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
3348 if (!can_nice(p, TASK_NICE(p))) 3336 if (!can_nice(p, task_nice(p)))
3349 return -EPERM; 3337 return -EPERM;
3350 } 3338 }
3351 3339
@@ -3385,7 +3373,7 @@ recheck:
3385 * If not changing anything there's no need to proceed further: 3373 * If not changing anything there's no need to proceed further:
3386 */ 3374 */
3387 if (unlikely(policy == p->policy)) { 3375 if (unlikely(policy == p->policy)) {
3388 if (fair_policy(policy) && attr->sched_nice != TASK_NICE(p)) 3376 if (fair_policy(policy) && attr->sched_nice != task_nice(p))
3389 goto change; 3377 goto change;
3390 if (rt_policy(policy) && attr->sched_priority != p->rt_priority) 3378 if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
3391 goto change; 3379 goto change;
@@ -3837,7 +3825,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
3837 else if (task_has_rt_policy(p)) 3825 else if (task_has_rt_policy(p))
3838 attr.sched_priority = p->rt_priority; 3826 attr.sched_priority = p->rt_priority;
3839 else 3827 else
3840 attr.sched_nice = TASK_NICE(p); 3828 attr.sched_nice = task_nice(p);
3841 3829
3842 rcu_read_unlock(); 3830 rcu_read_unlock();
3843 3831
@@ -7010,7 +6998,7 @@ void normalize_rt_tasks(void)
7010 * Renice negative nice level userspace 6998 * Renice negative nice level userspace
7011 * tasks back to 0: 6999 * tasks back to 0:
7012 */ 7000 */
7013 if (TASK_NICE(p) < 0 && p->mm) 7001 if (task_nice(p) < 0 && p->mm)
7014 set_user_nice(p, 0); 7002 set_user_nice(p, 0);
7015 continue; 7003 continue;
7016 } 7004 }
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 99947919e30b..58624a65f124 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -142,7 +142,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime,
142 p->utimescaled += cputime_scaled; 142 p->utimescaled += cputime_scaled;
143 account_group_user_time(p, cputime); 143 account_group_user_time(p, cputime);
144 144
145 index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER; 145 index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
146 146
147 /* Add user time to cpustat. */ 147 /* Add user time to cpustat. */
148 task_group_account_field(p, index, (__force u64) cputime); 148 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 p->gtime += cputime; 169 p->gtime += cputime;
170 170
171 /* Add guest time to cpustat. */ 171 /* Add guest time to cpustat. */
172 if (TASK_NICE(p) > 0) { 172 if (task_nice(p) > 0) {
173 cpustat[CPUTIME_NICE] += (__force u64) cputime; 173 cpustat[CPUTIME_NICE] += (__force u64) cputime;
174 cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime; 174 cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime;
175 } else { 175 } else {