Skip to contentSkip to conversation

global_mutex and multithread.

Qemu-devel Frederic Konrad 6 participants 22 messages Jan 15, 2015 – Jan 16, 2015

lore
Share & tools
lore
#0 lore raw

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex? We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

Thanks,
Fred

#1 lore raw
Quoted 3 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?

It shouldn't need any changes I think. You're basically bringing TCG into line with what KVM already has -- one thread per guest CPU; and qemu_global_mutex already works fine in that model.

-- PMM

#2 lore raw
Quoted 9 lines · Peter Maydell
Quoted 3 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?

It shouldn't need any changes I think. You're basically bringing TCG into line with what KVM already has -- one thread per guest CPU; and qemu_global_mutex already works fine in that model.

-- PMM

Hi Peter,

Thanks for your reply.
True that makes sense, I still think we need to synchronize vcpu when they exit?

Fred

#3 lore raw
In reply to Frederic Konrad
Quoted 6 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

And later on, once devices start being converted to run outside the BQL, that can be changed to use new functions address_space_rw_unlocked / io_mem_read_unlocked / io_mem_write_unlocked. Something like that is already visible at https://github.com/bonzini/qemu/commits/rcu (ignore patches after "kvm: Switch to unlocked MMIO").

Paolo

#4 lore raw
In reply to Frederic Konrad

[now with correct listserver address]

Quoted 8 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

And later on, once devices start being converted to run outside the BQL, that can be changed to use new functions address_space_rw_unlocked / io_mem_read_unlocked / io_mem_write_unlocked. Something like that is already visible at https://github.com/bonzini/qemu/commits/rcu (ignore patches after "kvm: Switch to unlocked MMIO").

Paolo

#5 lore raw
Quoted 18 lines · Paolo Bonzini

[now with correct listserver address]

Quoted 8 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

Quoted 7 lines

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

You'll have a similar problem for tb_flush() if you use a single tb cache. Just introduce a big hammer function for now that IPIs all the other threads, waits until they halted, do the atomic instruction (like change the memory map or flush the tb cache), then let them continue.

We can later one-by-one get rid of all callers of this.

Alex

#6 lore raw
Quoted 9 lines · Alexander Graf
Quoted 5 lines
Quoted 5 lines

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

You'll have a similar problem for tb_flush() if you use a single tb cache. Just introduce a big hammer function for now that IPIs all the other threads, waits until they halted, do the atomic instruction (like change the memory map or flush the tb cache), then let them continue.

For the memory map I played with just using cpu_interrupt instead of waiting for the halt of the other CPUs. That's safe for 1 VCPU thread, but not for >1 thread. Perhaps we can exit the other CPUs with a signal and cpu_resume_from_signal.

Paolo

#7 lore raw
In reply to Alexander Graf
Quoted 31 lines · Alexander Graf
Quoted 17 lines · Paolo Bonzini

[now with correct listserver address]

Quoted 8 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

Quoted 7 lines

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

You'll have a similar problem for tb_flush() if you use a single tb cache. Just introduce a big hammer function for now that IPIs all the other threads, waits until they halted, do the atomic instruction (like change the memory map or flush the tb cache), then let them continue.

Quoted 4 lines

We can later one-by-one get rid of all callers of this.

Alex

Maybe we can put a flag in the tb to say it's being executed so tb_alloc won't try to realloc it?

Maybe it's a bad idea and will be actually slower than exiting and waiting all the other cpu.

Fred

#8 lore raw

I think we call that flag “please dont reallocate this TB until at least after a CPU has exited and we do a global flush”… So if we sync and get all cpu’s to exit on a global flush, this flag is only there as a figment of our imagination… e.g. we’re safe without it?

Wish I could say the same of global_mutex :-(

Cheers

Mark.

Quoted 37 lines · Frederic Konrad
Quoted 34 lines · Alexander Graf
Quoted 17 lines · Paolo Bonzini

[now with correct listserver address]

Quoted 8 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

Quoted 7 lines

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

You'll have a similar problem for tb_flush() if you use a single tb cache. Just introduce a big hammer function for now that IPIs all the other threads, waits until they halted, do the atomic instruction (like change the memory map or flush the tb cache), then let them continue.

We can later one-by-one get rid of all callers of this.

Quoted 8 lines
Quoted 1 line

Alex

Maybe we can put a flag in the tb to say it's being executed so tb_alloc won't try to realloc it?

Maybe it's a bad idea and will be actually slower than exiting and waiting all the other cpu.

Fred

	 +44 (0)20 7100 3485 x 210

+33 (0)5 33 52 01 77x 210

	+33 (0)603762104
	mark.burton
#9 lore raw
In reply to Paolo Bonzini
Quoted 25 lines · Paolo Bonzini

[now with correct listserver address]

Quoted 8 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

Quoted 10 lines

And later on, once devices start being converted to run outside the BQL, that can be changed to use new functions address_space_rw_unlocked / io_mem_read_unlocked / io_mem_write_unlocked. Something like that is already visible at https://github.com/bonzini/qemu/commits/rcu (ignore patches after "kvm: Switch to unlocked MMIO").

Paolo

Hi Paolo,

Thanks for the reply.

As I understand the idea of Jan is to unlock the global_mutex during tcg execution. Is that right?
So that means it's currently not the case and we won't be able to run two TCG threads at the same time?

About the RCU, is there a lot of device which change the memory map?

Thanks,
Fred

#10 lore raw
Quoted 10 lines · Frederic Konrad

Thanks for the reply.

As I understand the idea of Jan is to unlock the global_mutex during tcg execution.
Is that right?
So that means it's currently not the case and we won't be able to run two TCG
threads at the same time?

Yes.

Quoted 1 line

About the RCU, is there a lot of device which change the memory map?

All PCI devices (when you program their BARs), but apart from that not much. As a first approximation, the patches on github which use CPU_INTERRUPT_TLBFLUSH should work even for multiple TCG threads.

I'll clean them up a bit further so that CPU_INTERRUPT_TLBFLUSH is used for CPUs other than the running one; the running CPU instead uses tlb_flush directly.

If anyone can sum up how cpu_resume_from_signal works, that would also be helpful.

Paolo

#11 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Frederic Konrad

Thanks for the reply.

As I understand the idea of Jan is to unlock the global_mutex during tcg execution.
Is that right?
So that means it's currently not the case and we won't be able to run two TCG
threads at the same time?

Quoted 6 lines

Yes.

Quoted 1 line

About the RCU, is there a lot of device which change the memory map?

All PCI devices (when you program their BARs), but apart from that not much. As a first approximation, the patches on github which use CPU_INTERRUPT_TLBFLUSH should work even for multiple TCG threads.

Ok that makes sense. Thanks!

Fred

PS: Any idea why listserver is dropped from listserver.greensocs.com?

Quoted 9 lines

I'll clean them up a bit further so that CPU_INTERRUPT_TLBFLUSH is used for CPUs other than the running one; the running CPU instead uses tlb_flush directly.

If anyone can sum up how cpu_resume_from_signal works, that would also be helpful.

Paolo

#12 lore raw
Quoted 1 line · Frederic Konrad

PS: Any idea why listserver is dropped from listserver.greensocs.com?

Paolo's mail client apparently has a bizarre allergy to the correct address...

-- PMM

#13 lore raw
In reply to Paolo Bonzini

Still in agony on this issue - I’ve CC’d Jan as his patch looks important…

the patch below would seem to offer by far and away the best result here. (If only we could get it working ;-) )
it allows threads to proceed as we want them to, it means we dont have to ‘count’ the number of CPU’s that are executing code (and could therefor potentially access IO space)…

However - if we go this route -the current patch is only for x86. (apart from the fact that we still seem to land in a deadlock…)

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

(It would help - I think - if we understood why you believed this patch wouldn’t work with SMP - I thought that was to do with the ‘round-robin’ mechanism - we’ve removed that for multi-thread anyway - but I guess we may have missed something there?)

Cheers

Mark.

Quoted 28 lines · Paolo Bonzini

[now with correct listserver address]

Quoted 8 lines · Frederic Konrad

Hi everybody,

In case of multithread TCG what is the best way to handle qemu_global_mutex?
We though to have one mutex per vcpu and then synchronize vcpu threads when they exit (eg: in tcg_exec_all).

Is that making sense?

The basic ideas from Jan's patch in
http://article.gmane.org/gmane.comp.emulators.qemu/118807 still apply.

RAM block reordering doesn't exist anymore, having been replaced with mru_block.

The patch reacquired the lock when entering MMIO or PIO emulation. That's enough while there is only one VCPU thread.

Once you have >1 VCPU thread you'll need the RCU work that I am slowly polishing and sending out. That's because one device can change the memory map, and that will cause a tlb_flush for all CPUs in tcg_commit, and that's not thread-safe.

Quoted 10 lines

And later on, once devices start being converted to run outside the BQL, that can be changed to use new functions address_space_rw_unlocked / io_mem_read_unlocked / io_mem_write_unlocked. Something like that is already visible at https://github.com/bonzini/qemu/commits/rcu (ignore patches after "kvm: Switch to unlocked MMIO").

Paolo

	 +44 (0)20 7100 3485 x 210

