linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "T. Zhou" <t.s.zhou@hotmail.com>
To: byungchul.park@lge.com
Cc: mingo@kernel.org, peterz@infradead.org,
	linux-kernel@vger.kernel.org, yuyang.du@intel.com
Subject: Re: [PATCH] sched: sync with the cfs_rq when changing sched class
Date: Fri, 14 Aug 2015 20:59:02 +0800	[thread overview]
Message-ID: <BLU436-SMTP9799BE9F3CEDC9A77A29D2C07C0@phx.gbl> (raw)
In-Reply-To: <1439445355-24137-1-git-send-email-byungchul.park@lge.com>

Hi,

On Thu, Aug 13, 2015 at 02:55:55PM +0900, byungchul.park@lge.com wrote:
> +static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
> +{
> +	se->avg.last_update_time = cfs_rq->avg.last_update_time;
> +	cfs_rq->avg.load_avg += se->avg.load_avg;
> +	cfs_rq->avg.load_sum += se->avg.load_sum;
> +	cfs_rq->avg.util_avg += se->avg.util_avg;
> +	cfs_rq->avg.util_sum += se->avg.util_sum;
> +}

I see this function is used in enqueue_entity_load_avg() also.
In tip tree code, enqueue_entity_load_avg() uses cfs_rq_clock_task()
as se->last_update_time in migration condition.
Here, you use cfs_rq->avg.last_update_time as se->last_update_time.
If se->last_update_time is different, next decay may be different too.
Just from inspecting code, maybe some reasonable there?

