Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loongarch Support #553

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/snmalloc/aal/aal.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
# define PLATFORM_IS_RISCV
#endif

#if defined(__loongarch__)
# define PLATFORM_IS_LOONGARCH
#endif

namespace snmalloc
{
/**
Expand Down Expand Up @@ -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__)
Expand Down
3 changes: 2 additions & 1 deletion src/snmalloc/aal/aal_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace snmalloc
X86,
X86_SGX,
Sparc,
RISCV
RISCV,
LoongArch
};
} // namespace snmalloc
57 changes: 57 additions & 0 deletions src/snmalloc/aal/aal_loongarch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#if __SIZEOF_POINTER__ == 8
# define SNMALLOC_VA_BITS_64
#else
# define SNMALLOC_VA_BITS_32
#endif

#include <cstddef>
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
5 changes: 3 additions & 2 deletions src/snmalloc/pal/pal_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +32 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should add an aal feature for non-4KiB-minimum-page-sizes and, if it's present, expose this as a size in the AAL. We could then have an aal_minimum_page_size() that returned 4KiB if you didn't set this feature and whatever size the AAL required if you did.


/**
* Linux requires an explicit no-reserve flag in `mmap` to guarantee lazy
Expand Down