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

Add cache flush for arm #9170

Merged
merged 2 commits into from
Oct 2, 2021
Merged
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
19 changes: 17 additions & 2 deletions src/runtime/rpc/rpc_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,33 @@ std::shared_ptr<RPCSession> RPCModuleGetSession(Module mod) {
* which leads to lower performance.
*/
inline void CPUCacheFlushImpl(const char* addr, unsigned int len) {
// TODO(FrozenGene): Support ARM.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should leave this TODO as we haven't completed support for arm 32 bits.

#if (defined(_M_X64) || defined(__x86_64__))
#if (defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__))

#if defined(__aarch64__)
size_t ctr_el0 = 0;
asm volatile("mrs %0, ctr_el0" : "=r"(ctr_el0));
const size_t cache_line = 4 << ((ctr_el0 >> 16) & 15);
#else
const size_t cache_line = 64;
#endif

if (addr == nullptr || len <= 0) {
return;
}

for (uintptr_t uptr = (uintptr_t)addr & ~(cache_line - 1); uptr < (uintptr_t)addr + len;
uptr += cache_line) {
#if defined(__aarch64__)
asm volatile("dc civac, %0\n\t" : : "r"(reinterpret_cast<const void*>(uptr)) : "memory");
#else
_mm_clflush(reinterpret_cast<const void*>(uptr));
#endif
}

#if defined(__aarch64__)
asm volatile("dmb ishst" : : : "memory");
#endif

#endif
}

Expand Down