Co-simulation



Prerequisites

SystemC-TLM and RTL experience to compile/develop the examples.

A download for SystemC-TLM can be found on Accellera's website.  Installation instructions are available in the INSTALL file.

This feature is predominantly suitable for experienced developers in SystemC/TLM and integration with mixed simulation environments.
This feature is
provided "as-is" and under an open source license model. Feel free to use our libSystemCTLM-SoC to interface your simulation environment to Xilinx's QEMU.
Please see the
SystemC page of Accellera’s website for further details and a demo with Accellera's Open Source SystemC Reference Simulation Environment. (Accellera's SystemC Reference Simulation Environment is free and under the Apache v2 License as of 2016).

Overview

You can use Xilinx QEMU to connect and drive mixed simulation environments using the included remote-port framework. This feature enables you to model large and complex systems right from the get-go.

Xilinx exposes a SystemC/TLM interface to connect QEMU, which models the hardened Processing System (PS) of any Zynq-based or Versal Adaptive SoC product, to a model of your own IP instantiated in the Programmable Logic (PL).
Your IP must be
written in either Verilog or SystemC.

The figure below gives a high level overview of the key components.

Figure 1 - Co-Simulation Block Diagram 

QEMU and the RTL or SystemC Simulator run on different processes enabling a less intrusive and much more flexible integration between your existing mixed simulation environment and QEMU.

Remote-Port

The underlying mechanism that QEMU uses to connect to external simulation environments is through remote-port (RP). Remote-port is a protocol/framework that uses sockets and shared memory to communicate transactions and synchronize time between simulators.

libsystemctlm-soc

libSystemCTLM-SoC provides a standard SystemC wrapper around Zynq7000, Zynq Ultrascale+ MPSoC, and Versal Adaptive SoC hardened PS (as seen in the right hand side of Figure 1), enabling integrators to connect various IP models just like any other SystemC compatible modeling environment.

These wrappers can be found in libsystemctlm-soc repositoryFor example see the SystemC/TLM-2.0 co-simulation demonstration.

SystemC/TLM-2.0 Co-Simulation Demo

The SystemC/TLM-2.0 co-simulation demonstration provides an example project that demonstrates how to use libsystemctlm-soc to connect custom SystemC/TLM-2.0 and RTL models to QEMU.

This demo is written using standard, compliant SystemC/TLM-2.0 APIs. You can run the demo on any SystemC/TLM-2.0 simulator that is compliant with Accellera Systems Initiative (ASI) industry standard specifications.
This open-source reference implementation of the simulator is tested and verified with Accellera’s standard.

You need a small configuration file (.config.mk) to be compile the demo source code package. an example of a .config.mk file is shown below for your reference:

CXXFLAGS += -std=c++14
HAVE_VERILOG=n
HAVE_VERILOG_VERILATOR=n
HAVE_VERILOG_VCS=n
SYSTEMC = /scratch/tool/systemc-2.3.1/                      //<<== Change to your local SystemC location.
LD_LIBRARY_PATH=/scratch/tool/systemc-2.3.1/lib-linux64/    //<<== Change to your local SystemC Library location.

Co-Simulating with QEMU

Generating Required Device Trees

You need to instruct QEMU to co-simulate with other simulation environments. This can be done by editing the hardware device tree passed into QEMU using the -hw-dtb option.

The hardware device tree is specific to QEMU, and should not be confused with the Linux guest device tree.

The device tree repository provides device tree blobs (DTBs) for co-simulation environments.
After building the DTBs, they are available in the LATEST/SINGLE_ARCH or LATEST/MULTI_ARCH directory and will have cosim in their names.

For more information on this process, see the QEMU device tree wiki page and the device tree repository.

Generating Zynq-7000 Device Trees

Zynq-7000 co-simulation DTBs are not built in the device tree repository, they must be built as part of a PetaLinux project.

To do this:

1. Create a Zynq-7000 PetaLinux project and enter the PetaLinux project directory
2. Copy the Zynq-7000 co-simulation device tree overlay to the PetaLinux project

cp /path/to/dts/zynq-pl-remoteport.dtsi subsystems/linux/configs/device-tree/zynq-pl-remoteport.dtsi

3. Now include the new file in the 'subsystems/linux/configs/device-tree/system-top.dts' file be including this line below the other includes:

/include/ "zynq-pl-remoteport.dtsi"

