ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_linuxaio.c
(Generate patch)

Comparing libev/ev_linuxaio.c (file contents):
Revision 1.29 by root, Tue Jun 25 06:43:04 2019 UTC vs.
Revision 1.30 by root, Tue Jun 25 17:54:02 2019 UTC

116 unsigned header_length; /* size of aio_ring */ 116 unsigned header_length; /* size of aio_ring */
117 117
118 struct io_event io_events[0]; 118 struct io_event io_events[0];
119}; 119};
120 120
121/*
122 * define some syscall wrappers for common architectures
123 * this is mostly for nice looks during debugging, not performance.
124 * our syscalls return < 0, not == -1, on error. which is good
125 * enough for linux aio.
126 * TODO: arm is also common nowadays, maybe even mips and x86
127 * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove...
128 */
129#if __GNUC__ && __linux && ECB_AMD64
130
131 #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5) \
132 ({ \
133 long res; \
134 register unsigned long r5 __asm__ ("r8" ); \
135 register unsigned long r4 __asm__ ("r10"); \
136 register unsigned long r3 __asm__ ("rdx"); \
137 register unsigned long r2 __asm__ ("rsi"); \
138 register unsigned long r1 __asm__ ("rdi"); \
139 if (narg >= 5) r5 = (unsigned long)(arg5); \
140 if (narg >= 4) r4 = (unsigned long)(arg4); \
141 if (narg >= 3) r3 = (unsigned long)(arg3); \
142 if (narg >= 2) r2 = (unsigned long)(arg2); \
143 if (narg >= 1) r1 = (unsigned long)(arg1); \
144 __asm__ __volatile__ ( \
145 "syscall\n\t" \
146 : "=a" (res) \
147 : "0" (nr), "r" (r1), "r" (r2), "r" (r3), "r" (r4), "r" (r5) \
148 : "cc", "r11", "cx", "memory"); \
149 errno = -res; \
150 res; \
151 })
152
153#endif
154
155#ifdef ev_syscall
156 #define ev_syscall0(nr) ev_syscall (nr, 0, 0, 0, 0, 0, 0
157 #define ev_syscall1(nr,arg1) ev_syscall (nr, 1, arg1, 0, 0, 0, 0)
158 #define ev_syscall2(nr,arg1,arg2) ev_syscall (nr, 2, arg1, arg2, 0, 0, 0)
159 #define ev_syscall3(nr,arg1,arg2,arg3) ev_syscall (nr, 3, arg1, arg2, arg3, 0, 0)
160 #define ev_syscall4(nr,arg1,arg2,arg3,arg4) ev_syscall (nr, 3, arg1, arg2, arg3, arg4, 0)
161 #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) ev_syscall (nr, 5, arg1, arg2, arg3, arg4, arg5)
162#else
163 #define ev_syscall0(nr) syscall (nr)
164 #define ev_syscall1(nr,arg1) syscall (nr, arg1)
165 #define ev_syscall2(nr,arg1,arg2) syscall (nr, arg1, arg2)
166 #define ev_syscall3(nr,arg1,arg2,arg3) syscall (nr, arg1, arg2, arg3)
167 #define ev_syscall4(nr,arg1,arg2,arg3,arg4) syscall (nr, arg1, arg2, arg3, arg4)
168 #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) syscall (nr, arg1, arg2, arg3, arg4, arg5)
169#endif
170
121inline_size 171inline_size
122int 172int
123evsys_io_setup (unsigned nr_events, aio_context_t *ctx_idp) 173evsys_io_setup (unsigned nr_events, aio_context_t *ctx_idp)
124{ 174{
125 return syscall (SYS_io_setup, nr_events, ctx_idp); 175 return ev_syscall2 (SYS_io_setup, nr_events, ctx_idp);
126} 176}
127 177
128inline_size 178inline_size
129int 179int
130evsys_io_destroy (aio_context_t ctx_id) 180evsys_io_destroy (aio_context_t ctx_id)
131{ 181{
132 return syscall (SYS_io_destroy, ctx_id); 182 return ev_syscall1 (SYS_io_destroy, ctx_id);
133} 183}
134 184
135inline_size 185inline_size
136int 186int
137evsys_io_submit (aio_context_t ctx_id, long nr, struct iocb *cbp[]) 187evsys_io_submit (aio_context_t ctx_id, long nr, struct iocb *cbp[])
138{ 188{
139 return syscall (SYS_io_submit, ctx_id, nr, cbp); 189 return ev_syscall3 (SYS_io_submit, ctx_id, nr, cbp);
140} 190}
141 191
142inline_size 192inline_size
143int 193int
144evsys_io_cancel (aio_context_t ctx_id, struct iocb *cbp, struct io_event *result) 194evsys_io_cancel (aio_context_t ctx_id, struct iocb *cbp, struct io_event *result)
145{ 195{
146 return syscall (SYS_io_cancel, ctx_id, cbp, result); 196 return ev_syscall3 (SYS_io_cancel, ctx_id, cbp, result);
147} 197}
148 198
149inline_size 199inline_size
150int 200int
151evsys_io_getevents (aio_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout) 201evsys_io_getevents (aio_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct timespec *timeout)
152{ 202{
153 return syscall (SYS_io_getevents, ctx_id, min_nr, nr, events, timeout); 203 return ev_syscall5 (SYS_io_getevents, ctx_id, min_nr, nr, events, timeout);
154} 204}
155 205
156/*****************************************************************************/ 206/*****************************************************************************/
157/* actual backed implementation */ 207/* actual backed implementation */
158 208
240 if (iocb->io.aio_reqprio < 0) 290 if (iocb->io.aio_reqprio < 0)
241 { 291 {
242 /* we handed this fd over to epoll, so undo this first */ 292 /* we handed this fd over to epoll, so undo this first */
243 /* we do it manually because the optimisations on epoll_modfy won't do us any good */ 293 /* we do it manually because the optimisations on epoll_modfy won't do us any good */
244 epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0); 294 epoll_ctl (backend_fd, EPOLL_CTL_DEL, fd, 0);
295 anfds [fd].emask = 0;
245 iocb->io.aio_reqprio = 0; 296 iocb->io.aio_reqprio = 0;
246 } 297 }
247 298
248 if (iocb->io.aio_buf) 299 if (iocb->io.aio_buf)
249 /* io_cancel always returns some error on relevant kernels, but works */ 300 /* io_cancel always returns some error on relevant kernels, but works */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines