| 1 | #!python3
 | 
|---|
| 2 | #
 | 
|---|
| 3 | # Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo
 | 
|---|
| 4 | #
 | 
|---|
| 5 | # The contents of this file are covered under the licence agreement in the
 | 
|---|
| 6 | # file "LICENCE" distributed with Cforall.
 | 
|---|
| 7 | #
 | 
|---|
| 8 | # call.cfa.in -- Python script to generate io/call.cfa
 | 
|---|
| 9 | #
 | 
|---|
| 10 | # Author           : Thierry Delisle
 | 
|---|
| 11 | # Created On       : Fri Sep 11 12:41:16 2020
 | 
|---|
| 12 | # Last Modified By :
 | 
|---|
| 13 | # Last Modified On :
 | 
|---|
| 14 | # Update Count     :
 | 
|---|
| 15 | #
 | 
|---|
| 16 | 
 | 
|---|
| 17 | Header = """//
 | 
|---|
| 18 | // Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo
 | 
|---|
| 19 | //
 | 
|---|
| 20 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
| 21 | // file "LICENCE" distributed with Cforall.
 | 
|---|
| 22 | //
 | 
|---|
| 23 | // call.cfa -- Api for cforall
 | 
|---|
| 24 | //
 | 
|---|
| 25 | // Author           : Generated from call.cfa.in
 | 
|---|
| 26 | // Created On       : {}
 | 
|---|
| 27 | //
 | 
|---|
| 28 | 
 | 
|---|
| 29 | """
 | 
|---|
| 30 | 
 | 
