diff options
| author | Dongsheng Yang <yangds.fnst@cn.fujitsu.com> | 2014-05-08 05:33:49 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2014-05-22 05:16:36 -0400 |
| commit | 7aa2c016db2162defff77f6f5731bff3f25e5175 (patch) | |
| tree | af4d613e911eec6db4ccffeb1d100f718a9de9c5 | |
| parent | a803f0261bb2bb57aab5542af3174db43b2a3887 (diff) | |
sched: Consolidate open coded implementations of nice level frobbing into nice_to_rlimit() and rlimit_to_nice()
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/a568a1e3cc8e78648f41b5035fa5e381d36274da.1399532322.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
| -rw-r--r-- | drivers/staging/android/binder.c | 2 | ||||
| -rw-r--r-- | include/linux/sched/prio.h | 16 | ||||
| -rw-r--r-- | kernel/sched/core.c | 2 | ||||
| -rw-r--r-- | kernel/sys.c | 6 |
4 files changed, 21 insertions, 5 deletions
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c index 179b21b66504..9311bb67ec35 100644 --- a/drivers/staging/android/binder.c +++ b/drivers/staging/android/binder.c | |||
| @@ -436,7 +436,7 @@ static void binder_set_nice(long nice) | |||
| 436 | set_user_nice(current, nice); | 436 | set_user_nice(current, nice); |
| 437 | return; | 437 | return; |
| 438 | } | 438 | } |
| 439 | min_nice = 20 - current->signal->rlim[RLIMIT_NICE].rlim_cur; | 439 | min_nice = rlimit_to_nice(current->signal->rlim[RLIMIT_NICE].rlim_cur); |
| 440 | binder_debug(BINDER_DEBUG_PRIORITY_CAP, | 440 | binder_debug(BINDER_DEBUG_PRIORITY_CAP, |
| 441 | "%d: nice value %ld not allowed use %ld instead\n", | 441 | "%d: nice value %ld not allowed use %ld instead\n", |
| 442 | current->pid, nice, min_nice); | 442 | current->pid, nice, min_nice); |
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h index ac322583c820..d9cf5a5762d9 100644 --- a/include/linux/sched/prio.h +++ b/include/linux/sched/prio.h | |||
| @@ -41,4 +41,20 @@ | |||
| 41 | #define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio) | 41 | #define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio) |
| 42 | #define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) | 42 | #define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) |
| 43 | 43 | ||
| 44 | /* | ||
| 45 | * Convert nice value [19,-20] to rlimit style value [1,40]. | ||
| 46 | */ | ||
| 47 | static inline long nice_to_rlimit(long nice) | ||
| 48 | { | ||
| 49 | return (MAX_NICE - nice + 1); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* | ||
| 53 | * Convert rlimit style value [1,40] to nice value [-20, 19]. | ||
| 54 | */ | ||
| 55 | static inline long rlimit_to_nice(long prio) | ||
| 56 | { | ||
| 57 | return (MAX_NICE - prio + 1); | ||
| 58 | } | ||
| 59 | |||
| 44 | #endif /* _SCHED_PRIO_H */ | 60 | #endif /* _SCHED_PRIO_H */ |
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index da302ca98f60..321d800e4baa 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
| @@ -3033,7 +3033,7 @@ EXPORT_SYMBOL(set_user_nice); | |||
| 3033 | int can_nice(const struct task_struct *p, const int nice) | 3033 | int can_nice(const struct task_struct *p, const int nice) |
| 3034 | { | 3034 | { |
| 3035 | /* convert nice value [19,-20] to rlimit style value [1,40] */ | 3035 | /* convert nice value [19,-20] to rlimit style value [1,40] */ |
| 3036 | int nice_rlim = 20 - nice; | 3036 | int nice_rlim = nice_to_rlimit(nice); |
| 3037 | 3037 | ||
| 3038 | return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || | 3038 | return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || |
| 3039 | capable(CAP_SYS_NICE)); | 3039 | capable(CAP_SYS_NICE)); |
diff --git a/kernel/sys.c b/kernel/sys.c index fba0f29401ea..66a751ebf9d9 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
| @@ -250,7 +250,7 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who) | |||
| 250 | else | 250 | else |
| 251 | p = current; | 251 | p = current; |
| 252 | if (p) { | 252 | if (p) { |
| 253 | niceval = 20 - task_nice(p); | 253 | niceval = nice_to_rlimit(task_nice(p)); |
| 254 | if (niceval > retval) | 254 | if (niceval > retval) |
| 255 | retval = niceval; | 255 | retval = niceval; |
| 256 | } | 256 | } |
| @@ -261,7 +261,7 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who) | |||
| 261 | else | 261 | else |
| 262 | pgrp = task_pgrp(current); | 262 | pgrp = task_pgrp(current); |
| 263 | do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { | 263 | do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { |
| 264 | niceval = 20 - task_nice(p); | 264 | niceval = nice_to_rlimit(task_nice(p)); |
| 265 | if (niceval > retval) | 265 | if (niceval > retval) |
| 266 | retval = niceval; | 266 | retval = niceval; |
| 267 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); | 267 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); |
| @@ -277,7 +277,7 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who) | |||
| 277 | 277 | ||
| 278 | do_each_thread(g, p) { | 278 | do_each_thread(g, p) { |
| 279 | if (uid_eq(task_uid(p), uid)) { | 279 | if (uid_eq(task_uid(p), uid)) { |
| 280 | niceval = 20 - task_nice(p); | 280 | niceval = nice_to_rlimit(task_nice(p)); |
| 281 | if (niceval > retval) | 281 | if (niceval > retval) |
| 282 | retval = niceval; | 282 | retval = niceval; |
| 283 | } | 283 | } |
