2
0

sys_membarrier.c 1.2 KB

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