Skip to content

Commit

Permalink
Revert "Refactor how ponyint_cpu_core_pause is called (#3989)"
Browse files Browse the repository at this point in the history
This reverts commit c63b8a7.

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.
  • Loading branch information
SeanTAllen committed Feb 20, 2022
1 parent 073bad6 commit b2bf395
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
45 changes: 24 additions & 21 deletions src/libponyrt/sched/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libponyrt/sched/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 1 addition & 3 deletions src/libponyrt/sched/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b2bf395

Please sign in to comment.