|---|
| 31 | Prelude = """#define __cforall_thread__
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #include <unistd.h>
 | 
|---|
| 34 | #include <errno.h>
 | 
|---|
| 35 | #include <sys/socket.h>
 | 
|---|
| 36 | #include <time.hfa>
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #include "bits/defs.hfa"
 | 
|---|
| 39 | #include "kernel.hfa"
 | 
|---|
| 40 | #include "io/types.hfa"
 | 
|---|
| 41 | #include "stats.hfa"
 | 
|---|
| 42 | 
 | 
|---|
| 43 | //=============================================================================================
 | 
|---|
| 44 | // I/O uring backend
 | 
|---|
| 45 | //=============================================================================================
 | 
|---|
| 46 | 
 | 
|---|
| 47 | #if defined(CFA_HAVE_LINUX_IO_URING_H)
 | 
|---|
| 48 |         #include <assert.h>
 | 
|---|
| 49 |         #include <stdint.h>
 | 
|---|
| 50 |         #include <linux/io_uring.h>
 | 
|---|
| 51 |         #include "kernel/fwd.hfa"
 | 
|---|
| 52 | 
 | 
|---|
| 53 |         static const __u8 REGULAR_FLAGS = 0
 | 
|---|
| 54 |                 #if defined(CFA_HAVE_IOSQE_FIXED_FILE)
 | 
|---|
| 55 |                         | IOSQE_FIXED_FILE
 | 
|---|
| 56 |                 #endif
 | 
|---|
| 57 |                 #if defined(CFA_HAVE_IOSQE_IO_DRAIN)
 | 
|---|
| 58 |                         | IOSQE_IO_DRAIN
 | 
|---|
| 59 |                 #endif
 | 
|---|
| 60 |                 #if defined(CFA_HAVE_IOSQE_IO_LINK)
 | 
|---|
| 61 |                         | IOSQE_IO_LINK
 | 
|---|
| 62 |                 #endif
 | 
|---|
| 63 |                 #if defined(CFA_HAVE_IOSQE_IO_HARDLINK)
 | 
|---|
| 64 |                         | IOSQE_IO_HARDLINK
 | 
|---|
| 65 |                 #endif
 | 
|---|
| 66 |                 #if defined(CFA_HAVE_IOSQE_ASYNC)
 | 
|---|
| 67 |                         | IOSQE_ASYNC
 | 
|---|
| 68 |                 #endif
 | 
|---|
| 69 |                 #if defined(CFA_HAVE_IOSQE_BUFFER_SELECTED)
 | 
|---|
| 70 |                         | IOSQE_BUFFER_SELECTED
 | 
|---|
| 71 |                 #endif
 | 
|---|
| 72 |         ;
 | 
|---|
| 73 | 
 | 
|---|
| 74 |         static const __u32 SPLICE_FLAGS = 0
 | 
|---|
| 75 |                 #if defined(CFA_HAVE_SPLICE_F_FD_IN_FIXED)
 | 
|---|
| 76 |                         | SPLICE_F_FD_IN_FIXED
 | 
|---|
| 77 |                 #endif
 | 
|---|
| 78 |         ;
 | 
|---|
| 79 | 
 | 
|---|
| 80 |         extern struct io_context$ * cfa_io_allocate(struct io_uring_sqe * out_sqes[], __u32 out_idxs[], __u32 want)  __attribute__((nonnull (1,2)));
 | 
|---|
| 81 |         extern void cfa_io_submit( struct io_context$ * in_ctx, __u32 in_idxs[], __u32 have, bool lazy ) __attribute__((nonnull (1,2)));
 | 
|---|
| 82 | #endif
 | 
|---|
| 83 | 
 | 
|---|
| 84 | //=============================================================================================
 | 
|---|
| 85 | // I/O Forwards
 | 
|---|
| 86 | //=============================================================================================
 | 
|---|
| 87 | 
 | 
|---|
| 88 | extern "C" {
 | 
|---|
| 89 | #if defined(CFA_HAVE_PREADV2)
 | 
|---|
| 90 |         struct iovec;
 | 
|---|
| 91 |         extern ssize_t preadv2 (int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags);
 | 
|---|
| 92 | #endif
 | 
|---|
| 93 | #if defined(CFA_HAVE_PWRITEV2)
 | 
|---|
| 94 |         struct iovec;
 | 
|---|
| 95 |         extern ssize_t pwritev2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags);
 | 
|---|
| 96 | #endif
 | 
|---|
| 97 | 
 | 
|---|
| 98 |         extern int fsync(int fd);
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         #if __OFF_T_MATCHES_OFF64_T
 | 
|---|
| 101 |                 typedef __off64_t off_t;
 | 
|---|
| 102 |         #else
 | 
|---|
| 103 |                 typedef __off_t off_t;
 | 
|---|
| 104 |         #endif
 | 
|---|
| 105 |         typedef __off64_t off64_t;
 | 
|---|
| 106 |         extern int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags);
 | 
|---|
| 107 | 
 | 
|---|
| 108 |         struct msghdr;
 | 
|---|
| 109 |         struct sockaddr;
 | 
|---|
| 110 |         extern ssize_t sendmsg(int sockfd, const struct msghdr * msg, int flags);
 | 
|---|
| 111 |         extern ssize_t recvmsg(int sockfd, struct msghdr * msg, int flags);
 | 
|---|
| 112 |         extern ssize_t send(int sockfd, const void * buf, size_t len, int flags);
 | 
|---|
| 113 |         extern ssize_t recv(int sockfd, void * buf, size_t len, int flags);
 | 
|---|
| 114 | 
 | 
|---|
| 115 |         extern int fallocate(int fd, int mode, off_t offset, off_t len);
 | 
|---|
| 116 |         extern int posix_fadvise(int fd, off_t offset, off_t len, int advice);
 | 
|---|
| 117 |         extern int madvise(void * addr, size_t length, int advice);
 | 
|---|
| 118 | 
 | 
|---|
| 119 |         extern int openat(int dirfd, const char * pathname, int flags, mode_t mode);
 | 
|---|
| 120 |         extern int close(int fd);
 | 
|---|
| 121 | 
 | 
|---|
| 122 |         extern ssize_t read (int fd, void * buf, size_t count);
 | 
|---|
| 123 | 
 | 
|---|
| 124 |         struct epoll_event;
 | 
|---|
| 125 |         extern int epoll_ctl(int epfd, int op, int fd, struct epoll_event * event);
 | 
|---|
| 126 | 
 | 
|---|
| 127 |         extern ssize_t splice(int fd_in, __off64_t * off_in, int fd_out, __off64_t * off_out, size_t len, unsigned int flags);
 | 
|---|
| 128 |         extern ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags);
 | 
|---|
| 129 | }
 | 
|---|
| 130 | 
 | 
|---|
| 131 | //=============================================================================================
 | 
|---|
| 132 | // I/O Interface
 | 
|---|
| 133 | //=============================================================================================
 | 
|---|
| 134 | #pragma GCC visibility push(default)
 | 
|---|
| 135 | """
 | 
