Skip to content

gpuserver: named semaphore to fix 100% idle CPU from sched_yield()#6

Open
antonvnv wants to merge 1 commit into
pskvins:masterfrom
antonvnv:gpusem-for-pskvins
Open

gpuserver: named semaphore to fix 100% idle CPU from sched_yield()#6
antonvnv wants to merge 1 commit into
pskvins:masterfrom
antonvnv:gpusem-for-pskvins

Conversation

@antonvnv
Copy link
Copy Markdown

The previous busy-wait loop used sched_yield(), which yields the thread's timeslice but immediately reschedules it if no other thread is waiting on the same core. On a machine with enough cores (typical for GPU servers), the OS has no reason to deschedule the thread, so it spins at 100% CPU while idle.

Replace with POSIX named semaphore so gpuserver blocks in sem_wait() and uses ~0% CPU when idle. sem_wait() uses an in-kernel futex, so the thread sleeps without context switches until the client posts.

Add GPUSharedMemorySem class to GpuUtil.h that owns the sem_t* internally; call sites are ifdef-free.

USE_GPU_SEM is automatically enabled when ENABLE_CUDA=1 in cmake. Disable with -DUSE_GPU_SEM=OFF.

The previous busy-wait loop used sched_yield(), which yields the
thread's timeslice but immediately reschedules it if no other thread
is waiting on the same core. On a machine with enough cores (typical
for GPU servers), the OS has no reason to deschedule the thread, so
it spins at 100% CPU while idle.

Replace with POSIX named semaphore so gpuserver blocks in sem_wait()
and uses ~0% CPU when idle. sem_wait() uses an in-kernel futex, so
the thread sleeps without context switches until the client posts.

Add GPUSharedMemorySem class to GpuUtil.h that owns the sem_t*
internally; call sites are ifdef-free.

USE_GPU_SEM is automatically enabled when ENABLE_CUDA=1 in cmake.
Disable with -DUSE_GPU_SEM=OFF.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant