aboutsummaryrefslogtreecommitdiffstats
path: root/tools/virtio/ringtest/ring.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/virtio/ringtest/ring.c')
-rw-r--r--tools/virtio/ringtest/ring.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/tools/virtio/ringtest/ring.c b/tools/virtio/ringtest/ring.c
index 747c5dd47be8..5a41404aaef5 100644
--- a/tools/virtio/ringtest/ring.c
+++ b/tools/virtio/ringtest/ring.c
@@ -84,12 +84,11 @@ void alloc_ring(void)
84 perror("Unable to allocate ring buffer.\n"); 84 perror("Unable to allocate ring buffer.\n");
85 exit(3); 85 exit(3);
86 } 86 }
87 event = malloc(sizeof *event); 87 event = calloc(1, sizeof(*event));
88 if (!event) { 88 if (!event) {
89 perror("Unable to allocate event buffer.\n"); 89 perror("Unable to allocate event buffer.\n");
90 exit(3); 90 exit(3);
91 } 91 }
92 memset(event, 0, sizeof *event);
93 guest.avail_idx = 0; 92 guest.avail_idx = 0;
94 guest.kicked_avail_idx = -1; 93 guest.kicked_avail_idx = -1;
95 guest.last_used_idx = 0; 94 guest.last_used_idx = 0;
@@ -102,12 +101,11 @@ void alloc_ring(void)
102 ring[i] = desc; 101 ring[i] = desc;
103 } 102 }
104 guest.num_free = ring_size; 103 guest.num_free = ring_size;
105 data = malloc(ring_size * sizeof *data); 104 data = calloc(ring_size, sizeof(*data));
106 if (!data) { 105 if (!data) {
107 perror("Unable to allocate data buffer.\n"); 106 perror("Unable to allocate data buffer.\n");
108 exit(3); 107 exit(3);
109 } 108 }
110 memset(data, 0, ring_size * sizeof *data);
111} 109}
112 110
113/* guest side */ 111/* guest side */
@@ -188,16 +186,18 @@ bool enable_call()
188 186
189void kick_available(void) 187void kick_available(void)
190{ 188{
189 bool need;
190
191 /* Flush in previous flags write */ 191 /* Flush in previous flags write */
192 /* Barrier C (for pairing) */ 192 /* Barrier C (for pairing) */
193 smp_mb(); 193 smp_mb();
194 if (!need_event(event->kick_index, 194 need = need_event(event->kick_index,
195 guest.avail_idx, 195 guest.avail_idx,
196 guest.kicked_avail_idx)) 196 guest.kicked_avail_idx);
197 return;
198 197
199 guest.kicked_avail_idx = guest.avail_idx; 198 guest.kicked_avail_idx = guest.avail_idx;
200 kick(); 199 if (need)
200 kick();
201} 201}
202 202
203/* host side */ 203/* host side */
@@ -253,14 +253,18 @@ bool use_buf(unsigned *lenp, void **bufp)
253 253
254void call_used(void) 254void call_used(void)
255{ 255{
256 bool need;
257
256 /* Flush in previous flags write */ 258 /* Flush in previous flags write */
257 /* Barrier D (for pairing) */ 259 /* Barrier D (for pairing) */
258 smp_mb(); 260 smp_mb();
259 if (!need_event(event->call_index, 261
262 need = need_event(event->call_index,
260 host.used_idx, 263 host.used_idx,
261 host.called_used_idx)) 264 host.called_used_idx);
262 return;
263 265
264 host.called_used_idx = host.used_idx; 266 host.called_used_idx = host.used_idx;
265 call(); 267
268 if (need)
269 call();
266} 270}