mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 18:38:29 +00:00
7b52aa7987
Actually enable the global memory barriers if supported by the OS. Because only recent versions of Linux include the support, they are disabled by default. Note that it also has to be disabled for QEMU to run under Wine. Before this patch, rcutorture reports 85 ns/read for my machine, after the patch it reports 12.5 ns/read. On the other hand updates go from 50 *micro*seconds to 20 *milli*seconds. Backports commit a40161cbe9ccbcbab798c3e4d257c4bba99d153a from qemu
49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
/*
|
|
* Process-global memory barriers
|
|
*
|
|
* Copyright (c) 2018 Red Hat, Inc.
|
|
*
|
|
* Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
*/
|
|
|
|
#include <qemu/osdep.h>
|
|
#include <qemu/sys_membarrier.h>
|
|
|
|
#ifdef CONFIG_LINUX
|
|
#include <linux/membarrier.h>
|
|
#include <sys/syscall.h>
|
|
|
|
static int
|
|
membarrier(int cmd, int flags)
|
|
{
|
|
return syscall(__NR_membarrier, cmd, flags);
|
|
}
|
|
#endif
|
|
|
|
void smp_mb_global(void)
|
|
{
|
|
#if defined CONFIG_WIN32
|
|
FlushProcessWriteBuffers();
|
|
#elif defined CONFIG_LINUX
|
|
membarrier(MEMBARRIER_CMD_SHARED, 0);
|
|
#else
|
|
#error --enable-membarrier is not supported on this operating system.
|
|
#endif
|
|
}
|
|
|
|
void smp_mb_global_init(void)
|
|
{
|
|
#ifdef CONFIG_LINUX
|
|
int ret = membarrier(MEMBARRIER_CMD_QUERY, 0);
|
|
if (ret < 0) {
|
|
//error_report("This QEMU binary requires the membarrier system call.");
|
|
//error_report("Please upgrade your system to a newer version of Linux");
|
|
exit(1);
|
|
}
|
|
if (!(ret & MEMBARRIER_CMD_SHARED)) {
|
|
//error_report("This QEMU binary requires MEMBARRIER_CMD_SHARED support.");
|
|
//error_report("Please upgrade your system to a newer version of Linux");
|
|
exit(1);
|
|
}
|
|
#endif
|
|
}
|