Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithreaded TCG of x86_64/i386 #257

Closed
sceptical-coder opened this issue Apr 12, 2020 · 19 comments
Closed

Multithreaded TCG of x86_64/i386 #257

sceptical-coder opened this issue Apr 12, 2020 · 19 comments
Labels
question Further information is requested

Comments

@sceptical-coder
Copy link

This one implies that subject should be possible since qemu 3.1. Is that true?

@osy osy added the question Further information is requested label Apr 12, 2020
@osy
Copy link
Contributor

osy commented Apr 12, 2020

It is implemented as Force Multicore.
image

@osy osy closed this as completed Apr 12, 2020
@sceptical-coder
Copy link
Author

But is the comment about incorrect emulation correct?

@sceptical-coder
Copy link
Author

And well, specifically, about x86 memory model being unsupported on ARM?

@professorUnknown
Copy link

Give him the link

@sceptical-coder
Copy link
Author

Give him the link

Whom did you meant? If that’s to me, then I’m referring to quite a hope-giving response of the bug I linked to earlier: https://bugs.launchpad.net/qemu/+bug/1735049/comments/1

@osy
Copy link
Contributor

osy commented Apr 12, 2020

I did find the commit they referenced qemu/qemu@b32dc3370a

@osy osy reopened this Apr 12, 2020
@osy
Copy link
Contributor

osy commented Apr 12, 2020

So yeah in theory it should work but I'm confused because this piece of code exists in QEMU

/*
 * We default to false if we know other options have been enabled
 * which are currently incompatible with MTTCG. Otherwise when each
 * guest (target) has been updated to support:
 *   - atomic instructions
 *   - memory ordering primitives (barriers)
 * they can set the appropriate CONFIG flags in ${target}-softmmu.mak
 *
 * Once a guest architecture has been converted to the new primitives
 * there are two remaining limitations to check.
 *
 * - The guest can't be oversized (e.g. 64 bit guest on 32 bit host)
 * - The host must have a stronger memory order than the guest
 *
 * It may be possible in future to support strong guests on weak hosts
 * but that will require tagging all load/stores in a guest with their
 * implicit memory order requirements which would likely slow things
 * down a lot.
 */

static bool check_tcg_memory_orders_compatible(void)
{
#if defined(TCG_GUEST_DEFAULT_MO) && defined(TCG_TARGET_DEFAULT_MO)
    return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) == 0;
#else
    return false;
#endif
}

That function will return false for x86_64 on ARM64.

On tcg/aarch64/tcg-target.h

#define TCG_TARGET_DEFAULT_MO (0)

On target/i386/cpu.h

/* The x86 has a strong memory model with some store-after-load re-ordering */
#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)

@osy
Copy link
Contributor

osy commented Apr 12, 2020

Yeah someone should contact the QEMU developer for clarification because the above code will default x86 on ARM64 to disable MTTCG. And we know from experience that forcing MTTCG results in random issues.

@professorUnknown
Copy link

https://www.qemu.org/support/ you can check out their mailing list

@osy
Copy link
Contributor

osy commented Apr 12, 2020

@professorIsaac yeah I think we all know what it means to contact

@professorUnknown
Copy link

I will do it

@sceptical-coder
Copy link
Author

sceptical-coder commented Apr 12, 2020

@professorIsaac yeah I think we all know what it means to contact

Ahm, is that some sort of inside knowledge? Could you please enlighten me about that well, supposed skepticism about contacting QEMU devs?

@professorUnknown
Copy link

In short they explained to me that since the host arm64 is a weaker memory order than the guest x86 they disabled mttcg because if they would implement it would slow everything down but the good news is that if the guest is the same memory order it is not disabled and if it is weaker memory order it is not disabled also.

@osy
Copy link
Contributor

osy commented Apr 12, 2020

Right, that's what I figured from the code. So basically the launchpad comment was incorrect. There is no MTTCG support for x86 on ARM64.

@osy osy closed this as completed May 8, 2020
@jkleckner
Copy link

I found it intriguing that Apple added support for x86 memory ordering to the M1 CPU.

@osy
Copy link
Contributor

osy commented Feb 26, 2022

Unfortunately there’s no public APIs for that yet. @saagarjha did you ever manage to benchmark the performance and see if it’s worth implementing?

@saagarjha
Copy link
Contributor

TSO’s overhead is something like 20% for most applications, tending towards 50% if you hit contended memory a lot.

@jkleckner
Copy link

jkleckner commented Apr 30, 2023

Adding a cross link to the trollstore ios code PR: #4866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants