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