Rosetta in Linux
2023年 10月 17日 火曜日
これは 2023/10/17 の MK 社内 LT で発表した内容です。
目的 (Goal)
- Apple シリコン上の ARM Linux で x86_64 Linux バイナリを実行する
- Running x86_64 Linux binaries on ARM Linux on Apple Silicon
- 公式開発ドキュメント:Running Intel Binaries in Linux VMs with Rosetta1
実現方法 (Method)
binfmt_misc
- カーネル機能 (Kernel function)
- インタプリタさえあればどんなバイナリでも実行できる
- Any binary can be executed as long as there is an interpreter
原理図解 (Principle Diagram)
-
ホスト CPU アーキテクチャ用のプログラムを実行する
-
他の CPU アーキテクチャのプログラムを実行する
設定例 (Settings Example)
- Rosetta
% mkdir /tmp/mountpoint
% sudo mount -t virtiofs EXAMPLE_TAG /tmp/mountpoint
% ls /tmp/mountpoint rosetta
% sudo /usr/sbin/update-binfmts --install rosetta /tmp/mountpoint/rosetta \
--magic "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00" \
--mask "\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" \
--credentials yes --preserve yes --fix-binary yes
- QEMU (arm64)
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm64-static:' > /proc/sys/fs/binfmt_misc/register
設定結果を見る (Check the settings)
cliff@PD-Jammy-00:~$ ls /proc/sys/fs/binfmt_misc
python3.10 register RosettaLinux status
cliff@PD-Jammy-00:~$ cat /proc/sys/fs/binfmt_misc/RosettaLinux
enabled
interpreter /media/psf/RosettaLinux/rosetta
flags: OCF
offset 0
magic 7f454c4602010100000000000000000002003e00
mask fffffffffffefe00fffffffffffffffffeffffff
動作環境 (Requirement)
- macOS 13+
- UTM or Parallels Desktop with ARM64 Linux VM
使い方 (Usage)
UTM
Parallels Desktop
ベンチマーク (Benchmark)
sudo apt install sysbench
sysbench cpu run
ARM64: Native (Virtualization by Parallels Desktop)
cliff@PD-Jammy-00:~$ sysbench cpu run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 8425.79
General statistics:
total time: 10.0002s
total number of events: 84266
Latency (ms):
min: 0.11
avg: 0.12
max: 0.23
95th percentile: 0.12
sum: 9982.57
Threads fairness:
events (avg/stddev): 84266.0000/0.00
execution time (avg/stddev): 9.9826/0.00
ARM64: Docker (Native)
docker@PD-Jammy-00:~$ sysbench cpu run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 8310.11
General statistics:
total time: 10.0001s
total number of events: 83108
Latency (ms):
min: 0.11
avg: 0.12
max: 0.26
95th percentile: 0.13
sum: 9974.35
Threads fairness:
events (avg/stddev): 83108.0000/0.00
execution time (avg/stddev): 9.9743/0.00
x86_64: Docker (QEMU)34
docker run --privileged --rm tonistiigi/binfmt --install amd64
/usr/bin/gemu-×86_64 /usr/bin/sysbench sysbench cpu run
docker@PD-Jammy-00:~$ sysbench cpu run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 283.95
General statistics:
total time: 10.0036s
total number of events: 2841
Latency (ms):
min: 3.35
avg: 3.52
max: 8.49
95th percentile: 3.75
sum: 9993.88
Threads fairness:
events (avg/stddev): 2841.0000/0.00
execution time (avg/stddev): 9.9939/0.00
x86_64: Docker (Rosetta)
docker@PD-Jammy-00:~$ sysbench cpu run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 7000.22
General statistics:
total time: 10.0006s
total number of events: 70012
Latency (ms):
min: 0.14
avg: 0.14
max: 0.80
95th percentile: 0.15
sum: 9976.68
Threads fairness:
events (avg/stddev): 70012.0000/0.00
execution time (avg/stddev): 9.9767/0.00
結果 (Result)
試したプログラム (Tried and Tested Programs)
Google Chrome
- 普通に使えると思うですが、YouTube の再生不能
- I think it can be used normally, but YouTube cannot be played
ALSA lib conf.c:4002:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib control.c:1528:(snd_ctl_open_noupdate) Invalid CTL hw:0
NVIDIA SDK Manager
- Jetson のイメージは作成できるが、焼くことはできない (NVIDIA SDK Manager からの制限)
- Jetson image can be created, but cannot be burned (limitation from NVIDIA SDK Manager)
Reference
この記事をシェア