[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))); |
---|
[dddb3dd0] | 77 | extern void cfa_io_submit( struct $io_context * in_ctx, __u32 in_idxs[], __u32 have, bool lazy ) __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" { |
---|
[44f09ea] | 90 | #include <asm/types.h> |
---|
[c402739f] | 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 | |
---|
[a5040fe] | 134 | 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] | 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 | //============================================================================================= |
---|
[108345a] | 141 | #pragma GCC visibility push(default) |
---|
[c402739f] | 142 | """ |
---|
| 143 | |
---|
| 144 | print(Header.format("A Date")) |
---|
| 145 | print(Prelude) |
---|
| 146 | |
---|
| 147 | import re |
---|
| 148 | import sys |
---|
| 149 | class Call: |
---|
| 150 | def __init__(self, op, signature, body, define=None): |
---|
| 151 | sig = re.search("(.*) (.*)\((.*)\)", signature) |
---|
| 152 | if not sig: |
---|
| 153 | print("OP '{}' has invalid signature {}".format(op, signature), file=sys.stderr) |
---|
| 154 | sys.exit(1) |
---|
| 155 | |
---|
| 156 | self.op = op |
---|
| 157 | self.ret = sig.group(1) |
---|
| 158 | self.name = sig.group(2) |
---|
| 159 | self.params = sig.group(3) |
---|
| 160 | self.define = define |
---|
| 161 | self.body = "" |
---|
| 162 | |
---|
| 163 | accepted_keys = [ 'ioprio', 'fd', 'off', 'addr2','addr', 'splice_off_in','len', |
---|
| 164 | 'rw_flags', 'fsync_flags', 'poll_events', 'poll32_events', |
---|
| 165 | 'sync_range_flags', 'msg_flags', 'timeout_flags', 'accept_flags', |
---|
| 166 | 'cancel_flags', 'open_flags', 'statx_flags', 'fadvise_advice', |
---|
| 167 | 'splice_flags', 'buf_index' ,'buf_group' 'personality', |
---|
| 168 | 'splice_fd_in' ] |
---|
| 169 | |
---|
| 170 | for k, v in body.items(): |
---|
| 171 | if not k in accepted_keys: |
---|
| 172 | print("OP '{}' has invalid body kew {}".format(op, k), file=sys.stderr) |
---|
| 173 | sys.exit(1) |
---|
| 174 | |
---|
| 175 | self.body += "\n sqe->{key} = {value};".format(key=k, value=v) |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | def args(self): |
---|
| 179 | param_a = self.params.split(',') |
---|
| 180 | args_a = [p.replace('*', ' ').split()[-1] for p in param_a] |
---|
| 181 | for a in args_a: |
---|
| 182 | if '*' in a: |
---|
| 183 | print("OP '{}' has invalid * in argument {}".format(self.op, a), file=sys.stderr) |
---|
| 184 | sys.exit(1) |
---|
| 185 | |
---|
| 186 | return ', '.join(args_a) |
---|
| 187 | |
---|
[dddb3dd0] | 188 | AsyncTemplate = """inline void async_{name}(io_future_t & future, {params}, __u64 submit_flags) {{ |
---|
[c402739f] | 189 | #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_{op}) |
---|
| 190 | ssize_t res = {name}({args}); |
---|
| 191 | if (res >= 0) {{ |
---|
| 192 | fulfil(future, res); |
---|
| 193 | }} |
---|
| 194 | else {{ |
---|
| 195 | fulfil(future, -errno); |
---|
| 196 | }} |
---|
| 197 | #else |
---|
| 198 | __u8 sflags = REGULAR_FLAGS & submit_flags; |
---|
| 199 | __u32 idx; |
---|
[7dafb7b] | 200 | struct io_uring_sqe * sqe; |
---|
[78da4ab] | 201 | struct $io_context * ctx = cfa_io_allocate( &sqe, &idx, 1 ); |
---|
[c402739f] | 202 | |
---|
| 203 | sqe->opcode = IORING_OP_{op}; |
---|
[57b3675] | 204 | sqe->user_data = (uintptr_t)&future; |
---|
[7dafb7b] | 205 | sqe->flags = sflags; |
---|
| 206 | sqe->ioprio = 0; |
---|
| 207 | sqe->fd = 0; |
---|
| 208 | sqe->off = 0; |
---|
| 209 | sqe->addr = 0; |
---|
| 210 | sqe->len = 0; |
---|
[ec19b21] | 211 | sqe->fsync_flags = 0; |
---|
[7dafb7b] | 212 | sqe->__pad2[0] = 0; |
---|
| 213 | sqe->__pad2[1] = 0; |
---|
| 214 | sqe->__pad2[2] = 0;{body} |
---|
| 215 | |
---|
| 216 | asm volatile("": : :"memory"); |
---|
[c402739f] | 217 | |
---|
[57b3675] | 218 | verify( sqe->user_data == (uintptr_t)&future ); |
---|
[dddb3dd0] | 219 | cfa_io_submit( ctx, &idx, 1, 0 != (submit_flags & CFA_IO_LAZY) ); |
---|
[c402739f] | 220 | #endif |
---|
| 221 | }}""" |
---|
| 222 | |
---|
[dddb3dd0] | 223 | SyncTemplate = """{ret} cfa_{name}({params}, __u64 submit_flags) {{ |
---|
[c402739f] | 224 | io_future_t future; |
---|
| 225 | |
---|
[78da4ab] | 226 | async_{name}( future, {args}, submit_flags ); |
---|
[c402739f] | 227 | |
---|
| 228 | wait( future ); |
---|
| 229 | if( future.result < 0 ) {{ |
---|
| 230 | errno = -future.result; |
---|
| 231 | return -1; |
---|
| 232 | }} |
---|
| 233 | return future.result; |
---|
| 234 | }}""" |
---|
| 235 | |
---|
| 236 | calls = [ |
---|
| 237 | # CFA_HAVE_IORING_OP_READV |
---|
| 238 | Call('READV', 'ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags)', { |
---|
| 239 | 'fd' : 'fd', |
---|
| 240 | 'off' : 'offset', |
---|
[57b3675] | 241 | 'addr': '(uintptr_t)iov', |
---|
[c402739f] | 242 | 'len' : 'iovcnt', |
---|
| 243 | }, define = 'CFA_HAVE_PREADV2'), |
---|
| 244 | # CFA_HAVE_IORING_OP_WRITEV |
---|
| 245 | Call('WRITEV', 'ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags)', { |
---|
| 246 | 'fd' : 'fd', |
---|
| 247 | 'off' : 'offset', |
---|
[57b3675] | 248 | 'addr': '(uintptr_t)iov', |
---|
[c402739f] | 249 | 'len' : 'iovcnt' |
---|
| 250 | }, define = 'CFA_HAVE_PWRITEV2'), |
---|
| 251 | # CFA_HAVE_IORING_OP_FSYNC |
---|
| 252 | Call('FSYNC', 'int fsync(int fd)', { |
---|
| 253 | 'fd': 'fd' |
---|
| 254 | }), |
---|
| 255 | # CFA_HAVE_IORING_OP_EPOLL_CTL |
---|
| 256 | Call('EPOLL_CTL', 'int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)', { |
---|
| 257 | 'fd': 'epfd', |
---|
| 258 | 'addr': 'fd', |
---|
| 259 | 'len': 'op', |
---|
[57b3675] | 260 | 'off': '(uintptr_t)event' |
---|
[c402739f] | 261 | }), |
---|
| 262 | # CFA_HAVE_IORING_OP_SYNC_FILE_RANGE |
---|
| 263 | Call('SYNC_FILE_RANGE', 'int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags)', { |
---|
| 264 | 'fd': 'fd', |
---|
| 265 | 'off': 'offset', |
---|
| 266 | 'len': 'nbytes', |
---|
| 267 | 'sync_range_flags': 'flags' |
---|
| 268 | }), |
---|
| 269 | # CFA_HAVE_IORING_OP_SENDMSG |
---|
| 270 | Call('SENDMSG', 'ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)', { |
---|
| 271 | 'fd': 'sockfd', |
---|
[57b3675] | 272 | 'addr': '(uintptr_t)(struct msghdr *)msg', |
---|
[c402739f] | 273 | 'len': '1', |
---|
| 274 | 'msg_flags': 'flags' |
---|
| 275 | }), |
---|
| 276 | # CFA_HAVE_IORING_OP_RECVMSG |
---|
| 277 | Call('RECVMSG', 'ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)', { |
---|
| 278 | 'fd': 'sockfd', |
---|
[57b3675] | 279 | 'addr': '(uintptr_t)(struct msghdr *)msg', |
---|
[c402739f] | 280 | 'len': '1', |
---|
| 281 | 'msg_flags': 'flags' |
---|
| 282 | }), |
---|
| 283 | # CFA_HAVE_IORING_OP_SEND |
---|
| 284 | Call('SEND', 'ssize_t send(int sockfd, const void *buf, size_t len, int flags)', { |
---|
| 285 | 'fd': 'sockfd', |
---|
[57b3675] | 286 | 'addr': '(uintptr_t)buf', |
---|
[c402739f] | 287 | 'len': 'len', |
---|
| 288 | 'msg_flags': 'flags' |
---|
| 289 | }), |
---|
| 290 | # CFA_HAVE_IORING_OP_RECV |
---|
| 291 | Call('RECV', 'ssize_t recv(int sockfd, void *buf, size_t len, int flags)', { |
---|
| 292 | 'fd': 'sockfd', |
---|
[57b3675] | 293 | 'addr': '(uintptr_t)buf', |
---|
[c402739f] | 294 | 'len': 'len', |
---|
| 295 | 'msg_flags': 'flags' |
---|
| 296 | }), |
---|
| 297 | # CFA_HAVE_IORING_OP_ACCEPT |
---|
[35fd2c4] | 298 | Call('ACCEPT', 'int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)', { |
---|
[c402739f] | 299 | 'fd': 'sockfd', |
---|
[57b3675] | 300 | 'addr': '(uintptr_t)addr', |
---|
| 301 | 'addr2': '(uintptr_t)addrlen', |
---|
[c402739f] | 302 | 'accept_flags': 'flags' |
---|
| 303 | }), |
---|
| 304 | # CFA_HAVE_IORING_OP_CONNECT |
---|
| 305 | Call('CONNECT', 'int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)', { |
---|
| 306 | 'fd': 'sockfd', |
---|
[57b3675] | 307 | 'addr': '(uintptr_t)addr', |
---|
[c402739f] | 308 | 'off': 'addrlen' |
---|
| 309 | }), |
---|
| 310 | # CFA_HAVE_IORING_OP_FALLOCATE |
---|
| 311 | Call('FALLOCATE', 'int fallocate(int fd, int mode, off_t offset, off_t len)', { |
---|
| 312 | 'fd': 'fd', |
---|
[57b3675] | 313 | 'addr': '(uintptr_t)len', |
---|
[c402739f] | 314 | 'len': 'mode', |
---|
| 315 | 'off': 'offset' |
---|
| 316 | }), |
---|
| 317 | # CFA_HAVE_IORING_OP_FADVISE |
---|
| 318 | Call('FADVISE', 'int posix_fadvise(int fd, off_t offset, off_t len, int advice)', { |
---|
| 319 | 'fd': 'fd', |
---|
[4ab3cf9b] | 320 | 'off': 'offset', |
---|
[c402739f] | 321 | 'len': 'len', |
---|
| 322 | 'fadvise_advice': 'advice' |
---|
| 323 | }), |
---|
| 324 | # CFA_HAVE_IORING_OP_MADVISE |
---|
| 325 | Call('MADVISE', 'int madvise(void *addr, size_t length, int advice)', { |
---|
[57b3675] | 326 | 'addr': '(uintptr_t)addr', |
---|
[c402739f] | 327 | 'len': 'length', |
---|
| 328 | 'fadvise_advice': 'advice' |
---|
| 329 | }), |
---|
| 330 | # CFA_HAVE_IORING_OP_OPENAT |
---|
| 331 | Call('OPENAT', 'int openat(int dirfd, const char *pathname, int flags, mode_t mode)', { |
---|
| 332 | 'fd': 'dirfd', |
---|
[57b3675] | 333 | 'addr': '(uintptr_t)pathname', |
---|
[c402739f] | 334 | 'len': 'mode', |
---|
| 335 | 'open_flags': 'flags;' |
---|
| 336 | }), |
---|
| 337 | # CFA_HAVE_IORING_OP_OPENAT2 |
---|
| 338 | Call('OPENAT2', 'int openat2(int dirfd, const char *pathname, struct open_how * how, size_t size)', { |
---|
| 339 | 'fd': 'dirfd', |
---|
| 340 | 'addr': 'pathname', |
---|
| 341 | 'len': 'sizeof(*how)', |
---|
[57b3675] | 342 | 'off': '(uintptr_t)how', |
---|
[c402739f] | 343 | }, define = 'CFA_HAVE_OPENAT2'), |
---|
| 344 | # CFA_HAVE_IORING_OP_CLOSE |
---|
| 345 | Call('CLOSE', 'int close(int fd)', { |
---|
| 346 | 'fd': 'fd' |
---|
| 347 | }), |
---|
| 348 | # CFA_HAVE_IORING_OP_STATX |
---|
| 349 | Call('STATX', 'int statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf)', { |
---|
| 350 | 'fd': 'dirfd', |
---|
[57b3675] | 351 | 'off': '(uintptr_t)statxbuf', |
---|
[c402739f] | 352 | 'addr': 'pathname', |
---|
| 353 | 'len': 'mask', |
---|
| 354 | 'statx_flags': 'flags' |
---|
| 355 | }, define = 'CFA_HAVE_STATX'), |
---|
| 356 | # CFA_HAVE_IORING_OP_READ |
---|
| 357 | Call('READ', 'ssize_t read(int fd, void * buf, size_t count)', { |
---|
| 358 | 'fd': 'fd', |
---|
[57b3675] | 359 | 'addr': '(uintptr_t)buf', |
---|
[c402739f] | 360 | 'len': 'count' |
---|
| 361 | }), |
---|
| 362 | # CFA_HAVE_IORING_OP_WRITE |
---|
| 363 | Call('WRITE', 'ssize_t write(int fd, void * buf, size_t count)', { |
---|
| 364 | 'fd': 'fd', |
---|
[57b3675] | 365 | 'addr': '(uintptr_t)buf', |
---|
[c402739f] | 366 | 'len': 'count' |
---|
| 367 | }), |
---|
| 368 | # CFA_HAVE_IORING_OP_SPLICE |
---|
[a5040fe] | 369 | 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] | 370 | 'splice_fd_in': 'fd_in', |
---|
[4ab3cf9b] | 371 | 'splice_off_in': 'off_in ? (__u64)*off_in : (__u64)-1', |
---|
[c402739f] | 372 | 'fd': 'fd_out', |
---|
[4ab3cf9b] | 373 | 'off': 'off_out ? (__u64)*off_out : (__u64)-1', |
---|
[c402739f] | 374 | 'len': 'len', |
---|
| 375 | 'splice_flags': 'flags' |
---|
| 376 | }), |
---|
| 377 | # CFA_HAVE_IORING_OP_TEE |
---|
| 378 | Call('TEE', 'ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags)', { |
---|
| 379 | 'splice_fd_in': 'fd_in', |
---|
| 380 | 'fd': 'fd_out', |
---|
| 381 | 'len': 'len', |
---|
| 382 | 'splice_flags': 'flags' |
---|
| 383 | }) |
---|
| 384 | ] |
---|
| 385 | |
---|
| 386 | print("//----------") |
---|
| 387 | print("// synchronous calls") |
---|
| 388 | for c in calls: |
---|
| 389 | if c.define: |
---|
| 390 | print("""#if defined({define}) |
---|
[dddb3dd0] | 391 | {ret} cfa_{name}({params}, __u64 submit_flags); |
---|
[c402739f] | 392 | #endif""".format(define=c.define,ret=c.ret, name=c.name, params=c.params)) |
---|
| 393 | else: |
---|
[dddb3dd0] | 394 | print("{ret} cfa_{name}({params}, __u64 submit_flags);" |
---|
[c402739f] | 395 | .format(ret=c.ret, name=c.name, params=c.params)) |
---|
| 396 | |
---|
| 397 | print("\n//----------") |
---|
| 398 | print("// asynchronous calls") |
---|
| 399 | for c in calls: |
---|
| 400 | if c.define: |
---|
| 401 | print("""#if defined({define}) |
---|
[dddb3dd0] | 402 | void async_{name}(io_future_t & future, {params}, __u64 submit_flags); |
---|
[c402739f] | 403 | #endif""".format(define=c.define,name=c.name, params=c.params)) |
---|
| 404 | else: |
---|
[dddb3dd0] | 405 | print("void async_{name}(io_future_t & future, {params}, __u64 submit_flags);" |
---|
[c402739f] | 406 | .format(name=c.name, params=c.params)) |
---|
| 407 | print("\n") |
---|
| 408 | |
---|
| 409 | for c in calls: |
---|
| 410 | print("//-----------------------------------------------------------------------------") |
---|
| 411 | print("// {}".format(c.name)) |
---|
| 412 | Async = AsyncTemplate.format( |
---|
| 413 | name = c.name, |
---|
| 414 | ret = c.ret, |
---|
| 415 | params = c.params, |
---|
| 416 | args = c.args(), |
---|
| 417 | op = c.op, |
---|
| 418 | body = c.body |
---|
| 419 | |
---|
| 420 | ) |
---|
| 421 | Sync = SyncTemplate.format( |
---|
| 422 | name = c.name, |
---|
| 423 | ret = c.ret, |
---|
| 424 | params = c.params, |
---|
| 425 | args = c.args() |
---|
| 426 | ) |
---|
| 427 | |
---|
| 428 | if c.define: |
---|
| 429 | print("""#if defined({}) |
---|
| 430 | //---------- |
---|
| 431 | // asynchronous call |
---|
| 432 | {} |
---|
| 433 | |
---|
| 434 | //---------- |
---|
| 435 | // synchronous call |
---|
| 436 | {} |
---|
| 437 | #endif |
---|
| 438 | """.format(c.define, "\n\t".join( Async.splitlines() ), "\n\t".join( Sync.splitlines() ))) |
---|
| 439 | else : |
---|
| 440 | print("""//---------- |
---|
| 441 | // asynchronous call |
---|
| 442 | {} |
---|
| 443 | |
---|
| 444 | //---------- |
---|
| 445 | // synchronous call |
---|
| 446 | {} |
---|
| 447 | """.format(Async, Sync)) |
---|
| 448 | |
---|
| 449 | print(""" |
---|
| 450 | //----------------------------------------------------------------------------- |
---|
| 451 | // Check if a function is has asynchronous |
---|
| 452 | bool has_user_level_blocking( fptr_t func ) { |
---|
| 453 | #if defined(CFA_HAVE_LINUX_IO_URING_H)""") |
---|
| 454 | |
---|
| 455 | for c in calls: |
---|
| 456 | if c.define: |
---|
| 457 | print(""" #if defined({define}) |
---|
| 458 | if( /*func == (fptr_t)preadv2 || */ |
---|
| 459 | func == (fptr_t)cfa_{name} || |
---|
| 460 | func == (fptr_t)async_{name} ) {{ |
---|
| 461 | #if defined(CFA_HAVE_IORING_OP_{op}) |
---|
| 462 | return true; |
---|
| 463 | #else |
---|
| 464 | return false; |
---|
| 465 | #endif |
---|
| 466 | }} |
---|
| 467 | #endif""".format(define=c.define, name=c.name, op=c.op)) |
---|
| 468 | else: |
---|
| 469 | print(""" if( /*func == (fptr_t)preadv2 || */ |
---|
| 470 | func == (fptr_t)cfa_{name} || |
---|
| 471 | func == (fptr_t)async_{name} ) {{ |
---|
| 472 | #if defined(CFA_HAVE_IORING_OP_{op}) |
---|
| 473 | return true; |
---|
| 474 | #else |
---|
| 475 | return false; |
---|
| 476 | #endif |
---|
| 477 | }}""".format(name=c.name, op=c.op)) |
---|
| 478 | |
---|
| 479 | print(""" #endif |
---|
| 480 | |
---|
| 481 | return false; |
---|
| 482 | }""") |
---|