|---|
| 136 | 
 | 
|---|
| 137 | print(Header.format("A Date"))
 | 
|---|
| 138 | print(Prelude)
 | 
|---|
| 139 | 
 | 
|---|
| 140 | import re
 | 
|---|
| 141 | import sys
 | 
|---|
| 142 | class Call:
 | 
|---|
| 143 |         def __init__(self, op, signature, body, define=None):
 | 
|---|
| 144 |                 sig = re.search("(.*) (.*)\((.*)\)", signature)
 | 
|---|
| 145 |                 if not sig:
 | 
|---|
| 146 |                         print("OP '{}' has invalid signature {}".format(op, signature), file=sys.stderr)
 | 
|---|
| 147 |                         sys.exit(1)
 | 
|---|
| 148 | 
 | 
|---|
| 149 |                 self.op     = op
 | 
|---|
| 150 |                 self.ret    = sig.group(1)
 | 
|---|
| 151 |                 self.name   = sig.group(2)
 | 
|---|
| 152 |                 self.params = sig.group(3)
 | 
|---|
| 153 |                 self.define = define
 | 
|---|
| 154 |                 self.body = ""
 | 
|---|
| 155 | 
 | 
|---|
| 156 |                 accepted_keys = [ 'ioprio', 'fd', 'off', 'addr2','addr', 'splice_off_in','len',
 | 
|---|
| 157 |                         'rw_flags', 'fsync_flags', 'poll_events', 'poll32_events',
 | 
|---|
| 158 |                         'sync_range_flags', 'msg_flags', 'timeout_flags', 'accept_flags',
 | 
|---|
| 159 |                         'cancel_flags', 'open_flags', 'statx_flags', 'fadvise_advice',
 | 
|---|
| 160 |                         'splice_flags', 'buf_index' ,'buf_group' 'personality',
 | 
|---|
| 161 |                         'splice_fd_in' ]
 | 
|---|
| 162 | 
 | 
|---|
| 163 |                 for k, v in body.items():
 | 
|---|
| 164 |                         if not k in accepted_keys:
 | 
|---|
| 165 |                                 print("OP '{}' has invalid body kew {}".format(op, k), file=sys.stderr)
 | 
|---|
| 166 |                                 sys.exit(1)
 | 
|---|
| 167 | 
 | 
|---|
| 168 |                         self.body += "\n                sqe->{key} = {value};".format(key=k, value=v)
 | 
|---|
| 169 | 
 | 
|---|
| 170 | 
 | 
|---|
| 171 |         def args(self):
 | 
|---|
| 172 |                 param_a = self.params.split(',')
 | 
|---|
| 173 |                 args_a = [p.replace('*', ' ').split()[-1] for p in param_a]
 | 
|---|
| 174 |                 for a in args_a:
 | 
|---|
| 175 |                         if '*' in a:
 | 
|---|
| 176 |                                 print("OP '{}' has invalid * in argument {}".format(self.op, a), file=sys.stderr)
 | 
|---|
| 177 |                                 sys.exit(1)
 | 
|---|
| 178 | 
 | 
|---|
| 179 |                 return ', '.join(args_a)
 | 
|---|
| 180 | 
 | 
|---|
| 181 | AsyncTemplate = """inline void async_{name}(io_future_t & future, {params}, __u64 submit_flags) {{
 | 
|---|
| 182 |         #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_{op})
 | 
|---|
| 183 |                 ssize_t res = {name}({args});
 | 
|---|
| 184 |                 if (res >= 0) {{
 | 
|---|
| 185 |                         fulfil(future, res);
 | 
|---|
| 186 |                 }}
 | 
|---|
| 187 |                 else {{
 | 
|---|
| 188 |                         fulfil(future, -errno);
 | 
|---|
| 189 |                 }}
 | 
|---|
| 190 |         #else
 | 
|---|
| 191 |                 __u8 sflags = REGULAR_FLAGS & submit_flags;
 | 
|---|
| 192 |                 __u32 idx;
 | 
|---|
| 193 |                 struct io_uring_sqe * sqe;
 | 
|---|
| 194 |                 struct io_context$ * ctx = cfa_io_allocate( &sqe, &idx, 1 );
 | 
|---|
| 195 | 
 | 
|---|
| 196 |                 memset(sqe, 0, sizeof(*sqe));
 | 
|---|
| 197 |                 sqe->opcode = IORING_OP_{op};
 | 
|---|
| 198 |                 sqe->flags = sflags;
 | 
|---|
| 199 |                 sqe->user_data = (uintptr_t)&future;
 | 
|---|
| 200 |                 {body}
 | 
|---|
| 201 | 
 | 
|---|
| 202 |                 asm volatile("": : :"memory");
 | 
|---|
| 203 | 
 | 
|---|
| 204 |                 verify( sqe->user_data == (uintptr_t)&future );
 | 
|---|
| 205 |                 cfa_io_submit( ctx, &idx, 1, 0 != (submit_flags & CFA_IO_LAZY) );
 | 
|---|
| 206 |         #endif
 | 
|---|
| 207 | }}"""
 | 
|---|
| 208 | 
 | 
|---|
| 209 | SyncTemplate = """{ret} cfa_{name}({params}, __u64 submit_flags) {{
 | 
|---|
| 210 |         io_future_t future;
 | 
|---|
| 211 | 
 | 
|---|
| 212 |         async_{name}( future, {args}, submit_flags );
 | 
|---|
| 213 | 
 | 
|---|
| 214 |         __attribute__((unused)) bool parked;
 | 
|---|
| 215 |         parked = wait( future );
 | 
|---|
| 216 |         __STATS__(false, if(!parked) io.submit.nblk += 1; )
 | 
|---|
| 217 |         if( future.result < 0 ) {{
 | 
|---|
| 218 |                 errno = -future.result;
 | 
|---|
| 219 |                 return -1;
 | 
|---|
| 220 |         }}
 | 
|---|
| 221 |         return future.result;
 | 
|---|
| 222 | }}"""
 | 
|---|
| 223 | 
 | 
|---|
| 224 | calls = [
 | 
|---|
| 225 |         # CFA_HAVE_IORING_OP_READV
 | 
|---|
| 226 |         Call('READV', 'ssize_t preadv2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags)', {
 | 
|---|
| 227 |                 'fd'  : 'fd',
 | 
|---|
| 228 |                 'addr': '(typeof(sqe->addr))iov',
 | 
|---|
| 229 |                 'len' : 'iovcnt',
 | 
|---|
| 230 |                 'off' : 'offset',
 | 
|---|
| 231 |                 'rw_flags' : 'flags'
 | 
|---|
| 232 |         }, define = 'CFA_HAVE_PREADV2'),
 | 
|---|
| 233 |         # CFA_HAVE_IORING_OP_WRITEV
 | 
|---|
| 234 |         Call('WRITEV', 'ssize_t pwritev2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags)', {
 | 
|---|
| 235 |                 'fd'  : 'fd',
 | 
|---|
| 236 |                 'addr': '(typeof(sqe->addr))iov',
 | 
|---|
| 237 |                 'len' : 'iovcnt',
 | 
|---|
| 238 |                 'off' : 'offset',
 | 
|---|
| 239 |                 'rw_flags' : 'flags'
 | 
|---|
| 240 |         }, define = 'CFA_HAVE_PWRITEV2'),
 | 
|---|
| 241 |         # CFA_HAVE_IORING_OP_FSYNC
 | 
|---|
| 242 |         Call('FSYNC', 'int fsync(int fd)', {
 | 
|---|
| 243 |                 'fd': 'fd'
 | 
|---|
| 244 |         }),
 | 
|---|
| 245 |         # CFA_HAVE_IORING_OP_EPOLL_CTL
 | 
|---|
| 246 |         Call('EPOLL_CTL', 'int epoll_ctl(int epfd, int op, int fd, struct epoll_event * event)', {
 | 
|---|
| 247 |                 'fd': 'epfd',
 | 
|---|
| 248 |                 'len': 'op',
 | 
|---|
| 249 |                 'addr': 'fd',
 | 
|---|
| 250 |                 'off': '(typeof(sqe->off))event'
 | 
|---|
| 251 |         }),
 | 
|---|
| 252 |         # CFA_HAVE_IORING_OP_SYNC_FILE_RANGE
 | 
|---|
| 253 |         Call('SYNC_FILE_RANGE', 'int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags)', {
 | 
|---|
| 254 |                 'fd': 'fd',
 | 
|---|
| 255 |                 'off': 'offset',
 | 
|---|
| 256 |                 'len': 'nbytes',
 | 
|---|
| 257 |                 'sync_range_flags': 'flags'
 | 
|---|
| 258 |         }),
 | 
|---|
| 259 |         # CFA_HAVE_IORING_OP_SENDMSG
 | 
|---|
| 260 |         Call('SENDMSG', 'ssize_t sendmsg(int sockfd, const struct msghdr * msg, int flags)', {
 | 
|---|
| 261 |                 'fd': 'sockfd',
 | 
|---|
| 262 |                 'addr': '(typeof(sqe->addr))(struct msghdr *)msg',
 | 
|---|
| 263 |                 'len': '1',
 | 
|---|
| 264 |                 'msg_flags': 'flags'
 | 
|---|
| 265 |         }),
 | 
|---|
| 266 |         # CFA_HAVE_IORING_OP_RECVMSG
 | 
|---|
| 267 |         Call('RECVMSG', 'ssize_t recvmsg(int sockfd, struct msghdr * msg, int flags)', {
 | 
|---|
| 268 |                 'fd': 'sockfd',
 | 
|---|
| 269 |                 'addr': '(typeof(sqe->addr))(struct msghdr *)msg',
 | 
|---|
| 270 |                 'len': '1',
 | 
|---|
| 271 |                 'msg_flags': 'flags'
 | 
|---|
| 272 |         }),
 | 
|---|
| 273 |         # CFA_HAVE_IORING_OP_SEND
 | 
|---|
| 274 |         Call('SEND', 'ssize_t send(int sockfd, const void * buf, size_t len, int flags)', {
 | 
|---|
| 275 |                 'fd': 'sockfd',
 | 
|---|
| 276 |                 'addr': '(typeof(sqe->addr))buf',
 | 
|---|
| 277 |                 'len': 'len',
 | 
|---|
| 278 |                 'msg_flags': 'flags'
 | 
|---|
| 279 |         }),
 | 
|---|
| 280 |         # CFA_HAVE_IORING_OP_RECV
 | 
|---|
| 281 |         Call('RECV', 'ssize_t recv(int sockfd, void * buf, size_t len, int flags)', {
 | 
|---|
| 282 |                 'fd': 'sockfd',
 | 
|---|
| 283 |                 'addr': '(typeof(sqe->addr))buf',
 | 
|---|
| 284 |                 'len': 'len',
 | 
|---|
| 285 |                 'msg_flags': 'flags'
 | 
|---|
| 286 |         }),
 | 
|---|
| 287 |         # CFA_HAVE_IORING_OP_ACCEPT
 | 
|---|
| 288 |         Call('ACCEPT', 'int accept4(int sockfd, __SOCKADDR_ARG addr, socklen_t * restrict addrlen, int flags)', {
 | 
|---|
| 289 |                 'fd': 'sockfd',
 | 
|---|
| 290 |                 'addr': '(typeof(sqe->addr))&addr',
 | 
|---|
| 291 |                 'addr2': '(typeof(sqe->addr2))addrlen',
 | 
|---|
| 292 |                 'accept_flags': 'flags'
 | 
|---|
| 293 |         }),
 | 
|---|
| 294 |         # CFA_HAVE_IORING_OP_CONNECT
 | 
|---|
| 295 |         Call('CONNECT', 'int connect(int sockfd, __CONST_SOCKADDR_ARG addr, socklen_t addrlen)', {
 | 
|---|
| 296 |                 'fd': 'sockfd',
 | 
|---|
| 297 |                 'addr': '(typeof(sqe->addr))&addr',
 | 
|---|
| 298 |                 'off': 'addrlen'
 | 
|---|
| 299 |         }),
 | 
|---|
| 300 |         # CFA_HAVE_IORING_OP_FALLOCATE
 | 
|---|
| 301 |         Call('FALLOCATE', 'int fallocate(int fd, int mode, off_t offset, off_t len)', {
 | 
|---|
| 302 |                 'fd': 'fd',
 | 
|---|
| 303 |                 'len': 'mode',
 | 
|---|
| 304 |                 'off': 'offset',
 | 
|---|
| 305 |                 'addr': 'len'
 | 
|---|
| 306 |         }),
 | 
|---|
| 307 |         # CFA_HAVE_IORING_OP_FADVISE
 | 
|---|
| 308 |         Call('FADVISE', 'int posix_fadvise(int fd, off_t offset, off_t len, int advice)', {
 | 
|---|
| 309 |                 'fd': 'fd',
 | 
|---|
| 310 |                 'off': 'offset',
 | 
|---|
| 311 |                 'len': 'len',
 | 
|---|
| 312 |                 'fadvise_advice': 'advice'
 | 
|---|
| 313 |         }),
 | 
|---|
| 314 |         # CFA_HAVE_IORING_OP_MADVISE
 | 
|---|
| 315 |         Call('MADVISE', 'int madvise(void * addr, size_t length, int advice)', {
 | 
|---|
| 316 |                 'addr': '(typeof(sqe->addr))addr',
 | 
|---|
| 317 |                 'len': 'length',
 | 
|---|
| 318 |                 'fadvise_advice': 'advice'
 | 
|---|
| 319 |         }),
 | 
|---|
| 320 |         # CFA_HAVE_IORING_OP_OPENAT
 | 
|---|
| 321 |         Call('OPENAT', 'int openat(int dirfd, const char * pathname, int flags, mode_t mode)', {
 | 
|---|
| 322 |                 'fd': 'dirfd',
 | 
|---|
| 323 |                 'addr': '(typeof(sqe->addr))pathname',
 | 
|---|
| 324 |                 'open_flags': 'flags;',
 | 
|---|
| 325 |                 'len': 'mode'
 | 
|---|
| 326 |         }),
 | 
|---|
| 327 |         # CFA_HAVE_IORING_OP_OPENAT2
 | 
|---|
| 328 |         Call('OPENAT2', 'int openat2(int dirfd, const char * pathname, struct open_how * how, size_t size)', {
 | 
|---|
| 329 |                 'fd': 'dirfd',
 | 
|---|
| 330 |                 'addr': '(typeof(sqe->addr))pathname',
 | 
|---|
| 331 |                 'off': '(typeof(sqe->off))how',
 | 
|---|
| 332 |                 'len': 'sizeof(*how)'
 | 
|---|
| 333 |         }, define = 'CFA_HAVE_OPENAT2'),
 | 
|---|
| 334 |         # CFA_HAVE_IORING_OP_CLOSE
 | 
|---|
| 335 |         Call('CLOSE', 'int close(int fd)', {
 | 
|---|
| 336 |                 'fd': 'fd'
 | 
|---|
| 337 |         }),
 | 
|---|
| 338 |         # CFA_HAVE_IORING_OP_STATX
 | 
|---|
| 339 |         Call('STATX', 'int statx(int dirfd, const char * pathname, int flags, unsigned int mask, struct statx * statxbuf)', {
 | 
|---|
| 340 |                 'fd': 'dirfd',
 | 
|---|
| 341 |                 'addr': '(typeof(sqe->addr))pathname',
 | 
|---|
| 342 |                 'statx_flags': 'flags',
 | 
|---|
| 343 |                 'len': 'mask',
 | 
|---|
| 344 |                 'off': '(typeof(sqe->off))statxbuf'
 | 
|---|
| 345 |         }, define = 'CFA_HAVE_STATX'),
 | 
|---|
| 346 |         # CFA_HAVE_IORING_OP_READ
 | 
|---|
| 347 |         Call('READ', 'ssize_t read(int fd, void * buf, size_t count)', {
 | 
|---|
| 348 |                 'fd': 'fd',
 | 
|---|
| 349 |                 'addr': '(typeof(sqe->addr))buf',
 | 
|---|
| 350 |                 'len': 'count'
 | 
|---|
| 351 |         }),
 | 
|---|
| 352 |         # CFA_HAVE_IORING_OP_WRITE
 | 
|---|
| 353 |         Call('WRITE', 'ssize_t write(int fd, void * buf, size_t count)', {
 | 
|---|
| 354 |                 'fd': 'fd',
 | 
|---|
| 355 |                 'addr': '(typeof(sqe->addr))buf',
 | 
|---|
| 356 |                 'len': 'count'
 | 
|---|
| 357 |         }),
 | 
|---|
| 358 |         # CFA_HAVE_IORING_OP_SPLICE
 | 
|---|
| 359 |         Call('SPLICE', 'ssize_t splice(int fd_in, __off64_t * off_in, int fd_out, __off64_t * off_out, size_t len, unsigned int flags)', {
 | 
|---|
| 360 |                 'splice_fd_in': 'fd_in',
 | 
|---|
| 361 |                 'splice_off_in': 'off_in ? (typeof(sqe->splice_off_in))*off_in : (typeof(sqe->splice_off_in))-1',
 | 
|---|
| 362 |                 'fd': 'fd_out',
 | 
|---|
| 363 |                 'off': 'off_out ? (typeof(sqe->off))*off_out : (typeof(sqe->off))-1',
 | 
|---|
| 364 |                 'len': 'len',
 | 
|---|
| 365 |                 'splice_flags': 'flags'
 | 
|---|
| 366 |         }),
 | 
|---|
| 367 |         # CFA_HAVE_IORING_OP_TEE
 | 
|---|
| 368 |         Call('TEE', 'ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags)', {
 | 
|---|
| 369 |                 'splice_fd_in': 'fd_in',
 | 
|---|
| 370 |                 'fd': 'fd_out',
 | 
|---|
| 371 |                 'len': 'len',
 | 
|---|
| 372 |                 'splice_flags': 'flags'
 | 
|---|
| 373 |         })
 | 
|---|
| 374 | ]
 | 
|---|
| 375 | 
 | 
|---|
| 376 | print("//----------")
 | 
|---|
| 377 | print("// synchronous calls")
 | 
|---|
| 378 | for c in calls:
 | 
|---|
| 379 |         if c.define:
 | 
|---|
| 380 |                 print("""#if defined({define})
 | 
|---|
| 381 |         {ret} cfa_{name}({params}, __u64 submit_flags);
 | 
|---|
| 382 | #endif""".format(define=c.define,ret=c.ret, name=c.name, params=c.params))
 | 
|---|
| 383 |         else:
 | 
|---|
| 384 |                 print("{ret} cfa_{name}({params}, __u64 submit_flags);"
 | 
|---|
| 385 |                 .format(ret=c.ret, name=c.name, params=c.params))
 | 
|---|
| 386 | 
 | 
|---|
| 387 | print("\n//----------")
 | 
|---|
| 388 | print("// asynchronous calls")
 | 
|---|
| 389 | for c in calls:
 | 
|---|
| 390 |         if c.define:
 | 
|---|
| 391 |                 print("""#if defined({define})
 | 
|---|
| 392 |         void async_{name}(io_future_t & future, {params}, __u64 submit_flags);
 | 
|---|
| 393 | #endif""".format(define=c.define,name=c.name, params=c.params))
 | 
