Эх сурвалжийг харах

sched: account the BSP tick with the period it covered

sched_tick_bsp() charged the elapsed tick with timer_tick_ms() read
after wake_sleepers_locked().  When the idle process is current, waking
a sleeper calls smp_resched_wake(), which reprograms the PIT to 1 kHz
and sets tick_ms to 1 for the next interval, so every 10 ms idle tick
was charged as 1 ms of idle.  On a 2-CPU machine the BSP therefore
looked ~90% busy at rest: the process monitor's CPU card showed ~58%
while its process rows summed to ~8%.

Read the period at entry, before any wake-up can shorten it, and use it
for power_tick() and tick_decide_locked().  The AP path captures
c->tick_ms the same way.

Tested in QEMU: before, BSP idle_ticks advanced ~10% of the wall clock
and most tick time was charged to neither idle nor a process; after,
idle_ticks + process ticks equal the elapsed ticks, and the process app
with 1 CPU shows 14.4% busy against 13.8% summed over the rows.
Johannes Zellner 2 өдөр өмнө
parent
commit
15a0c3e30c
1 өөрчлөгдсөн 12 нэмэгдсэн , 5 устгасан
  1. 12 5
      kernel/sched.c

+ 12 - 5
kernel/sched.c

@@ -814,14 +814,20 @@ int sched_tick_bsp(void)
 {
 	struct cpu *c = this_cpu();
 	struct process *p;
-	unsigned int flags = sched_lock_acquire();
+	unsigned int flags, ms;
 	int r;
 
+	/* Read the period this tick covered before anything else: waking a
+	 * sleeper shortens the next period (smp_resched_wake() reprograms the
+	 * PIT and sets tick_ms to 1), and charging the elapsed tick with the
+	 * new value made every 10 ms idle tick look like 1 ms of idle. */
+	ms = timer_tick_ms();
+	flags = sched_lock_acquire();
 	thermal_tick();
 	p = c->current;
-	power_tick(p == c->idle, timer_tick_ms());
+	power_tick(p == c->idle, ms);
 	wake_sleepers_locked();
-	r = tick_decide_locked(c, p, 0, timer_tick_ms());
+	r = tick_decide_locked(c, p, 0, ms);
 	sched_lock_release(flags);
 	return r;
 }
@@ -833,12 +839,13 @@ int sched_tick_ap(void)
 	struct cpu *c = this_cpu();
 	struct process *p;
 	unsigned int flags = sched_lock_acquire();
+	unsigned int ms = c->tick_ms;
 	int r;
 
 	thermal_tick();
 	p = c->current;
-	power_tick(p == c->idle, c->tick_ms);
-	r = tick_decide_locked(c, p, 1, c->tick_ms);
+	power_tick(p == c->idle, ms);
+	r = tick_decide_locked(c, p, 1, ms);
 	if (!r && p == c->idle && c->tick_ms != 10) {
 		/* Entered idle without a schedule(): stretch this CPU's LAPIC
 		 * period so MWAIT can hold C2 for 10 ms. */