4. Rebuild PetaLinux

petalinux-build

5. Either copy the built DTB to use with your scripts, or run your PetaLinux project with additional arguments to allow for co-simulation

petalinux-boot --qemu --kernel --qemu-args "-machine-path /tmp/cosim -icount 1 -sync-quantum 10000"

Extra Command-Line Options

When doing co-simulation, the -machine-path, -sync-quantum, and -icount options are used to allow communication between QEMU and the SystemC/TLM2.0 module.
icount is an optional option used to create more deterministic behavior in QEMU, while machine-path and sync-quantum are required for co-simulation.

More information on what -machine-path does can be found here, and the icount and sync-quantum options are explained below:

OptionDescriptionExample
-icount <N>[,sleep=on|off]

Enables virtual instruction counting with 2^N virtual nanoseconds per instruction.
This enables aligning the host and virtual clocks or disables real-time CPU sleeping.

When the virtual CPU is sleeping, the virtual time will advance at default speed unless sleep=off is specified.
With sleep=off, the virtual time will jump to the next timer deadline instantly whenever the virtual CPU goes to sleep and will not advance if no timer is enabled.

-icount 1

The virtual CPU will wait 2^1 nanoseconds of virtual time per instruction.

-sync-quantum <N>

Specifies the TLM synchronization quantum in nanoseconds.

As the sync-quantum decreases, the modeling accuracy increases, but its speed decreases.

Use the same sync-quantum number for any other simulators used in the co-simulation.

-sync-quantum 100000

The TLM synchronization quantum is set to 100000 nanoseconds

The following table is a good starting guideline for icount and sync-quantum values.

Platformsync-quantumicount (optional)
Zynq UltraScale+ MPSoC10000001
Versal Adaptive SoC10000001
Zynq 70001000007

Example QEMU Command

With icount

$QEMU_PATH/aarch64-softmmu/qemu-system-aarch64  -M arm-generic-fdt -nographic \
-dtb $DTS_PATH/zcu102-arm.cosim.dtb \
-device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4 \
-machine-path /tmp/cosim \
-icount 1 \
-sync-quantum 1000000

Without icount

$QEMU_PATH/aarch64-softmmu/qemu-system-aarch64  -M arm-generic-fdt -nographic \
-dtb $DTS_PATH/zcu102-arm.cosim.dtb \
-device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4 \
-machine-path /tmp/cosim \
-sync-quantum 1000000

PetaLinux Flow

Instead of using the commands shown above to start a QEMU machine for co-simulation, you could also use PetaLinux with additional arguments.

Once you're done building your project using the usual PetaLinux flow, launch QEMU using the command shown below:

petalinux-boot --qemu --kernel --qemu-args "-hw-dtb $DTS_PATH/LATEST/MULTI_ARCH/zcu102-arm.cosim.dtb -machine-path /tmp/cosim -sync-quantum 1000000"

Example Simulator Command

When the QEMU command shown above runs successfully, QEMU waits for SystemC/TLM-2.0 connection on the socket created in the directory that was supplied by the -machine-path argument.
You must use the same socket path while running the
SystemC application, as follows:

LD_LIBRARY_PATH=/path/to/systemc-2.3.1/lib-linux64/ ./demo-app unix:<socket path> <sync-quantum number>

For example,

/scratch/proj/tasks/ug1169_cosim/systemctlm-cosim-demo$ LD_LIBRARY_PATH=/path/to/systemc-2.3.1/lib-linux64/ ./zynqmp_demo  unix:/tmp/cosim/qemu-rport-_amba@0_cosim@0 1000000

        SystemC 2.3.1-Accellera --- Jul 11 2019 10:13:23
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED
connect to /tmp/cosim/qemu-rport-_amba@0_cosim@0

The commands shown above will only work in a BASH environment.


More details on how to build and run the SystemC demo application are in the systemctlm-cosim-demo repository.

POSH

As part of the DARPA POSH (Posh Open Source Hardware) program, Xilinx put in considerable effort to create open source tools to help in the development of complex mixed-simulation environments.

The combinations that can be instantiated include both pure software only simulation environments or software + hardware in the loop (HIL) environments. 

An overview of the POSH bridges and utilities can be found libSystemCTLM-SoC and in particular in the documentation section found here:

Some of the tools created are:

A diagram showing how these bridges might be used is shown below:


© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy