mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched: Improve the accuracy of sched_stat_wait statistics for rt and dl
@ 2024-03-22  8:15 Zhang Qiao
  2024-04-16  7:13 ` Zhang Qiao
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Qiao @ 2024-03-22  8:15 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel, qianjun.kernel, laoar.shao, Zhang Qiao

Where commit b9c88f752268 ("sched/fair: Improve the accuracy of
sched_stat_wait statistics") fixed a wrong scenairio for cfs schedstat.

This wrong scenario is also present for the RT task. For avoiding this
scenario, add wait_start check in __update_stats_wait_end();

Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
---
 kernel/sched/fair.c  |  9 ---------
 kernel/sched/stats.c | 11 ++++++++++-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 6a16129f9a5c..36c81fe0086b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1208,15 +1208,6 @@ update_stats_wait_end_fair(struct cfs_rq *cfs_rq, struct sched_entity *se)
 
 	stats = __schedstats_from_se(se);
 
-	/*
-	 * When the sched_schedstat changes from 0 to 1, some sched se
-	 * maybe already in the runqueue, the se->statistics.wait_start
-	 * will be 0.So it will let the delta wrong. We need to avoid this
-	 * scenario.
-	 */
-	if (unlikely(!schedstat_val(stats->wait_start)))
-		return;
-
 	if (entity_is_task(se))
 		p = task_of(se);
 
diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c
index 857f837f52cb..7077eb490c09 100644
--- a/kernel/sched/stats.c
+++ b/kernel/sched/stats.c
@@ -20,8 +20,17 @@ void __update_stats_wait_start(struct rq *rq, struct task_struct *p,
 void __update_stats_wait_end(struct rq *rq, struct task_struct *p,
 			     struct sched_statistics *stats)
 {
-	u64 delta = rq_clock(rq) - schedstat_val(stats->wait_start);
+	u64 delta;
 
+	/*
+	 * When the sched_schedstat changes from 0 to 1, some sched se
+	 * maybe already in the runqueue, the stats->wait_start will be 0.
+	 * So it will let the delta wrong. We need to avoid this scenario.
+	 */
+	if (unlikely(!schedstat_val(stats->wait_start)))
+		return;
+
+	delta = rq_clock(rq) - schedstat_val(stats->wait_start);
 	if (p) {
 		if (task_on_rq_migrating(p)) {
 			/*
-- 
2.18.0.huawei.25


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sched: Improve the accuracy of sched_stat_wait statistics for rt and dl
  2024-03-22  8:15 [PATCH] sched: Improve the accuracy of sched_stat_wait statistics for rt and dl Zhang Qiao
@ 2024-04-16  7:13 ` Zhang Qiao
  0 siblings, 0 replies; 2+ messages in thread
From: Zhang Qiao @ 2024-04-16  7:13 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel, qianjun.kernel, laoar.shao

ping.

在 2024/3/22 16:15, Zhang Qiao 写道:
> Where commit b9c88f752268 ("sched/fair: Improve the accuracy of
> sched_stat_wait statistics") fixed a wrong scenairio for cfs schedstat.
> 
> This wrong scenario is also present for the RT task. For avoiding this
> scenario, add wait_start check in __update_stats_wait_end();
> 
> Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
> ---
>  kernel/sched/fair.c  |  9 ---------
>  kernel/sched/stats.c | 11 ++++++++++-
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 6a16129f9a5c..36c81fe0086b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1208,15 +1208,6 @@ update_stats_wait_end_fair(struct cfs_rq *cfs_rq, struct sched_entity *se)
>  
>  	stats = __schedstats_from_se(se);
>  
> -	/*
> -	 * When the sched_schedstat changes from 0 to 1, some sched se
> -	 * maybe already in the runqueue, the se->statistics.wait_start
> -	 * will be 0.So it will let the delta wrong. We need to avoid this
> -	 * scenario.
> -	 */
> -	if (unlikely(!schedstat_val(stats->wait_start)))
> -		return;
> -
>  	if (entity_is_task(se))
>  		p = task_of(se);
>  
> diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c
> index 857f837f52cb..7077eb490c09 100644
> --- a/kernel/sched/stats.c
> +++ b/kernel/sched/stats.c
> @@ -20,8 +20,17 @@ void __update_stats_wait_start(struct rq *rq, struct task_struct *p,
>  void __update_stats_wait_end(struct rq *rq, struct task_struct *p,
>  			     struct sched_statistics *stats)
>  {
> -	u64 delta = rq_clock(rq) - schedstat_val(stats->wait_start);
> +	u64 delta;
>  
> +	/*
> +	 * When the sched_schedstat changes from 0 to 1, some sched se
> +	 * maybe already in the runqueue, the stats->wait_start will be 0.
> +	 * So it will let the delta wrong. We need to avoid this scenario.
> +	 */
> +	if (unlikely(!schedstat_val(stats->wait_start)))
> +		return;
> +
> +	delta = rq_clock(rq) - schedstat_val(stats->wait_start);
>  	if (p) {
>  		if (task_on_rq_migrating(p)) {
>  			/*
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-16  7:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22  8:15 [PATCH] sched: Improve the accuracy of sched_stat_wait statistics for rt and dl Zhang Qiao
2024-04-16  7:13 ` Zhang Qiao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®