+33 (0)5 33 52 01 77x 210

	+33 (0)603762104
	mark.burton
#14 lore raw
Quoted 2 lines · Mark Burton

However - if we go this route -the current patch is only for x86. (apart from the fact that we still seem to land in a deadlock…)

Jan said he had it working at least on ARM (MusicPal).

Quoted 5 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Paolo

#15 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 2 lines · Mark Burton

However - if we go this route -the current patch is only for x86. (apart from the fact that we still seem to land in a deadlock…)

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did… Indeed - he specifically says that doesn’t work…. :-)

Quoted 7 lines
Quoted 6 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Quoted 8 lines

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

Cheers

Mark.

Quoted 2 lines

Paolo

	 +44 (0)20 7100 3485 x 210

+33 (0)5 33 52 01 77x 210

	+33 (0)603762104
	mark.burton
#16 lore raw
Quoted 3 lines · Mark Burton
Quoted 1 line

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did…

Multithreaded TCG, or single-threaded TCG with SMP?

Quoted 15 lines
Quoted 6 lines
Quoted 5 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Quoted 8 lines

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Quoted 5 lines

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

That's the definition of RCU. :) Look at the docs in
http://permalink.gmane.org/gmane.comp.emulators.qemu/313929 for more information. :)

It's still not trivial to make it 100% correct, but at the same time it's not too hard to prepare something decent to play with. Also, most of the work can be done with KVM so it's more or less independent from what you guys have been doing so far.

Paolo

#17 lore raw
In reply to Mark Burton
Quoted 3 lines · Mark Burton
Quoted 1 line

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did…

Multithreaded TCG, or single-threaded TCG with SMP?

Quoted 15 lines
Quoted 6 lines
Quoted 5 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Quoted 8 lines

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Quoted 5 lines

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

That's the definition of RCU. :) Look at the docs in
http://permalink.gmane.org/gmane.comp.emulators.qemu/313929 for more information. :)

It's still not trivial to make it 100% correct, but at the same time it's not too hard to prepare something decent to play with. Also, most of the work can be done with KVM so it's more or less independent from what you guys have been doing so far.

Paolo

#18 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 3 lines · Mark Burton
Quoted 1 line

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did…

Multithreaded TCG, or single-threaded TCG with SMP?

He mentions SMP, - I assume thats single-threaded ….

Quoted 22 lines
Quoted 16 lines
Quoted 7 lines
Quoted 6 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Quoted 8 lines

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Quoted 5 lines

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

Quoted 3 lines

That's the definition of RCU. :) Look at the docs in
http://permalink.gmane.org/gmane.comp.emulators.qemu/313929 for more information. :)

Ahh - I see !

Quoted 5 lines

It's still not trivial to make it 100% correct, but at the same time it's not too hard to prepare something decent to play with. Also, most of the work can be done with KVM so it's more or less independent from what you guys have been doing so far.

Yes - the issue is if we end up relying on it.
But - I see what you mean - these 2 things can ‘dovetail’ together “independently” - so - Jan’s patch will be good for now, and then later we can use RCU to make it work more generally (and more efficiently).

So - our only small problem is getting Jan’s patch to work for multi-thread :-))

Cheers

Mark.

Quoted 2 lines

Paolo

	 +44 (0)20 7100 3485 x 210

+33 (0)5 33 52 01 77x 210

	+33 (0)603762104
	mark.burton
#19 lore raw
Quoted 5 lines · Mark Burton
Quoted 5 lines · Paolo Bonzini
Quoted 8 lines
Quoted 6 lines · Mark Burton
Quoted 3 lines
Quoted 1 line

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did…

Multithreaded TCG, or single-threaded TCG with SMP?

He mentions SMP, - I assume thats single-threaded ….

Yes, I didn't patched anything towards multi-threaded SMP. Main reason:
there was no answer on how to emulated the memory models of that target architecture over the host one which is mandatory if you let the emulated CPUs run unsynchronized in parallel. Did this change?

Quoted 35 lines
Quoted 23 lines
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Quoted 8 lines

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Quoted 5 lines

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

Quoted 3 lines

That's the definition of RCU. :) Look at the docs in
http://permalink.gmane.org/gmane.comp.emulators.qemu/313929 for more information. :)

Ahh - I see !

Quoted 5 lines

It's still not trivial to make it 100% correct, but at the same time it's not too hard to prepare something decent to play with. Also, most of the work can be done with KVM so it's more or less independent from what you guys have been doing so far.

Quoted 4 lines

Yes - the issue is if we end up relying on it.
But - I see what you mean - these 2 things can ‘dovetail’ together “independently” - so - Jan’s patch will be good for now, and then later we can use RCU to make it work more generally (and more efficiently).

