Ignore:
Timestamp:
Aug 14, 2020, 12:33:26 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7fdae38
Parents:
b353a49
Message:

I/O now uses onshot semaphore instead of raw park/unpark.
I/O now uses linux/types.h types instead of stdint.h types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/iocall.cfa

    rb353a49 r4998155  
    3232        #include "io/types.hfa"
    3333
    34         extern [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data );
    35         extern void __submit( struct io_context * ctx, uint32_t idx ) __attribute__((nonnull (1)));
    36 
    37         static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) {
     34        extern [* struct io_uring_sqe, __u32] __submit_alloc( struct __io_data & ring, __u64 data );
     35        extern void __submit( struct io_context * ctx, __u32 idx ) __attribute__((nonnull (1)));
     36
     37        static inline void ?{}(struct io_uring_sqe & this, __u8 opcode, int fd) {
    3838                this.opcode = opcode;
    3939                #if !defined(IOSQE_ASYNC)
     
    5151        }
    5252
    53         static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) {
     53        static inline void ?{}(struct io_uring_sqe & this, __u8 opcode, int fd, void * addr, __u32 len, __u64 off ) {
    5454                (this){ opcode, fd };
    5555                this.off = off;
    56                 this.addr = (uint64_t)(uintptr_t)addr;
     56                this.addr = (__u64)(uintptr_t)addr;
    5757                this.len = len;
    5858        }
     
    105105                (void)timeout; (void)cancellation; \
    106106                if( !context ) context = __get_io_context(); \
    107                 __io_user_data_t data = { 0, active_thread() }; \
     107                __io_user_data_t data = { 0 }; \
    108108                struct __io_data & ring = *context->thrd.ring; \
    109109                struct io_uring_sqe * sqe; \
    110                 uint32_t idx; \
    111                 uint8_t sflags = REGULAR_FLAGS & submit_flags; \
    112                 [sqe, idx] = __submit_alloc( ring, (uint64_t)(uintptr_t)&data ); \
     110                __u32 idx; \
     111                __u8 sflags = REGULAR_FLAGS & submit_flags; \
     112                [sqe, idx] = __submit_alloc( ring, (__u64)(uintptr_t)&data ); \
    113113                sqe->flags = sflags;
    114114
    115115        #define __submit_wait \
    116116                /*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \
    117                 verify( sqe->user_data == (uint64_t)(uintptr_t)&data ); \
     117                verify( sqe->user_data == (__u64)(uintptr_t)&data ); \
    118118                __submit( context, idx ); \
    119                 park( __cfaabi_dbg_ctx ); \
     119                wait( data.sem ); \
    120120                if( data.result < 0 ) { \
    121121                        errno = -data.result; \
     
    149149
    150150        extern int fsync(int fd);
    151         extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags);
     151
     152        typedef __off64_t off_t;
     153        typedef __off64_t off64_t;
     154        extern int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags);
    152155
    153156        struct msghdr;
     
    160163        extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
    161164
    162         extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len);
    163         extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice);
     165        extern int fallocate(int fd, int mode, off_t offset, off_t len);
     166        extern int posix_fadvise(int fd, off_t offset, off_t len, int advice);
    164167        extern int madvise(void *addr, size_t length, int advice);
    165168
     
    190193                        sqe->fd = fd;
    191194                        sqe->off = offset;
    192                         sqe->addr = (uint64_t)(uintptr_t)iov;
     195                        sqe->addr = (__u64)iov;
    193196                        sqe->len = iovcnt;
    194197                        sqe->rw_flags = 0;
     
    207210                        __submit_prelude
    208211
    209                         (*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset };
     212                        sqe->opcode = IORING_OP_WRITEV;
     213                        sqe->ioprio = 0;
     214                        sqe->fd = fd;
     215                        sqe->off = offset;
     216                        sqe->addr = (__u64)iov;
     217                        sqe->len = iovcnt;
     218                        sqe->rw_flags = 0;
     219                        sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0;
    210220
    211221                        __submit_wait
     
    220230                __submit_prelude
    221231
    222                 (*sqe){ IORING_OP_FSYNC, fd };
    223 
    224                 __submit_wait
    225         #endif
    226 }
    227 
    228 int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
     232                sqe->opcode = IORING_OP_FSYNC;
     233                sqe->ioprio = 0;
     234                sqe->fd = fd;
     235                sqe->off = 0;
     236                sqe->addr = 0;
     237                sqe->len = 0;
     238                sqe->rw_flags = 0;
     239                sqe->__pad2[0] = sqe->__pad2[1] = sqe->__pad2[2] = 0;
     240
     241                __submit_wait
     242        #endif
     243}
     244
     245int cfa_sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
    229246        #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_SYNC_FILE_RANGE)
    230247                return sync_file_range(fd, offset, nbytes, flags);
     
    275292
    276293                (*sqe){ IORING_OP_SEND, sockfd };
    277                 sqe->addr = (uint64_t)buf;
     294                sqe->addr = (__u64)buf;
    278295                sqe->len = len;
    279296                sqe->msg_flags = flags;
     
    290307
    291308                (*sqe){ IORING_OP_RECV, sockfd };
    292                 sqe->addr = (uint64_t)buf;
     309                sqe->addr = (__u64)buf;
    293310                sqe->len = len;
    294311                sqe->msg_flags = flags;
     
    305322
    306323                (*sqe){ IORING_OP_ACCEPT, sockfd };
    307                 sqe->addr = (uint64_t)(uintptr_t)addr;
    308                 sqe->addr2 = (uint64_t)(uintptr_t)addrlen;
     324                sqe->addr  = (__u64)addr;
     325                sqe->addr2 = (__u64)addrlen;
    309326                sqe->accept_flags = flags;
    310327
     
    320337
    321338                (*sqe){ IORING_OP_CONNECT, sockfd };
    322                 sqe->addr = (uint64_t)(uintptr_t)addr;
    323                 sqe->off  = (uint64_t)(uintptr_t)addrlen;
    324 
    325                 __submit_wait
    326         #endif
    327 }
    328 
    329 int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
     339                sqe->addr = (__u64)addr;
     340                sqe->off  = (__u64)addrlen;
     341
     342                __submit_wait
     343        #endif
     344}
     345
     346int cfa_fallocate(int fd, int mode, off_t offset, off_t len, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
    330347        #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_FALLOCATE)
    331348                return fallocate( fd, mode, offset, len );
     
    344361}
    345362
    346 int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
     363int cfa_fadvise(int fd, off_t offset, off_t len, int advice, int submit_flags, Duration timeout, io_cancellation * cancellation, io_context * context) {
    347364        #if !defined(CFA_HAVE_LINUX_IO_URING_H) || !defined(CFA_HAVE_IORING_OP_FADVISE)
    348365                return posix_fadvise( fd, offset, len, advice );
     
    351368
    352369                (*sqe){ IORING_OP_FADVISE, fd };
    353                 sqe->off = (uint64_t)offset;
     370                sqe->off = (__u64)offset;
    354371                sqe->len = len;
    355372                sqe->fadvise_advice = advice;
     
    366383
    367384                (*sqe){ IORING_OP_MADVISE, 0 };
    368                 sqe->addr = (uint64_t)addr;
     385                sqe->addr = (__u64)addr;
    369386                sqe->len = length;
    370387                sqe->fadvise_advice = advice;
     
    381398
    382399                (*sqe){ IORING_OP_OPENAT, dirfd };
    383                 sqe->addr = (uint64_t)pathname;
     400                sqe->addr = (__u64)pathname;
    384401                sqe->open_flags = flags;
    385402                sqe->len = mode;
     
    414431                __submit_prelude
    415432
    416                 (*sqe){ IORING_OP_STATX, dirfd, pathname, mask, (uint64_t)statxbuf };
     433                (*sqe){ IORING_OP_STATX, dirfd, pathname, mask, (__u64)statxbuf };
    417434                sqe->statx_flags = flags;
    418435
     
    456473                }
    457474                else {
    458                         sqe->off = (uint64_t)-1;
     475                        sqe->off = (__u64)-1;
    459476                }
    460477                sqe->len = len;
     
    464481                }
    465482                else {
    466                         sqe->splice_off_in = (uint64_t)-1;
     483                        sqe->splice_off_in = (__u64)-1;
    467484                }
    468485                sqe->splice_flags  = flags | (SPLICE_FLAGS & submit_flags);
Note: See TracChangeset for help on using the changeset viewer.