[c402739f] | 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 | |
---|
[f5f2768] | 33 | #include <unistd.h> |
---|
| 34 | #include <errno.h> |
---|
[2d028003] | 35 | #include <sys/socket.h> |
---|
[f5f2768] | 36 | #include <time.hfa> |
---|
| 37 | |
---|
[c402739f] | 38 | #include "bits/defs.hfa" |
---|
| 39 | #include "kernel.hfa" |
---|
[0e52f14] | 40 | #include "io/types.hfa" |
---|
[7ce8873] | 41 | #include "stats.hfa" |
---|
[c402739f] | 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 | |
---|
[290553a] | 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 |
---|
[78da4ab] | 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 |
---|
[290553a] | 72 | ; |
---|
[c402739f] | 73 | |
---|
[290553a] | 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 | ; |
---|
[c402739f] | 79 | |
---|
[8bee858] | 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))); |
---|
[c402739f] | 82 | #endif |
---|
| 83 | |
---|
| 84 | //============================================================================================= |
---|
| 85 | // I/O Forwards |
---|
| 86 | //============================================================================================= |
---|
| 87 | |
---|
| 88 | extern "C" { |
---|
[ace2e92] | 89 | #if defined(CFA_HAVE_PREADV2) |
---|
[c402739f] | 90 | struct iovec; |
---|
[1afd9ccb] | 91 | extern ssize_t preadv2 (int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags); |
---|
[c402739f] | 92 | #endif |
---|
[ace2e92] | 93 | #if defined(CFA_HAVE_PWRITEV2) |
---|
[c402739f] | 94 | struct iovec; |
---|
[1afd9ccb] | 95 | extern ssize_t pwritev2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags); |
---|
[c402739f] | 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; |
---|
[1afd9ccb] | 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); |
---|
[c402739f] | 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); |
---|
[1afd9ccb] | 117 | extern int madvise(void * addr, size_t length, int advice); |
---|
[c402739f] | 118 | |
---|
[1afd9ccb] | 119 | extern int openat(int dirfd, const char * pathname, int flags, mode_t mode); |
---|
[c402739f] | 120 | extern int close(int fd); |
---|
| 121 | |
---|
[1afd9ccb] | 122 | extern ssize_t read (int fd, void * buf, size_t count); |
---|
[c402739f] | 123 | |
---|
| 124 | struct epoll_event; |
---|
[1afd9ccb] | 125 | extern int epoll_ctl(int epfd, int op, int fd, struct epoll_event * event); |
---|
[c402739f] | 126 | |
---|
[1afd9ccb] | 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); |
---|
[c402739f] | 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 | //============================================================================================= |
---|
[108345a] | 134 | #pragma GCC visibility push(default) |
---|
[c402739f] | 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 | |
---|
[dddb3dd0] | 181 | AsyncTemplate = """inline void async_{name}(io_future_t & future, {params}, __u64 submit_flags) {{ |
---|
[c402739f] | 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; |
---|
[7dafb7b] | 193 | struct io_uring_sqe * sqe; |
---|
[8bee858] | 194 | struct io_context$ * ctx = cfa_io_allocate( &sqe, &idx, 1 ); |
---|
[c402739f] | 195 | |
---|
[cefd0b9] | 196 | memset(sqe, 0, sizeof(*sqe)); |
---|
[c402739f] | 197 | sqe->opcode = IORING_OP_{op}; |
---|
[7dafb7b] | 198 | sqe->flags = sflags; |
---|
[cefd0b9] | 199 | sqe->user_data = (uintptr_t)&future; |
---|
| 200 | {body} |
---|
[7dafb7b] | 201 | |
---|
| 202 | asm volatile("": : :"memory"); |
---|
[c402739f] | 203 | |
---|
[57b3675] | 204 | verify( sqe->user_data == (uintptr_t)&future ); |
---|
[dddb3dd0] | 205 | cfa_io_submit( ctx, &idx, 1, 0 != (submit_flags & CFA_IO_LAZY) ); |
---|
[c402739f] | 206 | #endif |
---|
| 207 | }}""" |
---|
| 208 | |
---|
[dddb3dd0] | 209 | SyncTemplate = """{ret} cfa_{name}({params}, __u64 submit_flags) {{ |
---|
[c402739f] | 210 | io_future_t future; |
---|
| 211 | |
---|
[78da4ab] | 212 | async_{name}( future, {args}, submit_flags ); |
---|
[c402739f] | 213 | |
---|
[7ce8873] | 214 | __attribute__((unused)) bool parked; |
---|
| 215 | parked = wait( future ); |
---|
| 216 | __STATS__(false, if(!parked) io.submit.nblk += 1; ) |
---|
[c402739f] | 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 |
---|
[1afd9ccb] | 226 | Call('READV', 'ssize_t preadv2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags)', { |
---|
[c402739f] | 227 | 'fd' : 'fd', |
---|
[1afd9ccb] | 228 | 'addr': '(typeof(sqe->addr))iov', |
---|
[c402739f] | 229 | 'len' : 'iovcnt', |
---|
[1afd9ccb] | 230 | 'off' : 'offset', |
---|
| 231 | 'rw_flags' : 'flags' |
---|
[c402739f] | 232 | }, define = 'CFA_HAVE_PREADV2'), |
---|
| 233 | # CFA_HAVE_IORING_OP_WRITEV |
---|
[1afd9ccb] | 234 | Call('WRITEV', 'ssize_t pwritev2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags)', { |
---|
[c402739f] | 235 | 'fd' : 'fd', |
---|
[1afd9ccb] | 236 | 'addr': '(typeof(sqe->addr))iov', |
---|
| 237 | 'len' : 'iovcnt', |
---|
[c402739f] | 238 | 'off' : 'offset', |
---|
[1afd9ccb] | 239 | 'rw_flags' : 'flags' |
---|
[c402739f] | 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 |
---|
[1afd9ccb] | 246 | Call('EPOLL_CTL', 'int epoll_ctl(int epfd, int op, int fd, struct epoll_event * event)', { |
---|
[c402739f] | 247 | 'fd': 'epfd', |
---|
| 248 | 'len': 'op', |
---|
[1afd9ccb] | 249 | 'addr': 'fd', |
---|
| 250 | 'off': '(typeof(sqe->off))event' |
---|
[c402739f] | 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 |
---|
[1afd9ccb] | 260 | Call('SENDMSG', 'ssize_t sendmsg(int sockfd, const struct msghdr * msg, int flags)', { |
---|
[c402739f] | 261 | 'fd': 'sockfd', |
---|
[1afd9ccb] | 262 | 'addr': '(typeof(sqe->addr))(struct msghdr *)msg', |
---|
[c402739f] | 263 | 'len': '1', |
---|
| 264 | 'msg_flags': 'flags' |
---|
| 265 | }), |
---|
| 266 | # CFA_HAVE_IORING_OP_RECVMSG |
---|
[1afd9ccb] | 267 | Call('RECVMSG', 'ssize_t recvmsg(int sockfd, struct msghdr * msg, int flags)', { |
---|
[c402739f] | 268 | 'fd': 'sockfd', |
---|
[1afd9ccb] | 269 | 'addr': '(typeof(sqe->addr))(struct msghdr *)msg', |
---|
[c402739f] | 270 | 'len': '1', |
---|
| 271 | 'msg_flags': 'flags' |
---|
| 272 | }), |
---|
| 273 | # CFA_HAVE_IORING_OP_SEND |
---|
[1afd9ccb] | 274 | Call('SEND', 'ssize_t send(int sockfd, const void * buf, size_t len, int flags)', { |
---|
[c402739f] | 275 | 'fd': 'sockfd', |
---|
[1afd9ccb] | 276 | 'addr': '(typeof(sqe->addr))buf', |
---|
[c402739f] | 277 | 'len': 'len', |
---|
| 278 | 'msg_flags': 'flags' |
---|
| 279 | }), |
---|
| 280 | # CFA_HAVE_IORING_OP_RECV |
---|
[1afd9ccb] | 281 | Call('RECV', 'ssize_t recv(int sockfd, void * buf, size_t len, int flags)', { |
---|
[c402739f] | 282 | 'fd': 'sockfd', |
---|
[1afd9ccb] | 283 | 'addr': '(typeof(sqe->addr))buf', |
---|
[c402739f] | 284 | 'len': 'len', |
---|
| 285 | 'msg_flags': 'flags' |
---|
| 286 | }), |
---|
| 287 | # CFA_HAVE_IORING_OP_ACCEPT |
---|
[f5f2768] | 288 | Call('ACCEPT', 'int accept4(int sockfd, __SOCKADDR_ARG addr, socklen_t * restrict addrlen, int flags)', { |
---|
[c402739f] | 289 | 'fd': 'sockfd', |
---|
[1afd9ccb] | 290 | 'addr': '(typeof(sqe->addr))&addr', |
---|
| 291 | 'addr2': '(typeof(sqe->addr2))addrlen', |
---|
[c402739f] | 292 | 'accept_flags': 'flags' |
---|
| 293 | }), |
---|
| 294 | # CFA_HAVE_IORING_OP_CONNECT |
---|
[f5f2768] | 295 | Call('CONNECT', 'int connect(int sockfd, __CONST_SOCKADDR_ARG addr, socklen_t addrlen)', { |
---|
[c402739f] | 296 | 'fd': 'sockfd', |
---|
[1afd9ccb] | 297 | 'addr': '(typeof(sqe->addr))&addr', |
---|
[c402739f] | 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', |
---|
[1afd9ccb] | 304 | 'off': 'offset', |
---|
| 305 | 'addr': 'len' |
---|
[c402739f] | 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', |
---|
[4ab3cf9b] | 310 | 'off': 'offset', |
---|
[c402739f] | 311 | 'len': 'len', |
---|
| 312 | 'fadvise_advice': 'advice' |
---|
| 313 | }), |
---|
| 314 | # CFA_HAVE_IORING_OP_MADVISE |
---|
[1afd9ccb] | 315 | Call('MADVISE', 'int madvise(void * addr, size_t length, int advice)', { |
---|
| 316 | 'addr': '(typeof(sqe->addr))addr', |
---|
[c402739f] | 317 | 'len': 'length', |
---|
| 318 | 'fadvise_advice': 'advice' |
---|
| 319 | }), |
---|
| 320 | # CFA_HAVE_IORING_OP_OPENAT |
---|
[1afd9ccb] | 321 | Call('OPENAT', 'int openat(int dirfd, const char * pathname, int flags, mode_t mode)', { |
---|
[c402739f] | 322 | 'fd': 'dirfd', |
---|
[1afd9ccb] | 323 | 'addr': '(typeof(sqe->addr))pathname', |
---|
| 324 | 'open_flags': 'flags;', |
---|
| 325 | 'len': 'mode' |
---|
[c402739f] | 326 | }), |
---|
| 327 | # CFA_HAVE_IORING_OP_OPENAT2 |
---|
[1afd9ccb] | 328 | Call('OPENAT2', 'int openat2(int dirfd, const char * pathname, struct open_how * how, size_t size)', { |
---|
[c402739f] | 329 | 'fd': 'dirfd', |
---|
[1afd9ccb] | 330 | 'addr': '(typeof(sqe->addr))pathname', |
---|
| 331 | 'off': '(typeof(sqe->off))how', |
---|
| 332 | 'len': 'sizeof(*how)' |
---|
[c402739f] | 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 |
---|
[1afd9ccb] | 339 | Call('STATX', 'int statx(int dirfd, const char * pathname, int flags, unsigned int mask, struct statx * statxbuf)', { |
---|
[c402739f] | 340 | 'fd': 'dirfd', |
---|
[1afd9ccb] | 341 | 'addr': '(typeof(sqe->addr))pathname', |
---|
| 342 | 'statx_flags': 'flags', |
---|
[c402739f] | 343 | 'len': 'mask', |
---|
[1afd9ccb] | 344 | 'off': '(typeof(sqe->off))statxbuf' |
---|
[c402739f] | 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', |
---|
[1afd9ccb] | 349 | 'addr': '(typeof(sqe->addr))buf', |
---|
[c402739f] | 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', |
---|
[1afd9ccb] | 355 | 'addr': '(typeof(sqe->addr))buf', |
---|
[c402739f] | 356 | 'len': 'count' |
---|
| 357 | }), |
---|
| 358 | # CFA_HAVE_IORING_OP_SPLICE |
---|
[1afd9ccb] | 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)', { |
---|
[c402739f] | 360 | 'splice_fd_in': 'fd_in', |
---|
[1afd9ccb] | 361 | 'splice_off_in': 'off_in ? (typeof(sqe->splice_off_in))*off_in : (typeof(sqe->splice_off_in))-1', |
---|
[c402739f] | 362 | 'fd': 'fd_out', |
---|
[1afd9ccb] | 363 | 'off': 'off_out ? (typeof(sqe->off))*off_out : (typeof(sqe->off))-1', |
---|
[c402739f] | 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}) |
---|
[dddb3dd0] | 381 | {ret} cfa_{name}({params}, __u64 submit_flags); |
---|
[c402739f] | 382 | #endif""".format(define=c.define,ret=c.ret, name=c.name, params=c.params)) |
---|
| 383 | else: |
---|
[dddb3dd0] | 384 | print("{ret} cfa_{name}({params}, __u64 submit_flags);" |
---|
[c402739f] | 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}) |
---|
[dddb3dd0] | 392 | void async_{name}(io_future_t & future, {params}, __u64 submit_flags); |
---|
[c402739f] | 393 | #endif""".format(define=c.define,name=c.name, params=c.params)) |
---|
| 394 | else: |
---|
[dddb3dd0] | 395 | print("void async_{name}(io_future_t & future, {params}, __u64 submit_flags);" |
---|
[c402739f] | 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; |
---|
[f5f2768] | 472 | }""") |
---|