From 009a33175c44c22a09589c100eae0eaea2fce47d Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Mon, 22 Aug 2022 11:21:15 -0400 Subject: [PATCH 1/3] update loongarch Signed-off-by: Schrodinger ZHU Yifan --- src/snmalloc/aal/aal.h | 6 ++++ src/snmalloc/aal/aal_consts.h | 3 +- src/snmalloc/aal/aal_loongarch.h | 57 ++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/snmalloc/aal/aal_loongarch.h diff --git a/src/snmalloc/aal/aal.h b/src/snmalloc/aal/aal.h index 3ee0d91b0..a3e730dbf 100644 --- a/src/snmalloc/aal/aal.h +++ b/src/snmalloc/aal/aal.h @@ -41,6 +41,10 @@ # define PLATFORM_IS_RISCV #endif +#if defined (__loongarch__) +# define PLATFORM_IS_LOONGARCH +#endif + namespace snmalloc { /** @@ -230,6 +234,8 @@ namespace snmalloc # include "aal_sparc.h" #elif defined(PLATFORM_IS_RISCV) # include "aal_riscv.h" +#elif defined(PLATFORM_IS_LOONGARCH) +# include "aal_loongarch.h" #endif #if defined(__CHERI_PURE_CAPABILITY__) diff --git a/src/snmalloc/aal/aal_consts.h b/src/snmalloc/aal/aal_consts.h index 8990a41df..afc4740ce 100644 --- a/src/snmalloc/aal/aal_consts.h +++ b/src/snmalloc/aal/aal_consts.h @@ -33,6 +33,7 @@ namespace snmalloc X86, X86_SGX, Sparc, - RISCV + RISCV, + LoongArch }; } // namespace snmalloc diff --git a/src/snmalloc/aal/aal_loongarch.h b/src/snmalloc/aal/aal_loongarch.h new file mode 100644 index 000000000..6e25c60ae --- /dev/null +++ b/src/snmalloc/aal/aal_loongarch.h @@ -0,0 +1,57 @@ +#pragma once + +#if __SIZEOF_POINTER__ == 8 +# define SNMALLOC_VA_BITS_64 +#else +# define SNMALLOC_VA_BITS_32 +#endif + +#include +namespace snmalloc +{ + /** + * Loongarch-specific architecture abstraction layer. + */ + class AAL_LoongArch + { + public: + /** + * Bitmap of AalFeature flags + */ + static constexpr uint64_t aal_features = + IntegerPointers | NoCpuCycleCounters; + + static constexpr enum AalName aal_name = LoongArch; + + static constexpr size_t smallest_page_size = 0x1000; + + /** + * On pipelined processors, notify the core that we are in a spin loop and + * that speculative execution past this point may not be a performance gain. + */ + static inline void pause() + { + __asm__ __volatile__("dbar 0" : : : "memory"); + } + + /** + * PRELD reads a cache-line of data from memory in advance into the Cache. + * The access address is the 12bit immediate number of the value in the + * general register rj plus the symbol extension. + * + * The processor learns from the hint in the PRELD instruction what type + * will be acquired and which level of Cache the data to be taken back fill + * in, hint has 32 optional values (0 to 31), 0 represents load to level 1 + * Cache If the Cache attribute of the access address of the PRELD + * instruction is not cached, then the instruction cannot generate a memory + * access action and is treated as a NOP instruction. The PRELD instruction + * will not trigger any exceptions related to MMU or address. + */ + static inline void prefetch(void* ptr) + { + __asm__ volatile("preld 0, %0, 0" : "=r"(ptr)); + } + }; + + using AAL_Arch = AAL_LoongArch; +} // namespace snmalloc \ No newline at end of file From 263543b47a51d9367ea809751ccb7dfb406ed2ee Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Mon, 22 Aug 2022 11:22:39 -0400 Subject: [PATCH 2/3] format Signed-off-by: Schrodinger ZHU Yifan --- src/snmalloc/aal/aal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snmalloc/aal/aal.h b/src/snmalloc/aal/aal.h index a3e730dbf..c25ce5f12 100644 --- a/src/snmalloc/aal/aal.h +++ b/src/snmalloc/aal/aal.h @@ -41,7 +41,7 @@ # define PLATFORM_IS_RISCV #endif -#if defined (__loongarch__) +#if defined(__loongarch__) # define PLATFORM_IS_LOONGARCH #endif From dc00d96a7a6ebd5d260f7c6943771e56e3860492 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Mon, 22 Aug 2022 17:38:34 -0400 Subject: [PATCH 3/3] fix page size Signed-off-by: Schrodinger ZHU Yifan --- src/snmalloc/pal/pal_linux.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/snmalloc/pal/pal_linux.h b/src/snmalloc/pal/pal_linux.h index 5e1289a13..beb06d5b5 100644 --- a/src/snmalloc/pal/pal_linux.h +++ b/src/snmalloc/pal/pal_linux.h @@ -29,8 +29,9 @@ namespace snmalloc */ static constexpr uint64_t pal_features = PALPOSIX::pal_features | Entropy; - static constexpr size_t page_size = - Aal::aal_name == PowerPC ? 0x10000 : PALPOSIX::page_size; + static constexpr size_t page_size = Aal::aal_name == PowerPC ? + 0x10000 : + (Aal::aal_name == LoongArch ? 0x4000 : PALPOSIX::page_size); /** * Linux requires an explicit no-reserve flag in `mmap` to guarantee lazy