Skip to contentSkip to conversation

tick/nohz: Make the idle_exittime update correctly

PATCH In review Yunfeng Ye 2 participants 7 messages Dec 5, 2020 – Feb 19, 2021 Nohz, dynticks support

lore
Share & tools
lore

Yunfeng Ye

author
#0 lore raw

PATCH 1/1 tick/nohz: Make the idle_exittime update correctly

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +1 -1
index 749ec2a583de..be2e5d772d50 100644
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;
 
 	sched_clock_idle_wakeup_event();
 }
@@ -901,7 +902,6 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
 	 * Cancel the scheduled timer and restore the tick
 	 */
 	ts->tick_stopped  = 0;
-	ts->idle_exittime = now;
 
 	tick_nohz_restart(ts, now);
 }
Signature · 1 line
2.18.4
author
#1 lore raw

PATCH 1/1 tick/nohz: Make the idle_exittime update correctly

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +1 -1
index 749ec2a583de..be2e5d772d50 100644
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;
 
 	sched_clock_idle_wakeup_event();
 }
@@ -901,7 +902,6 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
 	 * Cancel the scheduled timer and restore the tick
 	 */
 	ts->tick_stopped  = 0;
-	ts->idle_exittime = now;
 
 	tick_nohz_restart(ts, now);
 }
Signature · 1 line
2.18.4
#2 lore raw
Quoted 24 lines · Yunfeng Ye

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +0 -0
index 749ec2a583de..be2e5d772d50 100644

kernel/time/tick-sched.c static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) · line 594

Quoted 4 lines
kernel/time/tick-sched.c +1 -0
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;

This changes a bit the meaning of idle_exittime then since this is also called from idle interrupt entry.

__tick_nohz_idle_restart_tick() would be a better place.

Thanks.

Quoted 14 lines
kernel/time/tick-sched.c +0 -1
 	sched_clock_idle_wakeup_event();
 }
@@ -901,7 +902,6 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
 	 * Cancel the scheduled timer and restore the tick
 	 */
 	ts->tick_stopped  = 0;
-	ts->idle_exittime = now;
 
 	tick_nohz_restart(ts, now);
 }
Signature · 1 line
2.18.4
author
#3 lore raw
Quoted 33 lines · Frederic Weisbecker
Quoted 24 lines · Yunfeng Ye

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +0 -0
index 749ec2a583de..be2e5d772d50 100644

kernel/time/tick-sched.c static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) · line 594

Quoted 4 lines
kernel/time/tick-sched.c +1 -0
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;

This changes a bit the meaning of idle_exittime then since this is also called from idle interrupt entry.

Quoted 2 lines

__tick_nohz_idle_restart_tick() would be a better place.

So is it necessary to modify the comment "@idle_exittime: Time when the idle state was left" ?

On the other hand, if the patch "nohz: Update tick instead of restarting tick in tick_nohz_idle_exit()"
(https://www.spinics.net/lists/kernel/msg3747039.html ) applied, __tick_nohz_idle_restart_tick will not be called always, So is it put here also a better place?

Thanks.

Quoted 18 lines

Thanks.

Quoted 14 lines
kernel/time/tick-sched.c +0 -1
 	sched_clock_idle_wakeup_event();
 }
@@ -901,7 +902,6 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
 	 * Cancel the scheduled timer and restore the tick
 	 */
 	ts->tick_stopped  = 0;
-	ts->idle_exittime = now;
 
 	tick_nohz_restart(ts, now);
 }
Signature · 1 line
2.18.4

.

#4 lore raw
Quoted 36 lines · Yunfeng Ye
Quoted 33 lines · Frederic Weisbecker
Quoted 24 lines · Yunfeng Ye

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +0 -0
index 749ec2a583de..be2e5d772d50 100644

kernel/time/tick-sched.c static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) · line 594

Quoted 4 lines
kernel/time/tick-sched.c +1 -0
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;

This changes a bit the meaning of idle_exittime then since this is also called from idle interrupt entry.

Quoted 7 lines
Quoted 2 lines

__tick_nohz_idle_restart_tick() would be a better place.

So is it necessary to modify the comment "@idle_exittime: Time when the idle state was left" ?

On the other hand, if the patch "nohz: Update tick instead of restarting tick in tick_nohz_idle_exit()"
(https://www.spinics.net/lists/kernel/msg3747039.html ) applied, __tick_nohz_idle_restart_tick will not be called always, So is it put here also a better place?

Right but I need to re-order some code before. That's ok, I'll integrate this patch inside the changes.

Thanks.

author
#5 lore raw
Quoted 39 lines · Frederic Weisbecker
Quoted 38 lines · Yunfeng Ye
Quoted 35 lines · Frederic Weisbecker
Quoted 24 lines · Yunfeng Ye

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +0 -0
index 749ec2a583de..be2e5d772d50 100644

kernel/time/tick-sched.c static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) · line 594

Quoted 4 lines
kernel/time/tick-sched.c +1 -0
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;

This changes a bit the meaning of idle_exittime then since this is also called from idle interrupt entry.

__tick_nohz_idle_restart_tick() would be a better place.

Quoted 9 lines
Quoted 5 lines

So is it necessary to modify the comment "@idle_exittime: Time when the idle state was left" ?

On the other hand, if the patch "nohz: Update tick instead of restarting tick in tick_nohz_idle_exit()"
(https://www.spinics.net/lists/kernel/msg3747039.html ) applied, __tick_nohz_idle_restart_tick will not be called always, So is it put here also a better place?

Right but I need to re-order some code before. That's ok, I'll integrate this patch inside the changes.

Ok, thanks.

Quoted 3 lines

Thanks.
.

#6 lore raw
In reply to Yunfeng Ye
Quoted 32 lines · Yunfeng Ye

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured.

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

So move to tick_nohz_stop_idle() to make the idle_exittime update correctly.

---
 kernel/time/tick-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-sched.c +1 -0
index 749ec2a583de..be2e5d772d50 100644
@@ -591,6 +591,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now)
 {
 	update_ts_time_stats(smp_processor_id(), ts, now, NULL);
 	ts->idle_active = 0;
+	ts->idle_exittime = now;
 
 	sched_clock_idle_wakeup_event();
 }

kernel/time/tick-sched.c static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) · line 907

Quoted 7 lines
kernel/time/tick-sched.c +0 -1
@@ -901,7 +902,6 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
 	 * Cancel the scheduled timer and restore the tick
 	 */
 	ts->tick_stopped  = 0;
-	ts->idle_exittime = now;
 
 	tick_nohz_restart(ts, now);
 }

Hi,

I've edited and queued on top of latest changes, see below. I'll post it after the merge window.

---
From: Yunfeng Ye <[email protected]>
Date: Wed, 10 Feb 2021 00:08:54 +0100
Subject: [PATCH] tick/nohz: Update idle_exittime on actual idle exit

The idle_exittime field of tick_sched is used to record the time when the idle state was left. but currently the idle_exittime is updated in the function tick_nohz_restart_sched_tick(), which is not always in idle state when nohz_full is configured:

  tick_irq_exit
    tick_nohz_irq_exit
      tick_nohz_full_update_tick
        tick_nohz_restart_sched_tick
          ts->idle_exittime = now;

It's thus overwritten by mistake on nohz_full tick restart. Move the update to the appropriate idle exit path instead.

---
 kernel/time/tick-sched.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/time/tick-sched.c +1 -2
index 79796286a4ba..2907c762a8fe 100644
@@ -918,8 +918,6 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now)
 	 * Cancel the scheduled timer and restore the tick
 	 */
 	ts->tick_stopped  = 0;
-	ts->idle_exittime = now;
-
 	tick_nohz_restart(ts, now);
 }
 
@@ -1231,6 +1229,7 @@ static void tick_nohz_idle_update_tick(struct tick_sched *ts, ktime_t now)
 	else
 		tick_nohz_restart_sched_tick(ts, now);
 
+	ts->idle_exittime = now;
 	tick_nohz_account_idle_ticks(ts);
 }
 
Signature · 1 line
2.25.1