Multi-threaded user program support?
Hi, all
I am wondering if there is any plan to support multi-threaded
program in QEMU. I find a patch [1] which adds i386-linux-user NPTL support, but I don't see it's merged back into the trunk. I don't know why. Is there any consideration or difficulty on multi-threaded support?
Thanks!
Regards,
chenwj
[1] http://patchwork.ozlabs.org/patch/31746/
Signature · 4 lines
Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667
Quoted 5 lines · 陳韋任
I am wondering if there is any plan to support multi-threaded program in QEMU. I find a patch [1] which adds i386-linux-user NPTL support, but I don't see it's merged back into the trunk. I don't know why. Is there any consideration or difficulty on multi-threaded support?
So there are a number of issues here. Firstly, x86 targets in particular are worse than others for multi-threaded user
mode: the patch you note is almost certainly not the only area that needs addressing. (Properly handling the x86 LOCK prefix by making sure we take a host mutex is very likely broken, for instance.) If you look in MAINTAINERS you'll see that the status of the x86 target is listed as "Odd Fixes", which is why it's behind some of the others. So it's really waiting for somebody to step forward and start reviewing patches, fixing bugs and generally give it a bit of love and attention :-)
More generally and not x86-specific, there are problems with the multithreaded user-mode support which I suspect exist because nobody has ever sat down and worked out a coherent design for it, including what might need to be thread-local and what locking is required. So the result is that it mostly works but if you stress it (by spawning lots of interacting threads, for instance) qemu can crash. Fixing this is harder and may involve tough decisions like choosing to sacrifice a few % of performance in order to get a design that doesn't have locking issues...
-- PMM
Quoted 5 lines
More generally and not x86-specific, there are problems with the multithreaded user-mode support which I suspect exist because nobody has ever sat down and worked out a coherent design for it, including what might need to be thread-local and what locking is required. So the result is that it mostly works but if you
You mean some QEMU data structures need to be thread-local or lock
protected in order to emulate guest multi-threaded program correctly?
Regards,
chenwj
Signature · 4 lines
Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667
Quoted 8 lines · 陳韋任
Quoted 5 lines
More generally and not x86-specific, there are problems with the multithreaded user-mode support which I suspect exist because nobody has ever sat down and worked out a coherent design for it, including what might need to be thread-local and what locking is required. So the result is that it mostly works but if you
You mean some QEMU data structures need to be thread-local or lock protected in order to emulate guest multi-threaded program correctly?
Approximately, yes (the third option being "redesign the data structure so it can be sensibly protected"). See
https://bugs.launchpad.net/qemu/+bug/668799 for discussion of one example.
None of this is impossibly difficult; it just requires that somebody sits down and actually works through the problems and fixes them.
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 6 lines · 陳韋任
Quoted 5 lines
More generally and not x86-specific, there are problems with the multithreaded user-mode support which I suspect exist because nobody has ever sat down and worked out a coherent design for it, including what might need to be thread-local and what locking is required. So the result is that it mostly works but if you
Quoted 7 lines
Quoted 2 lines
You mean some QEMU data structures need to be thread-local or lock
protected in order to emulate guest multi-threaded program correctly?Approximately, yes (the third option being "redesign the data structure so it can be sensibly protected"). See
https://bugs.launchpad.net/qemu/+bug/668799 for discussion of one example.
I suspect that to make things tractable for i386, which has so many LOCKable instructions, that we'll also have to implement at least a compare-and-swap primitive in TCG.
r~
Quoted 6 lines
So there are a number of issues here. Firstly, x86 targets in particular are worse than others for multi-threaded user
mode: the patch you note is almost certainly not the only area that needs addressing. (Properly handling the x86 LOCK prefix by making sure we take a host mutex is very likely broken, for instance.) If you look inMAINTAINERSyou'll see
Just to be curious. *If* QEMU support multithreaded user
program, would the different memory (coherence/consistency) model between guest and host architecture become a problem?
Regards,
chenwj
Signature · 4 lines
Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667