Starfive VisonFive2(RISC-V SBC) で遊ぶ – その1 UnixBench

2023/01/06RISC-V, VisionFive-2

赛昉科技(StarFive)の VisonFive2 が届いたので、さっそく遊んでみました。Kickstarterで頼んだのが 2022年8月24日。11月出荷が遅れて12月になり、1月になって ようやく到着。



事前に目を通しておく


ダウンロードするもの


micro SDカードの準備

インストールイメージの作成には16GBでは不足する。私は32GBを買った。本格的に遊ぶと32GBでも足りないはずだし、microSDは信頼性に不安があるので、追加でM.2 SSDも買ってきた。

まず、ddでmicro SDにイメージを書く、提供されているイメージはdebian利用者向けのImage-55とImage-69、最小限の環境の入ったsdcard.imgがある。購入時の初期状態ではImage-69では起動しないので、Image-55を書き込んだ。

$ df -kh
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
(中略)
msdos://disk6s1/NO NAME 29Gi 128Ki 29Gi 1% 1 0 100% /Volumes/NO NAME
$ gzcat starfive-jh7110-VF2-VF2_515_v2.3.0-55.img.bz2 | sudo dd of=/dev/rdisk6 bs=1m
Password:
dd: /dev/rdisk6: Resource busy
$ sudo diskutil umount “/Volumes/NO NAME"
Volume NO NAME on disk6s1 unmounted
$ gzcat starfive-jh7110-VF2-VF2_515_v2.3.0-55.img.bz2 | sudo dd of=/dev/rdisk6 bs=64M

起動

2つあるLANポートのうちの内側にケーブルを繋ぎます。電源を入れて起動すると、DHCPでアドレスを取りにきます。

Jan 5 17:05:39 ZZZZ dhcpd[2358]: DHCPDISCOVER from XX:XX:XX:XX:XX:XX via eth0
Jan 5 17:05:40 ZZZZ dhcpd[2358]: DHCPOFFER on 192.168.XXX.XXX to XX:XX:XX:XX:XX:XX (starfive) via eth0
Jan 5 17:05:40 ZZZZ dhcpd[2358]: DHCPREQUEST for 192.168.XXX.XXX (192.168.YYY.YYY) from XX:XX:XX:XX (starfive) via eth0

$ ping 192.168.XXX.XXX
PING 192.168.XXX.XXX (192.168.1.XXX): 56 data bytes
64 bytes from 192.168.XXX.XXX: icmp_seq=0 ttl=64 time=14.661 ms
64 bytes from 192.168.XXX.XXX: icmp_seq=1 ttl=64 time=6.566 ms
64 bytes from 192.168.XXX.XXX: icmp_seq=2 ttl=64 time=7.090 ms
^C
— 192.168.XXX.XXX ping statistics —
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 6.566/9.439/14.661/3.699 ms

そのままではsshではつながらないので(root loginできないから)、GUIでログインしてsshd_configを書き換えておく。手順はQuick Start Guideに書かれている。

追記: userというアカウントが存在していて、それでsshログインできます。GUIログイン不要です。パスワードは root と同じ(QSGに書かれている)。’user’ アカウントはsudoもできる。この設定はセキュリティホールになり得るので、設定後にログイン不可にすべき。

DHCPでわかったIPアドレスに向けて 'ssh root@IPaddress’ すると繋がる。mDNSも使えるので 'ssh root@starfive.local’ でも良い。

rootログインできる状態のままだと危険なので、一般ユーザーを追加して PermitRootLogin はコメントアウトしておく。

$ ssh root@192.168.XXX.XXX
root@192.168.XXX.XXX’s password:
Linux starfive 5.15.0-starfive #1 SMP Fri Nov 11 06:58:52 EST 2022 riscv64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jan 5 08:55:57 2023 from 192.168.ZZZ.ZZZ
$



microSDカードにイメージを焼いただけでは、先頭の15GBしか使われません。もったいないので、microSD全体を使えるように拡張する。