Thanks
> +static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
> +{
> +	__update_load_avg(cfs_rq->avg.last_update_time, cpu_of(rq_of(cfs_rq)),
> +			&se->avg, se->on_rq * scale_load_down(se->load.weight),
> +			cfs_rq->curr == se, NULL);
> +
> +	cfs_rq->avg.load_avg =
> +		max_t(long, cfs_rq->avg.load_avg - se->avg.load_avg, 0);
> +	cfs_rq->avg.load_sum =
> +		max_t(s64, cfs_rq->avg.load_sum - se->avg.load_sum, 0);
> +	cfs_rq->avg.util_avg =
> +		max_t(long, cfs_rq->avg.util_avg - se->avg.util_avg, 0);
> +	cfs_rq->avg.util_sum =
> +		max_t(s32, cfs_rq->avg.util_sum - se->avg.util_sum, 0);
> +}
> +
>  /* Add the load generated by se into cfs_rq's load average */
>  static inline void
>  enqueue_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
> @@ -2717,27 +2742,20 @@ enqueue_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
>  	u64 now = cfs_rq_clock_task(cfs_rq);
>  	int migrated = 0, decayed;
>  
> -	if (sa->last_update_time == 0) {
> -		sa->last_update_time = now;
> +	if (sa->last_update_time == 0)
>  		migrated = 1;
> -	}
> -	else {
> +	else
>  		__update_load_avg(now, cpu_of(rq_of(cfs_rq)), sa,
> -			se->on_rq * scale_load_down(se->load.weight),
> -			cfs_rq->curr == se, NULL);
> -	}
> +				se->on_rq * scale_load_down(se->load.weight),
> +				cfs_rq->curr == se, NULL);
>  
>  	decayed = update_cfs_rq_load_avg(now, cfs_rq);
>  
>  	cfs_rq->runnable_load_avg += sa->load_avg;
>  	cfs_rq->runnable_load_sum += sa->load_sum;
>  
> -	if (migrated) {
> -		cfs_rq->avg.load_avg += sa->load_avg;
> -		cfs_rq->avg.load_sum += sa->load_sum;
> -		cfs_rq->avg.util_avg += sa->util_avg;
> -		cfs_rq->avg.util_sum += sa->util_sum;
> -	}
> +	if (migrated)
> +		attach_entity_load_avg(cfs_rq, se);
>  
>  	if (decayed || migrated)
>  		update_tg_load_avg(cfs_rq, 0);
> @@ -7911,17 +7929,7 @@ static void switched_from_fair(struct rq *rq, struct task_struct *p)
>  
>  #ifdef CONFIG_SMP
>  	/* Catch up with the cfs_rq and remove our load when we leave */
> -	__update_load_avg(cfs_rq->avg.last_update_time, cpu_of(rq), &se->avg,
> -		se->on_rq * scale_load_down(se->load.weight), cfs_rq->curr == se, NULL);
> -
> -	cfs_rq->avg.load_avg =
> -		max_t(long, cfs_rq->avg.load_avg - se->avg.load_avg, 0);
> -	cfs_rq->avg.load_sum =
> -		max_t(s64, cfs_rq->avg.load_sum - se->avg.load_sum, 0);
> -	cfs_rq->avg.util_avg =
> -		max_t(long, cfs_rq->avg.util_avg - se->avg.util_avg, 0);
> -	cfs_rq->avg.util_sum =
> -		max_t(s32, cfs_rq->avg.util_sum - se->avg.util_sum, 0);
> +	detach_entity_load_avg(cfs_rq, se);
>  #endif
>  }
>  
> @@ -7938,6 +7946,11 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p)
>  	 */
>  	se->depth = se->parent ? se->parent->depth + 1 : 0;
>  #endif
> +
> +#ifdef CONFIG_SMP
> +	/* synchronize task with its cfs_rq */
> +	attach_entity_load_avg(cfs_rq_of(&p->se), &p->se);
> +#endif
>  	if (!task_on_rq_queued(p))
>  		return;
>  
> @@ -8023,16 +8036,7 @@ static void task_move_group_fair(struct task_struct *p, int queued)
>  
>  #ifdef CONFIG_SMP
>  	/* synchronize task with its prev cfs_rq */
> -	if (!queued)
> -		__update_load_avg(cfs_rq->avg.last_update_time, cpu_of(rq_of(cfs_rq)),
> -				&se->avg, se->on_rq * scale_load_down(se->load.weight),
> -				cfs_rq->curr == se, NULL);
> -
> -	/* remove our load when we leave */
> -	cfs_rq->avg.load_avg = max_t(long, cfs_rq->avg.load_avg - se->avg.load_avg, 0);
> -	cfs_rq->avg.load_sum = max_t(s64, cfs_rq->avg.load_sum - se->avg.load_sum, 0);
> -	cfs_rq->avg.util_avg = max_t(long, cfs_rq->avg.util_avg - se->avg.util_avg, 0);
> -	cfs_rq->avg.util_sum = max_t(s32, cfs_rq->avg.util_sum - se->avg.util_sum, 0);
> +	detach_entity_load_avg(cfs_rq, se);
>  #endif
>  	set_task_rq(p, task_cpu(p));
>  	se->depth = se->parent ? se->parent->depth + 1 : 0;
> @@ -8042,11 +8046,7 @@ static void task_move_group_fair(struct task_struct *p, int queued)
>  
>  #ifdef CONFIG_SMP
>  	/* Virtually synchronize task with its new cfs_rq */
> -	p->se.avg.last_update_time = cfs_rq->avg.last_update_time;
> -	cfs_rq->avg.load_avg += p->se.avg.load_avg;
> -	cfs_rq->avg.load_sum += p->se.avg.load_sum;
> -	cfs_rq->avg.util_avg += p->se.avg.util_avg;
> -	cfs_rq->avg.util_sum += p->se.avg.util_sum;
> +	attach_entity_load_avg(cfs_rq, se);
>  #endif
>  }

-- 
Tao
--

  parent reply	other threads:[~2015-08-14 13:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-13  5:55 [PATCH] sched: sync with the cfs_rq when changing sched class byungchul.park
2015-08-12 22:41 ` Yuyang Du
2015-08-13  7:19   ` Byungchul Park
2015-08-13  2:30     ` Yuyang Du
2015-08-13  7:46 ` Peter Zijlstra
2015-08-13  8:21   ` Byungchul Park
2015-08-13  2:15     ` Yuyang Du
2015-08-13 10:56       ` Byungchul Park
2015-08-13 15:22       ` Peter Zijlstra
2015-08-13 23:20         ` Yuyang Du
2015-08-14  8:46           ` Peter Zijlstra
2015-08-15  6:52         ` Byungchul Park
2015-08-15  7:16           ` Byungchul Park
2015-08-13  8:42   ` Byungchul Park
2015-08-14 12:59 ` T. Zhou [this message]
2015-08-15  4:24   ` Byungchul Park
2015-08-15 12:34     ` T. Zhou

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=BLU436-SMTP9799BE9F3CEDC9A77A29D2C07C0@phx.gbl \
    --to=t.s.zhou@hotmail.com \
    --cc=byungchul.park@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yuyang.du@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).