Skip to contentSkip to conversation

sched/pelt: Add UTIL_AVG_UNCHANGED flag for last_enqueued_diff

PATCH In review Xuewen Yan 3 participants 7 messages May 6, 2021 – May 7, 2021 Scheduler

lore
Share & tools
lore

Xuewen Yan

author
#0 lore raw

PATCH 1/1 sched/pelt: Add UTIL_AVG_UNCHANGED flag for last_enqueued_diff

From: Xuewen Yan <[email protected]>

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Fixes b89997aa88f0b sched/pelt: Fix task util_est update filtering
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index e5e457fa9dc8..94d77b4fa601 100644
@@ -3996,7 +3996,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
 	if (ue.enqueued & UTIL_AVG_UNCHANGED)
 		return;
 
-	last_enqueued_diff = ue.enqueued;
+	last_enqueued_diff = (ue.enqueued | UTIL_AVG_UNCHANGED);
 
 	/*
 	 * Reset EWMA on utilization increases, the moving average is used only
Signature · 1 line
2.29.0
#1 lore raw
Quoted 29 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Fixes b89997aa88f0b sched/pelt: Fix task util_est update filtering
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index e5e457fa9dc8..94d77b4fa601 100644
@@ -3996,7 +3996,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
 	if (ue.enqueued & UTIL_AVG_UNCHANGED)
 		return;
 
-	last_enqueued_diff = ue.enqueued;
+	last_enqueued_diff = (ue.enqueued | UTIL_AVG_UNCHANGED);
 
 	/*
 	 * Reset EWMA on utilization increases, the moving average is used only
Signature · 1 line
2.29.0

Hi,

We do indeed for the diff use the flag for the value updated and no flag for the value before the update. However, last_enqueued_diff is only used for the margin check which is an heuristic and is not an accurate value (~1%) and as we know we already loose the LSB in util_est, I'm not sure this is really necessary.

Signature · 1 line
Vincent
author
#2 lore raw

Hi

Quoted 34 lines · Vincent Donnefort
Quoted 27 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Fixes b89997aa88f0b sched/pelt: Fix task util_est update filtering
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -2
index e5e457fa9dc8..94d77b4fa601 100644
@@ -3996,7 +3996,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
      if (ue.enqueued & UTIL_AVG_UNCHANGED)
              return;
 
-     last_enqueued_diff = ue.enqueued;
+     last_enqueued_diff = (ue.enqueued | UTIL_AVG_UNCHANGED);
 
      /*
       * Reset EWMA on utilization increases, the moving average is used only
--
Quoted 2 lines

2.29.0

Hi,

Quoted 3 lines

We do indeed for the diff use the flag for the value updated and no flag for the value before the update. However, last_enqueued_diff is only used for the margin check which is an heuristic and is not an accurate value (~1%) and as we know

The last_enqueued_diff is compared with the UTIL_EST_MARGIN which is "1024/100 = 10",
and The LSB may cause ~10% error.

Quoted 1 line

we already loose the LSB in util_est, I'm not sure this is really necessary.

I'm also not very sure, maybe the calculation will be more rigorous with the flag?

Quoted 4 lines

--
Vincent

#3 lore raw
Quoted 10 lines · Xuewen Yan

Hi

Quoted 7 lines · Vincent Donnefort
Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Could we change the description here a bit? I don't think this is accurately explaning the issue. Would probably be interesting to mention that by not setting the flag, which is the LSB, we add +1 to the diff. This is therefore reducing slightly UTIL_EST_MARGIN.

Quoted 27 lines
Quoted 27 lines
Quoted 22 lines
Fixes b89997aa88f0b sched/pelt: Fix task util_est update filtering
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -2
index e5e457fa9dc8..94d77b4fa601 100644
@@ -3996,7 +3996,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
      if (ue.enqueued & UTIL_AVG_UNCHANGED)
              return;
 
-     last_enqueued_diff = ue.enqueued;
+     last_enqueued_diff = (ue.enqueued | UTIL_AVG_UNCHANGED);
 
      /*
       * Reset EWMA on utilization increases, the moving average is used only
--
Quoted 2 lines

2.29.0

Hi,

Quoted 6 lines
Quoted 3 lines

We do indeed for the diff use the flag for the value updated and no flag for the value before the update. However, last_enqueued_diff is only used for the margin check which is an heuristic and is not an accurate value (~1%) and as we know

The last_enqueued_diff is compared with the UTIL_EST_MARGIN which is "1024/100 = 10",
and The LSB may cause ~10% error.

I meant ~1% being the original margin. With the bit set, we would use 0.87% instead of 0.97%.

Quoted 7 lines
Quoted 1 line

we already loose the LSB in util_est, I'm not sure this is really necessary.

I'm also not very sure, maybe the calculation will be more rigorous with the flag?

Quoted 4 lines

--
Vincent

author
#4 lore raw
Quoted 9 lines · Vincent Donnefort
Quoted 7 lines · Xuewen Yan

Hi

Quoted 4 lines · Vincent Donnefort
Quoted 2 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Could we change the description here a bit? I don't think this is accurately explaning the issue. Would probably be interesting to mention that by not setting the flag, which is the LSB, we add +1 to the diff. This is therefore reducing slightly UTIL_EST_MARGIN.

ok, If you agree with this patch, I'll change it in V2.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 23 lines
Fixes b89997aa88f0b sched/pelt: Fix task util_est update filtering
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -2
index e5e457fa9dc8..94d77b4fa601 100644
@@ -3996,7 +3996,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
      if (ue.enqueued & UTIL_AVG_UNCHANGED)
              return;
 
-     last_enqueued_diff = ue.enqueued;
+     last_enqueued_diff = (ue.enqueued | UTIL_AVG_UNCHANGED);
 
      /*
       * Reset EWMA on utilization increases, the moving average is used only
--
Quoted 2 lines

2.29.0

Hi,

We do indeed for the diff use the flag for the value updated and no flag for the value before the update. However, last_enqueued_diff is only used for the margin check which is an heuristic and is not an accurate value (~1%) and as we know

Quoted 6 lines
Quoted 3 lines

The last_enqueued_diff is compared with the UTIL_EST_MARGIN which is "1024/100 = 10",
and The LSB may cause ~10% error.

I meant ~1% being the original margin. With the bit set, we would use 0.87% instead of 0.97%.

Because the within_margin() does not contain “=”, if the enqueued without the flag, the margin may be 0.97%(10/1024), with the flag, be 1.07%(11/1024) instead of 0.87% I think.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

we already loose the LSB in util_est, I'm not sure this is really necessary.

I'm also not very sure, maybe the calculation will be more rigorous with the flag?

Quoted 4 lines

--
Vincent

maintainer
#5 lore raw
Quoted 16 lines · Xuewen Yan
Quoted 13 lines · Vincent Donnefort
Quoted 10 lines · Xuewen Yan

Hi

Quoted 7 lines · Vincent Donnefort
Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Quoted 6 lines
Quoted 4 lines

Could we change the description here a bit? I don't think this is accurately explaning the issue. Would probably be interesting to mention that by not setting the flag, which is the LSB, we add +1 to the diff. This is therefore reducing slightly UTIL_EST_MARGIN.

ok, If you agree with this patch, I'll change it in V2.

Although the impact is not significant , it's worth having an accurate computation. So the patch makes sense to me. Please submit a v2

Quoted 49 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 23 lines
Fixes b89997aa88f0b sched/pelt: Fix task util_est update filtering
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -2
index e5e457fa9dc8..94d77b4fa601 100644
@@ -3996,7 +3996,7 @@ static inline void util_est_update(struct cfs_rq *cfs_rq,
      if (ue.enqueued & UTIL_AVG_UNCHANGED)
              return;
 
-     last_enqueued_diff = ue.enqueued;
+     last_enqueued_diff = (ue.enqueued | UTIL_AVG_UNCHANGED);
 
      /*
       * Reset EWMA on utilization increases, the moving average is used only
--
Quoted 2 lines

2.29.0

Hi,

We do indeed for the diff use the flag for the value updated and no flag for the value before the update. However, last_enqueued_diff is only used for the margin check which is an heuristic and is not an accurate value (~1%) and as we know

Quoted 6 lines
Quoted 3 lines

The last_enqueued_diff is compared with the UTIL_EST_MARGIN which is "1024/100 = 10",
and The LSB may cause ~10% error.

I meant ~1% being the original margin. With the bit set, we would use 0.87% instead of 0.97%.

Because the within_margin() does not contain “=”, if the enqueued without the flag, the margin may be 0.97%(10/1024), with the flag, be 1.07%(11/1024) instead of 0.87% I think.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

we already loose the LSB in util_est, I'm not sure this is really necessary.

I'm also not very sure, maybe the calculation will be more rigorous with the flag?

Quoted 4 lines

--
Vincent

author
#6 lore raw
Quoted 23 lines · Vincent Guittot
Quoted 21 lines · Xuewen Yan
Quoted 17 lines · Vincent Donnefort
Quoted 10 lines · Xuewen Yan

Hi

Quoted 7 lines · Vincent Donnefort
Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

The UTIL_AVG_UNCHANGED flag had been cleared when the task util changed. And the enqueued is equal to task_util with the flag, so it is better to add the UTIL_AVG_UNCHANGED flag for last_enqueued_diff.

Could we change the description here a bit? I don't think this is accurately explaning the issue. Would probably be interesting to mention that by not setting the flag, which is the LSB, we add +1 to the diff. This is therefore reducing slightly UTIL_EST_MARGIN.

Quoted 4 lines
Quoted 1 line

ok, If you agree with this patch, I'll change it in V2.

Although the impact is not significant , it's worth having an accurate computation. So the patch makes sense to me. Please submit a v2

Okay, I'll submit a v2 later.