From 5131afcd078876180216f03ec99ab60f665f5a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Sun, 27 Oct 2019 00:00:00 +0000 Subject: [PATCH] cb6ea177715a43aeaa8314b4e7109535417d2315 --- index.html | 155 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 126 insertions(+), 29 deletions(-) diff --git a/index.html b/index.html index d43f6ca..2e74972 100644 --- a/index.html +++ b/index.html @@ -658,6 +658,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 9. KVM
  • 10. User mode simulation @@ -1204,10 +1205,15 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 19.19.5. gem5 stats internals
  • -
  • 19.19.6. gem5 build system +
  • 19.19.6. gem5 code generation +
  • +
  • 19.19.7. gem5 build system +
  • @@ -6899,7 +6905,7 @@ cat f

    KVM is Linux kernel interface that greatly speeds up execution of virtual machines.

    -

    You can make QEMU or gem5 by passing enabling KVM with:

    +

    You can make QEMU or gem5 by passing enabling KVM with:

    @@ -6907,14 +6913,6 @@ cat f
    -

    but it was broken in gem5 with pending patches: https://www.mail-archive.com/gem5-users@gem5.org/msg15046.html It fails immediately on:

    -
    -
    -
    -
    panic: KVM: Failed to enter virtualized mode (hw reason: 0x80000021)
    -
    -
    -

    KVM works by running userland instructions natively directly on the real hardware instead of running a software simulation of those instructions.

    @@ -6984,6 +6982,30 @@ sudo ./setup -y

    TODO: do the right thing and cross compile QEMU and gem5. gem5’s Python parts might be a pain. QEMU should be easy: https://stackoverflow.com/questions/26514252/cross-compile-qemu-for-arm

    +
    +

    9.2. gem5 KVM

    +
    +

    While gem5 does have KVM, as of 2019 its support has not been very good, because debugging it is harder and people haven’t focused intensively on it.

    +
    +
    +

    X86 was broken with pending patches: https://www.mail-archive.com/gem5-users@gem5.org/msg15046.html It failed immediately on:

    +
    +
    +
    +
    panic: KVM: Failed to enter virtualized mode (hw reason: 0x80000021)
    +
    +
    +
    +

    Bibliography:

    +
    + +
    @@ -17551,20 +17573,7 @@ root

    The only hairy thing in QEMU is the binary code generation.

    -

    gem5 however has tended towards intensive code generation in order to support all its different hardware types:

    -
    -
    - +

    gem5 however has tended towards horrendous intensive code generation in order to support all its different hardware types

    @@ -20373,6 +20382,9 @@ Indirect leak of 1346 byte(s) in 2 object(s) allocated from: +
    +

    KVM CPUs are an alternative way of fast forwarding boot when they work.

    +

    19.17.2. gem5 MinorCPU

    @@ -21150,9 +21162,81 @@ Text::end()
    -

    19.19.6. gem5 build system

    +

    19.19.6. gem5 code generation

    +
    +

    gem5 uses a ton of code generation, which makes the project horrendous:

    +
    +
    +
      +
    • +

      lots of magic happen on top of pybind11, which is already magic, to more automatically glue the C++ and Python worlds: gem5 Python C++ interaction

      +
    • +
    • +

      .isa code which describes most of the instructions

      +
    • +
    • +

      Ruby for memory systems

      +
    • +
    +
    +
    +

    To find the definition of generated code, do a:

    +
    +
    +
    +
    grep -I -r build/ 'code of interest'
    +
    +
    +
    +

    where:

    +
    +
    + +
    +
    +

    The code generation exists partly to support insanely generic cross ISA instructions mapping to one compute model, where it might be reasonable.

    +
    +
    +

    But it has been widely overused to insanity. It likely also exists partly because when the project started in 2003 C++ compilers weren’t that good, so you couldn’t rely on features like templates that much.

    +
    -
    19.19.6.1. gem5 polymorphic ISA includes
    +
    19.19.6.1. gem5 THE_ISA
    +
    +

    Generated code at: build/<ISA>/config/the_isa.hh which contains amongst other lines:

    +
    +
    +
    +
    #define X86_ISA 8
    +
    +enum class Arch {
    +  X86ISA = X86_ISA
    +};
    +
    +#define THE_ISA X86_ISA
    +
    +
    +
    +

    Generation code: src/SConscript at def makeTheISA.

    +
    +
    +

    Tested on gem5 211869ea950f3cc3116655f06b1d46d3fa39fb3a.

    +
    + +
    +
    +
    +

    19.19.7. gem5 build system

    +
    +
    19.19.7.1. gem5 polymorphic ISA includes

    E.g. src/cpu/decode_cache.hh includes:

    @@ -21231,7 +21315,7 @@ build/ARM/config/the_isa.hh
    -
    19.19.6.2. Why are all C++ symlinked into the gem5 build dir?
    +
    19.19.7.2. Why are all C++ symlinked into the gem5 build dir?

    Some scons madness.

    @@ -21244,6 +21328,19 @@ build/ARM/config/the_isa.hh

    It was not possible to disable the symlinks automatically for the entire project when I last asked: https://stackoverflow.com/questions/53656787/how-to-set-disable-duplicate-0-for-all-scons-build-variants-without-repeating-th

    +
    +

    The horrendous downsides of this are:

    +
    +
    +
      +
    • +

      when debugging the emulator, it shows you directories inside the build directory rather than in the source tree

      +
    • +
    • +

      it is harder to separate which files are generated and which are in-tree when grepping for code generated definitions

      +
    • +
    +