risc-v/mmu: Configure T-Head MMU to cache User Text, Data and Heap #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR configures the T-Head MMU to cache the the User Text, Data and Heap. We enable the MMU Flags for Shareable, Bufferable and Cacheable, as explained in this article.
This PR fixes the Slow Memory Access for NuttX Apps on BL808 and SG2000 SoCs: apache#12696. With this fix, SG2000 NuttX CoreMark jumps from 21 to 2,422. (Close to SG2000 Debian CoreMark)
We introduce a Kconfig Option:
ARCH_MMU_EXT_THEAD
("System Type > Enable T-Head MMU extension support"). Enabling this Kconfig Option will configure the T-Head MMU to cache the User Text, Data and Heap.This PR enables the MMU cache for only SG2000 SoC (Milk-V Duo S SBC). The next PR will apply the same settings to BL808 SoC (Pine64 Ox64 SBC).
Modified Files
arch/risc-v/Kconfig
: Added Kconfig OptionARCH_MMU_EXT_THEAD
that will configure the T-Head MMU. EnabledARCH_MMU_EXT_THEAD
for SG2000 SoC.arch/risc-v/src/common/riscv_mmu.h
: Set the T-Head MMU Flags (Shareable, Bufferable and Cacheable) for User Text, Data and Heap, ifARCH_MMU_EXT_THEAD
is enabledarch/risc-v/src/common/riscv_addrenv.c
: Extended the MMU Flags from 32 bits to 64 bits, to accommodate the T-Head MMU Flagsarch/risc-v/src/common/riscv_exception.c
: Extended the MMU Flags from 32 bits to 64 bit, to accommodate the T-Head MMU Flags. This code is enabled only for MMU Paging (CONFIG_PAGING
).Impact
This PR affects only the platforms that have
ARCH_MMU_EXT_THEAD
enabled. Right now, only SG2000 SoC enablesARCH_MMU_EXT_THEAD
.Testing
We tested on Milk-V Duo S SBC with SG2000 SoC:
Before the PR: CoreMark is 17 (NuttX Log)
After the PR: CoreMark increases to 1,759 (NuttX Log)
And OSTest completes successfully:
Note that CoreMark will increase further to 2,422 when we compile CoreMark optimised with
-O2
Regression Testing: We tested OSTest on QEMU RISC-V 32-bit and 64-bit (Flat Build and Kernel Build):
MMU Paging: With
CONFIG_PAGING
enabled,rv-virt:knsh_paging
compiles correctly. However we were unable to testknsh_paging
. OSTest failed with the same error, before and after our PR: