blob: 1362c0c4c5959d6a24e7af520b3f7913bc6791bb [file] [log] [blame]
Paolo Bonzinia40161c2018-02-16 10:05:23 +01001/*
2 * Process-global memory barriers
3 *
4 * Copyright (c) 2018 Red Hat, Inc.
5 *
6 * Author: Paolo Bonzini <pbonzini@redhat.com>
7 */
8
Bruce Rogersd6974842018-03-29 09:10:18 -06009#include "qemu/osdep.h"
10#include "qemu/sys_membarrier.h"
11#include "qemu/error-report.h"
Paolo Bonzinia40161c2018-02-16 10:05:23 +010012
13#ifdef CONFIG_LINUX
14#include <linux/membarrier.h>
15#include <sys/syscall.h>
16
17static int
18membarrier(int cmd, int flags)
19{
20 return syscall(__NR_membarrier, cmd, flags);
21}
22#endif
23
24void smp_mb_global(void)
25{
26#if defined CONFIG_WIN32
27 FlushProcessWriteBuffers();
28#elif defined CONFIG_LINUX
29 membarrier(MEMBARRIER_CMD_SHARED, 0);
30#else
31#error --enable-membarrier is not supported on this operating system.
32#endif
33}
34
35void smp_mb_global_init(void)
36{
37#ifdef CONFIG_LINUX
38 int ret = membarrier(MEMBARRIER_CMD_QUERY, 0);
39 if (ret < 0) {
40 error_report("This QEMU binary requires the membarrier system call.");
41 error_report("Please upgrade your system to a newer version of Linux");
42 exit(1);
43 }
44 if (!(ret & MEMBARRIER_CMD_SHARED)) {
45 error_report("This QEMU binary requires MEMBARRIER_CMD_SHARED support.");
46 error_report("Please upgrade your system to a newer version of Linux");
47 exit(1);
48 }
49#endif
50}