Hi,
I am encountering a bug when using the SCHED_FIFO scheduler for CPU fork and/or thread, setting the CPU where I want my fork to run, and trying to allocate memory for the cuda. Followed is a piece of program to reproduce the bug:
#define tryExit(var, msg) if(var != 0) {printf("-> %d <-\n",var); errno = var ; perror(msg);exit(EXIT_FAILURE); }
void child_func() {
int status = 0;
pid_t self = getpid();
struct sched_param sp;
sp.sched_priority = sched_get_priority_min(SCHED_FIFO);
status = sched_setscheduler(self, SCHED_FIFO, &sp);
tryExit(status, "child - sched_setscheduler ");
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset); // whatever number between 0-3
status = sched_setaffinity(self, sizeof(cpu_set_t), &cpuset);
tryExit(status, "child - sched_setaffinity(&attr,2)");
cout << "Start" << endl;
char *ptr;
cudaError_t cstatus = cudaHostAlloc((void**)&ptr, 12, cudaHostAllocMapped);
cout << cudaGetErrorString(cstatus) << endl;
cudaFreeHost(ptr);
}
int main(int argc, char** argv) {
pid_t child = fork();
if(child == 0) child_func();
int status = 0;
pid_t wpid;
while ((wpid = wait(&status)) > 0 || (wpid == -1 && errno == EINTR));
if(wpid == -1)
perror(strerror(errno));
return 0;
}
When running it, it hangs on the cudaHostAlloc, doing a htop I can see that the programme is running and its memory utilisation growing until there is no more memory available on the device.
If I remove the sched_setaffinity, it works. Or if I use an other scheduling policy, e.g. SCHED_RR, it works as well.
Could it be a driver bug? cuda bug? kernel bug?
Any ideas?