Ignore:
Timestamp:
Apr 25, 2025, 7:39:09 AM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
65bd3c2
Parents:
b195498
Message:

change backquote call to regular call

File:
1 edited

Legend:

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

    rb195498 r6b33e89  
    9595        static inline void __post(oneshot & this, bool kernel, unpark_hint hint) {
    9696                thread$ * t = post( this, false );
    97                 if(kernel) __kernel_unpark( t, hint );
     97                if (kernel) __kernel_unpark( t, hint );
    9898                else unpark( t, hint );
    9999        }
     
    108108                        // do the system call in a loop, repeat on interrupts
    109109                        ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, flags, (sigset_t *)0p, _NSIG / 8);
    110                         if( ret < 0 ) {
     110                        if ( ret < 0 ) {
    111111                                switch((int)errno) {
    112112                                case EINTR:
     
    154154                        const __u32 tail = *ctx->cq.tail;
    155155
    156                         if(head == tail) return false;
     156                        if (head == tail) return false;
    157157                }
    158158
    159159                // try a simple spinlock acquire, it's likely there are completions to drain
    160                 if(!__atomic_try_acquire(&ctx->cq.try_lock)) {
     160                if ( ! __atomic_try_acquire(&ctx->cq.try_lock)) {
    161161                        // some other processor already has it
    162162                        __STATS__( false, io.calls.locked++; )
     
    214214
    215215                        // we finished draining the completions... unless the ring buffer was full and there are more secret completions in the kernel.
    216                         if(likely(count < num)) break;
     216                        if (likely(count < num)) break;
    217217
    218218                        // the ring buffer was full, there could be more stuff in the kernel.
     
    243243
    244244                // if submitting must be submitted, do the system call
    245                 if(ctx.sq.to_submit != 0) {
     245                if (ctx.sq.to_submit != 0) {
    246246                        ioring_syscsll(ctx, 0, 0);
    247247                }
     
    278278                        // only help once every other time
    279279                        // pick a target when not helping
    280                         if(proc->io.target == UINT_MAX) {
     280                        if (proc->io.target == UINT_MAX) {
    281281                                uint64_t chaos = __tls_rand();
    282282                                // choose who to help and whether to accept helping far processors
     
    285285
    286286                                // if the processor is on the same cache line or is lucky ( 3 out of 256 odds ) help it
    287                                 if(ext < 3 || __atomic_load_n(&caches[other / __shard_factor.io].id, __ATOMIC_RELAXED) == this_cache) {
     287                                if (ext < 3 || __atomic_load_n(&caches[other / __shard_factor.io].id, __ATOMIC_RELAXED) == this_cache) {
    288288                                        proc->io.target = other;
    289289                                }
     
    294294                                /* paranoid */ verify( io.tscs[target].t.tv != ULLONG_MAX );
    295295                                // make sure the target hasn't stopped existing since last time
    296                                 HELP: if(target < ctxs_count) {
     296                                HELP: if (target < ctxs_count) {
    297297                                        // calculate it's age and how young it could be before we give up on helping
    298298                                        const __readyQ_avg_t cutoff = calc_cutoff(ctsc, ctx->cq.id, ctxs_count, io.data, io.tscs, __shard_factor.io, false);
     
    300300                                        __cfadbg_print_safe(io, "Kernel I/O: Help attempt on %u from %u, age %'llu vs cutoff %'llu, %s\n", target, ctx->cq.id, age, cutoff, age > cutoff ? "yes" : "no");
    301301                                        // is the target older than the cutoff, recall 0 is oldest and bigger ints are younger
    302                                         if(age <= cutoff) break HELP;
     302                                        if (age <= cutoff) break HELP;
    303303
    304304                                        // attempt to help the submission side
     
    306306
    307307                                        // attempt to help the completion side
    308                                         if(!try_acquire(io.data[target])) break HELP; // already acquire no help needed
     308                                        if ( ! try_acquire(io.data[target])) break HELP; // already acquire no help needed
    309309
    310310                                        // actually help
    311                                         if(!__cfa_do_drain( io.data[target], cltr )) break HELP;
     311                                        if ( ! __cfa_do_drain( io.data[target], cltr )) break HELP;
    312312
    313313                                        // track we did help someone
     
    322322
    323323                // Drain the local queue
    324                 if(try_acquire( proc->io.ctx )) {
     324                if (try_acquire( proc->io.ctx )) {
    325325                        local = __cfa_do_drain( proc->io.ctx, cltr );
    326326                }
     
    390390
    391391                // If we don't have enough sqes, fail
    392                 if((ftail - fhead) < want) { return false; }
     392                if ((ftail - fhead) < want) { return false; }
    393393
    394394                // copy all the indexes we want from the available list
     
    422422
    423423                // We can proceed to the fast path
    424                 if( __alloc(ctx, idxs, want) ) {
     424                if ( __alloc(ctx, idxs, want) ) {
    425425                        // Allocation was successful
    426426                        __STATS__( true, io.alloc.fast += 1; )
     
    456456        // barebones logic to submit a group of sqes
    457457        static inline void __submit_only( struct io_context$ * ctx, __u32 idxs[], __u32 have, bool lock) {
    458                 if(!lock)
     458                if ( ! lock)
    459459                        lock( ctx->ext_sq.lock __cfaabi_dbg_ctx2 );
    460460                // We can proceed to the fast path
     
    478478                __atomic_store_n(&ctx->proc->io.dirty  , true, __ATOMIC_RELAXED);
    479479
    480                 if(!lock)
     480                if ( ! lock)
    481481                        unlock( ctx->ext_sq.lock );
    482482        }
     
    487487                __submit_only(ctx, idxs, have, false);
    488488
    489                 if(sq.to_submit > 30) {
     489                if (sq.to_submit > 30) {
    490490                        __tls_stats()->io.flush.full++;
    491491                        __cfa_io_flush( ctx->proc );
    492492                }
    493                 if(!lazy) {
     493                if ( ! lazy ) {
    494494                        __tls_stats()->io.flush.eager++;
    495495                        __cfa_io_flush( ctx->proc );
     
    503503
    504504                disable_interrupts();
    505                 __STATS__( true, if(!lazy) io.submit.eagr += 1; )
     505                __STATS__( true, if ( ! lazy ) io.submit.eagr += 1; )
    506506                struct processor * proc = __cfaabi_tls.this_processor;
    507507                io_context$ * ctx = proc->io.ctx;
     
    510510
    511511                // Can we proceed to the fast path
    512                 if( ctx == inctx )              // We have the right instance?
     512                if ( ctx == inctx )             // We have the right instance?
    513513                {
    514514                        // yes! fast submit
     
    564564                __u32 count = chead - phead;
    565565
    566                 if(count == 0) {
     566                if (count == 0) {
    567567                        return 0;
    568568                }
     
    594594                lock( queue.lock __cfaabi_dbg_ctx2 );
    595595                {
    596                         was_empty = queue.queue`isEmpty;
     596                        was_empty = isEmpty( queue.queue );
    597597
    598598                        // Add our request to the list
     
    632632        // notify the arbiter that new allocations are available
    633633        static void __ioarbiter_notify( io_arbiter$ & this, io_context$ * ctx ) {
    634                 /* paranoid */ verify( !this.pending.queue`isEmpty );
     634                /* paranoid */ verify( ! isEmpty( this.pending.queue ) );
    635635                /* paranoid */ verify( __preemption_enabled() );
    636636
     
    642642                        // as long as there are pending allocations try to satisfy them
    643643                        // for simplicity do it in FIFO order
    644                         while( !this.pending.queue`isEmpty ) {
     644                        while( ! isEmpty( this.pending.queue ) ) {
    645645                                // get first pending allocs
    646646                                __u32 have = ctx->sq.free_ring.tail - ctx->sq.free_ring.head;
    647                                 __pending_alloc & pa = (__pending_alloc&)(this.pending.queue`first);
     647                                __pending_alloc & pa = (__pending_alloc&)( first( this.pending.queue ));
    648648
    649649                                // check if we have enough to satisfy the request
    650                                 if( have > pa.want ) goto DONE;
     650                                if ( have > pa.want ) goto DONE;
    651651
    652652                                // if there are enough allocations it means we can drop the request
    653                                 try_pop_front( this.pending.queue );
     653                                remove_first( this.pending.queue );
    654654
    655655                                /* paranoid */__attribute__((unused)) bool ret =
     
    676676        // short hand to avoid the mutual exclusion of the pending is empty regardless
    677677        static void __ioarbiter_notify( io_context$ & ctx ) {
    678                 if(empty( ctx.arbiter->pending )) return;
     678                if (empty( ctx.arbiter->pending )) return;
    679679                __ioarbiter_notify( *ctx.arbiter, &ctx );
    680680        }
     
    700700                // if this is the first to be enqueued, signal the processor in an attempt to speed up flushing
    701701                // if it's not the first enqueue, a signal is already in transit
    702                 if( we ) {
     702                if ( we ) {
    703703                        sigval_t value = { PREEMPT_IO };
    704704                        __cfaabi_pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
     
    716716        static void __ioarbiter_flush( io_context$ & ctx, bool kernel ) {
    717717                // if there are no external operations just return
    718                 if(empty( ctx.ext_sq )) return;
     718                if ( empty( ctx.ext_sq ) ) return;
    719719
    720720                // stats and logs
     
    727727                        // pop each operation one at a time.
    728728                        // There is no wait morphing because of the io sq ring
    729                         while( !ctx.ext_sq.queue`isEmpty ) {
     729                        while( ! isEmpty( ctx.ext_sq.queue ) ) {
    730730                                // drop the element from the queue
    731                                 __external_io & ei = (__external_io&)try_pop_front( ctx.ext_sq.queue );
     731                                __external_io & ei = (__external_io&)remove_first( ctx.ext_sq.queue );
    732732
    733733                                // submit it
Note: See TracChangeset for help on using the changeset viewer.