Running Intel Binaries in Linux VMs with Rosetta
developer.apple.com
developer.apple.com
[1] https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807...
https://steamcommunity.com/discussions/forum/0/2976275080122...
They did just that. The folder share is just for licensing as far as I can see.
Are you saying that it's always on for VMs?
That's... a weird way for coding a feature flag, but I guess it "just works".
This would still be pretty slow (see: Microsoft’s version of this under Windows ARM) due to the need to issue a ton of memory fence instructions to make ARM’s looser memory model behave like Intel’s, except that Apple baked the ability to switch the CPU into an Intel-like memory model directly into the silicon.
So in practice it is shockingly fast.
No it's not. Apple is not immune from fundamental computer science principles whatever their marketing team says, and even the original keynote acknowledged that Rosetta 2 emulates some instructions at runtime.
Imagine you're running Python under Rosetta. The original Python interpeter takes Python code, translates it into x86 assembly, and runs that x86 assembly. Those x86 instructions did not exist prior to execution! Even if Rosetta could translate the entire interpreter into ARM code, the interpreter would still be producing x86 assembly.
Other types of programs produce code at runtime as well. Rosetta 2 is able to cache a very impressive amount of instructions ahead of time, but it's still doing emulation.
So yeah, no real back and forth to the host platform.
You're still right that that's not sufficient, for example anything that generates Intel code will definitely need JIT (just in time) translation. But presumably a lot of code will still hit the happy AOP path.
That being said, a JIT does not have to be super slow. The early vwmware products, back before there was virtualization support in Intel products, actually had to do some translation as well: https://www.vmware.com/pdf/asplos235_adams.pdf
I mean, we can call it an ARM binary or we can call it an instruction cache. I generally prefer the latter term, because what Rosetta produces are not standalone executables, they're incomplete. I don't know how often the happy path is used, but Rosetta can always be observed doing work at runtime.
JITs are great and Rosetta 2 is incredible! I just can't imagine it working over any sort of shared filesystem, that would add an incredible amount of latency.
Not dynamically. They just call predefined C (or whatever the interpreter was written in) functions based on some internal mechanism.
> Or else what does the CPU execute?
Usually either the interpreter is just walking the AST and calling C functions based on the parse tree’s node type (this is very slow), or it will convert the AST into an opcode stream (not x86-64 opcodes, just internal names for integers, like OP_ADD = 0, OP_SUB = 1, etc) when parsing the file, and then the interpreter’s “core” will look something like a gigantic switch state statement with case OP_ADD: add(lhs, rhs) type cases. “add” in this case being a C function that implements the add semantics in this language. (The latter approach, where the input file is converted to some intermediate form for more efficient execution after the parse tree is derived, is more properly termed a virtual machine and “interpreter” generally only refers to the AST approach. People tend to use “interpreter” pretty broadly in informal conversations, but Python is strictly speaking a VM, not an interpreter)
In either case, the only thing emitting x86-64 is the compiler that built the interpreter’s binary.
> Am I totally misunderstanding how interpreters work?
You’re confusing them with JITs.
If every interpreter had to roll their own dynamic binary generation, they’d be a hell of a lot less portable (like JITs).
Probably, that binary is passing the instructions into native macOS Rosetta code for translation, but its also possible that the entire Rosetta code was ported to Linux.
Simply not possible. Apple Silicon is ARMv8, but with a number of their own custom extensions on top of it.
Docker is “just” a binary with cgroups magic.
Sounds like x86 binaries within an already running ARM Linux base image can run much faster.
At the moment the Docker desktop VM is setup to use qemu when running amd64 containers (processes) on the arm64 VM.
Rosetta would replace that qemu binfmt setup, or maybe qemu-static wraps rosetta when available.
That's 2019. I haven't tested 2017 or 2022, but I assume they don't work either. AFAIK the official advice is to use Azure SQL Edge instead.
But that doesn't answer the question of "does Rosetta deal with it properly?".
I understand that you can replace qemu by rosetta now.
Docker runs inside the VM, not the other way around.
If you /have/ to run an x86 kernel (I’m not sure what the reason would be?) you’re stuck with full system emulation a la qemu.
In reality what you probably have is a few x86 binaries that you need, and it sounds like this will let docker, VMware, qemu, whatever, leverage Rosetta w/o having to implement it themselves.
Now, if you’re running something that does codegen at runtime, then Rosetta is pretty much just as screwed as any other tech you might want to use.
Here's what I've learned:
1. You can run console Linux. But you need to download ARM ISO, extract kernel and initrd and find out exact kernel parameters. Not a big issue, but probably can't be done automatically. You can't just boot ISO.
2. Disk support is bad. No snapshots, etc. Just single file. I think that you can emulate snapshots with APFS CoW support, but that's not as good as something like qcow2.
3. No GUI support (for Linux, for macOS there's GUI support but I have no idea how it works).
4. Network support is limited. You can run NAT but then you can't communicate with host. You can run bridge, but I don't like this mode and didn't even try it. You can implement userspace networking completely by yourself, but that's a lot of work and I didn't try it either. But I think that if someone would want to build a virtualization frontend, he had to do it. Otherwise basic features like port mapping will not be available.
Now from what I read at this topic: ISO boot is coming, UEFI support is coming, Linux GUI support is coming. And I guess with enough tinkering it should be possible to run other BSDs, as they just leverage standard virtio protocols.
Also Windows virtualization theoretically should be possible. I mean it's just another UEFI OS. You would need to put virtio drivers, but Redhat wrote virtio drivers (for x86, but should be possible to compile for ARM).
I just wish that this virtualization framework was more extensible. Right now it's like use it or drop it. For example I didn't find any way to implement qcow2 support while using it for other things.
Outside of macOS, Apple has been providing Linux binaries of the Swift toolchain for years: https://www.swift.org/download/
Or we have a simpler mental model ? From a non-system land programmer point of view ?
If anything libhoudini is a rip off of Rosetta.
could still end up with some "works for me" but still broken on prod issues resulting from the underlying architecture being different (for intel backing infra), and also some questions around how it would work in practice in terms of integrating with production container workflows, but seems like a boon for anyone who is struggling today with intel vm or container performance issues on apple silicon.
nice!
Technically this would be replacing QEMU user-mode emulation. Which isn't fast in a large part because QEMU being portable to all host architectures was more important than speed.
it was particularly interesting to me as i always got the sense that a lot of the success of the intel era macs was carried by their popularity and (and recommendability) amongst the internet development and engineering crowd. it seemed to me like a mistake to potentially alienate that group.
Glad to see it.
Hope that by the time I get my next work laptop it’s still there, or better yet we’ve moved to a newer version of the software where this isn’t a problem.
> The remaining steps required to activate Rosetta in a Linux guest aren’t commands that your app can execute or that you can script from inside your application to a Linux VM; the user must perform them either interactively or as part of a script while logged in to the Linux guest. You must communicate these requirements to the user of your app.
That means Docker cannot do it magically for me?
It requires the share to be added to the vm and then a command to be run to register it with the Linux kernel.
https://developer.apple.com/documentation/virtualization/run...
x86/Win game -> Steam for Windows(?) -> Linux VM Guest OS -> MacOS 13 VM Host OS -> Mac HW
If your thinking involves a windows VM under linux you’re SOOL, as that has the same problem as an win/x86 vm on Mac: it’s a full system emulation - eg qemu, etc
Rosetta can translate user mode code, because every can either be translated to native code /or/ is a system call, and apparently Rosetta knows how to translate linux syscalls.
Steam for Windows -> Linux VM Guest OS
You can double click the Steam for Windows installer, in a Linux GUI and it installs right now? Using WINE? What magic is this?
(The x86_64 version of CCL actually works under Rosetta (more or less) which absolutely blows my mind since it's a compiler that emits x86 code at run-time!)
In a sense if you were to go through the hand assembly one at a time and do 1:1 substitution with ARMv8 equivalent you'd probably be able to do a bit better, just because you don't have to consider behaviour of generic x86 code.
I don’t have a M1 mac, but on my Mac a standard Linux VM has no impact on performance or battery life. The minute I use Docker the machine become sluggish and halves (literally) the batter life, I now avoids is as much as possible.
By my reading of TFA, your container runtime (eg Docker for Mac) should be able to provide an ARM VM, and use this Rosetta feature to run amd64 containers directly.
Potentially this could be used as an alternative?
This is only available in combination with Virtualization.framework, but Docker is already migrating from Hypervisor.framework to Virtualization.framework.
The containers should not need the mount. What happens is Rosetta gets registered with the kernel (binfmt_misc) to execute x86 binaries. The is the same mechanism that allows seamless qemu support.
However, in a few years' time the deal runs out and it might be possible again, unless they can think of a reason to renew the deal (i.e. inclusion of Qualcomm's optimised x86/amd64 translation layer).
https://www.androidauthority.com/qualcomm-nuvia-1192440/
> Nuvia was founded back in 2019 by former Apple silicon executive Gerard Williams III, along with Manu Gulati and John Bruno. Williams was the chief architect behind several major Apple CPUs and chipsets from 2010 to 2019 .. the Cyclone, Typhoon, Twister, Hurricane, Monsoon, Vortex, Lightning and Firestorm CPUs. These CPUs were featured in the Apple A7, A8, A9, A10, A11, A12 series, A13, and A14 respectively. The Nuvia founder’s profile also notes that he was the chief architect for Apple’s Mac hardware ... Going back even futher, the Nuvia co-founder worked at Arm from 1998 to 2010, working on CPU tech like the Arm Cortex-A8 and Cortex-A15 CPU cores.
This assumes that valuation is rational. It is not, and recent history is full of companies over-paying or under-paying for their acquisitions. The proof of the pudding will be in the eating, and the pudding will still take a while to get ready.
https://www.tomshardware.com/news/qualcomm-confirms-nuvia-ar...
And yeah, Nuvia is more “a handful of engineers” (though quite good at their job) than “the former Apple M1 team”. It took Apple billions upon billions and the better part of a decade. These things are very long term plans, and at this scale it depends at least as much on high-level strategies than on engineering.