QEMU with U-Boot uses 100% of CPU - virtualization

Inside a Lubuntu VirtualBox VM (macOS host) I'm running QEMU with a U-Boot kernel (?) to load my compiled ARM assembly code (using tftp addr *.bin and go addr).
My problem is that QEMU uses 100% of the CPU. I'm following an Assembly programming course and was told that it wasn't normal (that's also why I'm using a VM)…
I'm not sure where does the problem come from, is it a config issue with VirtualBox (Guest additions are installed) or with QEMU?
QEMU is launched with the following arguments:
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
Version is:
$ qemu-arm/arm-softmmu/qemu-system-arm --version
QEMU emulator version 2.4.1 (qemu-linaro from git), Copyright (c) 2003-2008 Fabrice Bellard
Boot output:
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 #

QEMU will use host CPU when the guest CPU is doing something, even if that "something" is "spin around in a tight loop". If the guest code uses the CPU instruction WFI ("wait for interrupt") in its idle loop, QEMU will handle that by stopping until a guest interrupt occurs. (WFI is an Arm instruction; for other guest architectures there is generally an equivalent instruction, like x86's HLT.)
So whether QEMU uses 100% CPU when the guest is "idle" depends on what exactly the guest's idle loop does. The idle loop in a "real OS" like Linux will use WFI (which on real hardware is useful for reducing power consumption) and so will idle at very low host CPU usage. CPU usage sitting at a u-boot prompt will depend on how u-boot is coded; CPU usage in your assembly code will depend on what it does.

You can use cpulimit with -l flag, to limit processor time for particular process. For example:
cpulimit -l 20 -- qemu-system-x86_64 -bios ./u-boot.rom
will limit qemu cpu usage by 20% of one core.
Also, more tricky way on native hardware (probably will not work in virtualbox): if you've got multicore processor, you may dedicate 1 cpu core for qemu, and limit it's clock frequency to lowest possible value, to save energy and keep it cool. Example on my Ryzen 4650u cpu:
install cpupower and tasksel: apt install linux-cpupower tasksel
get lowest possible core clock: cpupower -c 0 frequency-info -l
set core 0 clock frequency to lowest possible value: cpupower -c 0 frequency-set -u clock_freq 1400Mhz
run u-boot in qemu, assign process to core 0: qemu-system-x86_64 -bios ./u-boot.rom & taskset -cp 0 $!

Related

Using MPICH on two differnt architectures

I am new to MPI. I am trying to get my x86 laptop and and a raspberry pi to "work together" via mpi. However I am having a hard time setting it up for the two to work together. I made a machinefile to store IP addresses. When I am running on the raspberry pi with only its IP in the machine file everything runs as expected, it is the same with the laptop. However when I have both IPs in the machine file nothing happens, I have to use ctrl+c to kill the command. On the laptop I am running slackware and on the raspberry pi raspbian.
Here is what I get when i run mpiexec --version
# raspberry pi###############
HYDRA build details:
Version: 3.4.1
Release Date: Fri Jan 22 14:17:48 CST 2021
CC: gcc -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -ffile-prefix-map=/build/mpich-a7gXGS/mpich-3.4.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro
Configure options: '--with-hwloc-prefix=/usr' '--with-device=ch3' 'FFLAGS=-O2 -ffile-prefix-map=/build/mpich-a7gXGS/mpich-3.4.1=. -fstack-protector-strong -fallow-invalid-boz -fallow-argument-mismatch' '--prefix=/usr' 'CFLAGS=-g -O2 -ffile-prefix-map=/build/mpich-a7gXGS/mpich-3.4.1=. -fstack-protector-strong -Wformat -Werror=format-security' 'LDFLAGS=-Wl,-z,relro' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2'
Process Manager: pmi
Launchers available: ssh rsh fork slurm ll lsf sge manual persist
Topology libraries available:
Resource management kernels available: user slurm ll lsf sge pbs cobalt
Demux engines available: poll select
# Slackware
mpiexec (OpenRTE) 4.1.0
Report bugs to http://www.open-mpi.org/community/help/
the command I am running, on slackware, is
mpirun --hostfile machinefile -np 2 hostname
I want the laptop to be like a head for multiple raspberrys. I Imagined that since mpi is a standard I would be able to get these two versions to communicate without much of a hassle. Is there something I need to configure to get these two computers to work?
Thanks for your time

Error on boot after exporting VM from XenServer 6.5 in Ova format and importing on VirtualBox/VmWarePlayer

After exporting .Ova file, containing .ovf and .vhd resources, I'am facing errors during
boot of the VM in VirtualBox/VmwarePlayer. Output ad follow
'''
root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
kernel /vmlinuz-2.6.18-419.el5xen ro root=/dev/VolGroup00/LogVo100 console=xvc0
Error 13: Invalid or unsupported executable format
'''
I found the problem. It is related to the custom Xen kernel.
A fix can be found by installing a new kernel, disabling console on /etc/inittab and enabling tty.
Current kernel installed packages
<code># rpm -qa | grep ‘kernel’'</code>
Download the latest RPM
In my case I had to find it because the CentOs is very old
Checking the RPM signature
<code>#rpm -K *rpm</code>
Install/Update non-kernel RPMs (optional in my case)
<code> rpm -Uvh mkinitrd.rpm SysVinit.rpm initscripts.rpm </code>
(optional, for kernel developers)
<code>#rpm -Uvh kernel-headers.rpm kernel-source.rpm</code>
Install Kernel
<code>#rpm -ivh kernel-2.6.18-420.el5.x86_64.rpm</code>
*Note: Use ivh option "install" because Uvh option "Update" will delete previous installed kernel, which may need in case of any unsuccessful update.
Creating Initial RAM disk (optional, only if system has SCSI controllers/SCSI hard drive)
<code>#ls -l /boot/initrd-* </code>
If you can find an image for the currently running kernel, you need to proceed with this command for creating new initrd image for the new kernel:
<code>#mkinitrd /boot/initrd-2.2.17-14.img 2.2.17-14</code>
Verify the grub configuration "/etc/grub.conf"
Grub will be automatically configured with the new kernel upon RPM installation
Anyway if multiple kernels are avaible, you could specify on boot which one you want to use.
In grub.conf, the value “0” to “default” indicates that it will boot from the first kernel mentioned.
Edit /etc/inittab , This file defines three important items for the init process:
The system's default run level
What processes to start, monitor, and restart if they terminate
What actions to be taken when the system enters a new run level
Initializes console and identifies the terminal type
We are going to comment console line and uncomment text-only terminals as follows
##comment this##co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
Reboot the Macchine
In my case, after this operations I've been able to export and start the Vm on VirtualBox avoiding the previous error mentioned.

how to install MongoDb on Debian 11

I followed the description of how to install MongoDB to Debian 11 that can be found in severall places. Since all describe the same, I selected one of them.
Every input works as expected. Even the attempt to start the service with
sudo systemctl start mongod
does not create any error. When I check the status with
sudo systemctl status mongod
I receive:
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: signal) since Sat 2022-04-30 19:31:40 CEST; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 506851 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=killed, signal=ILL)
Main PID: 506851 (code=killed, signal=ILL)
CPU: 12ms
and if I try to call mongo, I receive the message in German:
"Ungültiger Maschinenbefehl"
I deinstalled and reistalled a few times, but the result is always the same.
Does anybody has any idea?
"Ungültiger Maschinenbefehl"
that looks very much like an "illegal instruction" (which is also hinted at by the (code=killed, signal=ILL) printout of systemd: according to man 7 signal, the meaning of SIGILL is indeed illegal instruction
.
An "illegal instruction" happens, when the machine code of your binary contains instructions that your CPU does not understand.
Now, there are a couple of safeguards that prevent you to run binaries that are totally incompatible (e.g. trying to run an amd64 binary on a RaspberryPi), but even for a given architecture (e.g. amd64) there are many CPU variants, with different (additional) instruction sets.
So in your case most likely MongoDB was compiled for the latest and greatest CPU (or your architecture) using all the nifty SIMD and whatnot accelerations available. Unfortunately your CPU appears to be older (not supporting these nifty and whatnot instructions), and as soon as the execution reaches such an instruction, the program terminates.
Now official Debian packages go to great lengths to support a minimal baseline CPU, that has an instruction set that is available on virtually all CPUs of the given architecture (with the drawback, that it is not the most optimized CPU).
However, you are using packages by some 3rd party, who seem to not care for compatibility with older CPUs (or who are just not aware of the problem).
How to solve the issue:
recompile your software specifically for your CPU
ask the providers of the binaries to also provide a binary for legacy CPUs (probably using a baseline CPU like Debian itself)
upgrade your CPU
I asked NetCup, my Provider of the V-Server. The system does support die AVX instruction set. Therefore MongoDB 5.0 cannot be installed and that is the reason for the instruction error.
I had to install MongoDB 4.4. That did work.

Buildroot and Qemu

I'm using buildroot to compile a minimalistic linux with a 4.19-rt kernel. It is supposed to run on a raspberry pi 3b (arm processor). Additionally I want to run it on a x86_64 linux computer and found qemu as an emulation solution for that.
Building linux and kernel and running it on the raspi works. It boots, I can login and use it.
To test qemu I followed this instruction [1]. A recent raspbian with 4.19 kernel is booting fine so qemu seems to be installed correctly.
sudo qemu-system-arm -kernel ./qemu-rpi-kernel/kernel-qemu-4.19.50-buster -hda 2019-09-26-raspbian-buster-lite.img -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -dtb qemu-rpi-kernel/versatile-pb.dtb
Bringing 1. and 2. together fails. When I try to emulate any self build linux, qemu only shows a black screen and one CPU is using 100%.
I used the same sdcard.img that works on the real hardware. I also tried to recompile the whole system with a normal 4.19 kernel (without real time). And I tried to build a versatile system (make qemu_arm_versatile_defconfig && make). None of it works.
Command to start the emulation:
sudo qemu-system-arm -kernel zImage -drive format=raw,file=sdcard.img -cpu arm1176 -m 256 -M versatilepb -no-reboot -append "root=/dev/mmcblk0p2 panic=1 rootfstype=ext4 rw" -serial stdio
My main problem is, that there is absolutly no useful output. The command outputs the following
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
sdl: SDL_OpenAudio failed
sdl: Reason: ALSA: Couldn't open audio device: Connection refused
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
sdl: SDL_OpenAudio failed
sdl: Reason: ALSA: Couldn't open audio device: Connection refused
audio: Failed to create voice `lm4549.out'
and opens a window for the graphics output (that does not show anything). The message also appears when emulating raspbian so it does not seem to be the reason.
When I run qemu with the prebuild raspbian but without the -dtb argument, I get a message like "Error: invalid dtb and unrecognized/unsupported machine ID". I would at least expect something like this with my self build code. But because there is no output I'm out of ideas what even to google for.
Does someone maybe have an idea what I'm doing wrong or how I get qemu to provide me any useful information on what went wrong?
[1] https://blog.agchapman.com/using-qemu-to-emulate-a-raspberry-pi/
The problem is that a kernel will only boot on a piece of Arm hardware if it is compiled for that hardware. Otherwise it will generally fail, usually by crashing before it is able to output anything useful.
In particular, the QEMU 'versatilepb' machine is completely different to the Raspberry Pi. Any working set of instructions that use that machine type are really running a kernel built to work with the versatilepb board and a raspi userspace/filesystem on top of that. You're trying to build a kernel that has support for only the raspi on a machine that isn't a raspi, which won't work.
It is possible to build a kernel that works on more than one piece of Arm hardware, if you compile in the support for both board types (all the device drivers for both, etc). If you want to go down that path, I would suggest looking at the differences between the kernel config for the kernel that works and your one, and add plausible looking missing things until you find out what is actually required.
Your attempt to boot on QEMU directly from sdcard.img will not work, because QEMU's versatilepb board model does not support direct boot from sdcard (this would require us to run some kind of BIOS/firmware image in the guest, which we don't have). For versatilepb you need to supply directly to QEMU the kernel, possibly an initrd, and definitely the correct dtb for the versatilepb.
You might instead try looking at QEMU's "raspi2" and "raspi3" board models, which really do model the hardware of Raspberry Pis. The disadvantages however are that these models are missing some features and are not very actively developed, so often newer kernels don't boot on them, and also since there is no USB controller model there is no way to get networking. (This is why most blog posts etc suggest using the 'versatilepb' -- userspace doesn't often really care about exactly what hardware it's running on, so unless you're trying to do kernel development you can just run a versatilepb kernel and take advantage of the features like networking that that QEMU model has.)
Advanced Linux Sound Architecture (ALSA) tries to open audio interface device . you must provide audio device in qemu . Because the kernel is compiled with ALSA audio driver and you have compiled sdl library in Buildroot.

(Cross-)Compiling Swift for Raspberry PI

Swift is now Open Source. Did anyone tried compiling Swift for a Raspberry PI? I started to do, but my 8 GB SD card seems to be too small for it ;) Is it possible to cross compile it from Ubuntu?
A 8GB SD Card works ok, but you'll need to extend the root volume. I have it working and the used space on /dev/root partition is around 3.1GB.
The steps below are based on the blog post by Andrew Madsen with a little extra focus on the steps inside fdisk.
Get Ubuntu
Download an image of Ubuntu 14.04 for Raspberry Pi 2 from finnie.org and copy it onto the SD card. Boot the Raspberry Pi.
Change the partition
Log into the Raspberry Pi and change the partition size. The default size for /dev/root is 1.7G with 1.1G available. That is not enough.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.7G 540M 1.1G 35% /
devtmpfs 458M 4.0K 458M 1% /dev
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 93M 228K 93M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 462M 0 462M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mmcblk0p1 64M 20M 45M 31% /boot/firmware
Run fdisk
sudo fdisk /dev/mmcblk0
At the prompt enter p for 'print the partition table'. There are two partitions
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
/dev/mmcblk0p2 133120 3670015 1768448 83 Linux
When prompted, enter d (for delete), then 2. Then, recreate the partition by entering n, then p, then 2, then pressing enter at the next two prompts accepting the defaults.
Enter p again and see the second partition is now bigger, now all space on an 8GB card is used.
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
/dev/mmcblk0p2 133120 15523839 7695360 83 Linux
Enter w to write the changes to disk, then reboot
sudo reboot
Resize the partition
After the reboot, resize the partition’s file system by running
sudo resize2fs /dev/mmcblk0p2
Swap space
Setup a swap file by doing
sudo apt-get install dphys-swapfile
Install libicu-dev and clang-3.6
sudo apt-get install libicu-dev clang-3.6
Use update-alternatives to provide /usr/bin links for clang and clang++:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
Then, add #iachievedit’s repository key:
wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -
Add the appropriate repository to sources.list:
echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list
Run apt-get update:
sudo apt-get update
Install Swift
sudo apt-get install swift-2.2
After the installation is complete, you’re ready to compile Swift programs!
Write Swift
Open your favorite text editor, write a program, and save it (e.g. to 'hello.swift’):
let device = "Raspberry Pi 2!"
print("Hello from Swift on \(device)")
Compile it
swiftc hello.swift
and run it:
./hello
Hello from Swift on Raspberry Pi 2!
That’s it! Swift running on Raspberry Pi
The Swift Package Manager got custom toolchain support via
PR-1098
end of April 2017.
I wrote up detailed instructions on how to build a RaspberryPi toolchain over here: macOS -> RasPi Cross Compilation Toolchain
and even the reverse (build macOS binaries on a RaspberryPi) for the fun of it.
The same would work for Intel-Linux to ARM-Linux w/ minimal modifications. The SwiftPM repo contains an example script on how to do this for Intel-macOS to Intel-Ubuntu.
You can find a 2017-05-01 update on Swift-on-ARM over here:
An Update on Swift 3.1.1 For Raspberry Pi Zero/1/2/3.
As a small summary, so that this answer isn't just links ;-), ARM status 2017-05-16:
you can compile Swift 3.1/3.1.1 on RaspberryPi Ubuntu
don't forget to setup swap, some minimal patches are required
for 3.1.1. 8GB disk may be a bit to little.
compilation on Raspbian doesn't seem to work yet (last known version
is 3.0.2)
you can cross-compile Swift using a custom toolchain, which is
reasonably easy to setup
you need to grab a SwiftPM snapshot (Swift 4) for this (but the toolchain itself can be 3.1 or even 3.0.2 w/ minor changes)
you can also run (and compile) Swift via Docker,
e.g. in HypriotOS.
there is a Slack group for Swift ARM: swift-arm