Description
Currently qthreads just intercepts calls to sleep and basically does a qthread_yield until the sleep time is up. For highly parallel applications this doesn't hurt performance since the sleeping task won't run much. Unfortunately, for applications that aren't very parallel, the sleeping qthread performs a sort of busy waiting by continuously yielding and getting re-scheduled. This can fully utilize a CPU, and it'd be ideal if the qthread could get descheduled somehow and use minimal CPU.
It'd also be nice if there was an actual qt_sleep that we could call. Currently we duplicate the syscall sleep logic in our own chpl_task_sleep and it'd be preferable if there was a common routine that Chapel, other users, and the sycall interception routines could call.
In code -- the problem is that sleeping fully utilizes a CPU:
#include <assert.h>
#include <unistd.h>
#include "qthread/qthread.h"
static aligned_t taskSleep(void *arg) {
sleep(50);
}
int main() {
aligned_t ret;
assert(qthread_initialize() == 0);
qthread_fork(taskSleep, NULL, &ret);
qthread_readFF(NULL, &ret);
}
and ideally we'd like it to use minimal CPU.
This is a low priority item for us since it doesn't impact the performance of highly parallel applications. That said, this does make it really hard for users to write background/daemon sort of programs in Chapel. I don't have a clear sense of how this would be implemented though, and I can imagine that it could be pretty difficult/invasive.