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