Ignore:
Timestamp:
Jan 1, 2022, 11:14:35 AM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
12c1eef
Parents:
7770cc8 (diff), db1ebed (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

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

    r7770cc8 r5235d49  
    3333                #include <sys/syscall.h>
    3434                #include <sys/eventfd.h>
     35                #include <sys/uio.h>
    3536
    3637                #include <linux/io_uring.h>
     
    133134        }
    134135
    135         bool __cfa_io_flush( processor * proc, bool wait ) {
     136        bool __cfa_io_flush( processor * proc, int min_comp ) {
    136137                /* paranoid */ verify( ! __preemption_enabled() );
    137138                /* paranoid */ verify( proc );
     
    144145
    145146                __STATS__( true, io.calls.flush++; )
    146                 int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, wait ? 1 : 0, 0, (sigset_t *)0p, _NSIG / 8);
     147                int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, min_comp > 0 ? IORING_ENTER_GETEVENTS : 0, (sigset_t *)0p, _NSIG / 8);
    147148                if( ret < 0 ) {
    148149                        switch((int)errno) {
     
    302303                ctx->proc->io.dirty   = true;
    303304                if(sq.to_submit > 30 || !lazy) {
    304                         __cfa_io_flush( ctx->proc, false );
     305                        __cfa_io_flush( ctx->proc, 0 );
    305306                }
    306307        }
     
    502503        }
    503504
    504         #if defined(IO_URING_IDLE)
    505                 bool __kernel_read(processor * proc, io_future_t & future, char buf[], int fd) {
     505        #if defined(CFA_WITH_IO_URING_IDLE)
     506                bool __kernel_read(processor * proc, io_future_t & future, iovec & iov, int fd) {
    506507                        $io_context * ctx = proc->io.ctx;
    507508                        /* paranoid */ verify( ! __preemption_enabled() );
     
    518519                        __fill( &sqe, 1, &idx, ctx );
    519520
    520                         sqe->opcode = IORING_OP_READ;
    521521                        sqe->user_data = (uintptr_t)&future;
    522522                        sqe->flags = 0;
     523                        sqe->fd = fd;
     524                        sqe->off = 0;
    523525                        sqe->ioprio = 0;
    524                         sqe->fd = 0;
    525                         sqe->off = 0;
    526526                        sqe->fsync_flags = 0;
    527527                        sqe->__pad2[0] = 0;
    528528                        sqe->__pad2[1] = 0;
    529529                        sqe->__pad2[2] = 0;
    530                         sqe->addr = (uintptr_t)buf;
    531                         sqe->len = sizeof(uint64_t);
     530
     531                        #if defined(CFA_HAVE_IORING_OP_READ)
     532                                sqe->opcode = IORING_OP_READ;
     533                                sqe->addr = (uint64_t)iov.iov_base;
     534                                sqe->len = iov.iov_len;
     535                        #elif defined(CFA_HAVE_READV) && defined(CFA_HAVE_IORING_OP_READV)
     536                                sqe->opcode = IORING_OP_READV;
     537                                sqe->addr = (uintptr_t)&iov;
     538                                sqe->len = 1;
     539                        #else
     540                                #error CFA_WITH_IO_URING_IDLE but none of CFA_HAVE_READV, CFA_HAVE_IORING_OP_READV or CFA_HAVE_IORING_OP_READ defined
     541                        #endif
    532542
    533543                        asm volatile("": : :"memory");
  • libcfa/src/concurrency/io/setup.cfa

    r7770cc8 r5235d49  
    3232
    3333        void __cfa_io_start( processor * proc ) {}
    34         bool __cfa_io_flush( processor * proc, bool ) {}
     34        bool __cfa_io_flush( processor * proc, int ) {}
    3535        void __cfa_io_stop ( processor * proc ) {}
    3636
     
    220220                cq.cqes = (struct io_uring_cqe *)(((intptr_t)cq.ring_ptr) + params.cq_off.cqes);
    221221
    222                 #if !defined(IO_URING_IDLE)
     222                #if !defined(CFA_WITH_IO_URING_IDLE)
    223223                        // Step 4 : eventfd
    224224                        // io_uring_register is so f*cking slow on some machine that it
  • libcfa/src/concurrency/kernel.cfa

    r7770cc8 r5235d49  
    2727extern "C" {
    2828        #include <sys/eventfd.h>
     29        #include <sys/uio.h>
    2930}
    3031
     
    125126static void __wake_one(cluster * cltr);
    126127
    127 static void idle_sleep(processor * proc, io_future_t & future, char buf[]);
     128static void idle_sleep(processor * proc, io_future_t & future, iovec & iov);
    128129static bool mark_idle (__cluster_proc_list & idles, processor & proc);
    129130static void mark_awake(__cluster_proc_list & idles, processor & proc);
     
    131132extern void __cfa_io_start( processor * );
    132133extern bool __cfa_io_drain( processor * );
    133 extern bool __cfa_io_flush( processor *, bool wait );
     134extern bool __cfa_io_flush( processor *, int min_comp );
    134135extern void __cfa_io_stop ( processor * );
    135136static inline bool __maybe_io_drain( processor * );
    136137
    137 #if defined(IO_URING_IDLE) && defined(CFA_HAVE_LINUX_IO_URING_H)
    138         extern bool __kernel_read(processor * proc, io_future_t & future, char buf[], int fd);
     138#if defined(CFA_WITH_IO_URING_IDLE)
     139        extern bool __kernel_read(processor * proc, io_future_t & future, iovec &, int fd);
    139140#endif
    140141
     
    171172        io_future_t future; // used for idle sleep when io_uring is present
    172173        future.self.ptr = 1p;  // mark it as already fulfilled so we know if there is a pending request or not
    173         char buf[sizeof(uint64_t)];
     174        eventfd_t idle_val;
     175        iovec idle_iovec = { &idle_val, sizeof(idle_val) };
    174176
    175177        __cfa_io_start( this );
     
    206208
    207209                        if( !readyThread ) {
    208                                 __cfa_io_flush( this, false );
     210                                __cfa_io_flush( this, 0 );
    209211
    210212                                readyThread = __next_thread_slow( this->cltr );
     
    237239                                }
    238240
    239                                 idle_sleep( this, future, buf );
     241                                idle_sleep( this, future, idle_iovec );
    240242
    241243                                // We were woken up, remove self from idle
     
    258260
    259261                        if(this->io.pending && !this->io.dirty) {
    260                                 __cfa_io_flush( this, false );
     262                                __cfa_io_flush( this, 0 );
    261263                        }
    262264
     
    274276
    275277                                // If we can't find a thread, might as well flush any outstanding I/O
    276                                 if(this->io.pending) { __cfa_io_flush( this, false ); }
     278                                if(this->io.pending) { __cfa_io_flush( this, 0 ); }
    277279
    278280                                // Spin a little on I/O, just in case
     
    369371
    370372                        if(this->io.pending && !this->io.dirty) {
    371                                 __cfa_io_flush( this, false );
     373                                __cfa_io_flush( this, 0 );
    372374                        }
    373375
     
    379381
    380382                __cfadbg_print_safe(runtime_core, "Kernel : core %p stopping\n", this);
     383        }
     384
     385        for(int i = 0; !available(future); i++) {
     386                if(i > 1000) __cfaabi_dbg_write( "ERROR: kernel has bin spinning on a flush after exit loop.\n", 60);
     387                __cfa_io_flush( this, 1 );
    381388        }
    382389
     
    779786}
    780787
    781 static void idle_sleep(processor * this, io_future_t & future, char buf[]) {
    782         #if !defined(IO_URING_IDLE) || !defined(CFA_HAVE_LINUX_IO_URING_H)
     788static void idle_sleep(processor * this, io_future_t & future, iovec & iov) {
     789        #if !defined(CFA_WITH_IO_URING_IDLE)
    783790                #if !defined(__CFA_NO_STATISTICS__)
    784791                        if(this->print_halts) {
     
    813820                #endif
    814821        #else
    815                 #if !defined(CFA_HAVE_IORING_OP_READ)
    816                         #error this is only implemented if the read is present
    817                 #endif
    818822                // Do we already have a pending read
    819823                if(available(future)) {
     
    821825                        reset(future);
    822826
    823                         __kernel_read(this, future, buf, this->idle_fd );
    824                 }
    825 
    826                 __cfa_io_flush( this, true );
     827                        __kernel_read(this, future, iov, this->idle_fd );
     828                }
     829
     830                __cfa_io_flush( this, 1 );
    827831        #endif
    828832}
  • libcfa/src/concurrency/kernel_private.hfa

    r7770cc8 r5235d49  
    3939}
    4040
    41 // #define IO_URING_IDLE
     41// Defines whether or not we *want* to use io_uring_enter as the idle_sleep blocking call
     42#define CFA_WANT_IO_URING_IDLE
     43
     44// Defines whether or not we *can* use io_uring_enter as the idle_sleep blocking call
     45#if defined(CFA_WANT_IO_URING_IDLE) && defined(CFA_HAVE_LINUX_IO_URING_H)
     46        #if defined(CFA_HAVE_IORING_OP_READ) || (defined(CFA_HAVE_READV) && defined(CFA_HAVE_IORING_OP_READV))
     47                #define CFA_WITH_IO_URING_IDLE
     48        #endif
     49#endif
    4250
    4351//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.