带有 U-Boot 的 QEMU 使用 100% CPU

QEMU with U-Boot uses 100% of CPU

在 Lubuntu VirtualBox VM(macOS 主机)中,我是 运行 QEMU 和 U-Boot 内核(?)加载我编译的 ARM 汇编代码(使用 tftp addr *.bingo addr).

我的问题是 QEMU 使用了 100% 的 CPU。我正在学习汇编编程课程,并被告知这是不正常的(这也是我使用 VM 的原因)…

我不确定问题出在哪里,是 VirtualBox(安装了来宾添加)还是 QEMU 的配置问题?

QEMU 使用以下参数启动:

export QEMU_AUDIO_DRV=none
qemu-arm/arm-softmmu/qemu-system-arm -s -localtime -m 256 -M reptar -kernel u-boot-arm/u-boot -tftp . -serial mon:stdio -nographic

版本是:

$ qemu-arm/arm-softmmu/qemu-system-arm --version
QEMU emulator version 2.4.1 (qemu-linaro from git), Copyright (c) 2003-2008 Fabrice Bellard

引导输出:

reptar-sp6-emul: sp6_emul_init
sp6_emul_init: failed to connect to SP6 server
sp6_emul_init: terminate thread


U-Boot 2016.09 (Sep 26 2018 - 17:19:23 +0200)

OMAP35XX-GP ES3.1, CPU-OPP2, L3-165MHz, Max CPU Clock 600 MHz
REDS Reptar board + LPDDR/NAND
I2C:   ready
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
Using default environment

Net:   smc911x-0
Reptar # 

当访客 CPU 正在做某事时,QEMU 将使用主机 CPU,即使那个 "something" 是 "spin around in a tight loop"。如果来宾代码在其空闲循环中使用 CPU 指令 WFI ("wait for interrupt"),QEMU 将通过停止来处理该问题,直到发生来宾中断。 (WFI 是 Arm 指令;对于其他客户体系结构,通常有等效指令,如 x86 的 HLT。)

因此,当客户机 "idle" 时,QEMU 是否使用 100% CPU 取决于客户机的空闲循环究竟做了什么。像 Linux 这样的 "real OS" 中的空闲循环将使用 WFI(在实际硬件上这对于降低功耗很有用),因此将在非常低的主机 CPU 使用率下空闲。 CPU 在 u-boot 提示符下的使用将取决于 u-boot 的编码方式; CPU 汇编代码中的用法将取决于它的作用。