| [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 | 
|---|
| [a0a949c] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [f898983] | 12 | // Last Modified On : Fri Jul 21 21:36:01 2023 | 
|---|
|  | 13 | // Update Count     : 3 | 
|---|
| [d384787] | 14 | // | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #pragma once | 
|---|
|  | 17 |  | 
|---|
| [519f11c] | 18 | #include <unistd.h> | 
|---|
| [2d028003] | 19 | #include <sys/socket.h> | 
|---|
| [f898983] | 20 | #include <string.h>                                                                             // memset | 
|---|
| [f5f2768] | 21 |  | 
|---|
| [e1801fc] | 22 | extern "C" { | 
|---|
| [44f09ea] | 23 | #include <asm/types.h> | 
|---|
| [93829cb] | 24 | #include <sys/stat.h> // needed for mode_t | 
|---|
| [f00b26d4] | 25 | #if CFA_HAVE_LINUX_IO_URING_H | 
|---|
|  | 26 | #include <linux/io_uring.h> | 
|---|
|  | 27 | #endif | 
|---|
| [e1801fc] | 28 | } | 
|---|
| [519f11c] | 29 | #include "bits/defs.hfa" | 
|---|
| [40a606d2] | 30 | #include "kernel/fwd.hfa" | 
|---|
| [f00b26d4] | 31 | #include "time.hfa" | 
|---|
|  | 32 |  | 
|---|
|  | 33 | #if defined(CFA_HAVE_IOSQE_FIXED_FILE) | 
|---|
|  | 34 | #define CFA_IO_FIXED_FD1 IOSQE_FIXED_FILE | 
|---|
|  | 35 | #endif | 
|---|
|  | 36 | #if defined(CFA_HAVE_SPLICE_F_FD_IN_FIXED) | 
|---|
|  | 37 | #define CFA_IO_FIXED_FD2 SPLICE_F_FD_IN_FIXED | 
|---|
|  | 38 | #endif | 
|---|
|  | 39 | #if defined(CFA_HAVE_IOSQE_IO_DRAIN) | 
|---|
|  | 40 | #define CFA_IO_DRAIN IOSQE_IO_DRAIN | 
|---|
|  | 41 | #endif | 
|---|
|  | 42 | #if defined(CFA_HAVE_IOSQE_ASYNC) | 
|---|
|  | 43 | #define CFA_IO_ASYNC IOSQE_ASYNC | 
|---|
|  | 44 | #endif | 
|---|
|  | 45 |  | 
|---|
| [6d1790c] | 46 | #if __OFF_T_MATCHES_OFF64_T | 
|---|
|  | 47 | typedef __off64_t off_t; | 
|---|
|  | 48 | #else | 
|---|
|  | 49 | typedef __off_t off_t; | 
|---|
|  | 50 | #endif | 
|---|
|  | 51 | typedef __off64_t off64_t; | 
|---|
|  | 52 |  | 
|---|
| [78da4ab] | 53 | struct epoll_event; | 
|---|
|  | 54 |  | 
|---|
| [40a606d2] | 55 | //----------------------------------------------------------------------- | 
|---|
|  | 56 | // IO user data | 
|---|
|  | 57 | struct io_future_t { | 
|---|
|  | 58 | future_t self; | 
|---|
|  | 59 | __s32 result; | 
|---|
|  | 60 | }; | 
|---|
|  | 61 |  | 
|---|
|  | 62 | static inline { | 
|---|
|  | 63 | thread$ * fulfil( io_future_t & this, __s32 result, bool do_unpark = true ) { | 
|---|
|  | 64 | this.result = result; | 
|---|
|  | 65 | return fulfil(this.self, do_unpark); | 
|---|
|  | 66 | } | 
|---|
|  | 67 |  | 
|---|
|  | 68 | // Wait for the future to be fulfilled | 
|---|
|  | 69 | bool wait     ( io_future_t & this ) { return wait     (this.self); } | 
|---|
|  | 70 | void reset    ( io_future_t & this ) { return reset    (this.self); } | 
|---|
|  | 71 | bool available( io_future_t & this ) { return available(this.self); } | 
|---|
| [f3da205] | 72 | bool setup    ( io_future_t & this, oneshot & ctx ) { return setup  (this.self, ctx); } | 
|---|
|  | 73 | bool retract  ( io_future_t & this, oneshot & ctx ) { return retract(this.self, ctx); } | 
|---|
| [40a606d2] | 74 | } | 
|---|
|  | 75 |  | 
|---|
| [78da4ab] | 76 | //---------- | 
|---|
|  | 77 | // underlying calls | 
|---|
| [8bee858] | 78 | extern struct io_context$ * cfa_io_allocate(struct io_uring_sqe * out_sqes[], __u32 out_idxs[], __u32 want)  __attribute__((nonnull (1,2))); | 
|---|
|  | 79 | extern void cfa_io_submit( struct io_context$ * in_ctx, __u32 in_idxs[], __u32 have, bool lazy ) __attribute__((nonnull (1,2))); | 
|---|
| [e1801fc] | 80 |  | 
|---|
| [c402739f] | 81 | //---------- | 
|---|
|  | 82 | // synchronous calls | 
|---|
|  | 83 | #if defined(CFA_HAVE_PREADV2) | 
|---|
| [a0a949c] | 84 | extern ssize_t cfa_preadv2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags, __u64 submit_flags); | 
|---|
| [c402739f] | 85 | #endif | 
|---|
|  | 86 | #if defined(CFA_HAVE_PWRITEV2) | 
|---|
| [a0a949c] | 87 | extern ssize_t cfa_pwritev2(int fd, const struct iovec * iov, int iovcnt, off_t offset, int flags, __u64 submit_flags); | 
|---|
| [c402739f] | 88 | #endif | 
|---|
| [dddb3dd0] | 89 | extern int cfa_fsync(int fd, __u64 submit_flags); | 
|---|
| [a0a949c] | 90 | extern int cfa_epoll_ctl(int epfd, int op, int fd, struct epoll_event * event, __u64 submit_flags); | 
|---|
| [dddb3dd0] | 91 | extern int cfa_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags, __u64 submit_flags); | 
|---|
| [a0a949c] | 92 | extern  ssize_t cfa_sendmsg(int sockfd, const struct msghdr * msg, int flags, __u64 submit_flags); | 
|---|
|  | 93 | extern ssize_t cfa_recvmsg(int sockfd, struct msghdr * msg, int flags, __u64 submit_flags); | 
|---|
|  | 94 | extern ssize_t cfa_send(int sockfd, const void * buf, size_t len, int flags, __u64 submit_flags); | 
|---|
|  | 95 | extern ssize_t cfa_recv(int sockfd, void * buf, size_t len, int flags, __u64 submit_flags); | 
|---|
| [f5f2768] | 96 | extern int cfa_accept4(int sockfd, __SOCKADDR_ARG addr, socklen_t * restrict addrlen, int flags, __u64 submit_flags); | 
|---|
|  | 97 | extern int cfa_connect(int sockfd, __CONST_SOCKADDR_ARG addr, socklen_t addrlen, __u64 submit_flags); | 
|---|
| [dddb3dd0] | 98 | extern int cfa_fallocate(int fd, int mode, off_t offset, off_t len, __u64 submit_flags); | 
|---|
|  | 99 | extern int cfa_posix_fadvise(int fd, off_t offset, off_t len, int advice, __u64 submit_flags); | 
|---|
| [a0a949c] | 100 | extern int cfa_madvise(void * addr, size_t length, int advice, __u64 submit_flags); | 
|---|
|  | 101 | extern int cfa_openat(int dirfd, const char * pathname, int flags, mode_t mode, __u64 submit_flags); | 
|---|
| [c402739f] | 102 | #if defined(CFA_HAVE_OPENAT2) | 
|---|
| [a0a949c] | 103 | extern int cfa_openat2(int dirfd, const char * pathname, struct open_how * how, size_t size, __u64 submit_flags); | 
|---|
| [c402739f] | 104 | #endif | 
|---|
| [dddb3dd0] | 105 | extern int cfa_close(int fd, __u64 submit_flags); | 
|---|
| [c402739f] | 106 | #if defined(CFA_HAVE_STATX) | 
|---|
| [a0a949c] | 107 | extern int cfa_statx(int dirfd, const char * pathname, int flags, unsigned int mask, struct statx * statxbuf, __u64 submit_flags); | 
|---|
| [c402739f] | 108 | #endif | 
|---|
| [dddb3dd0] | 109 | extern ssize_t cfa_read(int fd, void * buf, size_t count, __u64 submit_flags); | 
|---|
|  | 110 | extern ssize_t cfa_write(int fd, void * buf, size_t count, __u64 submit_flags); | 
|---|
| [a0a949c] | 111 | 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] | 112 | extern ssize_t cfa_tee(int fd_in, int fd_out, size_t len, unsigned int flags, __u64 submit_flags); | 
|---|
| [c402739f] | 113 |  | 
|---|
|  | 114 | //---------- | 
|---|
|  | 115 | // asynchronous calls | 
|---|
|  | 116 | #if defined(CFA_HAVE_PREADV2) | 
|---|
| [a0a949c] | 117 | 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] | 118 | #endif | 
|---|
|  | 119 | #if defined(CFA_HAVE_PWRITEV2) | 
|---|
| [a0a949c] | 120 | 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] | 121 | #endif | 
|---|
| [dddb3dd0] | 122 | extern void async_fsync(io_future_t & future, int fd, __u64 submit_flags); | 
|---|
| [a0a949c] | 123 | extern void async_epoll_ctl(io_future_t & future, int epfd, int op, int fd, struct epoll_event * event, __u64 submit_flags); | 
|---|
| [dddb3dd0] | 124 | extern void async_sync_file_range(io_future_t & future, int fd, off64_t offset, off64_t nbytes, unsigned int flags, __u64 submit_flags); | 
|---|
| [a0a949c] | 125 | extern void async_sendmsg(io_future_t & future, int sockfd, const struct msghdr * msg, int flags, __u64 submit_flags); | 
|---|
|  | 126 | extern void async_recvmsg(io_future_t & future, int sockfd, struct msghdr * msg, int flags, __u64 submit_flags); | 
|---|
|  | 127 | extern void async_send(io_future_t & future, int sockfd, const void * buf, size_t len, int flags, __u64 submit_flags); | 
|---|
|  | 128 | extern void async_recv(io_future_t & future, int sockfd, void * buf, size_t len, int flags, __u64 submit_flags); | 
|---|
| [f5f2768] | 129 | extern void async_accept4(io_future_t & future, int sockfd, __SOCKADDR_ARG addr, socklen_t * restrict addrlen, int flags, __u64 submit_flags); | 
|---|
|  | 130 | extern void async_connect(io_future_t & future, int sockfd, __CONST_SOCKADDR_ARG addr, socklen_t addrlen, __u64 submit_flags); | 
|---|
| [dddb3dd0] | 131 | extern void async_fallocate(io_future_t & future, int fd, int mode, off_t offset, off_t len, __u64 submit_flags); | 
|---|
|  | 132 | extern void async_posix_fadvise(io_future_t & future, int fd, off_t offset, off_t len, int advice, __u64 submit_flags); | 
|---|
| [a0a949c] | 133 | extern void async_madvise(io_future_t & future, void * addr, size_t length, int advice, __u64 submit_flags); | 
|---|
|  | 134 | extern void async_openat(io_future_t & future, int dirfd, const char * pathname, int flags, mode_t mode, __u64 submit_flags); | 
|---|
| [c402739f] | 135 | #if defined(CFA_HAVE_OPENAT2) | 
|---|
| [a0a949c] | 136 | extern void async_openat2(io_future_t & future, int dirfd, const char * pathname, struct open_how * how, size_t size, __u64 submit_flags); | 
|---|
| [c402739f] | 137 | #endif | 
|---|
| [dddb3dd0] | 138 | extern void async_close(io_future_t & future, int fd, __u64 submit_flags); | 
|---|
| [c402739f] | 139 | #if defined(CFA_HAVE_STATX) | 
|---|
| [a0a949c] | 140 | 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] | 141 | #endif | 
|---|
| [dddb3dd0] | 142 | void async_read(io_future_t & future, int fd, void * buf, size_t count, __u64 submit_flags); | 
|---|
|  | 143 | extern void async_write(io_future_t & future, int fd, void * buf, size_t count, __u64 submit_flags); | 
|---|
| [a0a949c] | 144 | 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] | 145 | extern void async_tee(io_future_t & future, int fd_in, int fd_out, size_t len, unsigned int flags, __u64 submit_flags); | 
|---|
| [c402739f] | 146 |  | 
|---|
| [d384787] | 147 |  | 
|---|
|  | 148 | //----------------------------------------------------------------------------- | 
|---|
|  | 149 | // Check if a function is blocks a only the user thread | 
|---|
| [93829cb] | 150 | bool has_user_level_blocking( fptr_t func ); | 
|---|
|  | 151 |  | 
|---|
|  | 152 | #if CFA_HAVE_LINUX_IO_URING_H | 
|---|
|  | 153 | static inline void zero_sqe(struct io_uring_sqe * sqe) { | 
|---|
| [374cdb66] | 154 | memset( sqe, 0, sizeof( struct io_uring_sqe ) ); | 
|---|
| [93829cb] | 155 | } | 
|---|
| [f5f2768] | 156 | #endif | 
|---|