So - our only small problem is getting Jan’s patch to work for multi-thread :-))

See above regarding the potential dimension.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#20 lore raw
Quoted 6 lines · Jan Kiszka
Quoted 5 lines · Mark Burton
Quoted 5 lines · Paolo Bonzini

On 15/01/2015 21:53, Mark Burton wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did…

Multithreaded TCG, or single-threaded TCG with SMP?

He mentions SMP, - I assume thats single-threaded ….

Yes, I didn't patched anything towards multi-threaded SMP. Main reason:
there was no answer on how to emulated the memory models of that target architecture over the host one which is mandatory if you let the emulated CPUs run unsynchronized in parallel. Did this change?

Hi Jan,

Actually it's what we are trying to do, running emulated CPUs in parallel.

I get a double mutex_lock error (eg: no unlock) I must have missed something during the "rebase".
I'll check.

Thanks,
Fred

Quoted 33 lines
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map. Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Quoted 8 lines
Quoted 5 lines

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

That's the definition of RCU. :) Look at the docs in
http://permalink.gmane.org/gmane.comp.emulators.qemu/313929 for more information. :)

Ahh - I see !

Quoted 8 lines
Quoted 4 lines

It's still not trivial to make it 100% correct, but at the same time it's not too hard to prepare something decent to play with. Also, most of the work can be done with KVM so it's more or less independent from what you guys have been doing so far.

Yes - the issue is if we end up relying on it.
But - I see what you mean - these 2 things can ‘dovetail’ together “independently” - so - Jan’s patch will be good for now, and then later we can use RCU to make it work more generally (and more efficiently).

So - our only small problem is getting Jan’s patch to work for multi-thread :-))

See above regarding the potential dimension.

Jan

#21 lore raw
In reply to Jan Kiszka
Quoted 14 lines · Jan Kiszka
Quoted 10 lines · Mark Burton
Quoted 10 lines · Paolo Bonzini
Quoted 3 lines · Mark Burton
Quoted 1 line

Jan said he had it working at least on ARM (MusicPal).

yeah - our problem is when we enable multi-threads - which I dont believe Jan did…

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Multithreaded TCG, or single-threaded TCG with SMP?

He mentions SMP, - I assume thats single-threaded ….

Yes, I didn't patched anything towards multi-threaded SMP. Main reason:
there was no answer on how to emulated the memory models of that target architecture over the host one which is mandatory if you let the emulated CPUs run unsynchronized in parallel. Did this change?

No - we just decided to stop pressing the button…
I think this is the ‘x86 on ARM’ issue ? - our plan is to get ARM of x86 working (or that class), and the worry about the other way round.

I dont see why SMP ARM on X86 wouldn’t work with your patch?

Cheers

Mark.

Quoted 35 lines
Quoted 35 lines
Quoted 23 lines
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines

One thing I wonder - why do we need to go to the extent of mutexing in the TCG like this? Why can’t you simply put a mutex get/release on the slow path? If the core is going to do ‘fast path’ access to the memory, - even if that memory was IO mapped - would it matter if it didn’t have the mutex?

Quoted 8 lines

Because there is no guarantee that the memory map isn't changed by a core under the feet of another. The TLB (in particular the "iotlb") is only valid with reference to a particular memory map.

Changes to the memory map certainly happen in the slow path, but lookups are part of the fast path. Even an rwlocks is too slow for a fast path, hence the plan of going with RCU.

Quoted 5 lines

Could we arrange the world such that lookups ‘succeed’ (the wheels dont fall off) -ether getting the old value, or the new, but not getting rubbish - and we still only take the mutex if we are going to make alterations to the MM itself? (I have’t looked at the code around that… so sorry if the question is ridiculous).

Quoted 3 lines

That's the definition of RCU. :) Look at the docs in
http://permalink.gmane.org/gmane.comp.emulators.qemu/313929 for more information. :)

Ahh - I see !

Quoted 5 lines

It's still not trivial to make it 100% correct, but at the same time it's not too hard to prepare something decent to play with. Also, most of the work can be done with KVM so it's more or less independent from what you guys have been doing so far.

Quoted 12 lines
Quoted 4 lines

Yes - the issue is if we end up relying on it.
But - I see what you mean - these 2 things can ‘dovetail’ together “independently” - so - Jan’s patch will be good for now, and then later we can use RCU to make it work more generally (and more efficiently).

So - our only small problem is getting Jan’s patch to work for multi-thread :-))

See above regarding the potential dimension.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
	 +44 (0)20 7100 3485 x 210

+33 (0)5 33 52 01 77x 210

	+33 (0)603762104
	mark.burton