|---|
| 394 |         else:
 | 
|---|
| 395 |                 print("void async_{name}(io_future_t & future, {params}, __u64 submit_flags);"
 | 
|---|
| 396 |                 .format(name=c.name, params=c.params))
 | 
|---|
| 397 | print("\n")
 | 
|---|
| 398 | 
 | 
|---|
| 399 | for c in calls:
 | 
|---|
| 400 |         print("//-----------------------------------------------------------------------------")
 | 
|---|
| 401 |         print("// {}".format(c.name))
 | 
|---|
| 402 |         Async = AsyncTemplate.format(
 | 
|---|
| 403 |                 name   = c.name,
 | 
|---|
| 404 |                 ret    = c.ret,
 | 
|---|
| 405 |                 params = c.params,
 | 
|---|
| 406 |                 args   = c.args(),
 | 
|---|
| 407 |                 op     = c.op,
 | 
|---|
| 408 |                 body   = c.body
 | 
|---|
| 409 | 
 | 
|---|
| 410 |         )
 | 
|---|
| 411 |         Sync = SyncTemplate.format(
 | 
|---|
| 412 |                 name   = c.name,
 | 
|---|
| 413 |                 ret    = c.ret,
 | 
|---|
| 414 |                 params = c.params,
 | 
|---|
| 415 |                 args   = c.args()
 | 
|---|
| 416 |         )
 | 
