Skip to content

Commit 564feca

Browse files
KevinMXRevySR
authored andcommitted
docs: add kvm/opensbi-h usage
Signed-off-by: Jingkun Zheng <[email protected]>
1 parent e6b5e80 commit 564feca

File tree

2 files changed

+402
-0
lines changed
  • docs/desktop
  • i18n/en/docusaurus-plugin-content-docs/current/desktop

2 files changed

+402
-0
lines changed

docs/desktop/kvm.md

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
title: KVM
3+
sidebar_position: 3
4+
---
5+
6+
# 基于 OpenSBI-H 的 KVM 虚拟化
7+
8+
RevyOS 为 `TH1520` 平台提供基于 OpenSBI-H 的 KVM 虚拟化。
9+
10+
目前已验证支持的开发板:
11+
12+
- Milk-V Meles
13+
- Sipeed Lichee Pi 4A
14+
15+
:::warning
16+
TH1520 平台的 OpenSBI-H 为**实验性支持**
17+
可能会遇到 KVM 启动时间久、控制台输出缓慢、特定场景性能下降严重等问题。
18+
:::
19+
20+
## 软件包安装
21+
22+
:::note
23+
旧版本系统不被支持,请使用最新版本镜像。
24+
:::
25+
26+
在安装之前,请务必执行一次全系统更新,并安装 `6.6.77` 版本内核。此版本附带了 `kvm` 内核模块。
27+
28+
安装结束后,重启系统。
29+
30+
```shell
31+
sudo apt update; sudo apt upgrade -y
32+
sudo apt install -y th1520-mainline-opensbi-h qemu-system wget linux-image-6.6.77-th1520
33+
# 如需使用 U-Boot 引导 VM:
34+
# sudo apt install -y u-boot-qemu
35+
sudo reboot
36+
```
37+
38+
## 验证
39+
40+
若您的开发板已连接 UART 串口,则可以在启动时的串口打印中看到类似如下字样:
41+
42+
```log
43+
Hypervisor Extension : Emulated
44+
Shadow PT Space Base : 0x3ff000000
45+
Shadow PT Space Size : 4096 pages
46+
```
47+
48+
此外,进入系统后,可检查 `/proc/cpuinfo`
49+
50+
```shell
51+
grep isa /proc/cpuinfo
52+
```
53+
54+
应当会输出类似如下内容(可以看到每个核心的 ISA 部分增加了 H 扩展):
55+
56+
```log
57+
processor : 0
58+
hart : 0
59+
isa : rv64imafdch_zicntr_zicsr_zifencei_zihpm_xtheadvector
60+
mmu : sv39
61+
uarch : thead,c910
62+
mvendorid : 0x5b7
63+
marchid : 0x0
64+
mimpid : 0x0
65+
66+
processor : 1
67+
hart : 1
68+
isa : rv64imafdch_zicntr_zicsr_zifencei_zihpm_xtheadvector
69+
mmu : sv39
70+
uarch : thead,c910
71+
mvendorid : 0x5b7
72+
marchid : 0x0
73+
mimpid : 0x0
74+
75+
processor : 2
76+
hart : 2
77+
isa : rv64imafdch_zicntr_zicsr_zifencei_zihpm_xtheadvector
78+
mmu : sv39
79+
uarch : thead,c910
80+
mvendorid : 0x5b7
81+
marchid : 0x0
82+
mimpid : 0x0
83+
84+
processor : 3
85+
hart : 3
86+
isa : rv64imafdch_zicntr_zicsr_zifencei_zihpm_xtheadvector
87+
mmu : sv39
88+
uarch : thead,c910
89+
mvendorid : 0x5b7
90+
marchid : 0x0
91+
mimpid : 0x0
92+
```
93+
94+
## 使用
95+
96+
加载 `kvm` 内核模块。
97+
98+
```shell
99+
sudo modprobe kvm
100+
```
101+
102+
检查 `dmesg`
103+
104+
```log
105+
$ sudo dmesg | grep kvm
106+
[ 1645.703407] kvm [762]: hypervisor extension available
107+
[ 1645.708548] kvm [762]: using Sv39x4 G-stage page table format
108+
[ 1645.714352] kvm [762]: VMID 0 bits available
109+
```
110+
111+
我们提供了一个基于 `busybox` 的 KVM demo,其中附带了一份静态编译的 `coremark` 二进制,可自行取用。
112+
113+
:::warning
114+
您可能会发现 `coremark` 执行速度非常慢,这是预期结果。
115+
目前的性能测试结果可能无法反映 VM 的真实性能。
116+
:::
117+
118+
```shell
119+
wget https://mirror.iscas.ac.cn/revyos/extra/kvm_demo/rootfs_kvm_guest.img \
120+
https://mirror.iscas.ac.cn/revyos/extra/kvm_demo/start_vm.sh \
121+
https://mirror.iscas.ac.cn/revyos/extra/kvm_demo/Image \
122+
```
123+
124+
启动 KVM:
125+
126+
```shell
127+
chmod +x start_vm.sh; ./start_vm.sh
128+
```
129+
130+
`qemu-system-riscv64` 的如下警告是预期的,可安全忽略:
131+
132+
```log
133+
qemu-system-riscv64: warning: disabling h extension for hart 0x0 because privilege spec version does not match
134+
qemu-system-riscv64: warning: disabling zba extension for hart 0x0 because privilege spec version does not match
135+
qemu-system-riscv64: warning: disabling zbb extension for hart 0x0 because privilege spec version does not match
136+
qemu-system-riscv64: warning: disabling zbc extension for hart 0x0 because privilege spec version does not match
137+
qemu-system-riscv64: warning: disabling zbs extension for hart 0x0 because privilege spec version does not match
138+
qemu-system-riscv64: warning: disabling sstc extension for hart 0x0 because privilege spec version does not match
139+
qemu-system-riscv64: warning: disabling h extension for hart 0x1 because privilege spec version does not match
140+
qemu-system-riscv64: warning: disabling zba extension for hart 0x1 because privilege spec version does not match
141+
qemu-system-riscv64: warning: disabling zbb extension for hart 0x1 because privilege spec version does not match
142+
qemu-system-riscv64: warning: disabling zbc extension for hart 0x1 because privilege spec version does not match
143+
qemu-system-riscv64: warning: disabling zbs extension for hart 0x1 because privilege spec version does not match
144+
qemu-system-riscv64: warning: disabling sstc extension for hart 0x1 because privilege spec version does not match
145+
```
146+
147+
`Enter` 激活终端:
148+
149+
```log
150+
[ 13.274754] Run /init as init process
151+
_ _
152+
| ||_|
153+
| | _ ____ _ _ _ _
154+
| || | _ \| | | |\ \/ /
155+
| || | | | | |_| |/ \
156+
|_||_|_| |_|\____|\_/\_/
157+
158+
Busybox Rootfs
159+
160+
Please press Enter to activate this console.
161+
/ #
162+
```
163+
164+
CoreMark 结果如下:
165+
166+
```log
167+
/ # coremark
168+
2K performance run parameters for coremark.
169+
CoreMark Size : 666
170+
Total ticks : 19343
171+
Total time (secs): 19.343000
172+
Iterations/Sec : 10339.657757
173+
Iterations : 200000
174+
Compiler version : GCC13.2.0
175+
Compiler flags : -O2 -lrt
176+
Memory location : Please put data memory location here
177+
(e.g. code in flash, data on heap etc)
178+
seedcrc : 0xe9f5
179+
[0]crclist : 0xe714
180+
[0]crcmatrix : 0x1fd7
181+
[0]crcstate : 0x8e3a
182+
[0]crcfinal : 0x4983
183+
Correct operation validated. See README.md for run and reporting rules.
184+
CoreMark 1.0 : 10339.657757 / GCC13.2.0 -O2 -lrt / Heap
185+
/ #
186+
```
187+
188+
## 恢复
189+
190+
恢复原本的 OpenSBI,然后重启即可。
191+
192+
```shell
193+
sudo apt install th1520-mainline-opensbi -y
194+
```
195+
196+
## 致谢
197+
198+
- [OpenSBI-H](https://github.com/dramforever/opensbi-h) - [dramforever](https://github.com/dramforever), [ZenithalHourlyRate](https://github.com/ZenithalHourlyRate)
199+
- [TH1520 OpenSBI-H](https://github.com/revyos/opensbi/tree/th1520-v1.6-h) 适配 - [wxjstz](https://github.com/wxjstz)
200+
- RevyOS - [RevySR](https://github.com/RevySR)
201+
- 测试及文档撰写 - [KevinMX](https://github.com/KevinMX)

0 commit comments

Comments
 (0)