mm/mempolicy.c: remove BUG_ON() checks for VMA inside mpol_misplaced()
[linux/fpc-iii.git] / tools / virtio / ringtest / main.h
blob90b0133004e17ddbc48b90a9eab2e6a489da13b0
1 /*
2 * Copyright (C) 2016 Red Hat, Inc.
3 * Author: Michael S. Tsirkin <mst@redhat.com>
4 * This work is licensed under the terms of the GNU GPL, version 2.
6 * Common macros and functions for ring benchmarking.
7 */
8 #ifndef MAIN_H
9 #define MAIN_H
11 #include <stdbool.h>
13 extern int param;
15 extern bool do_exit;
17 #if defined(__x86_64__) || defined(__i386__)
18 #include "x86intrin.h"
20 static inline void wait_cycles(unsigned long long cycles)
22 unsigned long long t;
24 t = __rdtsc();
25 while (__rdtsc() - t < cycles) {}
28 #define VMEXIT_CYCLES 500
29 #define VMENTRY_CYCLES 500
31 #elif defined(__s390x__)
32 static inline void wait_cycles(unsigned long long cycles)
34 asm volatile("0: brctg %0,0b" : : "d" (cycles));
37 /* tweak me */
38 #define VMEXIT_CYCLES 200
39 #define VMENTRY_CYCLES 200
41 #else
42 static inline void wait_cycles(unsigned long long cycles)
44 _Exit(5);
46 #define VMEXIT_CYCLES 0
47 #define VMENTRY_CYCLES 0
48 #endif
50 static inline void vmexit(void)
52 if (!do_exit)
53 return;
55 wait_cycles(VMEXIT_CYCLES);
57 static inline void vmentry(void)
59 if (!do_exit)
60 return;
62 wait_cycles(VMENTRY_CYCLES);
65 /* implemented by ring */
66 void alloc_ring(void);
67 /* guest side */
68 int add_inbuf(unsigned, void *, void *);
69 void *get_buf(unsigned *, void **);
70 void disable_call();
71 bool used_empty();
72 bool enable_call();
73 void kick_available();
74 /* host side */
75 void disable_kick();
76 bool avail_empty();
77 bool enable_kick();
78 bool use_buf(unsigned *, void **);
79 void call_used();
81 /* implemented by main */
82 extern bool do_sleep;
83 void kick(void);
84 void wait_for_kick(void);
85 void call(void);
86 void wait_for_call(void);
88 extern unsigned ring_size;
90 /* Compiler barrier - similar to what Linux uses */
91 #define barrier() asm volatile("" ::: "memory")
93 /* Is there a portable way to do this? */
94 #if defined(__x86_64__) || defined(__i386__)
95 #define cpu_relax() asm ("rep; nop" ::: "memory")
96 #elif defined(__s390x__)
97 #define cpu_relax() barrier()
98 #else
99 #define cpu_relax() assert(0)
100 #endif
102 extern bool do_relax;
104 static inline void busy_wait(void)
106 if (do_relax)
107 cpu_relax();
108 else
109 /* prevent compiler from removing busy loops */
110 barrier();
114 * Not using __ATOMIC_SEQ_CST since gcc docs say they are only synchronized
115 * with other __ATOMIC_SEQ_CST calls.
117 #define smp_mb() __sync_synchronize()
120 * This abuses the atomic builtins for thread fences, and
121 * adds a compiler barrier.
123 #define smp_release() do { \
124 barrier(); \
125 __atomic_thread_fence(__ATOMIC_RELEASE); \
126 } while (0)
128 #define smp_acquire() do { \
129 __atomic_thread_fence(__ATOMIC_ACQUIRE); \
130 barrier(); \
131 } while (0)
133 #endif