[d384787] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // iofwd.hfa -- |
---|
| 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Thu Apr 23 17:31:00 2020 |
---|
| 11 | // Last Modified By : |
---|
| 12 | // Last Modified On : |
---|
| 13 | // Update Count : |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
[519f11c] | 18 | #include <unistd.h> |
---|
[e1801fc] | 19 | extern "C" { |
---|
[44f09ea] | 20 | #include <asm/types.h> |
---|
[93829cb] | 21 | #include <sys/stat.h> // needed for mode_t |
---|
[f00b26d4] | 22 | #if CFA_HAVE_LINUX_IO_URING_H |
---|
| 23 | #include <linux/io_uring.h> |
---|
| 24 | #endif |
---|
[e1801fc] | 25 | } |
---|
[519f11c] | 26 | #include "bits/defs.hfa" |
---|
[f00b26d4] | 27 | #include "time.hfa" |
---|
| 28 | |
---|
| 29 | #if defined(CFA_HAVE_IOSQE_FIXED_FILE) |
---|
| 30 | #define CFA_IO_FIXED_FD1 IOSQE_FIXED_FILE |
---|
| 31 | #endif |
---|
| 32 | #if defined(CFA_HAVE_SPLICE_F_FD_IN_FIXED) |
---|
| 33 | #define CFA_IO_FIXED_FD2 SPLICE_F_FD_IN_FIXED |
---|
| 34 | #endif |
---|
| 35 | #if defined(CFA_HAVE_IOSQE_IO_DRAIN) |
---|
| 36 | #define CFA_IO_DRAIN IOSQE_IO_DRAIN |
---|
| 37 | #endif |
---|
| 38 | #if defined(CFA_HAVE_IOSQE_ASYNC) |
---|
| 39 | #define CFA_IO_ASYNC IOSQE_ASYNC |
---|
| 40 | #endif |
---|
| 41 | |
---|
[6d1790c] | 42 | #if __OFF_T_MATCHES_OFF64_T |
---|
| 43 | typedef __off64_t off_t; |
---|
| 44 | #else |
---|
| 45 | typedef __off_t off_t; |
---|
| 46 | #endif |
---|
| 47 | typedef __off64_t off64_t; |
---|
| 48 | |
---|
[f00b26d4] | 49 | struct cluster; |
---|
[c402739f] | 50 | struct io_future_t; |
---|
[78da4ab] | 51 | struct $io_context; |
---|
[519f11c] | 52 | |
---|
| 53 | struct iovec; |
---|
| 54 | struct msghdr; |
---|
| 55 | struct sockaddr; |
---|
| 56 | struct statx; |
---|
[78da4ab] | 57 | struct epoll_event; |
---|
| 58 | |
---|
[ff1240f] | 59 | struct io_uring_sqe; |
---|
| 60 | |
---|
[78da4ab] | 61 | //---------- |
---|
| 62 | // underlying calls |
---|
| 63 | extern struct $io_context * cfa_io_allocate(struct io_uring_sqe * out_sqes[], __u32 out_idxs[], __u32 want) __attribute__((nonnull (1,2))); |
---|
[dddb3dd0] | 64 | extern void cfa_io_submit( struct $io_context * in_ctx, __u32 in_idxs[], __u32 have, bool lazy ) __attribute__((nonnull (1,2))); |
---|
[e1801fc] | 65 | |
---|
[c402739f] | 66 | //---------- |
---|
| 67 | // synchronous calls |
---|
| 68 | #if defined(CFA_HAVE_PREADV2) |
---|
[dddb3dd0] | 69 | extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags, __u64 submit_flags); |
---|
[c402739f] | 70 | #endif |
---|
| 71 | #if defined(CFA_HAVE_PWRITEV2) |
---|
[dddb3dd0] | 72 | extern ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags, __u64 submit_flags); |
---|
[c402739f] | 73 | #endif |
---|
[dddb3dd0] | 74 | extern int cfa_fsync(int fd, __u64 submit_flags); |
---|
| 75 | extern int cfa_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event, __u64 submit_flags); |
---|
| 76 | extern int cfa_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags, __u64 submit_flags); |
---|
| 77 | extern ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags, __u64 submit_flags); |
---|
| 78 | extern ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags, __u64 submit_flags); |
---|
| 79 | extern ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags, __u64 submit_flags); |
---|
| 80 | extern ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags, __u64 submit_flags); |
---|
| 81 | extern int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags, __u64 submit_flags); |
---|
| 82 | extern int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen, __u64 submit_flags); |
---|
| 83 | extern int cfa_fallocate(int fd, int mode, off_t offset, off_t len, __u64 submit_flags); |
---|
| 84 | extern int cfa_posix_fadvise(int fd, off_t offset, off_t len, int advice, __u64 submit_flags); |
---|
| 85 | extern int cfa_madvise(void *addr, size_t length, int advice, __u64 submit_flags); |
---|
| 86 | extern int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode, __u64 submit_flags); |
---|
[c402739f] | 87 | #if defined(CFA_HAVE_OPENAT2) |
---|
[dddb3dd0] | 88 | extern int cfa_openat2(int dirfd, const char *pathname, struct open_how * how, size_t size, __u64 submit_flags); |
---|
[c402739f] | 89 | #endif |
---|
[dddb3dd0] | 90 | extern int cfa_close(int fd, __u64 submit_flags); |
---|
[c402739f] | 91 | #if defined(CFA_HAVE_STATX) |
---|
[dddb3dd0] | 92 | extern int cfa_statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf, __u64 submit_flags); |
---|
[c402739f] | 93 | #endif |
---|
[dddb3dd0] | 94 | extern ssize_t cfa_read(int fd, void * buf, size_t count, __u64 submit_flags); |
---|
| 95 | extern ssize_t cfa_write(int fd, void * buf, size_t count, __u64 submit_flags); |
---|
[a5040fe] | 96 | extern ssize_t cfa_splice(int fd_in, __off64_t *off_in, int fd_out, __off64_t *off_out, size_t len, unsigned int flags, __u64 submit_flags); |
---|
[dddb3dd0] | 97 | extern ssize_t cfa_tee(int fd_in, int fd_out, size_t len, unsigned int flags, __u64 submit_flags); |
---|
[c402739f] | 98 | |
---|
| 99 | //---------- |
---|
| 100 | // asynchronous calls |
---|
| 101 | #if defined(CFA_HAVE_PREADV2) |
---|
[dddb3dd0] | 102 | extern void async_preadv2(io_future_t & future, int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags, __u64 submit_flags); |
---|
[c402739f] | 103 | #endif |
---|
| 104 | #if defined(CFA_HAVE_PWRITEV2) |
---|
[dddb3dd0] | 105 | extern void async_pwritev2(io_future_t & future, int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags, __u64 submit_flags); |
---|
[c402739f] | 106 | #endif |
---|
[dddb3dd0] | 107 | extern void async_fsync(io_future_t & future, int fd, __u64 submit_flags); |
---|
| 108 | extern void async_epoll_ctl(io_future_t & future, int epfd, int op, int fd, struct epoll_event *event, __u64 submit_flags); |
---|
| 109 | extern void async_sync_file_range(io_future_t & future, int fd, off64_t offset, off64_t nbytes, unsigned int flags, __u64 submit_flags); |
---|
| 110 | extern void async_sendmsg(io_future_t & future, int sockfd, const struct msghdr *msg, int flags, __u64 submit_flags); |
---|
| 111 | extern void async_recvmsg(io_future_t & future, int sockfd, struct msghdr *msg, int flags, __u64 submit_flags); |
---|
| 112 | extern void async_send(io_future_t & future, int sockfd, const void *buf, size_t len, int flags, __u64 submit_flags); |
---|
| 113 | extern void async_recv(io_future_t & future, int sockfd, void *buf, size_t len, int flags, __u64 submit_flags); |
---|
| 114 | extern void async_accept4(io_future_t & future, int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags, __u64 submit_flags); |
---|
| 115 | extern void async_connect(io_future_t & future, int sockfd, const struct sockaddr *addr, socklen_t addrlen, __u64 submit_flags); |
---|
| 116 | extern void async_fallocate(io_future_t & future, int fd, int mode, off_t offset, off_t len, __u64 submit_flags); |
---|
| 117 | extern void async_posix_fadvise(io_future_t & future, int fd, off_t offset, off_t len, int advice, __u64 submit_flags); |
---|
| 118 | extern void async_madvise(io_future_t & future, void *addr, size_t length, int advice, __u64 submit_flags); |
---|
| 119 | extern void async_openat(io_future_t & future, int dirfd, const char *pathname, int flags, mode_t mode, __u64 submit_flags); |
---|
[c402739f] | 120 | #if defined(CFA_HAVE_OPENAT2) |
---|
[dddb3dd0] | 121 | extern void async_openat2(io_future_t & future, int dirfd, const char *pathname, struct open_how * how, size_t size, __u64 submit_flags); |
---|
[c402739f] | 122 | #endif |
---|
[dddb3dd0] | 123 | extern void async_close(io_future_t & future, int fd, __u64 submit_flags); |
---|
[c402739f] | 124 | #if defined(CFA_HAVE_STATX) |
---|
[dddb3dd0] | 125 | extern void async_statx(io_future_t & future, int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf, __u64 submit_flags); |
---|
[c402739f] | 126 | #endif |
---|
[dddb3dd0] | 127 | void async_read(io_future_t & future, int fd, void * buf, size_t count, __u64 submit_flags); |
---|
| 128 | extern void async_write(io_future_t & future, int fd, void * buf, size_t count, __u64 submit_flags); |
---|
[a5040fe] | 129 | extern void async_splice(io_future_t & future, int fd_in, __off64_t *off_in, int fd_out, __off64_t *off_out, size_t len, unsigned int flags, __u64 submit_flags); |
---|
[dddb3dd0] | 130 | extern void async_tee(io_future_t & future, int fd_in, int fd_out, size_t len, unsigned int flags, __u64 submit_flags); |
---|
[c402739f] | 131 | |
---|
[d384787] | 132 | |
---|
| 133 | //----------------------------------------------------------------------------- |
---|
| 134 | // Check if a function is blocks a only the user thread |
---|
[93829cb] | 135 | bool has_user_level_blocking( fptr_t func ); |
---|
| 136 | |
---|
| 137 | #if CFA_HAVE_LINUX_IO_URING_H |
---|
| 138 | static inline void zero_sqe(struct io_uring_sqe * sqe) { |
---|
| 139 | sqe->flags = 0; |
---|
| 140 | sqe->ioprio = 0; |
---|
| 141 | sqe->fd = 0; |
---|
| 142 | sqe->off = 0; |
---|
| 143 | sqe->addr = 0; |
---|
| 144 | sqe->len = 0; |
---|
| 145 | sqe->fsync_flags = 0; |
---|
| 146 | sqe->__pad2[0] = 0; |
---|
| 147 | sqe->__pad2[1] = 0; |
---|
| 148 | sqe->__pad2[2] = 0; |
---|
| 149 | sqe->fd = 0; |
---|
| 150 | sqe->off = 0; |
---|
| 151 | sqe->addr = 0; |
---|
| 152 | sqe->len = 0; |
---|
| 153 | } |
---|
| 154 | #endif |
---|