Wed Jul 27 23:10:41 2011 UTC ()
Make this use offsetof and __typeof__ to appease gcc4.5


(matt)
diff -r1.11 -r1.12 src/sys/arch/xen/include/xen3-public/io/ring.h

cvs diff -r1.11 -r1.12 src/sys/arch/xen/include/xen3-public/io/Attic/ring.h (switch to unified diff)

--- src/sys/arch/xen/include/xen3-public/io/Attic/ring.h 2008/08/22 15:28:11 1.11
+++ src/sys/arch/xen/include/xen3-public/io/Attic/ring.h 2011/07/27 23:10:40 1.12
@@ -1,316 +1,316 @@ @@ -1,316 +1,316 @@
1/* $NetBSD: ring.h,v 1.11 2008/08/22 15:28:11 cegger Exp $ */ 1/* $NetBSD: ring.h,v 1.12 2011/07/27 23:10:40 matt Exp $ */
2/****************************************************************************** 2/******************************************************************************
3 * ring.h 3 * ring.h
4 *  4 *
5 * Shared producer-consumer ring macros. 5 * Shared producer-consumer ring macros.
6 * 6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to 8 * of this software and associated documentation files (the "Software"), to
9 * deal in the Software without restriction, including without limitation the 9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is 11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions: 12 * furnished to do so, subject to the following conditions:
13 * 13 *
14 * The above copyright notice and this permission notice shall be included in 14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software. 15 * all copies or substantial portions of the Software.
16 * 16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE. 23 * DEALINGS IN THE SOFTWARE.
24 * 24 *
25 * Tim Deegan and Andrew Warfield November 2004. 25 * Tim Deegan and Andrew Warfield November 2004.
26 */ 26 */
27 27
28#ifndef __XEN_PUBLIC_IO_RING_H__ 28#ifndef __XEN_PUBLIC_IO_RING_H__
29#define __XEN_PUBLIC_IO_RING_H__ 29#define __XEN_PUBLIC_IO_RING_H__
30 30
31#include "../xen-compat.h" 31#include "../xen-compat.h"
32 32
33#if __XEN_INTERFACE_VERSION__ < 0x00030208 33#if __XEN_INTERFACE_VERSION__ < 0x00030208
34#if defined(__Linux__) 34#if defined(__Linux__)
35#define xen_mb() mb() 35#define xen_mb() mb()
36#define xen_rmb() rmb() 36#define xen_rmb() rmb()
37#define xen_wmb() wmb() 37#define xen_wmb() wmb()
38#endif 38#endif
39#endif 39#endif
40 40
41#if defined(__NetBSD__) 41#if defined(__NetBSD__)
42#define xen_mb() x86_mfence() 42#define xen_mb() x86_mfence()
43#define xen_rmb() x86_lfence() 43#define xen_rmb() x86_lfence()
44#define xen_wmb() x86_sfence() 44#define xen_wmb() x86_sfence()
45#endif 45#endif
46 46
47typedef unsigned int RING_IDX; 47typedef unsigned int RING_IDX;
48 48
49/* Round a 32-bit unsigned constant down to the nearest power of two. */ 49/* Round a 32-bit unsigned constant down to the nearest power of two. */
50#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1)) 50#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
51#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x)) 51#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
52#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x)) 52#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
53#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x)) 53#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
54#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x)) 54#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
55 55
56/* 56/*
57 * Calculate size of a shared ring, given the total available space for the 57 * Calculate size of a shared ring, given the total available space for the
58 * ring and indexes (_sz), and the name tag of the request/response structure. 58 * ring and indexes (_sz), and the name tag of the request/response structure.
59 * A ring contains as many entries as will fit, rounded down to the nearest  59 * A ring contains as many entries as will fit, rounded down to the nearest
60 * power of two (so we can mask with (size-1) to loop around). 60 * power of two (so we can mask with (size-1) to loop around).
61 */ 61 */
62#define __RING_SIZE(_s, _sz) \ 62#define __RING_SIZE(_s, _sz) \
63 (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0]))) 63 (__RD32(((_sz) - offsetof(__typeof__(*(_s)), ring)) / sizeof((_s)->ring[0])))
64 64
65/* 65/*
66 * Macros to make the correct C datatypes for a new kind of ring. 66 * Macros to make the correct C datatypes for a new kind of ring.
67 *  67 *
68 * To make a new ring datatype, you need to have two message structures, 68 * To make a new ring datatype, you need to have two message structures,
69 * let's say request_t, and response_t already defined. 69 * let's say request_t, and response_t already defined.
70 * 70 *
71 * In a header where you want the ring datatype declared, you then do: 71 * In a header where you want the ring datatype declared, you then do:
72 * 72 *
73 * DEFINE_RING_TYPES(mytag, request_t, response_t); 73 * DEFINE_RING_TYPES(mytag, request_t, response_t);
74 * 74 *
75 * These expand out to give you a set of types, as you can see below. 75 * These expand out to give you a set of types, as you can see below.
76 * The most important of these are: 76 * The most important of these are:
77 *  77 *
78 * mytag_sring_t - The shared ring. 78 * mytag_sring_t - The shared ring.
79 * mytag_front_ring_t - The 'front' half of the ring. 79 * mytag_front_ring_t - The 'front' half of the ring.
80 * mytag_back_ring_t - The 'back' half of the ring. 80 * mytag_back_ring_t - The 'back' half of the ring.
81 * 81 *
82 * To initialize a ring in your code you need to know the location and size 82 * To initialize a ring in your code you need to know the location and size
83 * of the shared memory area (PAGE_SIZE, for instance). To initialise 83 * of the shared memory area (PAGE_SIZE, for instance). To initialise
84 * the front half: 84 * the front half:
85 * 85 *
86 * mytag_front_ring_t front_ring; 86 * mytag_front_ring_t front_ring;
87 * SHARED_RING_INIT((mytag_sring_t *)shared_page); 87 * SHARED_RING_INIT((mytag_sring_t *)shared_page);
88 * FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE); 88 * FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
89 * 89 *
90 * Initializing the back follows similarly (note that only the front 90 * Initializing the back follows similarly (note that only the front
91 * initializes the shared ring): 91 * initializes the shared ring):
92 * 92 *
93 * mytag_back_ring_t back_ring; 93 * mytag_back_ring_t back_ring;
94 * BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE); 94 * BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
95 */ 95 */
96 96
97#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \ 97#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \
98 \ 98 \
99/* Shared ring entry */ \ 99/* Shared ring entry */ \
100union __name##_sring_entry { \ 100union __name##_sring_entry { \
101 __req_t req; \ 101 __req_t req; \
102 __rsp_t rsp; \ 102 __rsp_t rsp; \
103}; \ 103}; \
104 \ 104 \
105/* Shared ring page */ \ 105/* Shared ring page */ \
106struct __name##_sring { \ 106struct __name##_sring { \
107 RING_IDX req_prod, req_event; \ 107 RING_IDX req_prod, req_event; \
108 RING_IDX rsp_prod, rsp_event; \ 108 RING_IDX rsp_prod, rsp_event; \
109 uint8_t pad[48]; \ 109 uint8_t pad[48]; \
110 union __name##_sring_entry ring[1]; /* variable-length */ \ 110 union __name##_sring_entry ring[1]; /* variable-length */ \
111}; \ 111}; \
112 \ 112 \
113/* "Front" end's private variables */ \ 113/* "Front" end's private variables */ \
114struct __name##_front_ring { \ 114struct __name##_front_ring { \
115 RING_IDX req_prod_pvt; \ 115 RING_IDX req_prod_pvt; \
116 RING_IDX rsp_cons; \ 116 RING_IDX rsp_cons; \
117 unsigned int nr_ents; \ 117 unsigned int nr_ents; \
118 struct __name##_sring *sring; \ 118 struct __name##_sring *sring; \
119}; \ 119}; \
120 \ 120 \
121/* "Back" end's private variables */ \ 121/* "Back" end's private variables */ \
122struct __name##_back_ring { \ 122struct __name##_back_ring { \
123 RING_IDX rsp_prod_pvt; \ 123 RING_IDX rsp_prod_pvt; \
124 RING_IDX req_cons; \ 124 RING_IDX req_cons; \
125 unsigned int nr_ents; \ 125 unsigned int nr_ents; \
126 struct __name##_sring *sring; \ 126 struct __name##_sring *sring; \
127}; \ 127}; \
128 \ 128 \
129/* Syntactic sugar */ \ 129/* Syntactic sugar */ \
130typedef struct __name##_sring __name##_sring_t; \ 130typedef struct __name##_sring __name##_sring_t; \
131typedef struct __name##_front_ring __name##_front_ring_t; \ 131typedef struct __name##_front_ring __name##_front_ring_t; \
132typedef struct __name##_back_ring __name##_back_ring_t 132typedef struct __name##_back_ring __name##_back_ring_t
133 133
134/* 134/*
135 * Macros for manipulating rings. 135 * Macros for manipulating rings.
136 *  136 *
137 * FRONT_RING_whatever works on the "front end" of a ring: here  137 * FRONT_RING_whatever works on the "front end" of a ring: here
138 * requests are pushed on to the ring and responses taken off it. 138 * requests are pushed on to the ring and responses taken off it.
139 *  139 *
140 * BACK_RING_whatever works on the "back end" of a ring: here  140 * BACK_RING_whatever works on the "back end" of a ring: here
141 * requests are taken off the ring and responses put on. 141 * requests are taken off the ring and responses put on.
142 *  142 *
143 * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL.  143 * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL.
144 * This is OK in 1-for-1 request-response situations where the  144 * This is OK in 1-for-1 request-response situations where the
145 * requestor (front end) never has more than RING_SIZE()-1 145 * requestor (front end) never has more than RING_SIZE()-1
146 * outstanding requests. 146 * outstanding requests.
147 */ 147 */
148 148
149/* Initialising empty rings */ 149/* Initialising empty rings */
150#define SHARED_RING_INIT(_s) do { \ 150#define SHARED_RING_INIT(_s) do { \
151 (_s)->req_prod = (_s)->rsp_prod = 0; \ 151 (_s)->req_prod = (_s)->rsp_prod = 0; \
152 (_s)->req_event = (_s)->rsp_event = 1; \ 152 (_s)->req_event = (_s)->rsp_event = 1; \
153 (void)memset((_s)->pad, 0, sizeof((_s)->pad)); \ 153 (void)memset((_s)->pad, 0, sizeof((_s)->pad)); \
154} while(0) 154} while(0)
155 155
156#define FRONT_RING_INIT(_r, _s, __size) do { \ 156#define FRONT_RING_INIT(_r, _s, __size) do { \
157 (_r)->req_prod_pvt = 0; \ 157 (_r)->req_prod_pvt = 0; \
158 (_r)->rsp_cons = 0; \ 158 (_r)->rsp_cons = 0; \
159 (_r)->nr_ents = __RING_SIZE(_s, __size); \ 159 (_r)->nr_ents = __RING_SIZE(_s, __size); \
160 (_r)->sring = (_s); \ 160 (_r)->sring = (_s); \
161} while (0) 161} while (0)
162 162
163#define BACK_RING_INIT(_r, _s, __size) do { \ 163#define BACK_RING_INIT(_r, _s, __size) do { \
164 (_r)->rsp_prod_pvt = 0; \ 164 (_r)->rsp_prod_pvt = 0; \
165 (_r)->req_cons = 0; \ 165 (_r)->req_cons = 0; \
166 (_r)->nr_ents = __RING_SIZE(_s, __size); \ 166 (_r)->nr_ents = __RING_SIZE(_s, __size); \
167 (_r)->sring = (_s); \ 167 (_r)->sring = (_s); \
168} while (0) 168} while (0)
169 169
170/* Initialize to existing shared indexes -- for recovery */ 170/* Initialize to existing shared indexes -- for recovery */
171#define FRONT_RING_ATTACH(_r, _s, __size) do { \ 171#define FRONT_RING_ATTACH(_r, _s, __size) do { \
172 (_r)->sring = (_s); \ 172 (_r)->sring = (_s); \
173 (_r)->req_prod_pvt = (_s)->req_prod; \ 173 (_r)->req_prod_pvt = (_s)->req_prod; \
174 (_r)->rsp_cons = (_s)->rsp_prod; \ 174 (_r)->rsp_cons = (_s)->rsp_prod; \
175 (_r)->nr_ents = __RING_SIZE(_s, __size); \ 175 (_r)->nr_ents = __RING_SIZE(_s, __size); \
176} while (0) 176} while (0)
177 177
178#define BACK_RING_ATTACH(_r, _s, __size) do { \ 178#define BACK_RING_ATTACH(_r, _s, __size) do { \
179 (_r)->sring = (_s); \ 179 (_r)->sring = (_s); \
180 (_r)->rsp_prod_pvt = (_s)->rsp_prod; \ 180 (_r)->rsp_prod_pvt = (_s)->rsp_prod; \
181 (_r)->req_cons = (_s)->req_prod; \ 181 (_r)->req_cons = (_s)->req_prod; \
182 (_r)->nr_ents = __RING_SIZE(_s, __size); \ 182 (_r)->nr_ents = __RING_SIZE(_s, __size); \
183} while (0) 183} while (0)
184 184
185/* How big is this ring? */ 185/* How big is this ring? */
186#define RING_SIZE(_r) \ 186#define RING_SIZE(_r) \
187 ((_r)->nr_ents) 187 ((_r)->nr_ents)
188 188
189/* Number of free requests (for use on front side only). */ 189/* Number of free requests (for use on front side only). */
190#define RING_FREE_REQUESTS(_r) \ 190#define RING_FREE_REQUESTS(_r) \
191 (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons)) 191 (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
192 192
193/* Test if there is an empty slot available on the front ring. 193/* Test if there is an empty slot available on the front ring.
194 * (This is only meaningful from the front. ) 194 * (This is only meaningful from the front. )
195 */ 195 */
196#define RING_FULL(_r) \ 196#define RING_FULL(_r) \
197 (RING_FREE_REQUESTS(_r) == 0) 197 (RING_FREE_REQUESTS(_r) == 0)
198 198
199/* Test if there are outstanding messages to be processed on a ring. */ 199/* Test if there are outstanding messages to be processed on a ring. */
200#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ 200#define RING_HAS_UNCONSUMED_RESPONSES(_r) \
201 ((_r)->sring->rsp_prod - (_r)->rsp_cons) 201 ((_r)->sring->rsp_prod - (_r)->rsp_cons)
202 202
203#ifdef __GNUC__ 203#ifdef __GNUC__
204#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \ 204#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \
205 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \ 205 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \
206 unsigned int rsp = RING_SIZE(_r) - \ 206 unsigned int rsp = RING_SIZE(_r) - \
207 ((_r)->req_cons - (_r)->rsp_prod_pvt); \ 207 ((_r)->req_cons - (_r)->rsp_prod_pvt); \
208 req < rsp ? req : rsp; \ 208 req < rsp ? req : rsp; \
209}) 209})
210#else 210#else
211/* Same as above, but without the nice GCC ({ ... }) syntax. */ 211/* Same as above, but without the nice GCC ({ ... }) syntax. */
212#define RING_HAS_UNCONSUMED_REQUESTS(_r) \ 212#define RING_HAS_UNCONSUMED_REQUESTS(_r) \
213 ((((_r)->sring->req_prod - (_r)->req_cons) < \ 213 ((((_r)->sring->req_prod - (_r)->req_cons) < \
214 (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \ 214 (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \
215 ((_r)->sring->req_prod - (_r)->req_cons) : \ 215 ((_r)->sring->req_prod - (_r)->req_cons) : \
216 (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) 216 (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt)))
217#endif 217#endif
218 218
219/* Direct access to individual ring elements, by index. */ 219/* Direct access to individual ring elements, by index. */
220#define RING_GET_REQUEST(_r, _idx) \ 220#define RING_GET_REQUEST(_r, _idx) \
221 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req)) 221 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
222 222
223#define RING_GET_RESPONSE(_r, _idx) \ 223#define RING_GET_RESPONSE(_r, _idx) \
224 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp)) 224 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
225 225
226/* Loop termination condition: Would the specified index overflow the ring? */ 226/* Loop termination condition: Would the specified index overflow the ring? */
227#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \ 227#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \
228 (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r)) 228 (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
229 229
230#define RING_PUSH_REQUESTS(_r) do { \ 230#define RING_PUSH_REQUESTS(_r) do { \
231 xen_wmb(); /* back sees requests /before/ updated producer index */ \ 231 xen_wmb(); /* back sees requests /before/ updated producer index */ \
232 (_r)->sring->req_prod = (_r)->req_prod_pvt; \ 232 (_r)->sring->req_prod = (_r)->req_prod_pvt; \
233} while (0) 233} while (0)
234 234
235#define RING_PUSH_RESPONSES(_r) do { \ 235#define RING_PUSH_RESPONSES(_r) do { \
236 xen_wmb(); /* front sees resps /before/ updated producer index */ \ 236 xen_wmb(); /* front sees resps /before/ updated producer index */ \
237 (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \ 237 (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
238} while (0) 238} while (0)
239 239
240/* 240/*
241 * Notification hold-off (req_event and rsp_event): 241 * Notification hold-off (req_event and rsp_event):
242 *  242 *
243 * When queueing requests or responses on a shared ring, it may not always be 243 * When queueing requests or responses on a shared ring, it may not always be
244 * necessary to notify the remote end. For example, if requests are in flight 244 * necessary to notify the remote end. For example, if requests are in flight
245 * in a backend, the front may be able to queue further requests without 245 * in a backend, the front may be able to queue further requests without
246 * notifying the back (if the back checks for new requests when it queues 246 * notifying the back (if the back checks for new requests when it queues
247 * responses). 247 * responses).
248 *  248 *
249 * When enqueuing requests or responses: 249 * When enqueuing requests or responses:
250 *  250 *
251 * Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument 251 * Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument
252 * is a boolean return value. True indicates that the receiver requires an 252 * is a boolean return value. True indicates that the receiver requires an
253 * asynchronous notification. 253 * asynchronous notification.
254 *  254 *
255 * After dequeuing requests or responses (before sleeping the connection): 255 * After dequeuing requests or responses (before sleeping the connection):
256 *  256 *
257 * Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES(). 257 * Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES().
258 * The second argument is a boolean return value. True indicates that there 258 * The second argument is a boolean return value. True indicates that there
259 * are pending messages on the ring (i.e., the connection should not be put 259 * are pending messages on the ring (i.e., the connection should not be put
260 * to sleep). 260 * to sleep).
261 *  261 *
262 * These macros will set the req_event/rsp_event field to trigger a 262 * These macros will set the req_event/rsp_event field to trigger a
263 * notification on the very next message that is enqueued. If you want to 263 * notification on the very next message that is enqueued. If you want to
264 * create batches of work (i.e., only receive a notification after several 264 * create batches of work (i.e., only receive a notification after several
265 * messages have been enqueued) then you will need to create a customised 265 * messages have been enqueued) then you will need to create a customised
266 * version of the FINAL_CHECK macro in your own code, which sets the event 266 * version of the FINAL_CHECK macro in your own code, which sets the event
267 * field appropriately. 267 * field appropriately.
268 */ 268 */
269 269
270#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \ 270#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \
271 RING_IDX __old = (_r)->sring->req_prod; \ 271 RING_IDX __old = (_r)->sring->req_prod; \
272 RING_IDX __new = (_r)->req_prod_pvt; \ 272 RING_IDX __new = (_r)->req_prod_pvt; \
273 xen_wmb(); /* back sees requests /before/ updated producer index */ \ 273 xen_wmb(); /* back sees requests /before/ updated producer index */ \
274 (_r)->sring->req_prod = __new; \ 274 (_r)->sring->req_prod = __new; \
275 xen_mb(); /* back sees new requests /before/ we check req_event */ \ 275 xen_mb(); /* back sees new requests /before/ we check req_event */ \
276 (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \ 276 (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
277 (RING_IDX)(__new - __old)); \ 277 (RING_IDX)(__new - __old)); \
278} while (0) 278} while (0)
279 279
280#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \ 280#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \
281 RING_IDX __old = (_r)->sring->rsp_prod; \ 281 RING_IDX __old = (_r)->sring->rsp_prod; \
282 RING_IDX __new = (_r)->rsp_prod_pvt; \ 282 RING_IDX __new = (_r)->rsp_prod_pvt; \
283 xen_wmb(); /* front sees resps /before/ updated producer index */ \ 283 xen_wmb(); /* front sees resps /before/ updated producer index */ \
284 (_r)->sring->rsp_prod = __new; \ 284 (_r)->sring->rsp_prod = __new; \
285 xen_mb(); /* front sees new resps /before/ we check rsp_event */ \ 285 xen_mb(); /* front sees new resps /before/ we check rsp_event */ \
286 (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \ 286 (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
287 (RING_IDX)(__new - __old)); \ 287 (RING_IDX)(__new - __old)); \
288} while (0) 288} while (0)
289 289
290#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \ 290#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \
291 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \ 291 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
292 if (_work_to_do) break; \ 292 if (_work_to_do) break; \
293 (_r)->sring->req_event = (_r)->req_cons + 1; \ 293 (_r)->sring->req_event = (_r)->req_cons + 1; \
294 xen_mb(); \ 294 xen_mb(); \
295 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \ 295 (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
296} while (0) 296} while (0)
297 297
298#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \ 298#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \
299 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \ 299 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
300 if (_work_to_do) break; \ 300 if (_work_to_do) break; \
301 (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \ 301 (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
302 xen_mb(); \ 302 xen_mb(); \
303 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \ 303 (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
304} while (0) 304} while (0)
305 305
306#endif /* __XEN_PUBLIC_IO_RING_H__ */ 306#endif /* __XEN_PUBLIC_IO_RING_H__ */
307 307
308/* 308/*
309 * Local variables: 309 * Local variables:
310 * mode: C 310 * mode: C
311 * c-set-style: "BSD" 311 * c-set-style: "BSD"
312 * c-basic-offset: 4 312 * c-basic-offset: 4
313 * tab-width: 4 313 * tab-width: 4
314 * indent-tabs-mode: nil 314 * indent-tabs-mode: nil
315 * End: 315 * End:
316 */ 316 */