qemu-hdl-cosim
qemu-hdl-cosim copied to clipboard
VM-HDL Co-Simulation for Servers with PCIe-Connected FPGAs
Table of Contents
- Overview of qemu-hdl-cosim
- Install Qemu and Create a VM image
- Run Co-Simulation
- Run Vivado XSim in Host Machine
- Run application in Guest Machine
Overview of qemu-hdl-cosim
This repository contains work by COMPAS Lab. The original project introduction is here. Please site the paper and watch the presentation.
The demo code is ported here to use Vivado XSim instead of VCS, with minor improvements to the README. This example source release is the cosim demo for an accelerated sorting application.
Tools to use
This release has been tested with the following tools and libs:
Ubuntu 18.04.3 Vivado 2018.3 QEMU 2.10 rc3
Environment variables to set
COSIM_REPO_HOME -> Root of the source release COSIM_PORT -> Any 4-digit number. If you want to run multiple instances on the same machine, each one needs to have a different number.
ToDo List
Support Verilator/IVerilog as HDL simulator engine and GTKWave as waveform viewer.
Install Qemu and Create a VM image
Compile QEMU
- Install Dependencies:
sudo apt-get install libzmq3-dev libczmq-dev libncurses5-dev libncursesw5-dev libsdl2-dev
- Download QEMU 2.10 rc3
cd $COSIM_REPO_HOME/qemu wget http://download.qemu-project.org/qemu-2.10.0-rc3.tar.xz tar -xJf qemu-2.10.0-rc3.tar.xz
- Apply the patch
patch -s -p0 < qemu-cosim.patch Apply another patch https://git.qemu.org/?p=qemu.git;a=commitdiff;h=75e5b70e6b5dcc4f2219992d7cffa462aa406af0
- Configure and build
cd qemu-2.10.0-rc3 mkdir build cd build ../configure --target-list=x86_64-softmmu --disable-vnc --enable-sdl --enable-curses Modify config-host.mak, Add " -lzmq -lczmq" to the end of LIBS make -j32
- Copy the launch script
cp ../../../scripts/launch_fpga.sh ./ cd ../../
Create a QEMU image
- Create a QEMU image file called cosim.qcow2 in $COSIM_REPO_HOME/qemu and install Ubuntu 16.04.3.
qemu-2.10.0-rc3/build/qemu-img create -f qcow2 cosim.qcow2 16G sudo qemu-2.10.0-rc3/build/x86_64-softmmu/qemu-system-x86_64 -boot d -cdrom /path/to/ubuntu-16.04.6-server-amd64.iso -smp cpus=2 -accel kvm -m 4096 -hda cosim.qcow2 (name: user; passwd: user)
- Launch QEMU in one terminal
cd $COSIM_REPO_HOME/qemu/qemu-2.10.0-rc3/build ./launch_fpga.sh (sudo -E x86_64-softmmu/qemu-system-x86_64 -m 4G -enable-kvm -cpu host -smp cores=1 -drive file=../../cosim.qcow2,cache=writethrough -device accelerator-pcie -redir tcp:2200::22 -display none)
- Log in to the VM in another terminal
ssh -p 2200 user@localhost
- In the VM, Install necessary tools for compiling userspace program and kernel module
sudo apt-get update sudo apt-get upgrade sudo apt-get install build-essential
Copy driver and application to the image
- Copy $COSIM_REPO_HOME/software_sorting to the image.
cd $COSIM_REPO_HOME scp -P 2200 -r software_sorting/ user@localhost:/home/user/.
Shutdown and Backup the image(Optional)
- In the VM, Shutdown the VM
sudo poweroff
- In the host, Backup the installed image
cd $COSIM_REPO_HOME/qemu zip cosim.qcow2.zip cosim.qcow2
Run co-simulation
Run Vivado XSim in Host Machine
- In the host, Launch Vivado XSim Simulation in the 1st terminal
cd $COSIM_REPO_HOME/proj_sim_sorting source run_sim.sh
The waveform window will show AXI transactions when the application is launched in the VM.
Run application in Guest Machine
- In the host, Launch QEMU with accelerator in the 2nd terminal
cd $COSIM_REPO_HOME/qemu/qemu-2.10.0-rc3/build ./launch_fpga.sh (sudo -E x86_64-softmmu/qemu-system-x86_64 -m 4G -enable-kvm -cpu host -smp cores=1 -drive file=../../cosim.qcow2,cache=writethrough -device accelerator-pcie -redir tcp:2200::22 -display none)
- In the host, Log in to the VM in the 3rd terminal
ssh -p 2200 user@localhost
- In the VM, compile and load driver
cd software_sorting/driver/ ./loadRunModule.sh
- In the VM, compile the user space program
cd ../application gcc sort.c -o sort
- In the VM, run the sort program
sudo ./sort
The program will first print unsorted data, then print sorted result.