root@starfive:~# df -kh
Filesystem Size Used Avail Use% Mounted on
udev 1.7G 0 1.7G 0% /dev
tmpfs 390M 1.8M 388M 1% /run
/dev/mmcblk1p3 15G 12G 2.8G 81% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 390M 36K 390M 1% /run/user/0



Quick Start Guideの手順に従って拡張してみたが、parted resize するとエラーになります。

$ sudo parted /dev/mmcblk1
GNU Parted 3.5
Using /dev/mmcblk1
Welcome to GNU Parted! Type 'help’ to view a list of commands.
(parted) resize part3 100%
Error: The resize command has been removed in parted 3.0

領域サイズの変更は resizepart コマンドになったようだ。こちらを使う。

(parted) resizepart
Warning: Not all of the space available to /dev/mmcblk1 appears to be used, you can fix the GPT to
use all of the space (an extra 30302208 blocks) or continue with the current setting?
Fix/Ignore? Fix
Partition number? 3
Warning: Partition /dev/mmcblk1p3 is being used. Are you sure you want to continue?
Yes/No? yes
End? [15.7GB]? 100%
(parted) p free
Model: SD SA32G (sd/mmc)
Disk /dev/mmcblk1: 31.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
17.4kB 1049kB 1031kB Free Space
1 1049kB 17.8MB 16.8MB
2 17.8MB 123MB 105MB fat16 boot, esp
3 123MB 31.2GB 31.1GB ext4 legacy_boot

(parted) q
Information: You may need to update /etc/fstab.

あとは手順通りに resize2fs する。無事に拡張できた。

$ sudo resize2fs /dev/mmcblk1p3
sudo: unable to resolve host starfive: Name or service not known
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mmcblk1p3 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/mmcblk1p3 is now 7597819 (4k) blocks long.

shin@starfive:~$ df -kh
Filesystem Size Used Avail Use% Mounted on
udev 1.7G 0 1.7G 0% /dev
tmpfs 390M 1.8M 388M 1% /run
/dev/mmcblk1p3 29G 13G 16G 45% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 390M 36K 390M 1% /run/user/0
tmpfs 390M 28K 390M 1% /run/user/111
tmpfs 390M 24K 390M 1% /run/user/1001


Byte-UnixBench ベンチマーク

githubからByte-UnixBenchを入れる。Starfiveのdebian Imageには、コンパイルに必要なmakeやgccが無い。aptコマンドで追加する。

makeするとエラーになる。 RISC-V用のgccのコンパイラオプションでは、march=native の指定ができない。

$ make
make distr
make[1]: Entering directory '/home/shin/byte-unixbench/UnixBench’
Checking distribution of files
./pgms exists
./src exists
./testdir exists
./tmp exists
./results exists
make[1]: Leaving directory '/home/shin/byte-unixbench/UnixBench’
make programs
make[1]: Entering directory '/home/shin/byte-unixbench/UnixBench’
gcc -o pgms/arithoh -Wall -pedantic -O3 -ffast-math -march=native -mtune=native -I ./src -DTIME -Darithoh src/arith.c
gcc: error: '-march=native’: ISA string must begin with rv32 or rv64
make[1]: *** [Makefile:233: pgms/arithoh] Error 1
make[1]: Leaving directory '/home/shin/byte-unixbench/UnixBench’
make: *** [Makefile:174: all] Error 2

コンパイラオプションを march=rv64imafdc にすれば良い。

$ cat /proc/cpuinfo
processor : 0
hart : 1
isa : rv64imafdc
mmu : sv39
uarch : sifive,u74-mc


ベンチマーク結果

Raspberry Pi 4 Model B のベンチマークと比べると、Dhrystone/Whetstoneが悪くて、File Copyが良い。VisionFive 2のグラフでもCPU Benchmarksは悪いので、こんなもんか。 clangも試してみたけど大差ありませんでした。

========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)

System: starfive: GNU/Linux
OS: GNU/Linux — 5.15.0-starfive — #1 SMP Fri Nov 11 06:58:52 EST 2022
Machine: riscv64 (unknown)
Language: en_US.utf8 (charmap="ANSI_X3.4-1968″, collate="ANSI_X3.4-1968″)
09:04:41 up 59 min, 4 users, load average: 0.05, 0.04, 0.12; runlevel Jun

————————————————————————
Benchmark Run: Thu Jan 05 2023 09:04:41 – 09:32:45
4 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables 5639427.3 lps (10.0 s, 7 samples)
Double-Precision Whetstone 1463.3 MWIPS (10.0 s, 7 samples)
Execl Throughput 2063.2 lps (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks 193873.0 KBps (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks 67846.3 KBps (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks 338859.0 KBps (30.0 s, 2 samples)
Pipe Throughput 368578.1 lps (10.0 s, 7 samples)
Pipe-based Context Switching 31294.1 lps (10.0 s, 7 samples)
Process Creation 2024.8 lps (30.0 s, 2 samples)
Shell Scripts (1 concurrent) 3014.8 lpm (60.0 s, 2 samples)
Shell Scripts (8 concurrent) 1272.1 lpm (60.0 s, 2 samples)
System Call Overhead 814042.0 lps (10.0 s, 7 samples)

System Benchmarks Index Values BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 5639427.3 483.2
Double-Precision Whetstone 55.0 1463.3 266.0
Execl Throughput 43.0 2063.2 479.8
File Copy 1024 bufsize 2000 maxblocks 3960.0 193873.0 489.6
File Copy 256 bufsize 500 maxblocks 1655.0 67846.3 409.9
File Copy 4096 bufsize 8000 maxblocks 5800.0 338859.0 584.2
Pipe Throughput 12440.0 368578.1 296.3
Pipe-based Context Switching 4000.0 31294.1 78.2
Process Creation 126.0 2024.8 160.7
Shell Scripts (1 concurrent) 42.4 3014.8 711.0
Shell Scripts (8 concurrent) 6.0 1272.1 2120.2
System Call Overhead 15000.0 814042.0 542.7
========
System Benchmarks Index Score 409.2

————————————————————————
Benchmark Run: Thu Jan 05 2023 09:32:45 – 10:00:53
4 CPUs in system; running 4 parallel copies of tests

Dhrystone 2 using register variables 22569542.5 lps (10.0 s, 7 samples)
Double-Precision Whetstone 5857.3 MWIPS (10.0 s, 7 samples)
Execl Throughput 7756.8 lps (29.9 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks 422273.1 KBps (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks 124321.7 KBps (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks 684637.3 KBps (30.0 s, 2 samples)
Pipe Throughput 1469767.1 lps (10.0 s, 7 samples)
Pipe-based Context Switching 214946.4 lps (10.0 s, 7 samples)
Process Creation 16462.4 lps (30.0 s, 2 samples)
Shell Scripts (1 concurrent) 10502.1 lpm (60.0 s, 2 samples)
Shell Scripts (8 concurrent) 1362.1 lpm (60.1 s, 2 samples)
System Call Overhead 2963434.2 lps (10.0 s, 7 samples)

System Benchmarks Index Values BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 22569542.5 1934.0
Double-Precision Whetstone 55.0 5857.3 1065.0
Execl Throughput 43.0 7756.8 1803.9
File Copy 1024 bufsize 2000 maxblocks 3960.0 422273.1 1066.3
File Copy 256 bufsize 500 maxblocks 1655.0 124321.7 751.2
File Copy 4096 bufsize 8000 maxblocks 5800.0 684637.3 1180.4
Pipe Throughput 12440.0 1469767.1 1181.5
Pipe-based Context Switching 4000.0 214946.4 537.4
Process Creation 126.0 16462.4 1306.5
Shell Scripts (1 concurrent) 42.4 10502.1 2476.9
Shell Scripts (8 concurrent) 6.0 1362.1 2270.2
System Call Overhead 15000.0 2963434.2 1975.6
========
System Benchmarks Index Score 1336.1


続く。

リンク

RISC-V, VisionFive-2

Posted by ず@沖縄