sched: Consolidate open coded implementations of nice level frobbing into nice_to_rli...
authorDongsheng Yang <yangds.fnst@cn.fujitsu.com>
Thu, 8 May 2014 09:33:49 +0000 (18:33 +0900)
committerIngo Molnar <mingo@kernel.org>
Thu, 22 May 2014 09:16:36 +0000 (11:16 +0200)
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>
drivers/staging/android/binder.c
include/linux/sched/prio.h
kernel/sched/core.c
kernel/sys.c

index 179b21b665042c6efd1d32df435cb1e5cea326e8..9311bb67ec350157ea33e834da309493624ebc07 100644 (file)
@@ -436,7 +436,7 @@ static void binder_set_nice(long nice)
                set_user_nice(current, nice);
                return;
        }
-       min_nice = 20 - current->signal->rlim[RLIMIT_NICE].rlim_cur;
+       min_nice = rlimit_to_nice(current->signal->rlim[RLIMIT_NICE].rlim_cur);
        binder_debug(BINDER_DEBUG_PRIORITY_CAP,
                     "%d: nice value %ld not allowed use %ld instead\n",
                      current->pid, nice, min_nice);
index ac322583c82028233a2504fd5481c40a6cca36d4..d9cf5a5762d9d3c5fb12177543e282ba0de06e69 100644 (file)
 #define TASK_USER_PRIO(p)      USER_PRIO((p)->static_prio)
 #define MAX_USER_PRIO          (USER_PRIO(MAX_PRIO))
 
+/*
+ * Convert nice value [19,-20] to rlimit style value [1,40].
+ */
+static inline long nice_to_rlimit(long nice)
+{
+       return (MAX_NICE - nice + 1);
+}
+
+/*
+ * Convert rlimit style value [1,40] to nice value [-20, 19].
+ */
+static inline long rlimit_to_nice(long prio)
+{
+       return (MAX_NICE - prio + 1);
+}
+
 #endif /* _SCHED_PRIO_H */
index da302ca98f600a596278efe61e9f0aaf066cc31d..321d800e4baa24f82db15b48c5e3af0a253a404d 100644 (file)
@@ -3033,7 +3033,7 @@ EXPORT_SYMBOL(set_user_nice);
 int can_nice(const struct task_struct *p, const int nice)
 {
        /* convert nice value [19,-20] to rlimit style value [1,40] */
-       int nice_rlim = 20 - nice;
+       int nice_rlim = nice_to_rlimit(nice);
 
        return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
                capable(CAP_SYS_NICE));
index fba0f29401eafba43b29602b0296ee16022b4633..66a751ebf9d9c77be801d263d0844d40a8b52ad0 100644 (file)
@@ -250,7 +250,7 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
                        else
                                p = current;
                        if (p) {
-                               niceval = 20 - task_nice(p);
+                               niceval = nice_to_rlimit(task_nice(p));
                                if (niceval > retval)
                                        retval = niceval;
                        }
@@ -261,7 +261,7 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
                        else
                                pgrp = task_pgrp(current);
                        do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
-                               niceval = 20 - task_nice(p);
+                               niceval = nice_to_rlimit(task_nice(p));
                                if (niceval > retval)
                                        retval = niceval;
                        } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
@@ -277,7 +277,7 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
 
                        do_each_thread(g, p) {
                                if (uid_eq(task_uid(p), uid)) {
-                                       niceval = 20 - task_nice(p);
+                                       niceval = nice_to_rlimit(task_nice(p));
                                        if (niceval > retval)
                                                retval = niceval;
                                }