Ignore:
Timestamp:
Mar 21, 2022, 1:44:06 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
a76202d
Parents:
ef3c383 (diff), dbe2533 (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

File:
1 edited

Legend:

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

    ref3c383 rd672350  
    4141        #include "kernel.hfa"
    4242        #include "kernel/fwd.hfa"
    43         #include "kernel_private.hfa"
     43        #include "kernel/private.hfa"
    4444        #include "io/types.hfa"
    4545
     
    9393        extern void __kernel_unpark( thread$ * thrd, unpark_hint );
    9494
    95         bool __cfa_io_drain( processor * proc ) {
     95        bool __cfa_io_drain( $io_context * ctx ) {
    9696                /* paranoid */ verify( ! __preemption_enabled() );
    9797                /* paranoid */ verify( ready_schedule_islocked() );
    98                 /* paranoid */ verify( proc );
    99                 /* paranoid */ verify( proc->io.ctx );
     98                /* paranoid */ verify( ctx );
    10099
    101100                // Drain the queue
    102                 $io_context * ctx = proc->io.ctx;
    103101                unsigned head = *ctx->cq.head;
    104102                unsigned tail = *ctx->cq.tail;
     
    110108                if(count == 0) return false;
    111109
     110                if(!__atomic_try_acquire(&ctx->cq.lock)) {
     111                        return false;
     112                }
     113
    112114                for(i; count) {
    113115                        unsigned idx = (head + i) & mask;
     
    130132                /* paranoid */ verify( ready_schedule_islocked() );
    131133                /* paranoid */ verify( ! __preemption_enabled() );
     134
     135                __atomic_unlock(&ctx->cq.lock);
    132136
    133137                return true;
     
    175179                        /* paranoid */ verify( ! __preemption_enabled() );
    176180
    177                         ctx.proc->io.pending = false;
     181                        __atomic_store_n(&ctx.proc->io.pending, false, __ATOMIC_RELAXED);
    178182                }
    179183
    180184                ready_schedule_lock();
    181                 bool ret = __cfa_io_drain( proc );
     185                bool ret = __cfa_io_drain( &ctx );
    182186                ready_schedule_unlock();
    183187                return ret;
     
    287291        //=============================================================================================
    288292        // submission
    289         static inline void __submit( struct $io_context * ctx, __u32 idxs[], __u32 have, bool lazy) {
     293        static inline void __submit_only( struct $io_context * ctx, __u32 idxs[], __u32 have) {
    290294                // We can proceed to the fast path
    291295                // Get the right objects
     
    304308                sq.to_submit += have;
    305309
    306                 ctx->proc->io.pending = true;
    307                 ctx->proc->io.dirty   = true;
     310                __atomic_store_n(&ctx->proc->io.pending, true, __ATOMIC_RELAXED);
     311                __atomic_store_n(&ctx->proc->io.dirty  , true, __ATOMIC_RELAXED);
     312        }
     313
     314        static inline void __submit( struct $io_context * ctx, __u32 idxs[], __u32 have, bool lazy) {
     315                __sub_ring_t & sq = ctx->sq;
     316                __submit_only(ctx, idxs, have);
     317
    308318                if(sq.to_submit > 30) {
    309319                        __tls_stats()->io.flush.full++;
     
    402412// I/O Arbiter
    403413//=============================================================================================
    404         static inline void block(__outstanding_io_queue & queue, __outstanding_io & item) {
     414        static inline bool enqueue(__outstanding_io_queue & queue, __outstanding_io & item) {
     415                bool was_empty;
     416
    405417                // Lock the list, it's not thread safe
    406418                lock( queue.lock __cfaabi_dbg_ctx2 );
    407419                {
     420                        was_empty = empty(queue.queue);
     421
    408422                        // Add our request to the list
    409423                        add( queue.queue, item );
     
    414428                unlock( queue.lock );
    415429
    416                 wait( item.sem );
     430                return was_empty;
    417431        }
    418432
     
    432446                pa.want = want;
    433447
    434                 block(this.pending, (__outstanding_io&)pa);
     448                enqueue(this.pending, (__outstanding_io&)pa);
     449
     450                wait( pa.sem );
    435451
    436452                return pa.ctx;
     
    485501                ei.lazy = lazy;
    486502
    487                 block(ctx->ext_sq, (__outstanding_io&)ei);
     503                bool we = enqueue(ctx->ext_sq, (__outstanding_io&)ei);
     504
     505                __atomic_store_n(&ctx->proc->io.pending, true, __ATOMIC_SEQ_CST);
     506
     507                if( we ) {
     508                        sigval_t value = { PREEMPT_IO };
     509                        pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
     510                }
     511
     512                wait( ei.sem );
    488513
    489514                __cfadbg_print_safe(io, "Kernel I/O : %u submitted from arbiter\n", have);
     
    501526                                        __external_io & ei = (__external_io&)drop( ctx.ext_sq.queue );
    502527
    503                                         __submit(&ctx, ei.idxs, ei.have, ei.lazy);
     528                                        __submit_only(&ctx, ei.idxs, ei.have);
    504529
    505530                                        post( ei.sem );
Note: See TracChangeset for help on using the changeset viewer.