wvoec3: add membarriers to complete cache flush am: cbfc3c7193
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/13719187 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I6f57d5bacfef47e2ebed665cb540e29a1fd44fe6
This commit is contained in:
@@ -1,13 +1,65 @@
|
|||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if __mips__
|
#include <linux/membarrier.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <asm/cachectl.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#if __mips__
|
||||||
|
# include <asm/cachectl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
namespace wvoec3 {
|
namespace wvoec3 {
|
||||||
|
|
||||||
|
bool supports_membarier_syscall() {
|
||||||
|
// Check kernel version supports membarrier(2); version 4.16 is required.
|
||||||
|
static constexpr int kRequiredMajor = 4;
|
||||||
|
static constexpr int kRequiredMinor = 16;
|
||||||
|
struct utsname uts;
|
||||||
|
int major = 0, minor = 0;
|
||||||
|
if (uname(&uts) != 0 || strcmp(uts.sysname, "Linux") != 0 ||
|
||||||
|
sscanf(uts.release, "%d.%d", &major, &minor) != 2) {
|
||||||
|
LOGE("Failed to get kernel version");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (major < kRequiredMajor ||
|
||||||
|
(major == kRequiredMajor && minor < kRequiredMinor)) {
|
||||||
|
LOGE("Kernel version %d, %d < required %d, %d", major, minor,
|
||||||
|
kRequiredMajor, kRequiredMinor);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__NR_membarrier)
|
||||||
|
|
||||||
|
// membarrier function is used to complete flush of CPU instruction pipelines.
|
||||||
|
// Reference:
|
||||||
|
// * membarrier(2)
|
||||||
|
// * art::jit::JitMemoryRegion::CommitCode
|
||||||
|
int membarrier_function(int command) {
|
||||||
|
static bool supports_membarier = supports_membarier_syscall();
|
||||||
|
if (supports_membarier) {
|
||||||
|
return syscall(__NR_membarrier, command, 0);
|
||||||
|
}
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // __NR_membarrier
|
||||||
|
# pragma message \
|
||||||
|
"(info): __NR_membarrier unavailable; membarrier_function will be no-op."
|
||||||
|
|
||||||
|
int membarrier_function(int) {
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __NR_membarrier
|
||||||
|
|
||||||
// The Cache Flush function is very processor dependent, and is used by the
|
// The Cache Flush function is very processor dependent, and is used by the
|
||||||
// Level3 code using platform-specific flags.
|
// Level3 code using platform-specific flags.
|
||||||
// Linked in separately from the rest of the build, since this code isn't
|
// Linked in separately from the rest of the build, since this code isn't
|
||||||
@@ -58,6 +110,12 @@ void clear_cache_function(void *page, size_t len) {
|
|||||||
// TODO(fredgc): silence warning about unused variables.
|
// TODO(fredgc): silence warning about unused variables.
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__arm__) || defined(__aarch64__)
|
||||||
|
# pragma message "(info): inserting membarrier_function calls."
|
||||||
|
membarrier_function(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE);
|
||||||
|
membarrier_function(MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE);
|
||||||
|
#endif // defined(__arm__) || defined(__aarch64__)
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace wvoec3
|
} // namespace wvoec3
|
||||||
Reference in New Issue
Block a user