Changeset 31bb2e1


Ignore:
Timestamp:
Jul 1, 2020, 3:05:08 PM (15 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
4ec028d
Parents:
c33ed65
Message:

Moved implementations of cfa_[io call] to iocall.cfa

Location:
libcfa/src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    rc33ed65 r31bb2e1  
    5050thread_headers_nosrc = concurrency/invoke.h
    5151thread_headers = concurrency/coroutine.hfa concurrency/thread.hfa concurrency/kernel.hfa concurrency/monitor.hfa concurrency/mutex.hfa
    52 thread_libsrc = concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/io.cfa concurrency/preemption.cfa concurrency/ready_queue.cfa concurrency/stats.cfa ${thread_headers:.hfa=.cfa}
     52thread_libsrc = concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/io.cfa concurrency/iocall.cfa concurrency/preemption.cfa concurrency/ready_queue.cfa concurrency/stats.cfa ${thread_headers:.hfa=.cfa}
    5353else
    5454headers =
  • libcfa/src/Makefile.in

    rc33ed65 r31bb2e1  
    165165am__libcfathread_la_SOURCES_DIST =  \
    166166        concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa \
    167         concurrency/invoke.c concurrency/io.cfa \
     167        concurrency/invoke.c concurrency/io.cfa concurrency/iocall.cfa \
    168168        concurrency/preemption.cfa concurrency/ready_queue.cfa \
    169169        concurrency/stats.cfa concurrency/coroutine.cfa \
     
    176176@BUILDLIB_TRUE@ concurrency/CtxSwitch-@ARCHITECTURE@.lo \
    177177@BUILDLIB_TRUE@ concurrency/alarm.lo concurrency/invoke.lo \
    178 @BUILDLIB_TRUE@ concurrency/io.lo concurrency/preemption.lo \
     178@BUILDLIB_TRUE@ concurrency/io.lo concurrency/iocall.lo \
     179@BUILDLIB_TRUE@ concurrency/preemption.lo \
    179180@BUILDLIB_TRUE@ concurrency/ready_queue.lo concurrency/stats.lo \
    180181@BUILDLIB_TRUE@ $(am__objects_3)
     
    484485@BUILDLIB_FALSE@thread_headers =
    485486@BUILDLIB_TRUE@thread_headers = concurrency/coroutine.hfa concurrency/thread.hfa concurrency/kernel.hfa concurrency/monitor.hfa concurrency/mutex.hfa
    486 @BUILDLIB_TRUE@thread_libsrc = concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/io.cfa concurrency/preemption.cfa concurrency/ready_queue.cfa concurrency/stats.cfa ${thread_headers:.hfa=.cfa}
     487@BUILDLIB_TRUE@thread_libsrc = concurrency/CtxSwitch-@ARCHITECTURE@.S concurrency/alarm.cfa concurrency/invoke.c concurrency/io.cfa concurrency/iocall.cfa concurrency/preemption.cfa concurrency/ready_queue.cfa concurrency/stats.cfa ${thread_headers:.hfa=.cfa}
    487488
    488489#----------------------------------------------------------------------------------------------------------------
     
    620621        concurrency/$(DEPDIR)/$(am__dirstamp)
    621622concurrency/io.lo: concurrency/$(am__dirstamp) \
     623        concurrency/$(DEPDIR)/$(am__dirstamp)
     624concurrency/iocall.lo: concurrency/$(am__dirstamp) \
    622625        concurrency/$(DEPDIR)/$(am__dirstamp)
    623626concurrency/preemption.lo: concurrency/$(am__dirstamp) \
  • libcfa/src/concurrency/io.cfa

    rc33ed65 r31bb2e1  
    3838
    3939#else
     40        #define _GNU_SOURCE         /* See feature_test_macros(7) */
     41        #include <errno.h>
     42        #include <stdint.h>
     43        #include <string.h>
     44        #include <unistd.h>
     45        #include <sys/mman.h>
     46
    4047        extern "C" {
    41                 #define _GNU_SOURCE         /* See feature_test_macros(7) */
    42                 #include <errno.h>
    43                 #include <stdint.h>
    44                 #include <string.h>
    45                 #include <unistd.h>
    46                 #include <sys/mman.h>
    4748                #include <sys/syscall.h>
    4849
     
    420421// I/O Polling
    421422//=============================================================================================
    422         struct io_user_data {
    423                 int32_t result;
    424                 $thread * thrd;
    425         };
    426 
    427423        // Process a single completion message from the io_uring
    428424        // This is NOT thread-safe
     
    505501                        /* paranoid */ verify(&cqe);
    506502
    507                         struct io_user_data * data = (struct io_user_data *)(uintptr_t)cqe.user_data;
     503                        struct __io_user_data_t * data = (struct __io_user_data_t *)(uintptr_t)cqe.user_data;
    508504                        __cfadbg_print_safe( io, "Kernel I/O : Performed reading io cqe %p, result %d for %p\n", data, cqe.res, data->thrd );
    509505
     
    681677//
    682678
    683         static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
     679        [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
    684680                verify( data != 0 );
    685681
     
    730726        }
    731727
    732         static inline void __submit( struct __io_data & ring, uint32_t idx ) {
     728        void __submit( struct __io_data & ring, uint32_t idx ) {
    733729                // Get now the data we definetely need
    734730                uint32_t * const tail = ring.submit_q.tail;
     
    834830                this.len = len;
    835831        }
    836 
    837 
    838 //=============================================================================================
    839 // I/O Interface
    840 //=============================================================================================
    841 
    842         #define __submit_prelude \
    843                 io_user_data data = { 0, active_thread() }; \
    844                 struct __io_data & ring = *data.thrd->curr_cluster->io; \
    845                 struct io_uring_sqe * sqe; \
    846                 uint32_t idx; \
    847                 [sqe, idx] = __submit_alloc( ring, (uint64_t)(uintptr_t)&data );
    848 
    849         #define __submit_wait \
    850                 /*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \
    851                 verify( sqe->user_data == (uint64_t)(uintptr_t)&data ); \
    852                 __submit( ring, idx ); \
    853                 park( __cfaabi_dbg_ctx ); \
    854                 return data.result;
    855 #endif
    856 
    857 // Some forward declarations
    858 extern "C" {
    859         #include <unistd.h>
    860         #include <sys/types.h>
    861         #include <sys/socket.h>
    862         #include <sys/syscall.h>
    863 
    864 #if defined(HAVE_PREADV2)
    865         struct iovec;
    866         extern ssize_t preadv2 (int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
    867 #endif
    868 #if defined(HAVE_PWRITEV2)
    869         struct iovec;
    870         extern ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
    871 #endif
    872 
    873         extern int fsync(int fd);
    874         extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags);
    875 
    876         struct msghdr;
    877         struct sockaddr;
    878         extern ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
    879         extern ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
    880         extern ssize_t send(int sockfd, const void *buf, size_t len, int flags);
    881         extern ssize_t recv(int sockfd, void *buf, size_t len, int flags);
    882         extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
    883         extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
    884 
    885         extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len);
    886         extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice);
    887         extern int madvise(void *addr, size_t length, int advice);
    888 
    889         extern int openat(int dirfd, const char *pathname, int flags, mode_t mode);
    890         extern int close(int fd);
    891 
    892         extern ssize_t read (int fd, void *buf, size_t count);
    893 }
    894 
    895 //-----------------------------------------------------------------------------
    896 // Asynchronous operations
    897 #if defined(HAVE_PREADV2)
    898         ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
    899                 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READV)
    900                         return preadv2(fd, iov, iovcnt, offset, flags);
    901                 #else
    902                         __submit_prelude
    903 
    904                         (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset };
    905 
    906                         __submit_wait
    907                 #endif
    908         }
    909 #endif
    910 
    911 #if defined(HAVE_PWRITEV2)
    912         ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
    913                 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITEV)
    914                         return pwritev2(fd, iov, iovcnt, offset, flags);
    915                 #else
    916                         __submit_prelude
    917 
    918                         (*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset };
    919 
    920                         __submit_wait
    921                 #endif
    922         }
    923 #endif
    924 
    925 int cfa_fsync(int fd) {
    926         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FSYNC)
    927                 return fsync(fd);
    928         #else
    929                 __submit_prelude
    930 
    931                 (*sqe){ IORING_OP_FSYNC, fd };
    932 
    933                 __submit_wait
    934         #endif
    935 }
    936 
    937 int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) {
    938         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SYNC_FILE_RANGE)
    939                 return sync_file_range(fd, offset, nbytes, flags);
    940         #else
    941                 __submit_prelude
    942 
    943                 (*sqe){ IORING_OP_SYNC_FILE_RANGE, fd };
    944                 sqe->off = offset;
    945                 sqe->len = nbytes;
    946                 sqe->sync_range_flags = flags;
    947 
    948                 __submit_wait
    949         #endif
    950 }
    951 
    952 
    953 ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
    954         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SENDMSG)
    955                 return sendmsg(sockfd, msg, flags);
    956         #else
    957                 __submit_prelude
    958 
    959                 (*sqe){ IORING_OP_SENDMSG, sockfd, msg, 1, 0 };
    960                 sqe->msg_flags = flags;
    961 
    962                 __submit_wait
    963         #endif
    964 }
    965 
    966 ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags) {
    967         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECVMSG)
    968                 return recvmsg(sockfd, msg, flags);
    969         #else
    970                 __submit_prelude
    971 
    972                 (*sqe){ IORING_OP_RECVMSG, sockfd, msg, 1, 0 };
    973                 sqe->msg_flags = flags;
    974 
    975                 __submit_wait
    976         #endif
    977 }
    978 
    979 ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags) {
    980         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SEND)
    981                 return send( sockfd, buf, len, flags );
    982         #else
    983                 __submit_prelude
    984 
    985                 (*sqe){ IORING_OP_SEND, sockfd };
    986                 sqe->addr = (uint64_t)buf;
    987                 sqe->len = len;
    988                 sqe->msg_flags = flags;
    989 
    990                 __submit_wait
    991         #endif
    992 }
    993 
    994 ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags) {
    995         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECV)
    996                 return recv( sockfd, buf, len, flags );
    997         #else
    998                 __submit_prelude
    999 
    1000                 (*sqe){ IORING_OP_RECV, sockfd };
    1001                 sqe->addr = (uint64_t)buf;
    1002                 sqe->len = len;
    1003                 sqe->msg_flags = flags;
    1004 
    1005                 __submit_wait
    1006         #endif
    1007 }
    1008 
    1009 int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
    1010         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_ACCEPT)
    1011                 return accept4( sockfd, addr, addrlen, flags );
    1012         #else
    1013                 __submit_prelude
    1014 
    1015                 (*sqe){ IORING_OP_ACCEPT, sockfd };
    1016                 sqe->addr = addr;
    1017                 sqe->addr2 = addrlen;
    1018                 sqe->accept_flags = flags;
    1019 
    1020                 __submit_wait
    1021         #endif
    1022 }
    1023 
    1024 int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
    1025         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CONNECT)
    1026                 return connect( sockfd, addr, addrlen );
    1027         #else
    1028                 __submit_prelude
    1029 
    1030                 (*sqe){ IORING_OP_CONNECT, sockfd };
    1031                 sqe->addr = (uint64_t)addr;
    1032                 sqe->off = addrlen;
    1033 
    1034                 __submit_wait
    1035         #endif
    1036 }
    1037 
    1038 int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len) {
    1039         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FALLOCATE)
    1040                 return fallocate( fd, mode, offset, len );
    1041         #else
    1042                 __submit_prelude
    1043 
    1044                 (*sqe){ IORING_OP_FALLOCATE, fd };
    1045                 sqe->off = offset;
    1046                 sqe->len = length;
    1047                 sqe->mode = mode;
    1048 
    1049                 __submit_wait
    1050         #endif
    1051 }
    1052 
    1053 int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
    1054         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FADVISE)
    1055                 return posix_fadvise( fd, offset, len, advice );
    1056         #else
    1057                 __submit_prelude
    1058 
    1059                 (*sqe){ IORING_OP_FADVISE, fd };
    1060                 sqe->off = (uint64_t)offset;
    1061                 sqe->len = length;
    1062                 sqe->fadvise_advice = advice;
    1063 
    1064                 __submit_wait
    1065         #endif
    1066 }
    1067 
    1068 int cfa_madvise(void *addr, size_t length, int advice) {
    1069         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_MADVISE)
    1070                 return madvise( addr, length, advice );
    1071         #else
    1072                 __submit_prelude
    1073 
    1074                 (*sqe){ IORING_OP_MADVISE, 0 };
    1075                 sqe->addr = (uint64_t)addr;
    1076                 sqe->len = length;
    1077                 sqe->fadvise_advice = advice;
    1078 
    1079                 __submit_wait
    1080         #endif
    1081 }
    1082 
    1083 int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode) {
    1084         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_OPENAT)
    1085                 return openat( dirfd, pathname, flags, mode );
    1086         #else
    1087                 __submit_prelude
    1088 
    1089                 (*sqe){ IORING_OP_OPENAT, dirfd };
    1090                 sqe->addr = (uint64_t)pathname;
    1091                 sqe->open_flags = flags;
    1092                 sqe->mode = mode;
    1093 
    1094                 __submit_wait
    1095         #endif
    1096 }
    1097 
    1098 int cfa_close(int fd) {
    1099         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CLOSE)
    1100                 return close( fd );
    1101         #else
    1102                 __submit_prelude
    1103 
    1104                 (*sqe){ IORING_OP_CLOSE, fd };
    1105 
    1106                 __submit_wait
    1107         #endif
    1108 }
    1109 
    1110 
    1111 ssize_t cfa_read(int fd, void *buf, size_t count) {
    1112         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READ)
    1113                 return read( fd, buf, count );
    1114         #else
    1115                 __submit_prelude
    1116 
    1117                 (*sqe){ IORING_OP_READ, fd, buf, count, 0 };
    1118 
    1119                 __submit_wait
    1120         #endif
    1121 }
    1122 
    1123 ssize_t cfa_write(int fd, void *buf, size_t count) {
    1124         #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITE)
    1125                 return read( fd, buf, count );
    1126         #else
    1127                 __submit_prelude
    1128 
    1129                 (*sqe){ IORING_OP_WRITE, fd, buf, count, 0 };
    1130 
    1131                 __submit_wait
    1132         #endif
    1133 }
    1134 
    1135 //-----------------------------------------------------------------------------
    1136 // Check if a function is asynchronous
    1137 
    1138 // Macro magic to reduce the size of the following switch case
    1139 #define IS_DEFINED_APPLY(f, ...) f(__VA_ARGS__)
    1140 #define IS_DEFINED_SECOND(first, second, ...) second
    1141 #define IS_DEFINED_TEST(expansion) _CFA_IO_FEATURE_##expansion
    1142 #define IS_DEFINED(macro) IS_DEFINED_APPLY( IS_DEFINED_SECOND,IS_DEFINED_TEST(macro) false, true)
    1143 
    1144 bool has_user_level_blocking( fptr_t func ) {
    1145         #if defined(HAVE_LINUX_IO_URING_H)
    1146                 #if defined(HAVE_PREADV2)
    1147                         if( /*func == (fptr_t)preadv2 || */
    1148                                 func == (fptr_t)cfa_preadv2 )
    1149                                 #define _CFA_IO_FEATURE_IORING_OP_READV ,
    1150                                 return IS_DEFINED(IORING_OP_READV);
    1151                 #endif
    1152 
    1153                 #if defined(HAVE_PWRITEV2)
    1154                         if( /*func == (fptr_t)pwritev2 || */
    1155                                 func == (fptr_t)cfa_pwritev2 )
    1156                                 #define _CFA_IO_FEATURE_IORING_OP_WRITEV ,
    1157                                 return IS_DEFINED(IORING_OP_WRITEV);
    1158                 #endif
    1159 
    1160                 if( /*func == (fptr_t)fsync || */
    1161                         func == (fptr_t)cfa_fsync )
    1162                         #define _CFA_IO_FEATURE_IORING_OP_FSYNC ,
    1163                         return IS_DEFINED(IORING_OP_FSYNC);
    1164 
    1165                 if( /*func == (fptr_t)ync_file_range || */
    1166                         func == (fptr_t)cfa_sync_file_range )
    1167                         #define _CFA_IO_FEATURE_IORING_OP_SYNC_FILE_RANGE ,
    1168                         return IS_DEFINED(IORING_OP_SYNC_FILE_RANGE);
    1169 
    1170                 if( /*func == (fptr_t)sendmsg || */
    1171                         func == (fptr_t)cfa_sendmsg )
    1172                         #define _CFA_IO_FEATURE_IORING_OP_SENDMSG ,
    1173                         return IS_DEFINED(IORING_OP_SENDMSG);
    1174 
    1175                 if( /*func == (fptr_t)recvmsg || */
    1176                         func == (fptr_t)cfa_recvmsg )
    1177                         #define _CFA_IO_FEATURE_IORING_OP_RECVMSG ,
    1178                         return IS_DEFINED(IORING_OP_RECVMSG);
    1179 
    1180                 if( /*func == (fptr_t)send || */
    1181                         func == (fptr_t)cfa_send )
    1182                         #define _CFA_IO_FEATURE_IORING_OP_SEND ,
    1183                         return IS_DEFINED(IORING_OP_SEND);
    1184 
    1185                 if( /*func == (fptr_t)recv || */
    1186                         func == (fptr_t)cfa_recv )
    1187                         #define _CFA_IO_FEATURE_IORING_OP_RECV ,
    1188                         return IS_DEFINED(IORING_OP_RECV);
    1189 
    1190                 if( /*func == (fptr_t)accept4 || */
    1191                         func == (fptr_t)cfa_accept4 )
    1192                         #define _CFA_IO_FEATURE_IORING_OP_ACCEPT ,
    1193                         return IS_DEFINED(IORING_OP_ACCEPT);
    1194 
    1195                 if( /*func == (fptr_t)connect || */
    1196                         func == (fptr_t)cfa_connect )
    1197                         #define _CFA_IO_FEATURE_IORING_OP_CONNECT ,
    1198                         return IS_DEFINED(IORING_OP_CONNECT);
    1199 
    1200                 if( /*func == (fptr_t)fallocate || */
    1201                         func == (fptr_t)cfa_fallocate )
    1202                         #define _CFA_IO_FEATURE_IORING_OP_FALLOCATE ,
    1203                         return IS_DEFINED(IORING_OP_FALLOCATE);
    1204 
    1205                 if( /*func == (fptr_t)posix_fadvise || */
    1206                         func == (fptr_t)cfa_fadvise )
    1207                         #define _CFA_IO_FEATURE_IORING_OP_FADVISE ,
    1208                         return IS_DEFINED(IORING_OP_FADVISE);
    1209 
    1210                 if( /*func == (fptr_t)madvise || */
    1211                         func == (fptr_t)cfa_madvise )
    1212                         #define _CFA_IO_FEATURE_IORING_OP_MADVISE ,
    1213                         return IS_DEFINED(IORING_OP_MADVISE);
    1214 
    1215                 if( /*func == (fptr_t)openat || */
    1216                         func == (fptr_t)cfa_openat )
    1217                         #define _CFA_IO_FEATURE_IORING_OP_OPENAT ,
    1218                         return IS_DEFINED(IORING_OP_OPENAT);
    1219 
    1220                 if( /*func == (fptr_t)close || */
    1221                         func == (fptr_t)cfa_close )
    1222                         #define _CFA_IO_FEATURE_IORING_OP_CLOSE ,
    1223                         return IS_DEFINED(IORING_OP_CLOSE);
    1224 
    1225                 if( /*func == (fptr_t)read || */
    1226                         func == (fptr_t)cfa_read )
    1227                         #define _CFA_IO_FEATURE_IORING_OP_READ ,
    1228                         return IS_DEFINED(IORING_OP_READ);
    1229 
    1230                 if( /*func == (fptr_t)write || */
    1231                         func == (fptr_t)cfa_write )
    1232                         #define _CFA_IO_FEATURE_IORING_OP_WRITE ,
    1233                         return IS_DEFINED(IORING_OP_WRITE);
    1234         #endif
    1235 
    1236         return false;
    1237 }
  • libcfa/src/concurrency/kernel_private.hfa

    rc33ed65 r31bb2e1  
    277277
    278278//-----------------------------------------------------------------------
     279// IO user data
     280struct __io_user_data_t {
     281        int32_t result;
     282        $thread * thrd;
     283};
     284
     285//-----------------------------------------------------------------------
    279286// Statics call at the end of each thread to register statistics
    280287#if !defined(__CFA_NO_STATISTICS__)
Note: See TracChangeset for help on using the changeset viewer.