All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
To: Joe Perches <joe@perches.com>
Cc: linux-kernel@vger.kernel.org, fweisbec@gmail.com,
	rostedt@goodmis.org, peterz@infradead.org, mingo@redhat.com
Subject: Re: [PATCH] kernel/sys: Replace hardcoding of 20 with MAX_NICE + 1
Date: Tue, 11 Mar 2014 09:17:10 +0800	[thread overview]
Message-ID: <531E6416.6020106@cn.fujitsu.com> (raw)
In-Reply-To: <1394490222.21085.16.camel@joe-AO722>

Hi Joe,

On 03/11/2014 06:23 AM, Joe Perches wrote:
> Convert the use of 20 to NICE_MAX + 1.

What about adding a macro in prio.h to convert nice value [19,-20] to 
rlimit
style value [1,40]?

It seems that it will be used in several places.

- Dongsheng
>
> Reduce the indent the switch case labels while there.
>
> git diff -w shows 3 lines changed and a /* fall-through */ comment added
>
>    $ git diff -w -U0 kernel/sys.c
>    @@ -253 +253 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
>    -                               niceval = 20 - task_nice(p);
>    +                       niceval = MAX_NICE - task_nice(p) + 1;
>    @@ -264 +264 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
>    -                               niceval = 20 - task_nice(p);
>    +                       niceval = MAX_NICE - task_nice(p) + 1;
>    @@ -280 +280 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
>    -                                       niceval = 20 - task_nice(p);
>    +                               niceval = MAX_NICE - task_nice(p) + 1;
>    @@ -1558 +1558 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
>    -
>    +               /* fall-through */
>
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>   kernel/sys.c | 206 +++++++++++++++++++++++++++++------------------------------
>   1 file changed, 103 insertions(+), 103 deletions(-)
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index fba0f29..0bd5fe9 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -182,39 +182,39 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
>   	rcu_read_lock();
>   	read_lock(&tasklist_lock);
>   	switch (which) {
> -		case PRIO_PROCESS:
> -			if (who)
> -				p = find_task_by_vpid(who);
> -			else
> -				p = current;
> -			if (p)
> -				error = set_one_prio(p, niceval, error);
> -			break;
> -		case PRIO_PGRP:
> -			if (who)
> -				pgrp = find_vpid(who);
> -			else
> -				pgrp = task_pgrp(current);
> -			do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
> +	case PRIO_PROCESS:
> +		if (who)
> +			p = find_task_by_vpid(who);
> +		else
> +			p = current;
> +		if (p)
> +			error = set_one_prio(p, niceval, error);
> +		break;
> +	case PRIO_PGRP:
> +		if (who)
> +			pgrp = find_vpid(who);
> +		else
> +			pgrp = task_pgrp(current);
> +		do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
> +			error = set_one_prio(p, niceval, error);
> +		} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
> +		break;
> +	case PRIO_USER:
> +		uid = make_kuid(cred->user_ns, who);
> +		user = cred->user;
> +		if (!who)
> +			uid = cred->uid;
> +		else if (!uid_eq(uid, cred->uid) &&
> +			 !(user = find_user(uid)))
> +			goto out_unlock;	/* No processes for this user */
> +
> +		do_each_thread(g, p) {
> +			if (uid_eq(task_uid(p), uid))
>   				error = set_one_prio(p, niceval, error);
> -			} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
> -			break;
> -		case PRIO_USER:
> -			uid = make_kuid(cred->user_ns, who);
> -			user = cred->user;
> -			if (!who)
> -				uid = cred->uid;
> -			else if (!uid_eq(uid, cred->uid) &&
> -				 !(user = find_user(uid)))
> -				goto out_unlock;	/* No processes for this user */
> -
> -			do_each_thread(g, p) {
> -				if (uid_eq(task_uid(p), uid))
> -					error = set_one_prio(p, niceval, error);
> -			} while_each_thread(g, p);
> -			if (!uid_eq(uid, cred->uid))
> -				free_uid(user);		/* For find_user() */
> -			break;
> +		} while_each_thread(g, p);
> +		if (!uid_eq(uid, cred->uid))
> +			free_uid(user);		/* For find_user() */
> +		break;
>   	}
>   out_unlock:
>   	read_unlock(&tasklist_lock);
> @@ -244,47 +244,47 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
>   	rcu_read_lock();
>   	read_lock(&tasklist_lock);
>   	switch (which) {
> -		case PRIO_PROCESS:
> -			if (who)
> -				p = find_task_by_vpid(who);
> -			else
> -				p = current;
> -			if (p) {
> -				niceval = 20 - task_nice(p);
> +	case PRIO_PROCESS:
> +		if (who)
> +			p = find_task_by_vpid(who);
> +		else
> +			p = current;
> +		if (p) {
> +			niceval = MAX_NICE - task_nice(p) + 1;
> +			if (niceval > retval)
> +				retval = niceval;
> +		}
> +		break;
> +	case PRIO_PGRP:
> +		if (who)
> +			pgrp = find_vpid(who);
> +		else
> +			pgrp = task_pgrp(current);
> +		do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
> +			niceval = MAX_NICE - task_nice(p) + 1;
> +			if (niceval > retval)
> +				retval = niceval;
> +		} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
> +		break;
> +	case PRIO_USER:
> +		uid = make_kuid(cred->user_ns, who);
> +		user = cred->user;
> +		if (!who)
> +			uid = cred->uid;
> +		else if (!uid_eq(uid, cred->uid) &&
> +			 !(user = find_user(uid)))
> +			goto out_unlock;	/* No processes for this user */
> +
> +		do_each_thread(g, p) {
> +			if (uid_eq(task_uid(p), uid)) {
> +				niceval = MAX_NICE - task_nice(p) + 1;
>   				if (niceval > retval)
>   					retval = niceval;
>   			}
> -			break;
> -		case PRIO_PGRP:
> -			if (who)
> -				pgrp = find_vpid(who);
> -			else
> -				pgrp = task_pgrp(current);
> -			do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
> -				niceval = 20 - task_nice(p);
> -				if (niceval > retval)
> -					retval = niceval;
> -			} while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
> -			break;
> -		case PRIO_USER:
> -			uid = make_kuid(cred->user_ns, who);
> -			user = cred->user;
> -			if (!who)
> -				uid = cred->uid;
> -			else if (!uid_eq(uid, cred->uid) &&
> -				 !(user = find_user(uid)))
> -				goto out_unlock;	/* No processes for this user */
> -
> -			do_each_thread(g, p) {
> -				if (uid_eq(task_uid(p), uid)) {
> -					niceval = 20 - task_nice(p);
> -					if (niceval > retval)
> -						retval = niceval;
> -				}
> -			} while_each_thread(g, p);
> -			if (!uid_eq(uid, cred->uid))
> -				free_uid(user);		/* for find_user() */
> -			break;
> +		} while_each_thread(g, p);
> +		if (!uid_eq(uid, cred->uid))
> +			free_uid(user);		/* for find_user() */
> +		break;
>   	}
>   out_unlock:
>   	read_unlock(&tasklist_lock);
> @@ -1541,41 +1541,41 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
>   		return;
>   
>   	switch (who) {
> -		case RUSAGE_BOTH:
> -		case RUSAGE_CHILDREN:
> -			utime = p->signal->cutime;
> -			stime = p->signal->cstime;
> -			r->ru_nvcsw = p->signal->cnvcsw;
> -			r->ru_nivcsw = p->signal->cnivcsw;
> -			r->ru_minflt = p->signal->cmin_flt;
> -			r->ru_majflt = p->signal->cmaj_flt;
> -			r->ru_inblock = p->signal->cinblock;
> -			r->ru_oublock = p->signal->coublock;
> -			maxrss = p->signal->cmaxrss;
> -
> -			if (who == RUSAGE_CHILDREN)
> -				break;
> -
> -		case RUSAGE_SELF:
> -			thread_group_cputime_adjusted(p, &tgutime, &tgstime);
> -			utime += tgutime;
> -			stime += tgstime;
> -			r->ru_nvcsw += p->signal->nvcsw;
> -			r->ru_nivcsw += p->signal->nivcsw;
> -			r->ru_minflt += p->signal->min_flt;
> -			r->ru_majflt += p->signal->maj_flt;
> -			r->ru_inblock += p->signal->inblock;
> -			r->ru_oublock += p->signal->oublock;
> -			if (maxrss < p->signal->maxrss)
> -				maxrss = p->signal->maxrss;
> -			t = p;
> -			do {
> -				accumulate_thread_rusage(t, r);
> -			} while_each_thread(p, t);
> +	case RUSAGE_BOTH:
> +	case RUSAGE_CHILDREN:
> +		utime = p->signal->cutime;
> +		stime = p->signal->cstime;
> +		r->ru_nvcsw = p->signal->cnvcsw;
> +		r->ru_nivcsw = p->signal->cnivcsw;
> +		r->ru_minflt = p->signal->cmin_flt;
> +		r->ru_majflt = p->signal->cmaj_flt;
> +		r->ru_inblock = p->signal->cinblock;
> +		r->ru_oublock = p->signal->coublock;
> +		maxrss = p->signal->cmaxrss;
> +
> +		if (who == RUSAGE_CHILDREN)
>   			break;
> +		/* fall-through */
> +	case RUSAGE_SELF:
> +		thread_group_cputime_adjusted(p, &tgutime, &tgstime);
> +		utime += tgutime;
> +		stime += tgstime;
> +		r->ru_nvcsw += p->signal->nvcsw;
> +		r->ru_nivcsw += p->signal->nivcsw;
> +		r->ru_minflt += p->signal->min_flt;
> +		r->ru_majflt += p->signal->maj_flt;
> +		r->ru_inblock += p->signal->inblock;
> +		r->ru_oublock += p->signal->oublock;
> +		if (maxrss < p->signal->maxrss)
> +			maxrss = p->signal->maxrss;
> +		t = p;
> +		do {
> +			accumulate_thread_rusage(t, r);
> +		} while_each_thread(p, t);
> +		break;
>   
> -		default:
> -			BUG();
> +	default:
> +		BUG();
>   	}
>   	unlock_task_sighand(p, &flags);
>   
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>


  reply	other threads:[~2014-03-11  1:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-05 12:36 [PATCH 1/3] tracing: Use inline task_nice() to get rid of an open coded implementation of it Dongsheng Yang
2014-03-05 12:36 ` [PATCH 2/3] sched: Use clamp() and clamp_val() to make it more readable Dongsheng Yang
2014-03-05 15:17   ` Joe Perches
2014-03-05 15:26     ` Steven Rostedt
2014-03-05 15:29       ` Joe Perches
2014-03-05 12:36 ` [PATCH 3/3] sched/prio: Replace hardcoding of 40 with NICE_WIDTH Dongsheng Yang
2014-03-10 22:23   ` [PATCH] kernel/sys: Replace hardcoding of 20 with MAX_NICE + 1 Joe Perches
2014-03-11  1:17     ` Dongsheng Yang [this message]
2014-03-11  2:21       ` Joe Perches
2014-03-11  2:35         ` Dongsheng Yang
2014-03-11  5:04 ` [PATCH 1/3] tracing: Use inline task_nice() to get rid of an open coded implementation of it Dongsheng Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=531E6416.6020106@cn.fujitsu.com \
    --to=yangds.fnst@cn.fujitsu.com \
    --cc=fweisbec@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.