source: libcfa/src/concurrency/iofwd.hfa @ 858350a

ADTast-experimental
Last change on this file since 858350a was 2d028003, checked in by Peter A. Buhr <pabuhr@…>, 20 months ago

restructure #include files because issues with attribute transparent_union are resolved

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