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