12 ms·
Does anyone understand (or have any theories on) how this actually works? I don't understand how it's possible. Surely they didn't write a Linux version of Rose
by Wowfunhappy 4y ago
Does anyone understand (or have any theories on) how this actually works? I don't understand how it's possible. Surely they didn't write a Linux version of Rosetta, it must be talking to the host OS somehow—but how? Where is the boundary?
- qeternity 4y agoIt seems pretty clear from TFA - there’s a directory share with the host, and given that Rosetta isn’t an emulator, but rather a translation layer, they don’t need a Linux version: x86 instructions go in, arm64 come out.
- Wowfunhappy 4y agoBut surely that would be too slow? Although Rosetta is great at caching instructions ahead of time, it does need to emulate a lot of code (ie, anything generated at runtime).
- anyfoo 4y agoHave you tried Rosetta? It can be pretty impressive.
- Wowfunhappy 4y agoRosetta is very impressive! I just don't see how they could maintain that by passing instructions back and fourth over a shared drive, that would be a ridiculous amount of latency!
- my123 4y agoThe shared drive is just a licensing trick. They do an ioctl over /proc/self/exe as the licensing mechanism. (and that's routed over with virtio-fs to the host)
- deleted 4y ago[deleted]
- halifaxbeard 4y agoDidn’t Apple also implement togglable memory models for m1 (and I’m assuming m2)?
- msbarnett 4y agoIt’s doing an AOT translation of x86-64 opcodes to ARM64 equivalents. There isn’t really any back and forth, it just digests the binary all at once. 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.
- Wowfunhappy 4y ago> It’s doing an AOT translation of x86-64 opcodes to ARM64 equivalents. There isn’t really any back and forth, it just digests the binary all at once. 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.
- anyfoo 4y agoAOT (ahead of time) really does work on whole binaries. That is also why the first launch of an Intel app seems longer sometimes. Intel binary in, ARM binary out. 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 https://www.vmware.com/pdf/asplos235_adams.pdf
- Wowfunhappy 4y ago
- my123 4y ago> Surely they didn't write a Linux version of Rosetta They did just that. The folder share is just for licensing as far as I can see.
- garaetjjte 4y agoI wonder how they handled TSO mode. Do they enable it for the whole VM? Otherwise I cannot see how it would safely work given they could be context-switched anytime by the guest kernel.
- my123 4y agoEither that or not relying on HW TSO, didn't evaluate yet which path they took between those two options.
- my123 4y agoApple picked always-on TSO.
- Dylan16807 4y agoHuh? Are you saying it can't toggle? Are you saying that it's always on for VMs?
- rfoo 4y agoAlways on for VMs with the emulator shared filesystem attached. That's... a weird way for coding a feature flag, but I guess it "just works".
- kalleboo 4y agoAccording to Twitter, as soon as you attach the Rosetta volume it switches TSO to on
- Wowfunhappy 4y agoThat's super neat! I wonder if the "licensing trick" could be patched out some day, for use in e.g. Asahi Linux.
- metaltyphoon 4y agoIf I’m not mistaken this is also available on WSL. I was surprised, while in WSL, to be able to run windows binaries.
- w7 4y agoSort of, yes-- there is `binfmt_misc` handling of PE excutables and virtual filesystems (akin to VirtIOFS) involved, but no binary/architecture translation like Rosetta.
- metaltyphoon 4y agoAhhh ok, thanks for the clarification instead of down voting like others.
- morpheuskafka 4y agoThey are exporting some sort of Linux ARM binary under a virtual filesystem mount point that handles execution of x64 images. 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.