diff --git a/linux-user/main.c b/linux-user/main.c index 95b235eaaa8..ca11c948c54 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -641,6 +641,23 @@ int main(int argc, char **argv, char **envp) module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); + + cpu_set_t cpuset; + long ncpus; + int sched_cpu; + + srand(time(NULL) + getpid()); + + ncpus = sysconf(_SC_NPROCESSORS_ONLN); + sched_cpu = rand() % ncpus; + + CPU_ZERO(&cpuset); + CPU_SET(sched_cpu, &cpuset); + + if (sched_setaffinity(getpid(), sizeof(cpuset), &cpuset)) { + fprintf(stderr, "Warning: Unable to set CPU affinity\n"); + } + module_call_init(MODULE_INIT_QOM); envlist = envlist_create();