Hi Peter,
There are lots of hardcoding of -20 and 19 in kernel to represent
minimum and maximum of nice value currently. This patch set define three
macros in prio.h and replace some of the hardcoding with them.
Please help to take a look at it, thanx :)
Dongsheng Yang (9):
sched: Prio: Use DEFAULT_PRIO to define NICE_TO_PRIO and PRIO_TO_NICE.
sched: prio: Add 3 macros of MAX_NICE, MIN_NICE and NICE_WIDTH in
prio.h.
sched: prio: Use NICE_WIDTH macro to avoid using of hard coding of 40
and 20 in prio.h.
sched: prio: Add spaces before and after operator of '-'.
rcu: Use MAX_NICE to replace hard coding of 19.
sched: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
sys: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
workqueue: Replace hardcoding of -20 and 19 with MIN_NICE and
MAX_NICE.
trace: Replace hardcoding of 19 with MAX_NICE.
include/linux/sched/prio.h | 14 +++++++++-----
kernel/rcu/torture.c | 8 ++++----
kernel/sched/auto_group.c | 2 +-
kernel/sched/core.c | 12 ++++++------
kernel/sys.c | 8 ++++----
kernel/trace/ring_buffer_benchmark.c | 6 +++---
kernel/workqueue.c | 2 +-
7 files changed, 28 insertions(+), 24 deletions(-)
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Tejun Heo <[email protected]>
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 82ef9f3..e4f5905 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3218,7 +3218,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
return -ENOMEM;
if (sscanf(buf, "%d", &attrs->nice) == 1 &&
- attrs->nice >= -20 && attrs->nice <= 19)
+ attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
ret = apply_workqueue_attrs(wq, attrs);
else
ret = -EINVAL;
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Steven Rostedt <[email protected]>
cc: Frederic Weisbecker <[email protected]>
cc: Ingo Molnar <[email protected]>
---
kernel/trace/ring_buffer_benchmark.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index a5457d5..0434ff1 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -40,8 +40,8 @@ static int write_iteration = 50;
module_param(write_iteration, uint, 0644);
MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
-static int producer_nice = 19;
-static int consumer_nice = 19;
+static int producer_nice = MAX_NICE;
+static int consumer_nice = MAX_NICE;
static int producer_fifo = -1;
static int consumer_fifo = -1;
@@ -308,7 +308,7 @@ static void ring_buffer_producer(void)
/* Let the user know that the test is running at low priority */
if (producer_fifo < 0 && consumer_fifo < 0 &&
- producer_nice == 19 && consumer_nice == 19)
+ producer_nice == MAX_NICE && consumer_nice == MAX_NICE)
trace_printk("WARNING!!! This test is running at lowest priority.\n");
trace_printk("Time: %lld (usecs)\n", time);
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Ingo Molnar <[email protected]>
cc: Peter Zijlstra <[email protected]>
---
include/linux/sched/prio.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index c6974c4..ac32258 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -21,8 +21,8 @@
#define MAX_USER_RT_PRIO 100
#define MAX_RT_PRIO MAX_USER_RT_PRIO
-#define MAX_PRIO (MAX_RT_PRIO + 40)
-#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
+#define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH)
+#define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2)
/*
* Convert user-nice values [ -20 ... 0 ... 19 ]
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Ingo Molnar <[email protected]>
cc: Peter Zijlstra <[email protected]>
---
kernel/sched/auto_group.c | 2 +-
kernel/sched/core.c | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
index 4a07353..e73efba 100644
--- a/kernel/sched/auto_group.c
+++ b/kernel/sched/auto_group.c
@@ -203,7 +203,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
struct autogroup *ag;
int err;
- if (nice < -20 || nice > 19)
+ if (nice < MIN_NICE || nice > MAX_NICE)
return -EINVAL;
err = security_task_setnice(current, nice);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 104c816..46cf585 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)
unsigned long flags;
struct rq *rq;
- if (task_nice(p) == nice || nice < -20 || nice > 19)
+ if (task_nice(p) == nice || nice < MIN_NICE || nice > MAX_NICE)
return;
/*
* We have to be careful, if called from sys_setpriority(),
@@ -3079,10 +3079,10 @@ SYSCALL_DEFINE1(nice, int, increment)
increment = 40;
nice = task_nice(current) + increment;
- if (nice < -20)
- nice = -20;
- if (nice > 19)
- nice = 19;
+ if (nice < MIN_NICE)
+ nice = MIN_NICE;
+ if (nice > MAX_NICE)
+ nice = MAX_NICE;
if (increment < 0 && !can_nice(current, nice))
return -EPERM;
@@ -3605,7 +3605,7 @@ static int sched_copy_attr(struct sched_attr __user *uattr,
* XXX: do we want to be lenient like existing syscalls; or do we want
* to be strict and return an error on out-of-bounds values?
*/
- attr->sched_nice = clamp(attr->sched_nice, -20, 19);
+ attr->sched_nice = clamp(attr->sched_nice, MIN_NICE, MAX_NICE);
out:
return ret;
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Andrew Morton <[email protected]>
cc: Oleg Nesterov <[email protected]>
cc: Robin Holt <[email protected]>
cc: Al Viro <[email protected]>
cc: Kees Cook <[email protected]>
cc: "Eric W. Biederman" <[email protected]>
cc: Stephen Rothwell <[email protected]>
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
---
kernel/sys.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/sys.c b/kernel/sys.c
index c0a58be..adaeab6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
/* normalize: avoid signed division (rounding problems) */
error = -ESRCH;
- if (niceval < -20)
- niceval = -20;
- if (niceval > 19)
- niceval = 19;
+ if (niceval < MIN_NICE)
+ niceval = MIN_NICE;
+ if (niceval > MAX_NICE)
+ niceval = MAX_NICE;
rcu_read_lock();
read_lock(&tasklist_lock);
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Josh Triplett <[email protected]>
cc: "Paul E. McKenney" <[email protected]>
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
---
kernel/rcu/torture.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
index 732f8ae..219761d 100644
--- a/kernel/rcu/torture.c
+++ b/kernel/rcu/torture.c
@@ -805,7 +805,7 @@ rcu_torture_writer(void *arg)
static DEFINE_RCU_RANDOM(rand);
VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
schedule_timeout_uninterruptible(1);
@@ -871,7 +871,7 @@ rcu_torture_fakewriter(void *arg)
DEFINE_RCU_RANDOM(rand);
VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
@@ -987,7 +987,7 @@ rcu_torture_reader(void *arg)
unsigned long long ts;
VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
if (irqreader && cur_ops->irq_capable)
setup_timer_on_stack(&t, rcu_torture_timer, 0);
@@ -1584,7 +1584,7 @@ static int rcu_torture_barrier_cbs(void *arg)
init_rcu_head_on_stack(&rcu);
VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
wait_event(barrier_cbs_wq[myid],
(newphase =
--
1.8.2.1
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
---
include/linux/sched/prio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index ac32258..1bf9935 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -37,7 +37,7 @@
* can work with better when scaling various scheduler parameters,
* it's a [ 0 ... 39 ] range.
*/
-#define USER_PRIO(p) ((p)-MAX_RT_PRIO)
+#define USER_PRIO(p) ((p) - MAX_RT_PRIO)
#define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
--
1.8.2.1
Currently, there are lots of hard coding of 19 and -20 to represent
maximum and minimum of nice value.
This patch add three macros in prio.h for maximum, minimum and width
of nice value.
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
---
include/linux/sched/prio.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 1ceaaa1..c6974c4 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -1,6 +1,10 @@
#ifndef _SCHED_PRIO_H
#define _SCHED_PRIO_H
+#define MAX_NICE 19
+#define MIN_NICE -20
+#define NICE_WIDTH (MAX_NICE - MIN_NICE + 1)
+
/*
* Priority of a process goes from 0..MAX_PRIO-1, valid RT
* priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
--
1.8.2.1
There is already a macro named DEFAULT_PRIO in prio.h, we can use it
to define NICE_TO_PRIO and PRIO_TO_NICE rather than use hard coding
of (MAX_RT_PRIO + 20).
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
---
include/linux/sched/prio.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 410ccb7..1ceaaa1 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -25,8 +25,8 @@
* to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
* and back.
*/
-#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
-#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
+#define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO)
+#define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO)
/*
* 'User priority' is the nice value converted to something we
--
1.8.2.1
On Tue, Feb 11, 2014 at 03:34:49PM +0800, Dongsheng Yang wrote:
> Signed-off-by: Dongsheng Yang <[email protected]>
> cc: Josh Triplett <[email protected]>
> cc: "Paul E. McKenney" <[email protected]>
> cc: Peter Zijlstra <[email protected]>
> cc: Ingo Molnar <[email protected]>
Reviewed-by: Josh Triplett <[email protected]>
> kernel/rcu/torture.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
> index 732f8ae..219761d 100644
> --- a/kernel/rcu/torture.c
> +++ b/kernel/rcu/torture.c
> @@ -805,7 +805,7 @@ rcu_torture_writer(void *arg)
> static DEFINE_RCU_RANDOM(rand);
>
> VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
> - set_user_nice(current, 19);
> + set_user_nice(current, MAX_NICE);
>
> do {
> schedule_timeout_uninterruptible(1);
> @@ -871,7 +871,7 @@ rcu_torture_fakewriter(void *arg)
> DEFINE_RCU_RANDOM(rand);
>
> VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
> - set_user_nice(current, 19);
> + set_user_nice(current, MAX_NICE);
>
> do {
> schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
> @@ -987,7 +987,7 @@ rcu_torture_reader(void *arg)
> unsigned long long ts;
>
> VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
> - set_user_nice(current, 19);
> + set_user_nice(current, MAX_NICE);
> if (irqreader && cur_ops->irq_capable)
> setup_timer_on_stack(&t, rcu_torture_timer, 0);
>
> @@ -1584,7 +1584,7 @@ static int rcu_torture_barrier_cbs(void *arg)
>
> init_rcu_head_on_stack(&rcu);
> VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
> - set_user_nice(current, 19);
> + set_user_nice(current, MAX_NICE);
> do {
> wait_event(barrier_cbs_wq[myid],
> (newphase =
> --
> 1.8.2.1
>
On Tue, Feb 11, 2014 at 07:37:32AM -0800, Josh Triplett wrote:
> On Tue, Feb 11, 2014 at 03:34:49PM +0800, Dongsheng Yang wrote:
> > Signed-off-by: Dongsheng Yang <[email protected]>
> > cc: Josh Triplett <[email protected]>
> > cc: "Paul E. McKenney" <[email protected]>
> > cc: Peter Zijlstra <[email protected]>
> > cc: Ingo Molnar <[email protected]>
>
> Reviewed-by: Josh Triplett <[email protected]>
I get complaints about MAX_NICE being undefined, and I don't see any
definition of MAX_NICE in sched.h as of 3.14-rc2. Am I looking in
the wrong place, or is this symbol not yet quite in mainline?
Thanx, Paul
> > kernel/rcu/torture.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
> > index 732f8ae..219761d 100644
> > --- a/kernel/rcu/torture.c
> > +++ b/kernel/rcu/torture.c
> > @@ -805,7 +805,7 @@ rcu_torture_writer(void *arg)
> > static DEFINE_RCU_RANDOM(rand);
> >
> > VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
> > - set_user_nice(current, 19);
> > + set_user_nice(current, MAX_NICE);
> >
> > do {
> > schedule_timeout_uninterruptible(1);
> > @@ -871,7 +871,7 @@ rcu_torture_fakewriter(void *arg)
> > DEFINE_RCU_RANDOM(rand);
> >
> > VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
> > - set_user_nice(current, 19);
> > + set_user_nice(current, MAX_NICE);
> >
> > do {
> > schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
> > @@ -987,7 +987,7 @@ rcu_torture_reader(void *arg)
> > unsigned long long ts;
> >
> > VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
> > - set_user_nice(current, 19);
> > + set_user_nice(current, MAX_NICE);
> > if (irqreader && cur_ops->irq_capable)
> > setup_timer_on_stack(&t, rcu_torture_timer, 0);
> >
> > @@ -1584,7 +1584,7 @@ static int rcu_torture_barrier_cbs(void *arg)
> >
> > init_rcu_head_on_stack(&rcu);
> > VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
> > - set_user_nice(current, 19);
> > + set_user_nice(current, MAX_NICE);
> > do {
> > wait_event(barrier_cbs_wq[myid],
> > (newphase =
> > --
> > 1.8.2.1
> >
>
On Tue, Feb 11, 2014 at 08:13:13AM -0800, Paul E. McKenney wrote:
> On Tue, Feb 11, 2014 at 07:37:32AM -0800, Josh Triplett wrote:
> > On Tue, Feb 11, 2014 at 03:34:49PM +0800, Dongsheng Yang wrote:
> > > Signed-off-by: Dongsheng Yang <[email protected]>
> > > cc: Josh Triplett <[email protected]>
> > > cc: "Paul E. McKenney" <[email protected]>
> > > cc: Peter Zijlstra <[email protected]>
> > > cc: Ingo Molnar <[email protected]>
> >
> > Reviewed-by: Josh Triplett <[email protected]>
>
> I get complaints about MAX_NICE being undefined, and I don't see any
> definition of MAX_NICE in sched.h as of 3.14-rc2. Am I looking in
> the wrong place, or is this symbol not yet quite in mainline?
It is not.. its a proposed thingy. I'm still trying to make up my mind
on it.
On Tue, Feb 11, 2014 at 05:42:30PM +0100, Peter Zijlstra wrote:
> On Tue, Feb 11, 2014 at 08:13:13AM -0800, Paul E. McKenney wrote:
> > On Tue, Feb 11, 2014 at 07:37:32AM -0800, Josh Triplett wrote:
> > > On Tue, Feb 11, 2014 at 03:34:49PM +0800, Dongsheng Yang wrote:
> > > > Signed-off-by: Dongsheng Yang <[email protected]>
> > > > cc: Josh Triplett <[email protected]>
> > > > cc: "Paul E. McKenney" <[email protected]>
> > > > cc: Peter Zijlstra <[email protected]>
> > > > cc: Ingo Molnar <[email protected]>
> > >
> > > Reviewed-by: Josh Triplett <[email protected]>
> >
> > I get complaints about MAX_NICE being undefined, and I don't see any
> > definition of MAX_NICE in sched.h as of 3.14-rc2. Am I looking in
> > the wrong place, or is this symbol not yet quite in mainline?
>
> It is not.. its a proposed thingy. I'm still trying to make up my mind
> on it.
OK, will hold off then.
Thanx, Paul
On Tue, Feb 11, 2014 at 03:34:52PM +0800, Dongsheng Yang wrote:
> Signed-off-by: Dongsheng Yang <[email protected]>
> cc: Tejun Heo <[email protected]>
> cc: Peter Zijlstra <[email protected]>
> cc: Ingo Molnar <[email protected]>
> ---
> kernel/workqueue.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 82ef9f3..e4f5905 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -3218,7 +3218,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
> return -ENOMEM;
>
> if (sscanf(buf, "%d", &attrs->nice) == 1 &&
> - attrs->nice >= -20 && attrs->nice <= 19)
> + attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
No objection. If this gets accepted, it will be routed through -tip,
I suppose? Please feel free to add
Acked-by: Tejun Heo <[email protected]>
Thanks.
--
tejun
On Mon, Feb 10, 2014 at 11:34 PM, Dongsheng Yang
<[email protected]> wrote:
> Signed-off-by: Dongsheng Yang <[email protected]>
> cc: Andrew Morton <[email protected]>
> cc: Oleg Nesterov <[email protected]>
> cc: Robin Holt <[email protected]>
> cc: Al Viro <[email protected]>
> cc: Kees Cook <[email protected]>
> cc: "Eric W. Biederman" <[email protected]>
> cc: Stephen Rothwell <[email protected]>
> cc: Peter Zijlstra <[email protected]>
> cc: Ingo Molnar <[email protected]>
> ---
> kernel/sys.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index c0a58be..adaeab6 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
>
> /* normalize: avoid signed division (rounding problems) */
> error = -ESRCH;
> - if (niceval < -20)
> - niceval = -20;
> - if (niceval > 19)
> - niceval = 19;
> + if (niceval < MIN_NICE)
> + niceval = MIN_NICE;
> + if (niceval > MAX_NICE)
> + niceval = MAX_NICE;
Good catch! I'm all for using names instead of numeric values,
however, I wonder if it'd be more readable to use "clamp" instead?
niceval = clamp(niceval, MIN_NICE, MAX_NICE);
-Kees
>
> rcu_read_lock();
> read_lock(&tasklist_lock);
> --
> 1.8.2.1
>
--
Kees Cook
Chrome OS Security
Hi Kees,
On 02/12/2014 02:27 AM, Kees Cook wrote:
> On Mon, Feb 10, 2014 at 11:34 PM, Dongsheng Yang
> <[email protected]> wrote:
>> Signed-off-by: Dongsheng Yang <[email protected]>
>> cc: Andrew Morton <[email protected]>
>> cc: Oleg Nesterov <[email protected]>
>> cc: Robin Holt <[email protected]>
>> cc: Al Viro <[email protected]>
>> cc: Kees Cook <[email protected]>
>> cc: "Eric W. Biederman" <[email protected]>
>> cc: Stephen Rothwell <[email protected]>
>> cc: Peter Zijlstra <[email protected]>
>> cc: Ingo Molnar <[email protected]>
>> ---
>> kernel/sys.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/sys.c b/kernel/sys.c
>> index c0a58be..adaeab6 100644
>> --- a/kernel/sys.c
>> +++ b/kernel/sys.c
>> @@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
>>
>> /* normalize: avoid signed division (rounding problems) */
>> error = -ESRCH;
>> - if (niceval < -20)
>> - niceval = -20;
>> - if (niceval > 19)
>> - niceval = 19;
>> + if (niceval < MIN_NICE)
>> + niceval = MIN_NICE;
>> + if (niceval > MAX_NICE)
>> + niceval = MAX_NICE;
> Good catch! I'm all for using names instead of numeric values,
> however, I wonder if it'd be more readable to use "clamp" instead?
>
> niceval = clamp(niceval, MIN_NICE, MAX_NICE);
Good suggestion! This patch here is just to replace the numeric values with
a name defined in prio.h. So I will send another patch to make it more
readable
with clamp after the patch set here applied. Is this plan ok to you?
Thanx.
>
> -Kees
>
>> rcu_read_lock();
>> read_lock(&tasklist_lock);
>> --
>> 1.8.2.1
>>
>
>
On Tue, Feb 11, 2014 at 7:59 PM, Dongsheng Yang
<[email protected]> wrote:
> Hi Kees,
>
>
> On 02/12/2014 02:27 AM, Kees Cook wrote:
>>
>> On Mon, Feb 10, 2014 at 11:34 PM, Dongsheng Yang
>> <[email protected]> wrote:
>>>
>>> Signed-off-by: Dongsheng Yang <[email protected]>
>>> cc: Andrew Morton <[email protected]>
>>> cc: Oleg Nesterov <[email protected]>
>>> cc: Robin Holt <[email protected]>
>>> cc: Al Viro <[email protected]>
>>> cc: Kees Cook <[email protected]>
>>> cc: "Eric W. Biederman" <[email protected]>
>>> cc: Stephen Rothwell <[email protected]>
>>> cc: Peter Zijlstra <[email protected]>
>>> cc: Ingo Molnar <[email protected]>
>>> ---
>>> kernel/sys.c | 8 ++++----
>>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/kernel/sys.c b/kernel/sys.c
>>> index c0a58be..adaeab6 100644
>>> --- a/kernel/sys.c
>>> +++ b/kernel/sys.c
>>> @@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who,
>>> int, niceval)
>>>
>>> /* normalize: avoid signed division (rounding problems) */
>>> error = -ESRCH;
>>> - if (niceval < -20)
>>> - niceval = -20;
>>> - if (niceval > 19)
>>> - niceval = 19;
>>> + if (niceval < MIN_NICE)
>>> + niceval = MIN_NICE;
>>> + if (niceval > MAX_NICE)
>>> + niceval = MAX_NICE;
>>
>> Good catch! I'm all for using names instead of numeric values,
>> however, I wonder if it'd be more readable to use "clamp" instead?
>>
>> niceval = clamp(niceval, MIN_NICE, MAX_NICE);
>
>
> Good suggestion! This patch here is just to replace the numeric values with
> a name defined in prio.h. So I will send another patch to make it more
> readable
> with clamp after the patch set here applied. Is this plan ok to you?
Sounds good to me. Thanks!
-Kees
>
> Thanx.
>
>>
>> -Kees
>>
>>> rcu_read_lock();
>>> read_lock(&tasklist_lock);
>>> --
>>> 1.8.2.1
>>>
>>
>>
>
--
Kees Cook
Chrome OS Security
Hi Ingo & Peter,
What's your opinion on this patchset?
On 02/11/2014 03:34 PM, Dongsheng Yang wrote:
> Hi Peter,
> There are lots of hardcoding of -20 and 19 in kernel to represent
> minimum and maximum of nice value currently. This patch set define three
> macros in prio.h and replace some of the hardcoding with them.
>
> Please help to take a look at it, thanx :)
>
> Dongsheng Yang (9):
> sched: Prio: Use DEFAULT_PRIO to define NICE_TO_PRIO and PRIO_TO_NICE.
> sched: prio: Add 3 macros of MAX_NICE, MIN_NICE and NICE_WIDTH in
> prio.h.
> sched: prio: Use NICE_WIDTH macro to avoid using of hard coding of 40
> and 20 in prio.h.
> sched: prio: Add spaces before and after operator of '-'.
> rcu: Use MAX_NICE to replace hard coding of 19.
> sched: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
> sys: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
> workqueue: Replace hardcoding of -20 and 19 with MIN_NICE and
> MAX_NICE.
> trace: Replace hardcoding of 19 with MAX_NICE.
>
> include/linux/sched/prio.h | 14 +++++++++-----
> kernel/rcu/torture.c | 8 ++++----
> kernel/sched/auto_group.c | 2 +-
> kernel/sched/core.c | 12 ++++++------
> kernel/sys.c | 8 ++++----
> kernel/trace/ring_buffer_benchmark.c | 6 +++---
> kernel/workqueue.c | 2 +-
> 7 files changed, 28 insertions(+), 24 deletions(-)
>
On Fri, Feb 14, 2014 at 05:22:50PM +0800, Dongsheng Yang wrote:
> Hi Ingo & Peter,
> What's your opinion on this patchset?
I queued it; I wasn't convinced but people seem to like it, which is
good enough.
On 02/14/2014 05:51 PM, Peter Zijlstra wrote:
> On Fri, Feb 14, 2014 at 05:22:50PM +0800, Dongsheng Yang wrote:
>> Hi Ingo & Peter,
>> What's your opinion on this patchset?
> I queued it; I wasn't convinced but people seem to like it, which is
> good enough.
Thank you :)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
Commit-ID: 103fc73128e3c55773d7f60998f9296c256df3a5
Gitweb: http://git.kernel.org/tip/103fc73128e3c55773d7f60998f9296c256df3a5
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:45 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:20 +0100
sched: Prio: Use DEFAULT_PRIO to define NICE_TO_PRIO and PRIO_TO_NICE.
There is already a macro named DEFAULT_PRIO in prio.h, we can use it
to define NICE_TO_PRIO and PRIO_TO_NICE rather than use hard coding
of (MAX_RT_PRIO + 20).
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/4e28ec36fb49e8906027cbbdd900ab26a149905e.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/sched/prio.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 410ccb7..1ceaaa1 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -25,8 +25,8 @@
* to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
* and back.
*/
-#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
-#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
+#define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO)
+#define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO)
/*
* 'User priority' is the nice value converted to something we
Commit-ID: 798fa741dd4e5a2d15e862367000a0ac63253978
Gitweb: http://git.kernel.org/tip/798fa741dd4e5a2d15e862367000a0ac63253978
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:46 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:20 +0100
sched: prio: Add 3 macros of MAX_NICE, MIN_NICE and NICE_WIDTH in prio.h.
Currently, there are lots of hard coding of 19 and -20 to represent
maximum and minimum of nice value.
This patch add three macros in prio.h for maximum, minimum and width
of nice value.
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/3994e89327b2b15f992277cdf9f409c516f87d1b.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/sched/prio.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 1ceaaa1..c6974c4 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -1,6 +1,10 @@
#ifndef _SCHED_PRIO_H
#define _SCHED_PRIO_H
+#define MAX_NICE 19
+#define MIN_NICE -20
+#define NICE_WIDTH (MAX_NICE - MIN_NICE + 1)
+
/*
* Priority of a process goes from 0..MAX_PRIO-1, valid RT
* priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
Commit-ID: eb2ae7dad9dad350b4444962465d7e09bcfc128a
Gitweb: http://git.kernel.org/tip/eb2ae7dad9dad350b4444962465d7e09bcfc128a
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:47 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:20 +0100
sched: prio: Use NICE_WIDTH macro to avoid using of hard coding of 40 and 20 in prio.h.
cc: Ingo Molnar <[email protected]>
cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/72dc351df816a975e30b6320754fb52823d2aa3f.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/sched/prio.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index c6974c4..ac32258 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -21,8 +21,8 @@
#define MAX_USER_RT_PRIO 100
#define MAX_RT_PRIO MAX_USER_RT_PRIO
-#define MAX_PRIO (MAX_RT_PRIO + 40)
-#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
+#define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH)
+#define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2)
/*
* Convert user-nice values [ -20 ... 0 ... 19 ]
Commit-ID: 02228c930672ec5476cf8ef84e4f3f45ab01b597
Gitweb: http://git.kernel.org/tip/02228c930672ec5476cf8ef84e4f3f45ab01b597
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:48 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:20 +0100
sched: prio: Add spaces before and after operator of '-'.
cc: Peter Zijlstra <[email protected]>
cc: Ingo Molnar <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/bcbf88bb25b5423e8d33b3aa0c2e829a23d56c76.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/sched/prio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index ac32258..1bf9935 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -37,7 +37,7 @@
* can work with better when scaling various scheduler parameters,
* it's a [ 0 ... 39 ] range.
*/
-#define USER_PRIO(p) ((p)-MAX_RT_PRIO)
+#define USER_PRIO(p) ((p) - MAX_RT_PRIO)
#define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)
#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
Commit-ID: c30f4ba1cb3f89cefba728f5289caf3c0fc7149d
Gitweb: http://git.kernel.org/tip/c30f4ba1cb3f89cefba728f5289caf3c0fc7149d
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:49 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:20 +0100
rcu: Use MAX_NICE to replace hard coding of 19.
Cc: "Paul E. McKenney" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Reviewed-by: Josh Triplett <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/5b3bf232f41b33ab703a1595e94671b303e2d1fc.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/rcu/torture.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
index 732f8ae..219761d 100644
--- a/kernel/rcu/torture.c
+++ b/kernel/rcu/torture.c
@@ -805,7 +805,7 @@ rcu_torture_writer(void *arg)
static DEFINE_RCU_RANDOM(rand);
VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
schedule_timeout_uninterruptible(1);
@@ -871,7 +871,7 @@ rcu_torture_fakewriter(void *arg)
DEFINE_RCU_RANDOM(rand);
VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
@@ -987,7 +987,7 @@ rcu_torture_reader(void *arg)
unsigned long long ts;
VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
if (irqreader && cur_ops->irq_capable)
setup_timer_on_stack(&t, rcu_torture_timer, 0);
@@ -1584,7 +1584,7 @@ static int rcu_torture_barrier_cbs(void *arg)
init_rcu_head_on_stack(&rcu);
VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
wait_event(barrier_cbs_wq[myid],
(newphase =
Commit-ID: 82abc86e6bcd0ab6b2efad1d8201abb463422034
Gitweb: http://git.kernel.org/tip/82abc86e6bcd0ab6b2efad1d8201abb463422034
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:50 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:20 +0100
sched: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/bd80780f19b4f9b4a765acc353c8dbc130274dd6.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/sched/auto_group.c | 2 +-
kernel/sched/core.c | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
index 4a07353..e73efba 100644
--- a/kernel/sched/auto_group.c
+++ b/kernel/sched/auto_group.c
@@ -203,7 +203,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
struct autogroup *ag;
int err;
- if (nice < -20 || nice > 19)
+ if (nice < MIN_NICE || nice > MAX_NICE)
return -EINVAL;
err = security_task_setnice(current, nice);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 67a24fa..67fcadb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3001,7 +3001,7 @@ void set_user_nice(struct task_struct *p, long nice)
unsigned long flags;
struct rq *rq;
- if (task_nice(p) == nice || nice < -20 || nice > 19)
+ if (task_nice(p) == nice || nice < MIN_NICE || nice > MAX_NICE)
return;
/*
* We have to be careful, if called from sys_setpriority(),
@@ -3080,10 +3080,10 @@ SYSCALL_DEFINE1(nice, int, increment)
increment = 40;
nice = task_nice(current) + increment;
- if (nice < -20)
- nice = -20;
- if (nice > 19)
- nice = 19;
+ if (nice < MIN_NICE)
+ nice = MIN_NICE;
+ if (nice > MAX_NICE)
+ nice = MAX_NICE;
if (increment < 0 && !can_nice(current, nice))
return -EPERM;
@@ -3631,7 +3631,7 @@ static int sched_copy_attr(struct sched_attr __user *uattr,
* XXX: do we want to be lenient like existing syscalls; or do we want
* to be strict and return an error on out-of-bounds values?
*/
- attr->sched_nice = clamp(attr->sched_nice, -20, 19);
+ attr->sched_nice = clamp(attr->sched_nice, MIN_NICE, MAX_NICE);
out:
return ret;
Commit-ID: dbebf7f826e1b3935f8bcd5d9681bf97708a7ddb
Gitweb: http://git.kernel.org/tip/dbebf7f826e1b3935f8bcd5d9681bf97708a7ddb
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:52 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:21 +0100
workqueue: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
Cc: Ingo Molnar <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/6d85138180c00ce86975addab6e34b24b84f00a5.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 193e977..3fa5b8f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3225,7 +3225,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
return -ENOMEM;
if (sscanf(buf, "%d", &attrs->nice) == 1 &&
- attrs->nice >= -20 && attrs->nice <= 19)
+ attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
ret = apply_workqueue_attrs(wq, attrs);
else
ret = -EINVAL;
Commit-ID: 4870c6e5774424c994bfd606cd8adb8818e8a85c
Gitweb: http://git.kernel.org/tip/4870c6e5774424c994bfd606cd8adb8818e8a85c
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:51 +0800
Committer: Thomas Gleixner <[email protected]>
CommitDate: Fri, 21 Feb 2014 21:43:21 +0100
sys: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE.
Cc: Andrew Morton <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Stephen Rothwell <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/0261f094b836f1acbcdf52e7166487c0c77323c8.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/sys.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/sys.c b/kernel/sys.c
index c0a58be..adaeab6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
/* normalize: avoid signed division (rounding problems) */
error = -ESRCH;
- if (niceval < -20)
- niceval = -20;
- if (niceval > 19)
- niceval = 19;
+ if (niceval < MIN_NICE)
+ niceval = MIN_NICE;
+ if (niceval > MAX_NICE)
+ niceval = MAX_NICE;
rcu_read_lock();
read_lock(&tasklist_lock);
Hi Peter.
It seems the all other patches in this set were all applied to tip
except this one.
What is the problem with the [9/9]? Is there any thing I can do?
Thanx
On 02/11/2014 03:34 PM, Dongsheng Yang wrote:
> Signed-off-by: Dongsheng Yang <[email protected]>
> cc: Steven Rostedt <[email protected]>
> cc: Frederic Weisbecker <[email protected]>
> cc: Ingo Molnar <[email protected]>
> ---
> kernel/trace/ring_buffer_benchmark.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
> index a5457d5..0434ff1 100644
> --- a/kernel/trace/ring_buffer_benchmark.c
> +++ b/kernel/trace/ring_buffer_benchmark.c
> @@ -40,8 +40,8 @@ static int write_iteration = 50;
> module_param(write_iteration, uint, 0644);
> MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
>
> -static int producer_nice = 19;
> -static int consumer_nice = 19;
> +static int producer_nice = MAX_NICE;
> +static int consumer_nice = MAX_NICE;
>
> static int producer_fifo = -1;
> static int consumer_fifo = -1;
> @@ -308,7 +308,7 @@ static void ring_buffer_producer(void)
>
> /* Let the user know that the test is running at low priority */
> if (producer_fifo < 0 && consumer_fifo < 0 &&
> - producer_nice == 19 && consumer_nice == 19)
> + producer_nice == MAX_NICE && consumer_nice == MAX_NICE)
> trace_printk("WARNING!!! This test is running at lowest priority.\n");
>
> trace_printk("Time: %lld (usecs)\n", time);
On Sat, Feb 22, 2014 at 05:05:36PM +0800, Dongsheng Yang wrote:
> Hi Peter.
> It seems the all other patches in this set were all applied to tip
> except this one.
> What is the problem with the [9/9]? Is there any thing I can do?
I might have just missed it; fail on my end. I'll try and sort it on
monday.
Commit-ID: 7e298d60f717257dc8365c975f45ff9c37165362
Gitweb: http://git.kernel.org/tip/7e298d60f717257dc8365c975f45ff9c37165362
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:45 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 22 Feb 2014 18:11:29 +0100
sched/prio: Use DEFAULT_PRIO to define NICE_TO_PRIO() and PRIO_TO_NICE()
There is already a macro named DEFAULT_PRIO in prio.h, we can use it
to define NICE_TO_PRIO and PRIO_TO_NICE rather than use hard coding
of (MAX_RT_PRIO + 20).
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/4e28ec36fb49e8906027cbbdd900ab26a149905e.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
include/linux/sched/prio.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 410ccb7..1ceaaa1 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -25,8 +25,8 @@
* to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
* and back.
*/
-#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
-#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
+#define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO)
+#define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO)
/*
* 'User priority' is the nice value converted to something we
Commit-ID: 3ee237dddcd885d4e525791299d62de33b2ca117
Gitweb: http://git.kernel.org/tip/3ee237dddcd885d4e525791299d62de33b2ca117
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:46 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 22 Feb 2014 18:14:13 +0100
sched/prio: Add 3 macros of MAX_NICE, MIN_NICE and NICE_WIDTH in prio.h
Currently there is lots of hard coding to 19 and -20, to represent
maximum and minimum of nice values.
This patch add three macros in prio.h for maximum, minimum and width
of nice value, and uses it to remove hardcoded values in prio.h.
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/3994e89327b2b15f992277cdf9f409c516f87d1b.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
[ Collapsed two small patches. ]
Signed-off-by: Ingo Molnar <[email protected]>
---
include/linux/sched/prio.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
index 1ceaaa1..ac32258 100644
--- a/include/linux/sched/prio.h
+++ b/include/linux/sched/prio.h
@@ -1,6 +1,10 @@
#ifndef _SCHED_PRIO_H
#define _SCHED_PRIO_H
+#define MAX_NICE 19
+#define MIN_NICE -20
+#define NICE_WIDTH (MAX_NICE - MIN_NICE + 1)
+
/*
* Priority of a process goes from 0..MAX_PRIO-1, valid RT
* priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
@@ -17,8 +21,8 @@
#define MAX_USER_RT_PRIO 100
#define MAX_RT_PRIO MAX_USER_RT_PRIO
-#define MAX_PRIO (MAX_RT_PRIO + 40)
-#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
+#define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH)
+#define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2)
/*
* Convert user-nice values [ -20 ... 0 ... 19 ]
Commit-ID: 75e45d512f257beedae0d8a67d053cde5537bd4c
Gitweb: http://git.kernel.org/tip/75e45d512f257beedae0d8a67d053cde5537bd4c
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:50 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 22 Feb 2014 18:15:54 +0100
sched: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/bd80780f19b4f9b4a765acc353c8dbc130274dd6.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/sched/auto_group.c | 2 +-
kernel/sched/core.c | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
index 4a07353..e73efba 100644
--- a/kernel/sched/auto_group.c
+++ b/kernel/sched/auto_group.c
@@ -203,7 +203,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
struct autogroup *ag;
int err;
- if (nice < -20 || nice > 19)
+ if (nice < MIN_NICE || nice > MAX_NICE)
return -EINVAL;
err = security_task_setnice(current, nice);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cc4965e..a8a73b8 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2993,7 +2993,7 @@ void set_user_nice(struct task_struct *p, long nice)
unsigned long flags;
struct rq *rq;
- if (task_nice(p) == nice || nice < -20 || nice > 19)
+ if (task_nice(p) == nice || nice < MIN_NICE || nice > MAX_NICE)
return;
/*
* We have to be careful, if called from sys_setpriority(),
@@ -3072,10 +3072,10 @@ SYSCALL_DEFINE1(nice, int, increment)
increment = 40;
nice = task_nice(current) + increment;
- if (nice < -20)
- nice = -20;
- if (nice > 19)
- nice = 19;
+ if (nice < MIN_NICE)
+ nice = MIN_NICE;
+ if (nice > MAX_NICE)
+ nice = MAX_NICE;
if (increment < 0 && !can_nice(current, nice))
return -EPERM;
@@ -3623,7 +3623,7 @@ static int sched_copy_attr(struct sched_attr __user *uattr,
* XXX: do we want to be lenient like existing syscalls; or do we want
* to be strict and return an error on out-of-bounds values?
*/
- attr->sched_nice = clamp(attr->sched_nice, -20, 19);
+ attr->sched_nice = clamp(attr->sched_nice, MIN_NICE, MAX_NICE);
out:
return ret;
Commit-ID: d277d868dab6537a85f4757e39648b1d6afc60d5
Gitweb: http://git.kernel.org/tip/d277d868dab6537a85f4757e39648b1d6afc60d5
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:49 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 22 Feb 2014 18:15:24 +0100
rcu: Use MAX_NICE to replace hardcoding of 19
Reviewed-by: Josh Triplett <[email protected]>
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Link: http://lkml.kernel.org/r/5b3bf232f41b33ab703a1595e94671b303e2d1fc.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/rcu/torture.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
index 732f8ae..219761d 100644
--- a/kernel/rcu/torture.c
+++ b/kernel/rcu/torture.c
@@ -805,7 +805,7 @@ rcu_torture_writer(void *arg)
static DEFINE_RCU_RANDOM(rand);
VERBOSE_PRINTK_STRING("rcu_torture_writer task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
schedule_timeout_uninterruptible(1);
@@ -871,7 +871,7 @@ rcu_torture_fakewriter(void *arg)
DEFINE_RCU_RANDOM(rand);
VERBOSE_PRINTK_STRING("rcu_torture_fakewriter task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
schedule_timeout_uninterruptible(1 + rcu_random(&rand)%10);
@@ -987,7 +987,7 @@ rcu_torture_reader(void *arg)
unsigned long long ts;
VERBOSE_PRINTK_STRING("rcu_torture_reader task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
if (irqreader && cur_ops->irq_capable)
setup_timer_on_stack(&t, rcu_torture_timer, 0);
@@ -1584,7 +1584,7 @@ static int rcu_torture_barrier_cbs(void *arg)
init_rcu_head_on_stack(&rcu);
VERBOSE_PRINTK_STRING("rcu_torture_barrier_cbs task started");
- set_user_nice(current, 19);
+ set_user_nice(current, MAX_NICE);
do {
wait_event(barrier_cbs_wq[myid],
(newphase =
Commit-ID: c4a4d2f43177f6165132c6d36a4d46963018f726
Gitweb: http://git.kernel.org/tip/c4a4d2f43177f6165132c6d36a4d46963018f726
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:51 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 22 Feb 2014 18:16:19 +0100
sys: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Stephen Rothwell <[email protected]>
Link: http://lkml.kernel.org/r/0261f094b836f1acbcdf52e7166487c0c77323c8.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/sys.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/sys.c b/kernel/sys.c
index c0a58be..adaeab6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -174,10 +174,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
/* normalize: avoid signed division (rounding problems) */
error = -ESRCH;
- if (niceval < -20)
- niceval = -20;
- if (niceval > 19)
- niceval = 19;
+ if (niceval < MIN_NICE)
+ niceval = MIN_NICE;
+ if (niceval > MAX_NICE)
+ niceval = MAX_NICE;
rcu_read_lock();
read_lock(&tasklist_lock);
Commit-ID: 144818422bfa272531250473b888394c21e6fe19
Gitweb: http://git.kernel.org/tip/144818422bfa272531250473b888394c21e6fe19
Author: Dongsheng Yang <[email protected]>
AuthorDate: Tue, 11 Feb 2014 15:34:52 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 22 Feb 2014 18:16:41 +0100
workqueue: Replace hardcoding of -20 and 19 with MIN_NICE and MAX_NICE
Signed-off-by: Dongsheng Yang <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/6d85138180c00ce86975addab6e34b24b84f00a5.1392103744.git.yangds.fnst@cn.fujitsu.com
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 193e977..3fa5b8f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3225,7 +3225,7 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
return -ENOMEM;
if (sscanf(buf, "%d", &attrs->nice) == 1 &&
- attrs->nice >= -20 && attrs->nice <= 19)
+ attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
ret = apply_workqueue_attrs(wq, attrs);
else
ret = -EINVAL;
On Sat, Feb 22, 2014 at 05:05:36PM +0800, Dongsheng Yang wrote:
> Hi Peter.
> It seems the all other patches in this set were all applied to tip
> except this one.
> What is the problem with the [9/9]? Is there any thing I can do?
The problem is that it never actually made it to my inbox; could you
verify that I was indeed on the recipient list? And if not resend it.
In case I was actually on the recipient list I need to go figure out
where it went.
On 02/24/2014 06:46 PM, Peter Zijlstra wrote:
> On Sat, Feb 22, 2014 at 05:05:36PM +0800, Dongsheng Yang wrote:
>> Hi Peter.
>> It seems the all other patches in this set were all applied to tip
>> except this one.
>> What is the problem with the [9/9]? Is there any thing I can do?
> The problem is that it never actually made it to my inbox; could you
> verify that I was indeed on the recipient list? And if not resend it.
Oh, yes. Sorry for that. I will resend it soon with ccing you.
>
> In case I was actually on the recipient list I need to go figure out
> where it went.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
Signed-off-by: Dongsheng Yang <[email protected]>
cc: Steven Rostedt <[email protected]>
cc: Frederic Weisbecker <[email protected]>
cc: Ingo Molnar <[email protected]>
cc: Peter Zijlstra <[email protected]>
---
kernel/trace/ring_buffer_benchmark.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index a5457d5..0434ff1 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -40,8 +40,8 @@ static int write_iteration = 50;
module_param(write_iteration, uint, 0644);
MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
-static int producer_nice = 19;
-static int consumer_nice = 19;
+static int producer_nice = MAX_NICE;
+static int consumer_nice = MAX_NICE;
static int producer_fifo = -1;
static int consumer_fifo = -1;
@@ -308,7 +308,7 @@ static void ring_buffer_producer(void)
/* Let the user know that the test is running at low priority */
if (producer_fifo < 0 && consumer_fifo < 0 &&
- producer_nice == 19 && consumer_nice == 19)
+ producer_nice == MAX_NICE && consumer_nice == MAX_NICE)
trace_printk("WARNING!!! This test is running at lowest priority.\n");
trace_printk("Time: %lld (usecs)\n", time);
--
1.8.2.1
On Mon, Feb 24, 2014 at 10:12:01PM +0800, Dongsheng Yang wrote:
> Signed-off-by: Dongsheng Yang <[email protected]>
"Use MAX_NICE instead of the value 19 for ring_buffer_benchmark."
> cc: Steven Rostedt <[email protected]>
> cc: Frederic Weisbecker <[email protected]>
> cc: Ingo Molnar <[email protected]>
> cc: Peter Zijlstra <[email protected]>
> ---
Thanks.
On Mon, 24 Feb 2014 22:12:01 +0800
Dongsheng Yang <[email protected]> wrote:
> Signed-off-by: Dongsheng Yang <[email protected]>
> cc: Steven Rostedt <[email protected]>
> cc: Frederic Weisbecker <[email protected]>
> cc: Ingo Molnar <[email protected]>
> cc: Peter Zijlstra <[email protected]>
Peter,
If you want to take this, you can add my Acked-by.
-- Steve
> ---
> kernel/trace/ring_buffer_benchmark.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
> index a5457d5..0434ff1 100644
> --- a/kernel/trace/ring_buffer_benchmark.c
> +++ b/kernel/trace/ring_buffer_benchmark.c
> @@ -40,8 +40,8 @@ static int write_iteration = 50;
> module_param(write_iteration, uint, 0644);
> MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
>
> -static int producer_nice = 19;
> -static int consumer_nice = 19;
> +static int producer_nice = MAX_NICE;
> +static int consumer_nice = MAX_NICE;
>
> static int producer_fifo = -1;
> static int consumer_fifo = -1;
> @@ -308,7 +308,7 @@ static void ring_buffer_producer(void)
>
> /* Let the user know that the test is running at low priority */
> if (producer_fifo < 0 && consumer_fifo < 0 &&
> - producer_nice == 19 && consumer_nice == 19)
> + producer_nice == MAX_NICE && consumer_nice == MAX_NICE)
> trace_printk("WARNING!!! This test is running at lowest priority.\n");
>
> trace_printk("Time: %lld (usecs)\n", time);
On Mon, Feb 24, 2014 at 09:29:34AM -0500, Steven Rostedt wrote:
> On Mon, 24 Feb 2014 22:12:01 +0800
> Dongsheng Yang <[email protected]> wrote:
>
> > Signed-off-by: Dongsheng Yang <[email protected]>
> > cc: Steven Rostedt <[email protected]>
> > cc: Frederic Weisbecker <[email protected]>
> > cc: Ingo Molnar <[email protected]>
> > cc: Peter Zijlstra <[email protected]>
>
> Peter,
>
> If you want to take this, you can add my Acked-by.
Done, thanks!
Commit-ID: 2b3942e4bb20ef8ef26515bd958c2df83d9a6210
Gitweb: http://git.kernel.org/tip/2b3942e4bb20ef8ef26515bd958c2df83d9a6210
Author: Dongsheng Yang <[email protected]>
AuthorDate: Mon, 24 Feb 2014 22:12:01 +0800
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 27 Feb 2014 12:41:03 +0100
trace: Replace hardcoding of 19 with MAX_NICE
Use MAX_NICE instead of the value 19 for ring_buffer_benchmark.
Signed-off-by: Dongsheng Yang <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Acked-by: Steven Rostedt <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
kernel/trace/ring_buffer_benchmark.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index a5457d5..0434ff1 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -40,8 +40,8 @@ static int write_iteration = 50;
module_param(write_iteration, uint, 0644);
MODULE_PARM_DESC(write_iteration, "# of writes between timestamp readings");
-static int producer_nice = 19;
-static int consumer_nice = 19;
+static int producer_nice = MAX_NICE;
+static int consumer_nice = MAX_NICE;
static int producer_fifo = -1;
static int consumer_fifo = -1;
@@ -308,7 +308,7 @@ static void ring_buffer_producer(void)
/* Let the user know that the test is running at low priority */
if (producer_fifo < 0 && consumer_fifo < 0 &&
- producer_nice == 19 && consumer_nice == 19)
+ producer_nice == MAX_NICE && consumer_nice == MAX_NICE)
trace_printk("WARNING!!! This test is running at lowest priority.\n");
trace_printk("Time: %lld (usecs)\n", time);