|---|
| 417 | 
 | 
|---|
| 418 |         if c.define:
 | 
|---|
| 419 |                 print("""#if defined({})
 | 
|---|
| 420 |         //----------
 | 
|---|
| 421 |         // asynchronous call
 | 
|---|
| 422 |         {}
 | 
|---|
| 423 | 
 | 
|---|
| 424 |         //----------
 | 
|---|
| 425 |         // synchronous call
 | 
|---|
| 426 |         {}
 | 
|---|
| 427 | #endif
 | 
|---|
| 428 | """.format(c.define, "\n\t".join( Async.splitlines() ), "\n\t".join( Sync.splitlines() )))
 | 
|---|
| 429 |         else :
 | 
|---|
| 430 |                 print("""//----------
 | 
|---|
| 431 | // asynchronous call
 | 
|---|
| 432 | {}
 | 
|---|
| 433 | 
 | 
|---|
| 434 | //----------
 | 
|---|
| 435 | // synchronous call
 | 
|---|
| 436 | {}
 | 
|---|
| 437 | """.format(Async, Sync))
 | 
|---|
| 438 | 
 | 
|---|
| 439 | print("""
 | 
|---|
| 440 | //-----------------------------------------------------------------------------
 | 
|---|
| 441 | // Check if a function is has asynchronous
 | 
|---|
| 442 | bool has_user_level_blocking( fptr_t func ) {
 | 
|---|
| 443 |         #if defined(CFA_HAVE_LINUX_IO_URING_H)""")
 | 
|---|
| 444 | 
 | 
|---|
| 445 | for c in calls:
 | 
|---|
| 446 |         if c.define:
 | 
|---|
| 447 |                 print("""               #if defined({define})
 | 
|---|
| 448 |                         if( /*func == (fptr_t)preadv2 || */
 | 
|---|
| 449 |                                 func == (fptr_t)cfa_{name} ||
 | 
|---|
| 450 |                                 func == (fptr_t)async_{name} ) {{
 | 
|---|
| 451 |                                 #if defined(CFA_HAVE_IORING_OP_{op})
 | 
|---|
| 452 |                                         return true;
 | 
|---|
| 453 |                                 #else
 | 
|---|
| 454 |                                         return false;
 | 
|---|
| 455 |                                 #endif
 | 
|---|
| 456 |                         }}
 | 
|---|
| 457 |                 #endif""".format(define=c.define, name=c.name, op=c.op))
 | 
|---|
| 458 |         else:
 | 
|---|
| 459 |                 print("""               if( /*func == (fptr_t)preadv2 || */
 | 
|---|
| 460 |                         func == (fptr_t)cfa_{name} ||
 | 
|---|
| 461 |                         func == (fptr_t)async_{name} ) {{
 | 
|---|
| 462 |                         #if defined(CFA_HAVE_IORING_OP_{op})
 | 
|---|
| 463 |                                 return true;
 | 
|---|
| 464 |                         #else
 | 
|---|
| 465 |                                 return false;
 | 
|---|
| 466 |                         #endif
 | 
|---|
| 467 |                 }}""".format(name=c.name, op=c.op))
 | 
|---|
| 468 | 
 | 
|---|
| 469 | print("""       #endif
 | 
|---|
| 470 | 
 | 
|---|
| 471 |         return false;
 | 
|---|
| 472 | }""")
 | 
|---|