diff --git a/index.html b/index.html index 2c6b5a2..8e79ff0 100644 --- a/index.html +++ b/index.html @@ -1245,6 +1245,12 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 20.9. Report upstream bugs
  • 20.10. libc choice
  • 20.11. Buildroot hello world
  • +
  • 20.12. Update the toolchain + +
  • 21. Userland content @@ -1604,9 +1610,11 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 24.6.4. ARM SIMD bibliography
  • 24.6.5. ARM SVE @@ -1824,7 +1832,11 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
  • 31.12.3.2. patches/manual directory
  • -
  • 31.12.4. rootfs_overlay
  • +
  • 31.12.4. rootfs_overlay + +
  • 31.12.5. lkmc.c
  • 31.12.6. rand_check.out
  • 31.12.7. lkmc_home
  • @@ -19672,6 +19684,9 @@ m5_fail(ints[1], ints[0]);

    https://gem5.googlesource.com/arm/linux/ contains an ARM Linux kernel forks with a few gem5 specific Linux kernel patches on top of mainline created by ARM Holdings on top of a few upstream kernel releases.

    +

    Our build script automatically adds that remote for us as gem5-arm.

    +
    +

    The patches are optional: the vanilla kernel does boot. But they add some interesting gem5-specific optimizations, instrumentations and device support.

    @@ -19685,7 +19700,7 @@ m5_fail(ints[1], ints[0]);
    -
    git -C "$(./getvar linux_source_dir)" fetch https://gem5.googlesource.com/arm/linux gem5/v4.15:gem5/v4.15
    +
    git -C "$(./getvar linux_source_dir)" fetch gem5-arm:gem5/v4.15
     git -C "$(./getvar linux_source_dir)" checkout gem5/v4.15
     ./build-linux \
       --arch aarch64 \
    @@ -21959,13 +21974,205 @@ git -C "$(./getvar qemu_source_dir)" checkout -
     

    These can come in handy if you want to debug something in Buildroot itself and possibly report an upstream bug.

    +
    +

    20.12. Update the toolchain

    +
    +

    Users of this repo will often want to update the compilation toolchain to the latest version to get fresh new features like new ISA instructions.

    +
    +
    +

    Because the toolchain is so complex and tightly knitted with the rest of the system, this is more of an art than a science.

    +
    +
    +

    However, it is not something to be feared, and you will get there without help in most cases.

    +
    +
    +

    In this section we cover the most common cases.

    +
    +
    +

    20.12.1. Update GCC: GCC supported by Buildroot

    +
    +

    This is of course the simplest case.

    +
    +
    +

    You can quickly determine all the GCC versions supported by Buildroot by looking at:

    +
    +
    +
    +
    submodules/buildroot/package/gcc/Config.in.host
    +
    +
    +
    +

    For example, in Buildroot 2018.08, which was used at LKMC 5d10529c10ad8a4777b0bac1543320df0c89a1ce, the default toolchain was 7.3.0, and the latest supported one was 8.2.0.

    +
    +
    +

    To just upgrade the toolchain to 8.2.0, and rebuild some userland executables to later run them, we could do:

    +
    +
    +
    +
    cd submodules/gcc
    +git fetch up
    +git checkout -b lkmc-gcc-8_2_0-release gcc-8_2_0-release
    +git am ../buildroot/package/gcc/8.2.0/*
    +cd ../..
    +./build-buildroot \
    +  --arch aarch64 \
    +  --buildroot-build-id gcc-8-2 \
    +  --config 'BR2_GCC_VERSION_8_X=y' \
    +  --config 'BR2_GCC_VERSION="8.2.0"' \
    +  --no-all \
    +  -- \
    +  toolchain \
    +;
    +./build-userland \
    +  --arch aarch64 \
    +  --buildroot-build-id gcc-8-2 \
    +  --out-rootfs-overlay-dir-prefix gcc-8-2 \
    +  --userland-build-id gcc-8-2 \
    +;
    +./build-buildroot --arch aarch64
    +
    +
    +
    +

    where the toolchain Buildroot target builds only Buildroot: https://stackoverflow.com/questions/44521150/buildroot-install-and-build-the-toolchain-only

    +
    +
    +

    Note that this setup did not overwrite any of our default Buildroot due to careful namespacing with our gcc-8-2 prefix!

    +
    +
    +

    Now you can either run the executables on User mode simulation with:

    +
    +
    +
    +
    ./run --arch aarch64 --userland userland/c/hello.c --userland-build-id gcc-8-2
    +
    +
    +
    +

    or in full system with:

    +
    +
    +
    +
    ./run --arch aarch64 --eval-after './gcc-8-2/c/hello.out'
    +
    +
    +
    +

    where the gcc-8-2 prefix was added by --out-rootfs-overlay-dir-prefix.

    +
    +
    +

    ARM SVE support was only added to GCC 8 and can be enabled with the flag: -march=armv8.2-a+sve.

    +
    +
    +

    We already even had a C SVE test in-tree, but it was disabled because the old toolchain does not support it.

    +
    +
    +

    So once the new GCC 8 toolchain was built, we can first enable that test by editing the path_properties file to not skip C SVE tests anymore:

    +
    +
    +
    +
                    #os.path.splitext(self.path_components[-1])[1] == '.c' and self['arm_sve']
    +
    +
    +
    +

    and then rebuild run one of the experiments from Change ARM SVE vector length in emulators:

    +
    +
    +
    +
    ./build-userland \
    +  --arch aarch64 \
    +  --buildroot-build-id gcc-8-2 \
    +  --force-rebuild \
    +  --march=armv8.2-a+sve \
    +  --out-rootfs-overlay-dir-prefix gcc-8-2 \
    +  --static \
    +  --userland-build-id gcc-8-2 \
    +;
    +./run \
    +  --arch aarch64 \
    +  --userland userland/arch/aarch64/inline_asm/sve_addvl.c \
    +  --userland-build-id gcc-8-2 \
    +  --static \
    +  --gem5-worktree master \
    +  -- \
    +  --param 'system.cpu[:].isa[:].sve_vl_se = 4' \
    +
    +
    +
    +

    Bibliography:

    +
    + +
    +
    +

    20.12.2. Update GCC: GCC not supported by Buildroot

    +
    +

    Now it gets fun, but well, guess what, we will try to do the same as Section 20.12.1, “Update GCC: GCC supported by Buildroot” but:

    +
    +
    +
      +
    • +

      pick the Buildroot version that comes closest to the GCC you want

      +
    • +
    • +

      if any git am patches don’t apply, skip them

      +
    • +
    +
    +
    +

    Now, if things fail, you can try:

    +
    +
    +
      +
    • +

      if the GCC version is supported by a newer Buildroot version:

      +
      +
        +
      • +

        quick and dirty: see what they are doing differently there, and patch it in here

        +
      • +
      • +

        golden star: upgrade our default Buildroot, test it well, and send a pull request!

        +
      • +
      +
      +
    • +
    • +

      otherwise: OK, go and patch Buildroot, time to become a Buildroot dev

      +
    • +
    +
    +
    +

    Known setups:

    +
    +
    + +
    +
    +

    21. Userland content

    -

    This section contains userland content, such as C, C++ and POSIX examples.

    +

    This section documents our test and educational userland content, such as C, C++ and POSIX examples, present mostly under userland/.

    Getting started at: Section 1.6, “Userland setup”

    @@ -27302,7 +27509,14 @@ AArch64, see Procedure Call Standard for the ARM 64-bit Architecture.

    Scalable Vector Extension.

    -

    Example: userland/arch/aarch64/sve.S

    +

    Examples:

    +
    +

    To understand it, the first thing you have to look at is the execution example at Fig 1 of: https://alastairreid.github.io/papers/sve-ieee-micro-2017.pdf

    @@ -27345,7 +27559,60 @@ AArch64, see Procedure Call Standard for the ARM 64-bit Architecture.

    Using SVE normally requires setting the CPACR_EL1.FPEN and ZEN bits, which as as of lkmc 29fd625f3fda79f5e0ee6cac43517ba74340d513 + 1 we also enable in our Baremetal bootloaders, see also: aarch64 baremetal NEON setup.

    -
    24.6.5.1. SVE bibliography
    +
    24.6.5.1. ARM SVE VADDL instruction
    +
    +

    Get the SVE vector length. The following programs do that and print it to stdout:

    +
    + +
    +
    +
    24.6.5.2. Change ARM SVE vector length in emulators
    + +
    +

    It is fun to observe this directly with the ARM SVE VADDL instruction in SE:

    +
    +
    +
    +
    ./run --arch aarch64 --userland userland/arch/aarch64/sve_addvl.S --static --emulator gem5 -- --param 'system.cpu[:].isa[:].sve_vl_se = 1'
    +./run --arch aarch64 --userland userland/arch/aarch64/sve_addvl.S --static --emulator gem5 -- --param 'system.cpu[:].isa[:].sve_vl_se = 2'
    +./run --arch aarch64 --userland userland/arch/aarch64/sve_addvl.S --static --emulator gem5 -- --param 'system.cpu[:].isa[:].sve_vl_se = 4'
    +
    +
    +
    +

    which consecutively:

    +
    +
    +
    +
    0x0000000000000080
    +0x0000000000000100
    +0x0000000000000200
    +
    +
    +
    +

    which are multiples of 128.

    +
    +
    +

    TODO how to set it on QEMU at runtime? As of LKMC 37b93ecfbb5a1fcbd0c631dd0b42c5b9f2f8a89a + 1 QEMU outputs:

    +
    +
    +
    +
    0x0000000000000800
    +
    +
    +
    +
    +
    24.6.5.3. SVE bibliography
    • @@ -27360,7 +27627,7 @@ AArch64, see Procedure Call Standard for the ARM 64-bit Architecture.

    -
    24.6.5.1.1. SVE spec
    +
    24.6.5.3.1. SVE spec

    ARMv8 architecture reference manual A1.7 "ARMv8 architecture extensions" says:

    @@ -31303,7 +31570,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -

    31.12.2. buildroot_packages directory

    Every directory inside it is a Buildroot package.

    @@ -31428,6 +31695,9 @@ git -C "$(./getvar buildroot_source_dir)" checkout -

    31.12.4. rootfs_overlay

    +

    Source: rootfs_overlay.

    +
    +

    We use this directory for:

    @@ -31469,6 +31739,39 @@ git -C "$(./getvar buildroot_source_dir)" checkout -

    This way you can just hack away the scripts and try them out immediately without any further operations.

    +
    +
    31.12.4.1. out_rootfs_overlay_dir
    +
    +

    This path can be found with:

    +
    +
    +
    +
    ./getvar out_rootfs_overlay_dir
    +
    +
    +
    +

    This output directory contains all the files that LKMC will put inside the final image, including for example:

    +
    +
    + +
    +
    +

    LKMC first collects all the files that it will dump into the guest there, and then in the very last step dumps everything into the final image.

    +
    +
    +

    In Buildroot, this is done by pointing BR2_ROOTFS_OVERLAY to that directory.

    +
    +
    +

    This does not include native image modification mechanisms such as Buildroot packages, which we let Buildroot itself manage.

    +
    +

    31.12.5. lkmc.c

    @@ -32060,7 +32363,6 @@ git remote set-url origin git@github.com:cirosantilli/linux.git git push git checkout master -git remote add up git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git git fetch up git rebase --onto "$next_mainline_revision" "$last_mainline_revision"