From 591b683a255792e3ede0fa304ff89dfb6d6c3496 Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Tue, 30 Sep 2014 12:59:22 +0930 Subject: core: make time_wait call pollers if on boot CPU Instead of running the pollers flat out, instead call them once every 5ms. This helps in situations where pollers are taking locks that are also taken by tasks completing on other CPUs. The 5ms time is arbitrary; it was chosen such that most callers of time_wait will call the pollers at least twice. Signed-off-by: Joel Stanley Signed-off-by: Benjamin Herrenschmidt --- core/timebase.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/timebase.c b/core/timebase.c index fb46bcf..7e3345f 100644 --- a/core/timebase.c +++ b/core/timebase.c @@ -18,15 +18,31 @@ #include #include -void time_wait(unsigned long duration) +static void time_wait_poll(unsigned long duration) { + unsigned long remaining = duration; unsigned long end = mftb() + duration; + unsigned long period = msecs_to_tb(5); + + while (tb_compare(mftb(), end) != TB_AAFTERB) { + /* Call pollers periodically but not continually to avoid + * bouncing cachelines due to lock contention. */ + if (remaining >= period) { + opal_run_pollers(); + time_wait_nopoll(period); + remaining -= period; + } - while(tb_compare(mftb(), end) != TB_AAFTERB) { - opal_run_pollers(); cpu_relax(); - } + } +} +void time_wait(unsigned long duration) +{ + if (this_cpu() != boot_cpu) + time_wait_nopoll(duration); + else + time_wait_poll(duration); } void time_wait_nopoll(unsigned long duration) -- cgit v1.1