Changeset df40a56 for libcfa


Ignore:
Timestamp:
Jul 1, 2020, 3:06:46 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:
4ec028d
Parents:
c33ed65
Message:

minor improvements to io

File:
1 edited

Legend:

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

    rc33ed65 rdf40a56  
    580580                                int count;
    581581                                bool again;
    582                                 [count, again] = __drain_io( ring, &mask, 1, true );
     582                                [count, again] = __drain_io( ring, &mask, 0, true );
    583583
    584584                                // Update statistics
     
    593593
    594594                unregister( &ring.poller.slow.id );
     595
     596                #if !defined(__CFA_NO_STATISTICS__)
     597                        __tally_stats(cltr->stats, &local_stats);
     598                #endif
    595599
    596600                return 0p;
     
    681685//
    682686
     687        // [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) __attribute__((noinline));
    683688        static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
    684689                verify( data != 0 );
     
    730735        }
    731736
     737        static inline uint32_t __submit_to_ready_array( struct __io_data & ring, uint32_t idx, const uint32_t mask ) {
     738                /* paranoid */ verify( idx <= mask   );
     739                /* paranoid */ verify( idx != -1ul32 );
     740
     741                // We need to find a spot in the ready array
     742                __attribute((unused)) int len   = 0;
     743                __attribute((unused)) int block = 0;
     744                uint32_t ready_mask = ring.submit_q.ready_cnt - 1;
     745
     746                disable_interrupts();
     747                        uint32_t off = __tls_rand();
     748                enable_interrupts( __cfaabi_dbg_ctx );
     749
     750                uint32_t picked;
     751                LOOKING: for() {
     752                        for(i; ring.submit_q.ready_cnt) {
     753                                picked = (i + off) & ready_mask;
     754                                uint32_t expected = -1ul32;
     755                                if( __atomic_compare_exchange_n( &ring.submit_q.ready[picked], &expected, idx, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) ) {
     756                                        break LOOKING;
     757                                }
     758                                verify(expected != idx);
     759
     760                                len ++;
     761                        }
     762
     763                        block++;
     764                        yield();
     765                }
     766
     767                // update statistics
     768                #if !defined(__CFA_NO_STATISTICS__)
     769                disable_interrupts();
     770                        __tls_stats()->io.submit_q.look_avg.val   += len;
     771                        __tls_stats()->io.submit_q.look_avg.block += block;
     772                        __tls_stats()->io.submit_q.look_avg.cnt   += 1;
     773                enable_interrupts( __cfaabi_dbg_ctx );
     774                #endif
     775
     776                return picked;
     777        }
     778
     779        // void __submit( struct __io_data & ring, uint32_t idx ) __attribute__((noinline));
    732780        static inline void __submit( struct __io_data & ring, uint32_t idx ) {
    733781                // Get now the data we definetely need
     
    735783                const uint32_t mask = *ring.submit_q.mask;
    736784
    737                 disable_interrupts();
    738 
    739785                // There are 2 submission schemes, check which one we are using
    740786                if( ring.cltr_flags & CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS ) {
    741787                        // If the poller thread submits, then we just need to add this to the ready array
    742788
    743                         /* paranoid */ verify( idx <= mask   );
    744                         /* paranoid */ verify( idx != -1ul32 );
    745 
    746                         // We need to find a spot in the ready array
    747                         __attribute((unused)) int len   = 0;
    748                         __attribute((unused)) int block = 0;
    749                         uint32_t ready_mask = ring.submit_q.ready_cnt - 1;
    750                         uint32_t off = __tls_rand();
    751                         LOOKING: for() {
    752                                 for(i; ring.submit_q.ready_cnt) {
    753                                         uint32_t ii = (i + off) & ready_mask;
    754                                         uint32_t expected = -1ul32;
    755                                         if( __atomic_compare_exchange_n( &ring.submit_q.ready[ii], &expected, idx, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) ) {
    756                                                 break LOOKING;
    757                                         }
    758                                         verify(expected != idx);
    759 
    760                                         len ++;
    761                                 }
    762 
    763                                 block++;
    764                                 yield();
    765                         }
     789                        __submit_to_ready_array( ring, idx, mask );
    766790
    767791                        __wake_poller( ring );
    768 
    769                         // update statistics
    770                         #if !defined(__CFA_NO_STATISTICS__)
    771                                 __tls_stats()->io.submit_q.look_avg.val   += len;
    772                                 __tls_stats()->io.submit_q.look_avg.block += block;
    773                                 __tls_stats()->io.submit_q.look_avg.cnt   += 1;
    774                         #endif
    775792
    776793                        __cfadbg_print_safe( io, "Kernel I/O : Added %u to ready for %p\n", idx, active_thread() );
     
    808825                        __cfadbg_print_safe( io, "Kernel I/O : Performed io_submit for %p, returned %d\n", active_thread(), ret );
    809826                }
    810 
    811                 enable_interrupts( __cfaabi_dbg_ctx );
    812827        }
    813828
Note: See TracChangeset for help on using the changeset viewer.