Thanks - unfortunately, I’ve already tried that method, and it doesn’t work reliably.
The magic code in that patch,
pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
is consistent with Apple’s scheduling guidelines, but I spent part of today messing with it, with the following results:
I tried adding this the pthread_set_qos_class_self_np call to the start of qemu_thread_start in util/qemu_thread_posix.c - which is definitely getting called, and seems to be the only thing that pthread_create creates - which is how qemu, as I understand it, is creating threads.
Results with -smp 4:
QOS_CLASS_USER_INTERACTIVE: No meaningful change from default behavior. Still lives on performance cores when in the foreground and utility cores in the background.
QOS_CLASS_USER_INITIATED: Definite improvements. Remains on the performance cores far, far longer when minimized, but will still shuttle over to the efficiency cores at some point. Remains on the performance cores for a short period with the screen locked, but still ends up on the efficiency cores after a while.
QOS_CLASS_UTILITY: Same general behavior as QOS_CLASS_USER_INITIATED, still moves to the efficiency cores.
QOS_CLASS_BACKGROUND: Runs purely on the efficiency cores. Performance sucks. However, if you were on a laptop and really didn’t want your VM to impact battery life, this might be useful.
Results with -smp 8:
QOS_CLASS_USER_INTERACTIVE: Hangs out on the performance cores for a while, including for a reasonable period of time (I got bored of waiting) when minimized. Still migrates off to the efficiency cores after the screen has been locked for a while.
QOS_CLASS_USER_INITIATED: Still moves to the efficiency cores, but takes longer when minimized. Remains on the performance cores for a while with screen lock, but eventually migrates over.
QOS_CLASS_UTILITY: Still migrates all threads to efficiency cores after being minimized for a while.
QOS_CLASS_BACKGROUND: Launches all 8 threads on the efficiency cores.
I’m still looking for some way to keep a VM on the performance cores, even with the screen locked, for long periods of time.
I was not aware of the default-TSO in some of the ARM cores, though - thanks! Very interesting!