Skip to content

Commit 57380fd

Browse files
Rtoaxmstsirkin
authored andcommitted
tools/virtio: Fix arm64 ringtest compilation error
Add cpu_relax() for arm64 instead of directly assert(), and add assert.h header file. Also, add smp_wmb and smp_mb for arm64. Compilation error as follows, avoid __always_inline undefined. $ make cc -Wall -pthread -O2 -ggdb -flto -fwhole-program -c -o ring.o ring.c In file included from ring.c:10: main.h: In function ‘busy_wait’: main.h:99:21: warning: implicit declaration of function ‘assert’ [-Wimplicit-function-declaration] 99 | #define cpu_relax() assert(0) | ^~~~~~ main.h:107:17: note: in expansion of macro ‘cpu_relax’ 107 | cpu_relax(); | ^~~~~~~~~ main.h:12:1: note: ‘assert’ is defined in header ‘<assert.h>’; did you forget to ‘#include <assert.h>’? 11 | #include <stdbool.h> +++ |+#include <assert.h> 12 | main.h: At top level: main.h:143:23: error: expected ‘;’ before ‘void’ 143 | static __always_inline | ^ | ; 144 | void __read_once_size(const volatile void *p, void *res, int size) | ~~~~ main.h:158:23: error: expected ‘;’ before ‘void’ 158 | static __always_inline void __write_once_size(volatile void *p, void *res, int size) | ^~~~~ | ; make: *** [<builtin>: ring.o] Error 1 Signed-off-by: Rong Tao <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a90e860 commit 57380fd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/virtio/ringtest/main.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef MAIN_H
99
#define MAIN_H
1010

11+
#include <assert.h>
1112
#include <stdbool.h>
1213

1314
extern int param;
@@ -95,6 +96,8 @@ extern unsigned ring_size;
9596
#define cpu_relax() asm ("rep; nop" ::: "memory")
9697
#elif defined(__s390x__)
9798
#define cpu_relax() barrier()
99+
#elif defined(__aarch64__)
100+
#define cpu_relax() asm ("yield" ::: "memory")
98101
#else
99102
#define cpu_relax() assert(0)
100103
#endif
@@ -112,6 +115,8 @@ static inline void busy_wait(void)
112115

113116
#if defined(__x86_64__) || defined(__i386__)
114117
#define smp_mb() asm volatile("lock; addl $0,-132(%%rsp)" ::: "memory", "cc")
118+
#elif defined(__aarch64__)
119+
#define smp_mb() asm volatile("dmb ish" ::: "memory")
115120
#else
116121
/*
117122
* Not using __ATOMIC_SEQ_CST since gcc docs say they are only synchronized
@@ -136,10 +141,16 @@ static inline void busy_wait(void)
136141

137142
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__)
138143
#define smp_wmb() barrier()
144+
#elif defined(__aarch64__)
145+
#define smp_wmb() asm volatile("dmb ishst" ::: "memory")
139146
#else
140147
#define smp_wmb() smp_release()
141148
#endif
142149

150+
#ifndef __always_inline
151+
#define __always_inline inline __attribute__((always_inline))
152+
#endif
153+
143154
static __always_inline
144155
void __read_once_size(const volatile void *p, void *res, int size)
145156
{

0 commit comments

Comments
 (0)