All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
To: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Cc: peterz@infradead.org, linux-kernel@vger.kernel.org,
	raistlin@linux.it, juri.lelli@gmail.com,
	clark.williams@gmail.com, mingo@redhat.com, rostedt@goodmis.org
Subject: Re: [PATCH 3/3 V2] sched: Implement task_nice as static inline function.
Date: Mon, 27 Jan 2014 22:27:55 -0500	[thread overview]
Message-ID: <52E723BB.9070100@cn.fujitsu.com> (raw)
In-Reply-To: <1390878045-7096-1-git-send-email-yangds.fnst@cn.fujitsu.com>

Peter, what about this version?

On 01/27/2014 10:00 PM, Dongsheng Yang wrote:
> As commit 0e0c0797 expose 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 implement it in linux/sched/sched.h as static inline function,
> saving the kernel stack and enhancing the performance.
>
> Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
> ---
>      Changelog:
>          - v1:
>              * leave the task_prio() in kernel/sched/core.c
>              * remove macro TASK_NICE and implement it as static inline
>                function in include/linux/sched.h.
>   include/linux/sched.h      | 11 ++++++++++-
>   include/linux/sched/prio.h |  1 -
>   kernel/sched/core.c        | 26 +++++++-------------------
>   kernel/sched/cputime.c     |  4 ++--
>   4 files changed, 19 insertions(+), 23 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index ba1b732..5b63361 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -2083,7 +2083,16 @@ static inline void sched_autogroup_exit(struct signal_struct *sig) { }
>   extern bool yield_to(struct task_struct *p, bool preempt);
>   extern void set_user_nice(struct task_struct *p, long nice);
>   extern int task_prio(const struct task_struct *p);
> -extern int task_nice(const struct task_struct *p);
> +/**
> + * task_nice - return the nice value of a given task.
> + * @p: the task in question.
> + *
> + * Return: The nice value [ -20 ... 0 ... 19 ].
> + */
> +static inline int task_nice(const struct task_struct *p)
> +{
> +	return PRIO_TO_NICE((p)->static_prio);
> +}
>   extern int can_nice(const struct task_struct *p, const int nice);
>   extern int task_curr(const struct task_struct *p);
>   extern int idle_cpu(int cpu);
> diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
> index 13216f1..410ccb7 100644
> --- a/include/linux/sched/prio.h
> +++ b/include/linux/sched/prio.h
> @@ -27,7 +27,6 @@
>    */
>   #define NICE_TO_PRIO(nice)	(MAX_RT_PRIO + (nice) + 20)
>   #define PRIO_TO_NICE(prio)	((prio) - MAX_RT_PRIO - 20)
> -#define TASK_NICE(p)		PRIO_TO_NICE((p)->static_prio)
>   
>   /*
>    * 'User priority' is the nice value converted to something we
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 7fea865..b2bc1db 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2998,7 +2998,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 < -20 || nice > 19)
>   		return;
>   	/*
>   	 * We have to be careful, if called from sys_setpriority(),
> @@ -3076,7 +3076,7 @@ SYSCALL_DEFINE1(nice, int, increment)
>   	if (increment > 40)
>   		increment = 40;
>   
> -	nice = TASK_NICE(current) + increment;
> +	nice = task_nice(current) + increment;
>   	if (nice < -20)
>   		nice = -20;
>   	if (nice > 19)
> @@ -3109,18 +3109,6 @@ int task_prio(const struct task_struct *p)
>   }
>   
>   /**
> - * task_nice - return the nice value of a given task.
> - * @p: the task in question.
> - *
> - * Return: The nice value [ -20 ... 0 ... 19 ].
> - */
> -int task_nice(const struct task_struct *p)
> -{
> -	return TASK_NICE(p);
> -}
> -EXPORT_SYMBOL(task_nice);
> -
> -/**
>    * idle_cpu - is a given cpu idle currently?
>    * @cpu: the processor in question.
>    *
> @@ -3319,7 +3307,7 @@ recheck:
>   	 */
>   	if (user && !capable(CAP_SYS_NICE)) {
>   		if (fair_policy(policy)) {
> -			if (attr->sched_nice < TASK_NICE(p) &&
> +			if (attr->sched_nice < task_nice(p) &&
>   			    !can_nice(p, attr->sched_nice))
>   				return -EPERM;
>   		}
> @@ -3343,7 +3331,7 @@ recheck:
>   		 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
>   		 */
>   		if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
> -			if (!can_nice(p, TASK_NICE(p)))
> +			if (!can_nice(p, task_nice(p)))
>   				return -EPERM;
>   		}
>   
> @@ -3383,7 +3371,7 @@ recheck:
>   	 * If not changing anything there's no need to proceed further:
>   	 */
>   	if (unlikely(policy == p->policy)) {
> -		if (fair_policy(policy) && attr->sched_nice != TASK_NICE(p))
> +		if (fair_policy(policy) && attr->sched_nice != task_nice(p))
>   			goto change;
>   		if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
>   			goto change;
> @@ -3835,7 +3823,7 @@ SYSCALL_DEFINE3(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
>   	else if (task_has_rt_policy(p))
>   		attr.sched_priority = p->rt_priority;
>   	else
> -		attr.sched_nice = TASK_NICE(p);
> +		attr.sched_nice = task_nice(p);
>   
>   	rcu_read_unlock();
>   
> @@ -7006,7 +6994,7 @@ void normalize_rt_tasks(void)
>   			 * Renice negative nice level userspace
>   			 * tasks back to 0:
>   			 */
> -			if (TASK_NICE(p) < 0 && p->mm)
> +			if (task_nice(p) < 0 && p->mm)
>   				set_user_nice(p, 0);
>   			continue;
>   		}
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 9994791..58624a6 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,
>   	p->utimescaled += cputime_scaled;
>   	account_group_user_time(p, cputime);
>   
> -	index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
> +	index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
>   
>   	/* Add user time to cpustat. */
>   	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,
>   	p->gtime += cputime;
>   
>   	/* Add guest time to cpustat. */
> -	if (TASK_NICE(p) > 0) {
> +	if (task_nice(p) > 0) {
>   		cpustat[CPUTIME_NICE] += (__force u64) cputime;
>   		cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime;
>   	} else {


  reply	other threads:[~2014-01-27 15:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-22 22:41 [PATCH] tracing: Use task_nice() in function __update_max_tr() to get the nice value of task Dongsheng Yang
2014-01-23  3:56 ` Steven Rostedt
2014-01-23  4:00   ` Steven Rostedt
2014-01-23 17:11     ` Dongsheng Yang
2014-01-23  8:26       ` Peter Zijlstra
2014-01-23 11:52         ` Steven Rostedt
2014-01-27 22:15           ` [PATCH 0/3] sched: Collect the bits about priority into a new header file, include/linux/sched/prio.h Dongsheng Yang
2014-01-27 15:45             ` Steven Rostedt
     [not found]               ` <CA+qeAOqW58894hGvCP0N0E-EUESfFPeqMmXUuhqxEZrRjDV97A@mail.gmail.com>
2014-01-28 16:06                 ` Steven Rostedt
2014-01-27 22:15             ` [PATCH 1/3] sched: Move the priority specific bits into a new header file Dongsheng Yang
2014-01-29  5:28               ` Namhyung Kim
2014-02-10  2:56                 ` Dongsheng Yang
2014-02-10 14:09                   ` Steven Rostedt
2014-02-11  1:10                     ` Dongsheng Yang
2014-02-10 13:30               ` [tip:sched/core] " tip-bot for Dongsheng Yang
2014-01-27 22:15             ` [PATCH 2/3] sched: Expose some macros related with priority Dongsheng Yang
2014-02-10 13:30               ` [tip:sched/core] sched: Expose some macros related to priority tip-bot for Dongsheng Yang
2014-01-27 22:15             ` [PATCH 3/3] sched: Implement task_nice and task_prio as static inline functions Dongsheng Yang
2014-01-27 10:32               ` Peter Zijlstra
2014-01-28  1:09                 ` Dongsheng Yang
2014-01-27 12:16                   ` Peter Zijlstra
2014-01-28  1:59                     ` Dongsheng Yang
2014-01-27 13:08                       ` Peter Zijlstra
2014-01-28  3:00                         ` [PATCH 3/3 V2] sched: Implement task_nice as static inline function Dongsheng Yang
2014-01-28  3:27                           ` Dongsheng Yang [this message]
2014-02-10 13:32                           ` [tip:sched/core] sched: Implement task_nice() " tip-bot for Dongsheng Yang
2014-01-23 21:43         ` [PATCH] tracing: Use task_nice() in function __update_max_tr() to get the nice value of task Dongsheng Yang
2014-02-11  3:19 ` 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=52E723BB.9070100@cn.fujitsu.com \
    --to=yangds.fnst@cn.fujitsu.com \
    --cc=clark.williams@gmail.com \
    --cc=juri.lelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=raistlin@linux.it \
    --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.