[Skiboot] [PATCH 26/34] time: Setup DEC and call cpu_idle() in time_wait_nopoll()

Benjamin Herrenschmidt benh at kernel.crashing.org
Sun Jul 24 09:27:20 AEST 2016


This will currently do nothing more than spin but will eventually
allow us to nap until the decrementer fires.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
 core/timebase.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/core/timebase.c b/core/timebase.c
index 152bc2f..24511c6 100644
--- a/core/timebase.c
+++ b/core/timebase.c
@@ -68,14 +68,27 @@ void time_wait(unsigned long duration)
 void time_wait_nopoll(unsigned long duration)
 {
 	unsigned long end = mftb() + duration;
+	unsigned long min = usecs_to_tb(10);
 
 	if (this_cpu()->tb_invalid) {
 		cpu_relax();
 		return;
 	}
 
-	while(tb_compare(mftb(), end) != TB_AAFTERB)
-		cpu_relax();
+	for (;;) {
+		uint64_t delay, tb = mftb();
+
+		if (tb_compare(tb, end) == TB_AAFTERB)
+			break;
+		delay = end - tb;
+		if (delay >= 0x7fffffff)
+			delay = 0x7fffffff;
+		if (delay >= min) {
+			mtspr(SPR_DEC, delay);
+			cpu_idle(cpu_wake_on_dec);
+		} else
+			cpu_relax();
+	}
 }
 
 void time_wait_ms(unsigned long ms)
-- 
2.7.4



More information about the Skiboot mailing list