Skip to content

Fix #471: Improve x86_64 emulation on arm64 platform #494

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

Merged
merged 1 commit into from
Dec 28, 2021

Conversation

gayanper
Copy link
Contributor

This change will use qemu64 cpu for better emulation
and add some extra parameters like tcg accel and
force multi threading where multiple host threads will
be used for vcpus according to qemu documentation.
Added few more extra parameters which are used by
UTM for better emulation of x86_64

pkg/qemu/qemu.go Outdated
if origV, ok := argValue(args, k); ok {
logrus.Warnf("Not adding QEMU argument %q %q, as it conflicts with %q %q", k, v, k, origV)
return args
if k != "-global" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need to allow multiple -global arguments which doesn't seems to conflict according to UTM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can use args = append(args, "-global", ...) without using appendArgsIfNoConflict

// https://qemu-project.gitlab.io/qemu/system/invocation.html?highlight=tcg%20opts
// this will make sure each vCPU will be backed by 1 host user thread.
args = appendArgsIfNoConflict(args, "-accel", "tcg,thread=multi,tb-size=512")
// This will disable CPU S3 state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running emulations I found that the VM doesn't use more than 125%. Which seems that nor more than 1 thread is used from host vm for emulation. But adding this tcg accel cause the VM to use more host threads (CPUs). After this change when running the VM load i found the CPU usage spike up to 300% - 400% on the same apple silicon machine. I found this when comparing the load test on the VM created using UTM App and Lima. The last s3 state toggle might not effect the performance directly. But may be it will help the VM to run without going into s3 state.

@AkihiroSuda AkihiroSuda linked an issue Dec 27, 2021 that may be closed by this pull request
This change will use qemu64 cpu for better emulation
and add some extra parameters like tcg accel and
force multi threading where multiple host threads will
be used for vcpus according to qemu documentation.
Added few more extra parameters which are used by
UTM for better emulation of x86_64

Signed-off-by: Gayan Perera <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda added this to the v0.8.1 milestone Dec 27, 2021
// this will make sure each vCPU will be backed by 1 host user thread.
args = appendArgsIfNoConflict(args, "-accel", "tcg,thread=multi,tb-size=512")
// This will disable CPU S3 state.
args = append(args, "-global", "ICH9-LPC.disable_s3=1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason you don't also disable the S4 state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s4 state is for hibernate if i'm not mistaken. It was not part of the UTM parameter list and also i thought that the hibernate state is not something that will the VM automatically go into. Thats why i didn't thought of adding it.

@AkihiroSuda
Copy link
Member

https://www.qemu.org/docs/master/system/i386/cpu.html

qemu64 does not support x86_64-v3 needed by RHEL 10.
AlmaLinux 10 supports v2, but qemu64 does not seem to even support v2.

Can we switch back to Haswell-v4 or something newer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve x86_64 emulation on arm64 platform
3 participants