Workaround for QEMU behaviour. (#147)

* Fixes for ARM

* Workaround for QEMU behaviour.
This commit is contained in:
Matthew Parkinson
2020-03-19 12:37:44 +00:00
committed by GitHub
parent a6d6eecf22
commit 4246d9a065
3 changed files with 29 additions and 0 deletions

View File

@@ -2,8 +2,14 @@
#if defined(__aarch64__)
# define SNMALLOC_VA_BITS_64
# ifdef _MSC_VER
# include <arm64_neon.h>
# endif
#else
# define SNMALLOC_VA_BITS_32
# ifdef _MSC_VER
# include <arm_neon.h>
# endif
#endif
#include <iostream>
@@ -20,13 +26,27 @@ namespace snmalloc
*/
static constexpr uint64_t aal_features =
IntegerPointers | NoCpuCycleCounters;
/**
* 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()
{
#ifdef _MSC_VER
__yield();
#else
__asm__ volatile("yield");
#endif
}
static inline void prefetch(void* ptr)
{
#ifdef _MSC_VER
__prefetch(ptr);
#else
__asm__ inline("prfm pldl1keep, [%0]" : "=r"(ptr));
#endif
}
};

View File

@@ -37,12 +37,16 @@ namespace snmalloc
template<bool page_aligned = false>
void zero(void* p, size_t size) noexcept
{
// QEMU does not seem to be giving the desired behaviour for MADV_DONTNEED.
// switch back to memset only for QEMU.
# ifndef SNMALLOC_QEMU_WORKAROUND
if (page_aligned || is_aligned_block<OS_PAGE_SIZE>(p, size))
{
SNMALLOC_ASSERT(is_aligned_block<OS_PAGE_SIZE>(p, size));
madvise(p, size, MADV_DONTNEED);
}
else
# endif
{
::memset(p, 0, size);
}