Ignore:
Timestamp:
Apr 23, 2020, 4:21:49 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:
ecf6b46
Parents:
8962722
Message:

Removed the async_ prefix of I/O functions

File:
1 edited

Legend:

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

    r8962722 r2489d31  
    293293//
    294294
    295 static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct io_ring & ring ) {
    296         // Wait for a spot to be available
    297         P(ring.submit);
    298 
    299         // Allocate the sqe
    300         uint32_t idx = __atomic_fetch_add(&ring.submit_q.alloc, 1ul32, __ATOMIC_SEQ_CST);
    301 
    302         // Validate that we didn't overflow anything
    303         // Check that nothing overflowed
    304         /* paranoid */ verify( true );
    305 
    306         // Check that it goes head -> tail -> alloc and never head -> alloc -> tail
    307         /* paranoid */ verify( true );
    308 
    309         // Return the sqe
    310         return [&ring.submit_q.sqes[ idx & (*ring.submit_q.mask)], idx];
    311 }
    312 
    313 static inline void __submit( struct io_ring & ring, uint32_t idx ) {
    314         // get mutual exclusion
    315         lock(ring.submit_q.lock __cfaabi_dbg_ctx2);
    316 
    317         // Append to the list of ready entries
    318         uint32_t * tail = ring.submit_q.tail;
    319         const uint32_t mask = *ring.submit_q.mask;
    320 
    321         ring.submit_q.array[ (*tail) & mask ] = idx & mask;
    322         __atomic_fetch_add(tail, 1ul32, __ATOMIC_SEQ_CST);
    323 
    324         // Submit however, many entries need to be submitted
    325         int ret = syscall( __NR_io_uring_enter, ring.fd, 1, 0, 0, 0p, 0);
    326         // __cfaabi_bits_print_safe( STDERR_FILENO, "Performed io_submit, returned %d\n", ret );
    327         if( ret < 0 ) {
    328                 switch((int)errno) {
    329                 default:
    330                         abort( "KERNEL ERROR: IO_URING SUBMIT - %s\n", strerror(errno) );
     295        static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct io_ring & ring ) {
     296                // Wait for a spot to be available
     297                P(ring.submit);
     298
     299                // Allocate the sqe
     300                uint32_t idx = __atomic_fetch_add(&ring.submit_q.alloc, 1ul32, __ATOMIC_SEQ_CST);
     301
     302                // Validate that we didn't overflow anything
     303                // Check that nothing overflowed
     304                /* paranoid */ verify( true );
     305
     306                // Check that it goes head -> tail -> alloc and never head -> alloc -> tail
     307                /* paranoid */ verify( true );
     308
     309                // Return the sqe
     310                return [&ring.submit_q.sqes[ idx & (*ring.submit_q.mask)], idx];
     311        }
     312
     313        static inline void __submit( struct io_ring & ring, uint32_t idx ) {
     314                // get mutual exclusion
     315                lock(ring.submit_q.lock __cfaabi_dbg_ctx2);
     316
     317                // Append to the list of ready entries
     318                uint32_t * tail = ring.submit_q.tail;
     319                const uint32_t mask = *ring.submit_q.mask;
     320
     321                ring.submit_q.array[ (*tail) & mask ] = idx & mask;
     322                __atomic_fetch_add(tail, 1ul32, __ATOMIC_SEQ_CST);
     323
     324                // Submit however, many entries need to be submitted
     325                int ret = syscall( __NR_io_uring_enter, ring.fd, 1, 0, 0, 0p, 0);
     326                // __cfaabi_bits_print_safe( STDERR_FILENO, "Performed io_submit, returned %d\n", ret );
     327                if( ret < 0 ) {
     328                        switch((int)errno) {
     329                        default:
     330                                abort( "KERNEL ERROR: IO_URING SUBMIT - %s\n", strerror(errno) );
     331                        }
    331332                }
    332         }
    333 
    334         unlock(ring.submit_q.lock);
    335         // Make sure that idx was submitted
    336         // Be careful to not get false positive if we cycled the entire list or that someone else submitted for us
    337 }
    338 
    339 static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) {
    340         this.opcode = opcode;
    341         #if !defined(IOSQE_ASYNC)
    342                 this.flags = 0;
    343         #else
    344                 this.flags = IOSQE_ASYNC;
    345         #endif
    346         this.ioprio = 0;
    347         this.fd = fd;
    348         this.off = 0;
    349         this.addr = 0;
    350         this.len = 0;
    351         this.rw_flags = 0;
    352         this.__pad2[0] = this.__pad2[1] = this.__pad2[2] = 0;
    353 }
    354 
    355 static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) {
    356         (this){ opcode, fd };
    357         this.off = off;
    358         this.addr = (uint64_t)addr;
    359         this.len = len;
    360 }
     333
     334                unlock(ring.submit_q.lock);
     335                // Make sure that idx was submitted
     336                // Be careful to not get false positive if we cycled the entire list or that someone else submitted for us
     337        }
     338
     339        static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) {
     340                this.opcode = opcode;
     341                #if !defined(IOSQE_ASYNC)
     342                        this.flags = 0;
     343                #else
     344                        this.flags = IOSQE_ASYNC;
     345                #endif
     346                this.ioprio = 0;
     347                this.fd = fd;
     348                this.off = 0;
     349                this.addr = 0;
     350                this.len = 0;
     351                this.rw_flags = 0;
     352                this.__pad2[0] = this.__pad2[1] = this.__pad2[2] = 0;
     353        }
     354
     355        static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) {
     356                (this){ opcode, fd };
     357                this.off = off;
     358                this.addr = (uint64_t)addr;
     359                this.len = len;
     360        }
    361361
    362362//=============================================================================================
     
    388388//-----------------------------------------------------------------------------
    389389// Asynchronous operations
    390         ssize_t async_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
     390        ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
    391391                #if !defined(IORING_OP_READV)
    392392                        return preadv2(fd, iov, iovcnt, offset, flags);
     
    400400        }
    401401
    402         ssize_t async_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
     402        ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
    403403                #if !defined(IORING_OP_WRITEV)
    404404                        return pwritev2(fd, iov, iovcnt, offset, flags);
     
    412412        }
    413413
    414         int async_fsync(int fd) {
     414        int cfa_fsync(int fd) {
    415415                #if !defined(IORING_OP_FSYNC)
    416416                        return fsync(fd);
     
    424424        }
    425425
    426         int async_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) {
     426        int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) {
    427427                #if !defined(IORING_OP_SYNC_FILE_RANGE)
    428428                        return sync_file_range(fd, offset, nbytes, flags);
     
    440440
    441441
    442         ssize_t async_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
     442        ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
    443443                #if !defined(IORING_OP_SENDMSG)
    444444                        return recv(sockfd, msg, flags);
     
    453453        }
    454454
    455         ssize_t async_recvmsg(int sockfd, struct msghdr *msg, int flags) {
     455        ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags) {
    456456                #if !defined(IORING_OP_RECVMSG)
    457457                        return recv(sockfd, msg, flags);
     
    466466        }
    467467
    468         ssize_t async_send(int sockfd, const void *buf, size_t len, int flags) {
     468        ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags) {
    469469                #if !defined(IORING_OP_SEND)
    470470                        return send( sockfd, buf, len, flags );
     
    481481        }
    482482
    483         ssize_t async_recv(int sockfd, void *buf, size_t len, int flags) {
     483        ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags) {
    484484                #if !defined(IORING_OP_RECV)
    485485                        return recv( sockfd, buf, len, flags );
     
    496496        }
    497497
    498         int async_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
     498        int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
    499499                #if !defined(IORING_OP_ACCEPT)
    500500                        __SOCKADDR_ARG _addr;
     
    513513        }
    514514
    515         int async_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
     515        int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
    516516                #if !defined(IORING_OP_CONNECT)
    517517                        __CONST_SOCKADDR_ARG _addr;
     
    529529        }
    530530
    531         int async_fallocate(int fd, int mode, uint64_t offset, uint64_t len) {
     531        int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len) {
    532532                #if !defined(IORING_OP_FALLOCATE)
    533533                        return fallocate( fd, mode, offset, len );
     
    544544        }
    545545
    546         int async_fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
     546        int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
    547547                #if !defined(IORING_OP_FADVISE)
    548548                        return posix_fadvise( fd, offset, len, advice );
     
    559559        }
    560560
    561         int async_madvise(void *addr, size_t length, int advice) {
     561        int cfa_madvise(void *addr, size_t length, int advice) {
    562562                #if !defined(IORING_OP_MADVISE)
    563563                        return madvise( addr, length, advice );
     
    574574        }
    575575
    576         int async_openat(int dirfd, const char *pathname, int flags, mode_t mode) {
     576        int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode) {
    577577                #if !defined(IORING_OP_OPENAT)
    578578                        return openat( dirfd, pathname, flags, mode );
     
    589589        }
    590590
    591         int async_close(int fd) {
     591        int cfa_close(int fd) {
    592592                #if !defined(IORING_OP_CLOSE)
    593593                        return close( fd );
     
    601601        }
    602602
    603         int async_statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf) {
     603        int cfa_statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf) {
    604604                #if !defined(IORING_OP_STATX)
    605605                        //return statx( dirfd, pathname, flags, mask, statxbuf );
     
    619619
    620620
    621         ssize_t async_read(int fd, void *buf, size_t count) {
     621        ssize_t cfa_read(int fd, void *buf, size_t count) {
    622622                #if !defined(IORING_OP_READ)
    623623                        return read( fd, buf, count );
     
    631631        }
    632632
    633         ssize_t async_write(int fd, void *buf, size_t count) {
     633        ssize_t cfa_write(int fd, void *buf, size_t count) {
    634634                #if !defined(IORING_OP_WRITE)
    635635                        return read( fd, buf, count );
     
    655655
    656656                if( /*func == (fptr_t)preadv2 || */
    657                         func == (fptr_t)async_preadv2 )
     657                        func == (fptr_t)cfa_preadv2 )
    658658                        #define _CFA_IO_FEATURE_IORING_OP_READV ,
    659659                        return IS_DEFINED(IORING_OP_READV);
    660660
    661661                if( /*func == (fptr_t)pwritev2 || */
    662                       func == (fptr_t)async_pwritev2 )
     662                      func == (fptr_t)cfa_pwritev2 )
    663663                        #define _CFA_IO_FEATURE_IORING_OP_WRITEV ,
    664664                        return IS_DEFINED(IORING_OP_WRITEV);
    665665
    666666                if( /*func == (fptr_t)fsync || */
    667                       func == (fptr_t)async_fsync )
     667                      func == (fptr_t)cfa_fsync )
    668668                        #define _CFA_IO_FEATURE_IORING_OP_FSYNC ,
    669669                        return IS_DEFINED(IORING_OP_FSYNC);
    670670
    671671                if( /*func == (fptr_t)ync_file_range || */
    672                       func == (fptr_t)async_sync_file_range )
     672                      func == (fptr_t)cfa_sync_file_range )
    673673                        #define _CFA_IO_FEATURE_IORING_OP_SYNC_FILE_RANGE ,
    674674                        return IS_DEFINED(IORING_OP_SYNC_FILE_RANGE);
    675675
    676676                if( /*func == (fptr_t)sendmsg || */
    677                       func == (fptr_t)async_sendmsg )
     677                      func == (fptr_t)cfa_sendmsg )
    678678                        #define _CFA_IO_FEATURE_IORING_OP_SENDMSG ,
    679679                        return IS_DEFINED(IORING_OP_SENDMSG);
    680680
    681681                if( /*func == (fptr_t)recvmsg || */
    682                       func == (fptr_t)async_recvmsg )
     682                      func == (fptr_t)cfa_recvmsg )
    683683                        #define _CFA_IO_FEATURE_IORING_OP_RECVMSG ,
    684684                        return IS_DEFINED(IORING_OP_RECVMSG);
    685685
    686686                if( /*func == (fptr_t)send || */
    687                         func == (fptr_t)async_send )
     687                        func == (fptr_t)cfa_send )
    688688                        #define _CFA_IO_FEATURE_IORING_OP_SEND ,
    689689                        return IS_DEFINED(IORING_OP_SEND);
    690690
    691691                if( /*func == (fptr_t)recv || */
    692                         func == (fptr_t)async_recv )
     692                        func == (fptr_t)cfa_recv )
    693693                        #define _CFA_IO_FEATURE_IORING_OP_RECV ,
    694694                        return IS_DEFINED(IORING_OP_RECV);
    695695
    696696                if( /*func == (fptr_t)accept4 || */
    697                         func == (fptr_t)async_accept4 )
     697                        func == (fptr_t)cfa_accept4 )
    698698                        #define _CFA_IO_FEATURE_IORING_OP_ACCEPT ,
    699699                        return IS_DEFINED(IORING_OP_ACCEPT);
    700700
    701701                if( /*func == (fptr_t)connect || */
    702                         func == (fptr_t)async_connect )
     702                        func == (fptr_t)cfa_connect )
    703703                        #define _CFA_IO_FEATURE_IORING_OP_CONNECT ,
    704704                        return IS_DEFINED(IORING_OP_CONNECT);
    705705
    706706                if( /*func == (fptr_t)fallocate || */
    707                         func == (fptr_t)async_fallocate )
     707                        func == (fptr_t)cfa_fallocate )
    708708                        #define _CFA_IO_FEATURE_IORING_OP_FALLOCATE ,
    709709                        return IS_DEFINED(IORING_OP_FALLOCATE);
    710710
    711711                if( /*func == (fptr_t)fadvise || */
    712                         func == (fptr_t)async_fadvise )
     712                        func == (fptr_t)cfa_fadvise )
    713713                        #define _CFA_IO_FEATURE_IORING_OP_FADVISE ,
    714714                        return IS_DEFINED(IORING_OP_FADVISE);
    715715
    716716                if( /*func == (fptr_t)madvise || */
    717                         func == (fptr_t)async_madvise )
     717                        func == (fptr_t)cfa_madvise )
    718718                        #define _CFA_IO_FEATURE_IORING_OP_MADVISE ,
    719719                        return IS_DEFINED(IORING_OP_MADVISE);
    720720
    721721                if( /*func == (fptr_t)openat || */
    722                         func == (fptr_t)async_openat )
     722                        func == (fptr_t)cfa_openat )
    723723                        #define _CFA_IO_FEATURE_IORING_OP_OPENAT ,
    724724                        return IS_DEFINED(IORING_OP_OPENAT);
    725725
    726726                if( /*func == (fptr_t)close || */
    727                         func == (fptr_t)async_close )
     727                        func == (fptr_t)cfa_close )
    728728                        #define _CFA_IO_FEATURE_IORING_OP_CLOSE ,
    729729                        return IS_DEFINED(IORING_OP_CLOSE);
    730730
    731731                if( /*func == (fptr_t)statx || */
    732                         func == (fptr_t)async_statx )
     732                        func == (fptr_t)cfa_statx )
    733733                        #define _CFA_IO_FEATURE_IORING_OP_STATX ,
    734734                        return IS_DEFINED(IORING_OP_STATX);
    735735
    736736                if( /*func == (fptr_t)read || */
    737                       func == (fptr_t)async_read )
     737                      func == (fptr_t)cfa_read )
    738738                        #define _CFA_IO_FEATURE_IORING_OP_READ ,
    739739                        return IS_DEFINED(IORING_OP_READ);
    740740
    741741                if( /*func == (fptr_t)write || */
    742                       func == (fptr_t)async_write )
     742                      func == (fptr_t)cfa_write )
    743743                        #define _CFA_IO_FEATURE_IORING_OP_WRITE ,
    744744                        return IS_DEFINED(IORING_OP_WRITE);
Note: See TracChangeset for help on using the changeset viewer.