1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

In split() release the lock before slow search stack copy

Once we have allocated our slave threads and we have removed
master from available threads we can safely remove the lock
so that the lenghty search stack copy operation will not
impact lock contention.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-01-25 14:06:35 +01:00
parent 0ff91e16da
commit c5858ff9ae

View file

@ -2950,7 +2950,6 @@ namespace {
assert(ActiveThreads > 1); assert(ActiveThreads > 1);
SplitPoint* splitPoint; SplitPoint* splitPoint;
int i;
lock_grab(&MPLock); lock_grab(&MPLock);
@ -2983,34 +2982,42 @@ namespace {
splitPoint->cpus = 1; splitPoint->cpus = 1;
splitPoint->pos = &p; splitPoint->pos = &p;
splitPoint->parentSstack = sstck; splitPoint->parentSstack = sstck;
for (i = 0; i < ActiveThreads; i++) for (int i = 0; i < ActiveThreads; i++)
splitPoint->slaves[i] = 0; splitPoint->slaves[i] = 0;
// Copy the tail of current search stack to the master thread Threads[master].idle = false;
memcpy(splitPoint->sstack[master] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
Threads[master].splitPoint = splitPoint; Threads[master].splitPoint = splitPoint;
// Make copies of the current position and search stack for each thread // Allocate available threads setting idle flag to false
for (i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint; i++) for (int i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint; i++)
if (thread_is_available(i, master)) if (thread_is_available(i, master))
{ {
memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack)); Threads[i].idle = false;
Threads[i].splitPoint = splitPoint; Threads[i].splitPoint = splitPoint;
splitPoint->slaves[i] = 1; splitPoint->slaves[i] = 1;
splitPoint->cpus++; splitPoint->cpus++;
} }
assert(splitPoint->cpus > 1);
// We can release the lock because master and slave threads are already booked
lock_release(&MPLock);
// Copy the tail of current search stack to the master thread
memcpy(splitPoint->sstack[master] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
// Tell the threads that they have work to do. This will make them leave // Tell the threads that they have work to do. This will make them leave
// their idle loop. // their idle loop. Also copy search stack tail for each slave thread.
for (i = 0; i < ActiveThreads; i++) for (int i = 0; i < ActiveThreads; i++)
{
if (i == master || splitPoint->slaves[i]) if (i == master || splitPoint->slaves[i])
{ {
Threads[i].workIsWaiting = true; Threads[i].workIsWaiting = true;
Threads[i].idle = false;
Threads[i].stop = false; Threads[i].stop = false;
} }
if (splitPoint->slaves[i])
lock_release(&MPLock); memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
}
// Everything is set up. The master thread enters the idle loop, from // Everything is set up. The master thread enters the idle loop, from
// which it will instantly launch a search, because its workIsWaiting // which it will instantly launch a search, because its workIsWaiting