RISC-V SystemC-TLM Simulator
RISC-V SystemC-TLM Simulator
Marius Monton
marius.monton@uab.cat
Departament de microelectrònica i sistemes electrònics
Universitat Autònoma de Barcelona
Barcelona, Spain
expandable of a RISC-V. It is built around a full RISC-V instruction with a length and some attributes. The Slave will respond to the
set simulator that supports full RISC-V ISA and extensions M, A, C, transaction within a time (that can be 0 for a basic modeling) and
Zicsr and Zifencei. the writing or reading of the transaction. All other details of the
The ISS is encapsulated in a TLM-2 wrapper that enables it transaction (bus access, signals change, etc.) are not modeled. In
to communicate with any other TLM-2 compatible module. The more detailed modeling, the different phases of a bus access can
simulator also includes a very basic set of peripherals to enable a be specified. Currently, SystemC standard includes TLM modeling
complete SoC simulator. The running code can be compiled with [1]. The modules can also interchange data using direct pointers to
standard tools and using standard C libraries without modifications. memory instead to transactions to increase simulation speed. This
The simulator is able to correctly execute the riscv-compliance technique is named Direct Memory Interface (DMI).
suite. The entire simulator is published as a docker image to ease its TLM has boosted the interoperability between vendors models
installation and use by developers. A porting of FreeRTOSv10.2.1 and the appearance of many IPs that are interchangeable and fully
for the simulated SoC is also published. compatible among different systems and vendors. The fundamental
idea of this work is to introduce all these features to a RISC-V
CCS CONCEPTS simulator.
The source code of the entire project is open-source and pub-
· Computer systems organization → Embedded hardware;
lished [14].
High-level language architectures; · Hardware → Simulation
The presented simulator is intended for an easy use and simple
and emulation.
to extend, with clear code and able to simulate an entire SoC, like
any embedded microcontroller in the market. To keep the code
KEYWORDS simple, meta-programming has been avoided and C++ templates
RISC-V, SystemC, TLM-2.0, Simulation Infrastructure, ISS use is keep as low as possible.
The paper is structured in the following sections: Section II
1 INTRODUCTION depicts the architecture of the entire simulator, Section III show
Many simulators has been published since the release of first drafts software particularities and tool-chain modifications, Section IV
of RISC-V ISA [8]. These simulators use different techniques and shows simulation performance and compliance results. Section V
technologies to achieve different requirements: good performance, concludes the paper.
good visualization of the processor, architectural exploration, etc.
Most of them conform to RISC-V ISA specifications; some of them 2 SIMULATOR ARCHITECTURE
use a previous infrastructure and adapt the ISS to follow the RISC-V
One of the main goals of this simulator was to be easily extensible
ISA and re-uses some peripherals already simulated [3, 4, 7, 19].
and modifiable. To achieve this objective, the original design was
Others are written from scratch and includes the ISS and a mini-
very simple and clear, with the use of naive techniques and a source
mum set of peripherals [6, 11]. There are FPGA-based simulators
code designed for simplicity.
to increase performance and simulation speed [9] as well as the
The simulator architecture includes a ISS for RV32I ISA [20], a
precision of the simulation results.
bus controller, the main memory and peripherals. Communication
The Spike simulator is most common simulator and it is used
between these modules is done by TLM-2 sockets (see Figure 1).
as reference model for RISC-V ISA [6]. Other simulators are in-
tended for a graphical visualization for the entire execution of the
instructions inside the CPU [15]. 2.1 CPU
SystemC is a set of libraries for the C++ language to allow the The ISS simulates a single hardware thread (HART) and includes
description and simulation of hardware based systems by a event- privileged instructions. It is divided in three modules: Instruction,
driven simulation model. This libraries add time management, con- Execute and Registers:
currency and hardware-like data types to C++ [1].
Transaction Level Modelling adds a layer to SystemC in order • Instruction Decodes instructions and checks for extensions.
to model the interface between different modules in a lightweight This module can access all fields of each instruction type (R,
way. This model technique uses transactions to abstract any kind of I, S, B, U and J type).
M. Montón
5 CONCLUSIONS
This paper introduces a new RISC-V simulator. It has been designed
from scratch to simulate an entire SoC with simplicity on focus. It
has been designed in SystemC and TLM-2 as language and modeling
schema.
It has been presented the main architecture of the simulator,
the software configuration and tools required. Followed by a brief
discussion about the simulation performance and the conformance
to the specifications.
The use of standards is important in any aspects of the engineer-
ing effort. In the case of system-level simulators, the existence of
the TLM-2 and SystemC standards should be encourage and used
by vendors and researchers to increase the interoperability and
Figure 4: Execution results for all tests re-usability of the components. This simple simulator is a first step
towards this achievement.
REFERENCES
[1] 2012. IEEE Standard for Standard SystemC Language Reference Manual. IEEE
Std 1666-2011 (Revision of IEEE Std 1666-2005) (2012), 1ś638.
[2] Inc Amazon Web Services. 2020. FreeRTOS HomePage. https://www.freertos.org/
[3] Fabrice Bellard. 2005. QEMU, a Fast and Portable Dynamic Translator. In Proceed-
ings of the Annual Conference on USENIX Annual Technical Conference (Anaheim,
CA) (ATEC ’05). USENIX Association, USA, 41.
[4] Nathan Binkert, Bradford Beckmann, Gabriel Black, Steven K. Reinhardt, Ali
Saidi, Arkaprava Basu, Joel Hestness, Derek R. Hower, Tushar Krishna, Somayeh
Sardashti, Rathijit Sen, Korey Sewell, Muhammad Shoaib, Nilay Vaish, Mark D.
Hill, and David A. Wood. 2011. The Gem5 Simulator. SIGARCH Comput. Archit.
News 39, 2 (Aug. 2011), 1ś7. https://doi.org/10.1145/2024716.2024718
[5] Codacy. 2020. Codacy - RISC-V-TLM Dashboard. https://app.codacy.com/manual/
mariusmm/RISC-V-TLM/dashboard
[6] RISC-V foundation. 2020. RISC-V Spike. https://github.com/riscv/riscv-tools
[7] Imperas. 2020. A Complete, Fully Functional, Configurable RISC-V Simulator.
https://github.com/riscv/riscv-ovpsim
Figure 5: Execution results for all tests with the Docker ver- [8] RISC-V International. 2020. RISC-V Software Ecosystem Overview - Simulators.
sion https://riscv.org/software-status/#simulators
[9] Jonathan Bachrach Scott Beamer et al Krste Asanović, Rimas Avižienis. 2016.
The Rocket Chip Generator. Technical Report Technical Report UCB/EECS-2016-
17. EECS Department, University of California, Berkeley. https://github.com/
instructions per second (see Table 1 and Figure 4) in a Intel Core chipsalliance/rocket-chip
i7-8550U CPU @ 1.88 GHz with 16 GB of memory. As a reference, [10] ARM Limited. 2020. Cortex™-M3 Technical Reference Manual - ITM.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/
in the same computer the Spike simulator performance is about BABCCDFD.html
170 million of simulated instructions per second. [11] Neethu Bal Mallya, Cecilia Gonzalez-Alvarez, and Trevor E Carlson. 2018. Flexible
The low performance of Test2 can be due to the intensive use of timing simulation of RISC-V processors with sniper. Simulation 4 (2018), 1.
[12] Dirk Merkel. 2014. Docker: Lightweight Linux Containers for Consistent Devel-
the Trace module and the overhead it implies. opment and Deployment. Linux J. 2014, 239, Article 2 (March 2014), 1 pages.
For the Dhrystone benchmark, it is executed with good results [13] Màrius Montón. 2020. mariusmm/riscv-tlm. https://hub.docker.com/repository/
and the performance is about 7200 Dhrystones/second. It has been docker/mariusmm/riscv-tlm
[14] Màrius Montón. 2020. RISC-V-TLM Simulator. https://github.com/mariusmm/
tested with 10.000, 250.000 and 500.000 loops of the Dhrystone test. RISC-V-TLM
[15] Morten Petersen. 2020. Ripes. https://github.com/mortbopet/Ripes
[16] RISCV.org. 2020. RISC-V Compliance Task Group. https://github.com/riscv/riscv-
4.3 Docker version compliance/
The same tests has been run with the docker version of the simulator. [17] RISCV.org. 2020. RISC-V Unit Tests. https://github.com/riscv/riscv-tests
[18] Synopsys. 2020. Coverity - RISC-V-TLM. https://scan.coverity.com/projects/
The results are summarized in Table 1 and depicted in Figure 5. mariusmm-risc-v-tlm
In case of docker version, the performance has a penalty from [19] Tuan Ta, Lin Cheng, and Christopher Batten. 2018. Simulating multi-core RISC-V
47% to up to 69% depending on the test. The performance of this systems in gem5. In Workshop on Computer Architecture Research with RISC-V.
[20] Andrew Waterman and Krste Asanovi. 2019. The RISC-V Instruction Set Manual,
version is depicted in Figure 5. Volume I: User-Level ISA. Technical Report Version 20191213. RISC-V Foundation.
[21] Andrew Waterman and Krste Asanovi. 2019. The RISC-V Instruction Set Manual,
Volume II: Privileged Architecture. Technical Report Version 20190608-Priv-MSU-
Ratified. RISC-V Foundation.