Skip to content

Commit a3a0df9

Browse files
committed
Set timer to a fixed interval
And remove a complex (and broken) formula. Indeed previous code was broken in case of TC with big time increments where available_time() was too similar to total time yielding to many time losses, so for instance: go wtime 2600 winc 2600 info nodes 4432770 time 2601 <-- time forfeit! maximum search time = 2530 ms available_time = 2300 ms For a reference and further details see: https://groups.google.com/forum/?fromgroups=#!topic/fishcooking/dCPAvQDcm2E Speed tested with bench disabling timer alltogheter vs timer set at max resolution, showed we have no speed regressions both in single core and when using all physical cores. No functional change.
1 parent e8f9447 commit a3a0df9

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

src/search.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ namespace {
5555
// Set to true to force running with one thread. Used for debugging
5656
const bool FakeSplit = false;
5757

58-
// This is the minimum interval in msec between two check_time() calls
59-
const int TimerResolution = 5;
60-
6158
// Different node types, used as template parameter
6259
enum NodeType { Root, PV, NonPV, SplitPointRoot, SplitPointPV, SplitPointNonPV };
6360

@@ -243,19 +240,12 @@ void Search::think() {
243240
Threads[i]->maxPly = 0;
244241

245242
Threads.sleepWhileIdle = Options["Idle Threads Sleep"];
246-
247-
// Set best timer interval to avoid lagging under time pressure. Timer is
248-
// used to check for remaining available thinking time.
249-
Threads.timer->msec =
250-
Limits.use_time_management() ? std::min(100, std::max(TimeMgr.available_time() / 16, TimerResolution)) :
251-
Limits.nodes ? 2 * TimerResolution
252-
: 100;
253-
243+
Threads.timer->run = true;
254244
Threads.timer->notify_one(); // Wake up the recurring timer
255245

256246
id_loop(RootPos); // Let's start searching !
257247

258-
Threads.timer->msec = 0; // Stop the timer
248+
Threads.timer->run = false; // Stop the timer
259249
Threads.sleepWhileIdle = true; // Send idle threads to sleep
260250

261251
if (Options["Write Search Log"])
@@ -1764,7 +1754,7 @@ void check_time() {
17641754
&& !Signals.failedLowAtRoot
17651755
&& elapsed > TimeMgr.available_time();
17661756

1767-
bool noMoreTime = elapsed > TimeMgr.maximum_time() - 2 * TimerResolution
1757+
bool noMoreTime = elapsed > TimeMgr.maximum_time() - 2 * TimerThread::Resolution
17681758
|| stillAtFirstMove;
17691759

17701760
if ( (Limits.use_time_management() && noMoreTime)

src/thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ void TimerThread::idle_loop() {
101101
mutex.lock();
102102

103103
if (!exit)
104-
sleepCondition.wait_for(mutex, msec ? msec : INT_MAX);
104+
sleepCondition.wait_for(mutex, run ? Resolution : INT_MAX);
105105

106106
mutex.unlock();
107107

108-
if (msec)
108+
if (run)
109109
check_time();
110110
}
111111
}

src/thread.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ struct MainThread : public Thread {
143143
};
144144

145145
struct TimerThread : public ThreadBase {
146-
TimerThread() : msec(0) {}
146+
TimerThread() : run(false) {}
147147
virtual void idle_loop();
148-
int msec;
148+
bool run;
149+
static const int Resolution = 5; // msec between two check_time() calls
149150
};
150151

151152

0 commit comments

Comments
 (0)