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

feat: Make CPU model and flags configurable #34

Merged
merged 2 commits into from
Jun 10, 2024
Merged

feat: Make CPU model and flags configurable #34

merged 2 commits into from
Jun 10, 2024

Conversation

seitenca
Copy link
Collaborator

@seitenca seitenca commented Jun 10, 2024

Add cpu features as osx-kvm

@seitenca
Copy link
Collaborator Author

seitenca commented Jun 10, 2024

#33 as mentioned here maybe if the CPU hasn't this features, Macos doesn't boot
cant replicate as I don't have an AMD CPU

@seitenca seitenca requested a review from kroese June 10, 2024 21:12
@kroese
Copy link
Contributor

kroese commented Jun 10, 2024

Hi Seitenca,

I am not sure if this is needed. Because I already did that by setting the CPU model:

CPU_MODEL="Haswell-noTSX"

In osx-kvm, they used a much older model (Penryn) and thats why they need to add certain features, because the Penryn CPU does not have those instructions.

But we use the Hasswel CPU, so many of these flags (like +sse4.2,+avx) are already standard for that CPU.

I also don't have a AMD cpu, but I am pretty confident it will work as it is now. And if some AMD user complaints that it doesnt work, we can try to see which cpu instruction is missing.

EDIT: Okay, sorry, I did not see that there was already a complaint, lol! But instead of modifying the code, I would suggest that he first tries out the flags by using the CPU_FLAGS environment variable, and only after it is confirmed to work, then to add them to the code.

@seitenca
Copy link
Collaborator Author

Hi Seitenca,

I am not sure if this is needed. Because I already did that by setting the CPU model:

CPU_MODEL="Haswell-noTSX"

In osx-kvm, they used a much older model (Penryn) and thats why they need to add certain features, because the Penryn CPU does not have those instructions.

But we use the Hasswel CPU, so many of these flags (like +sse4.2,+avx) are already standard for that CPU.

I also don't have a AMD cpu, but I am pretty confident it will work as it is now. And if some AMD user complaints that it doesnt work, we can try to see which cpu instruction is missing.

Hi @kroese,
I didn't know that emulating Hasswel CPU also comes with those flags. I'm not sure if this will work, but I don't know what else to try.
Right now, it's not possible to change the CPU_FLAGS in the Docker Compose file, right? Maybe we should change that.

@kroese
Copy link
Contributor

kroese commented Jun 10, 2024

It is already possible to set CPU_FLAGS from the compose file.

The reason why I am so hestitant is that emulating CPU instructions that the host processor does not have, is pretty slow. So it should be avoided at all costs, because its better for the guest OS to know that the CPU cannot provide certain instructions (so it can choose to take a different codepath), then to let the guest OS think that the host can hardware accelerate certain operations, while in reality they need to be emulated behind the scenes.

@seitenca
Copy link
Collaborator Author

seitenca commented Jun 10, 2024

It is already possible to set CPU_FLAGS from the compose file.

Yes but I think the value is overwritten in code

The reason why I am so hestitant is that emulating CPU instructions that the host processor does not have, is pretty slow. So it should be avoided at all costs, because its better for the guest OS to know that the CPU cannot provide certain instructions (so it can choose to take a different codepath), then to let the guest OS think that the host can hardware accelerate certain operations, while in reality they need to be emulated behind the scenes.

Yes maybe add it to the README at best

@kroese
Copy link
Contributor

kroese commented Jun 10, 2024

You are right.. in qemu-docker you can set them, but in this project they are overwritten with a fixed value. I will fix that now.

@kroese
Copy link
Contributor

kroese commented Jun 10, 2024

Okay, it is fixed now.. I had to refresh my memory how these flags actually work in QEMU, but it was like this:

If you have KVM enabled, then the only thing they do is to print a warning when the host CPU does not have that feature. So they do not provide any feature that the host does not have (which makes them a bit useless).

If you have KVM disabled, those instructions will be emulated and they DO provide features that the host does not have. So you can emulate SSE4 when the host does not have SSE4. But: in most cases its better to not do that, because it prevents the guest from making smart decisions.

For example, if the guest knows you have no hardware for SSE4 it can decide to use hardware SSE3 and still have good performance. But if it does not know that, it will use the (slow) emulated SSE4. So unless strictly necessary (for example, a guest that refuses to boot without SSE4) its better to not use them.

So this means we cannot magically make macOS work on CPU's that are missing the required instructions/features, unless its without KVM (which is unusably slow).

@kroese kroese changed the title feat: add cpu features feat: Make CPU model and flags configurable Jun 10, 2024
@kroese kroese merged commit 9bcc4bb into master Jun 10, 2024
1 check passed
@kroese kroese deleted the cpu-flags branch June 10, 2024 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants