From b2bf3950f2c14ff1b9b2113849cb749627243724 Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Sat, 19 Feb 2022 20:27:14 -0500 Subject: [PATCH] Revert "Refactor how ponyint_cpu_core_pause is called (#3989)" This reverts commit c63b8a78be17b5bffcafdd15bb6fbd58be736295. This actually did change runtime behavior slightly. Ooops. Bad me for not seeing that originally. The change has brought some racy behavior with Windows to the fore so I'm going to revert this. --- src/libponyrt/sched/cpu.c | 45 ++++++++++++++++++--------------- src/libponyrt/sched/cpu.h | 2 +- src/libponyrt/sched/scheduler.c | 4 +-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/libponyrt/sched/cpu.c b/src/libponyrt/sched/cpu.c index 6a517b64ea..a35d6ea22c 100644 --- a/src/libponyrt/sched/cpu.c +++ b/src/libponyrt/sched/cpu.c @@ -317,7 +317,7 @@ void ponyint_cpu_affinity(uint32_t cpu) /** * Only nanosleep if sufficient cycles have elapsed. */ -void ponyint_cpu_core_pause(uint64_t tsc, uint64_t tsc2) +void ponyint_cpu_core_pause(uint64_t tsc, uint64_t tsc2, bool yield) { uint64_t diff = ponyint_cpu_tick_diff(tsc, tsc2); @@ -331,39 +331,42 @@ void ponyint_cpu_core_pause(uint64_t tsc, uint64_t tsc2) struct timespec ts = {0, 0}; #endif - // A billion cycles is roughly half a second, depending on clock speed. - if(diff > 10000000000) + if(yield) { - // If it has been 10 billion cycles, pause 30 ms. + // A billion cycles is roughly half a second, depending on clock speed. + if(diff > 10000000000) + { + // If it has been 10 billion cycles, pause 30 ms. #ifdef PLATFORM_IS_WINDOWS - ts = 30; + ts = 30; #else - ts.tv_nsec = 30000000; + ts.tv_nsec = 30000000; #endif - } else if(diff > 3000000000) { - // If it has been 3 billion cycles, pause 10 ms. + } else if(diff > 3000000000) { + // If it has been 3 billion cycles, pause 10 ms. #ifdef PLATFORM_IS_WINDOWS - ts = 10; + ts = 10; #else - ts.tv_nsec = 10000000; + ts.tv_nsec = 10000000; #endif - } else if(diff > 1000000000) { - // If it has been 1 billion cycles, pause 1 ms. + } else if(diff > 1000000000) { + // If it has been 1 billion cycles, pause 1 ms. #ifdef PLATFORM_IS_WINDOWS - ts = 1; + ts = 1; #else - ts.tv_nsec = 1000000; + ts.tv_nsec = 1000000; #endif - } - else - { + } + else + { #ifdef PLATFORM_IS_WINDOWS - // Otherwise, pause for 1 ms (minimum on windows) - ts = 1; + // Otherwise, pause for 1 ms (minimum on windows) + ts = 1; #else - // Otherwise, pause for 100 microseconds - ts.tv_nsec = 100000; + // Otherwise, pause for 100 microseconds + ts.tv_nsec = 100000; #endif + } } #ifdef PLATFORM_IS_WINDOWS diff --git a/src/libponyrt/sched/cpu.h b/src/libponyrt/sched/cpu.h index 4eb9bc263a..f29f8ea67f 100644 --- a/src/libponyrt/sched/cpu.h +++ b/src/libponyrt/sched/cpu.h @@ -17,7 +17,7 @@ uint32_t ponyint_cpu_assign(uint32_t count, scheduler_t* scheduler, void ponyint_cpu_affinity(uint32_t cpu); -void ponyint_cpu_core_pause(uint64_t tsc, uint64_t tsc2); +void ponyint_cpu_core_pause(uint64_t tsc, uint64_t tsc2, bool yield); void ponyint_cpu_relax(); diff --git a/src/libponyrt/sched/scheduler.c b/src/libponyrt/sched/scheduler.c index 3a5275c779..0705415b69 100644 --- a/src/libponyrt/sched/scheduler.c +++ b/src/libponyrt/sched/scheduler.c @@ -429,9 +429,7 @@ static bool quiescent(scheduler_t* sched, uint64_t tsc, uint64_t tsc2) } } - if (use_yield) - ponyint_cpu_core_pause(tsc, tsc2); - + ponyint_cpu_core_pause(tsc, tsc2, use_yield); return false; }