Skip to content

RISCV VM testing of popcorn

AshwinKrishn edited this page Jun 18, 2020 · 15 revisions

Overview

This tutorial details the steps to test x86 , riscv testing of popcorn kernel.

--------------   --------------
|   Node 0   |   |   Node 1   |
|            |   |            |
|    x86     |   |   riscv    |
| 10.4.4.100 |   | 10.4.4.101 |
--------------   --------------
|  qem-x86   |   |  qemu-riscv|
-------------------------------
|  linux-x86       linux-riscv|
|                             |   ------------
|         host (x86)          |   | Gateway  |
|          10.4.4.10          |---| 10.4.4.1 |--- Internet
-------------------------------   ------------

Prepare for the setup

  • The machine should have;

    • At least 20 GB of storage
    • 8 GB of RAM (qemu scripts below initiate VMs with 4 GB each. You can change -m option in the scripts to use different size of memory)
  • Let's start with updating apt repository and install some utilities:

$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev libncursesw5-dev git curl bc

Download the patch files and support files

Compile the RISCV QEMU

$ git clone --recursive https://github.com/riscv/riscv-qemu.git
$ cd riscv-qemu
$ ./configure --target-list=riscv64-softmmu
$ make -j$(nproc)
$ make install

Compiling the RISCV GNU toolchain

  • Follow the instructions to build and install riscv gnu toolchain.This build takes time.
$ git clone --recursive https://github.com/riscv/riscv-gnu-toolchain.git
$ ./configure --prefix=/opt/riscv --with-target-cflags="-ffunction-sections -fdata-sections"
$ make linux LINUX_TUPLE="riscv64-linux-gnu"
$ export PATH=/opt/riscv/bin:$PATH
  • Test if /opt/riscv/bin is present in $PATH
$echo $PATH 
/opt/riscv/bin/:/home/userr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin

Compiling the popcorn compiler with riscv support

  • Instructions to build popcorn-compiler. This build takes around one hour.
$ https://github.com/ssrg-vt/popcorn-compiler.git
$ cd popcorn-compiler
$ patch -p1 < ../riscv_support_dir/popocorn-compiler.patch
$ ./install_compiler.py --install-path=/path/to/install --install-all

Compiling NPB applications for testing

  • The riscv_support_dir contains NPB benchmarking suite.
  • To compile the applications change the popcorn compiler path to the newly built compiler.
  • This will compile the NPBB applications for both the arhitectures. (x86 , RISCV).

Compiling the popcorn RISCV kernel

  • We are using the mainlin 5.2.21 kernel. Apply the patch from riscv_support_dir.
  • Copy the riscv64-config from the support directory
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
$ git checkout v5.2.21
$ patch -p1 < ../riscv_support_dir/popcorn-kernel.diff
$ cp riscv64-config .config
$ ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make -j24
$ cp arch/riscv/boot/Image ../riscv_support_dir/riscv64-Image

Booting the RISCV kernel

  • The support_dir contains the disk image file. (riscv_diskimg.ext4)
  • Support_dir also contains a SBI loader.(fw_jump.elf). Riscv QEMU needs this to boot the kernel.
  • Once the kernel is copied from the kernel directory , we must be ready to boot the kernel.
riscv_support_dir$./start-riscv 
  • Make sure to copy your kernel to the support folder "riscv_support_dir".
sudo 	qemu-system-riscv64 \
	-machine virt -cpu rv64 -m 4G -nographic -s \
	-drive id=root,if=none,media=disk,file=riscv_diskimg.ext4 \    ---> The root file system
	-smp 4 \
	-device virtio-blk-device,drive=root \
	-device virtio-net-device,netdev=net0,mac=52:54:00:12:35:02 \
	-netdev tap,id=net0 \
	-kernel fw_jump.elf \                                           --->  "The SBI loader file "   
	-device loader,file=riscv64-Image,addr=0x80200000 \             --->  "Make sure you copied this file"
	-object rng-random,filename=/dev/urandom,id=rng -device virtio-rng-device,rng=rng \
	-append 'root=/dev/vda rw highres=off  console=ttyS0 earlycon=sbi '

Setting up messaging layer

Now execute the following command in both the machines:

In the riscv VM : root@riscv:~# modprobe msg_socket

In the x86 VM : user@x86 # modprobe msg_socket

  • If all works fine you are set with environment.

Testing the x86 <-> RISCV popcorn system

After booting the x86 and riscv QEMU VMs, copy the npb applications into the VMs.

  • Setup the messaging layer -- Create a folder /etc/popcorn in both VMs. -- Create a file inside /etc/popcorn/nodes in both VMs. -- The nodes file must contain the " same order " of IP addresses. In the above diagram both the VMs must contain the files in the below fashion.
$cat etc/popcorn/nodes
10.4.4.100
10.4.4.101
  • Copy the executables into the VMs
$scp ep_riscv ep_x86-64 [email protected]
$scp ep_riscv ep_x86-64 [email protected]
  • In the x86 VM
x86 $ cp ep_x86-64 ep
  • In the riscv VM
riscv $ cp ep_riscv ep
  • Now you can start testing the ep by executing the application in the 0th Node. (in the x86 VM in this example)

Please continue to next page for trying popcorn on readl Hardware.