

Quick Look at Rosetta on Linux
source link: https://threedots.ovh/blog/2022/06/quick-look-at-rosetta-on-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Quick look at Rosetta on Linux
Yesterday, Apple did release RosettaLinux as part of the macOS Ventura preview. Let’s take a first quick look…
Location
RosettaLinux is located at /Library/Apple/usr/libexec/oah/RosettaLinux
. A rosetta
ELF executable is present on that directory.
Does it do AoT?
No. Rosetta on Linux exclusively operates in JIT mode, at least for the time being.
Mapping to the VM
That directory is mapped through virtiofs
to the virtual machine. binfmt_misc
is then used to make execution attempts of x86_64 binaries run through Rosetta.
When the Rosetta directory is mapped to the virtual machine, all of the VM runs in Total Store Ordering mode. This provides the guarantees needed by Rosetta to provide x86-compatible memory model semantics.
If TSO mode is not present or not active on a given Arm platform, Rosetta explicitly does not provide those guarantees. It does not try to handle that use case. As such, to provide proper semantics on those environments, you can use taskset
to bind applications using Rosetta to a single core.
Not-really-DSMOS*
Rosetta has a mechanism to restrict it to Virtualization.framework
virtual machines. The ioctl
is passed through virtiofs
to the host.
A re-creation of that mechanism is pasted below:
char* AppleRosettaKey = "Our hard work\nby these words guarded\nplease don't steal\n Apple Inc";
int fd = openat(AT_FDCWD ,"/proc/self/exe", 0);
if (fd < 0) {
rosetta_error("Unable to open /proc/self/exe: %lu", fd);
}
char key[45];
int ioctl_result = ioctl(fd, _IOC(_IOC_READ, 0x61, 0x22, 0x45), key);
if (ioctl_result < 0 || memcmp(key,AppleRosettaKey,0x45) != 0) {
rosetta_error(
"Rosetta is only intended to run on Apple Silicon with a macOS host \
using Virtualization.framework with Rosetta mode enabled"
);
}
As we can see, the mechanism is quite trivial to bypass. However, please rely on another solution if you’re running on non-Apple hardware.
Running it on non-Apple CPUs?
Running it on a Mac is fun, but what if we try to run it on other processors?
Tegra Xavier testing
My first thought was the Tegra Xavier processor, which provides sequential consistency in hardware. As such, it satisfies the programmer-visible memory ordering constraints required for Rosetta to be functional.
However, Rosetta relies on FEAT_FlagM
flag manipulation instructions. Those are not implemented on Carmel. As such, I skipped over to another potential testing target.
And the CNTFRQ_EL0
timer frequency of 31.25MHz on Xavier doesn’t match with what Rosetta expects either.
Graviton3 testing
Which Arm platforms are easily accessible with flag manipulation instructions? There are some, such as the AWS Graviton3 processor, which uses Arm’s Neoverse V1 core.
rosetta error: Unsupported counter frequency, check value of CNTFRQ_EL0
Trace/breakpoint trap
Rosetta supports CNTFRQ_EL0
timer frequencies of 24 MHz and 1.00GHz, which is unlike the 1.05 GHz value used by the Graviton3 platform.
Let’s override the value reported to Rosetta with 1.00 GHz. This is close enough for things to work fine for testing purposes.
This allows to make a Geekbench 5 run, showing ~70% of native performance for Rosetta 2 on a c7g.large dual-core instance. Anecdotally, the HDR subtest of Geekbench anomalously gives higher performance inside of the Rosetta environment than outside for this configuration.
However, a reminder that x86 memory ordering semantics aren’t provided is required to put that score into perspective.
* Don’t Steal Mac OS X, the system used to restrict x86_64 macOS from running on non-Apple hardware.
Recommend
-
78
-
22
Rosetta@home How does it work? By running Rosetta@home on your computer when you're not using it you will spe...
-
16
As the HPC community prepares for the era of exascale, over the past year, Cray scored a number of highly valuable contracts by the De...
-
33
律动 BlockBeats 消息,6 月 17 日,Coinbase 官方公布了一个开源规范和工具「Rosetta」,可以使与区块链的集成更简单、更快、更可靠。根据公告,Coinbase 最初开发 Rosetta 作为中间件,目的是为了安全地、轻松地将区块链集成到其平台中,「希...
-
15
The Rosetta@home project is a not-for-profit distributed computing project created by the Baker laboratory at the University of Washington. The project uses idle compute capacit...
-
14
2020-12-20 22:06 Coinbase宣布启动开源项目Rosetta资助计划 12月19日,Coinbase发文称,Coinbase在2020年6月推出开源规范和工具Rosetta,使与区块链的集成更加简单、快速和可靠。为了鼓励Rosetta生态系统的...
-
9
Navigating the Docker ecosystem can be confusing at the best of times. I’ve been involved in numerous conversations where people have confused Indexes, Registries, Commits, diffs, pushes, Pods, Containers, Images… the list goes on....
-
17
OverviewIn macOS 13 and later on Mac computers with Apple silicon chips, the Virtualization framework supports Rosetta in ARM Linux virtual machines (VMs). Rosetta is a translation process that allows users to run apps that...
-
5
rosetta meets linux — Apple will allow Linux VMs to run Intel apps with Rosetta in macOS Ventura You can even use Rosetta with non-Apple Arm CPUs, though you probably shoul...
-
10
macOS Ventura gives Linux VMs the ability to run x86 apps via Rosetta Tuesday, June 7, 2022 4:03 pm
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK