Ignore:
Timestamp:
Feb 19, 2021, 3:10:10 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4c4d854
Parents:
4f762d3
Message:

Fixed statistic for new io approach

Location:
libcfa/src/concurrency
Files:
3 edited

Legend:

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

    r4f762d3 rd60d30e  
    1717
    1818#if defined(__CFA_DEBUG__)
    19         #define __CFA_DEBUG_PRINT_IO__
    20         #define __CFA_DEBUG_PRINT_IO_CORE__
     19        // #define __CFA_DEBUG_PRINT_IO__
     20        // #define __CFA_DEBUG_PRINT_IO_CORE__
    2121#endif
    2222
     
    8383//=============================================================================================
    8484        static int __io_uring_enter( struct $io_context & ctx, unsigned to_submit, bool get ) {
     85                __STATS__( false, io.calls.count++; )
    8586                bool need_sys_to_submit = false;
    8687                bool need_sys_to_complete = false;
     
    109110                if( need_sys_to_submit || need_sys_to_complete ) {
    110111                        __cfadbg_print_safe(io_core, "Kernel I/O : IO_URING enter %d %u %u\n", ctx.fd, to_submit, flags);
     112                        __STATS__( false, io.calls.blocks++; )
    111113                        ret = syscall( __NR_io_uring_enter, ctx.fd, to_submit, 0, flags, (sigset_t *)0p, _NSIG / 8);
    112114                        __cfadbg_print_safe(io_core, "Kernel I/O : IO_URING %d returned %d\n", ctx.fd, ret);
     
    124126        static inline __u32 __release_sqes( struct $io_context & );
    125127
    126         static [int, bool] __drain_io( & struct  $io_context ctx ) {
     128        static bool __drain_io( struct  $io_context & ctx ) {
    127129                unsigned to_submit = __flush( ctx );
    128130                int ret = __io_uring_enter( ctx, to_submit, true );
     
    132134                        case EINTR:
    133135                        case EBUSY:
    134                                 return [0, true];
     136                                // Update statistics
     137                                __STATS__( false, io.calls.errors.busy ++; )
     138                                return true;
    135139                                break;
    136140                        default:
     
    141145                // update statistics
    142146                if (to_submit > 0) {
    143                         __STATS__( false,
    144                                 if( to_submit > 0 ) {
    145                                         io.submit_q.submit_avg.rdy += to_submit;
    146                                         io.submit_q.submit_avg.csm += ret;
    147                                         io.submit_q.submit_avg.cnt += 1;
    148                                 }
    149                         )
     147                        __STATS__( false, io.calls.submitted += ret; )
    150148                        /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
    151149
     
    170168                // Nothing was new return 0
    171169                if (head == tail) {
    172                         return [0, to_submit > 0];
     170                        return ctx.sq.to_submit > 0;
    173171                }
    174172
    175173                __u32 count = tail - head;
    176174                /* paranoid */ verify( count != 0 );
     175                __STATS__( false, io.calls.submitted += count; )
     176
    177177                for(i; count) {
    178178                        unsigned idx = (head + i) & mask;
     
    195195                __atomic_store_n( ctx.cq.head, head + count, __ATOMIC_SEQ_CST );
    196196
    197                 return [count, count > 0 || to_submit > 0];
     197                return count > 0 || to_submit > 0;
    198198        }
    199199
     
    212212
    213213                        // Drain the io
    214                         int count;
    215                         bool again;
    216                         [count, again] = __drain_io( this );
     214                        bool again = __drain_io( this );
    217215
    218216                        if(!again) reset--;
    219 
    220                         // Update statistics
    221                         __STATS__( false,
    222                                 io.complete_q.completed_avg.val += count;
    223                                 io.complete_q.completed_avg.cnt += 1;
    224                         )
    225217
    226218                        // If we got something, just yield and check again
     
    241233
    242234                        __STATS__( false,
    243                                 io.complete_q.blocks += 1;
     235                                io.calls.blocks += 1;
    244236                        )
    245237                        __cfadbg_print_safe(io_core, "Kernel I/O : Parking io poller %d (%p)\n", this.fd, &this);
     
    342334                                // Mark the instance as no longer in-use and re-enable interrupts
    343335                                __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE );
     336                                __STATS__( true, io.alloc.fast += 1; )
    344337                                enable_interrupts( __cfaabi_dbg_ctx );
    345338
     
    350343                        }
    351344                        // The fast path failed, fallback
     345                        __STATS__( true, io.alloc.fail += 1; )
    352346                }
    353347
    354348                // Fast path failed, fallback on arbitration
    355349                __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE );
     350                __STATS__( true, io.alloc.slow += 1; )
    356351                enable_interrupts( __cfaabi_dbg_ctx );
    357352
     
    409404                        // Mark the instance as no longer in-use, re-enable interrupts and return
    410405                        __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE );
     406                        __STATS__( true, io.submit.fast += 1; )
    411407                        enable_interrupts( __cfaabi_dbg_ctx );
    412408
     
    417413                // Fast path failed, fallback on arbitration
    418414                __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE );
     415                __STATS__( true, io.submit.slow += 1; )
    419416                enable_interrupts( __cfaabi_dbg_ctx );
    420417
     
    556553                        __revoke( this, c );
    557554
     555                        __STATS__( false, io.alloc.revoke += 1; )
     556
    558557                        if(__alloc(c, idxs, want)) {
    559558                                __assign( this, c, proc);
     
    564563                __cfadbg_print_safe(io, "Kernel I/O : waiting for available resources\n");
    565564
     565                __STATS__( false, io.alloc.block += 1; )
     566
    566567                // No one has any resources left, wait for something to finish
    567568                // Mark as pending
     
    626627        static void __ioarbiter_flush( $io_arbiter & mutex this, $io_context * ctx ) {
    627628                /* paranoid */ verify( &this == ctx->arbiter );
     629
     630                __STATS__( false, io.flush.external += 1; )
    628631
    629632                __revoke( this, ctx );
  • libcfa/src/concurrency/stats.cfa

    r4f762d3 rd60d30e  
    2525
    2626                #if defined(CFA_HAVE_LINUX_IO_URING_H)
    27                         stats->io.submit_q.submit_avg.rdy = 0;
    28                         stats->io.submit_q.submit_avg.csm = 0;
    29                         stats->io.submit_q.submit_avg.cnt = 0;
    30                         stats->io.submit_q.look_avg.val   = 0;
    31                         stats->io.submit_q.look_avg.cnt   = 0;
    32                         stats->io.submit_q.look_avg.block = 0;
    33                         stats->io.submit_q.alloc_avg.val   = 0;
    34                         stats->io.submit_q.alloc_avg.cnt   = 0;
    35                         stats->io.submit_q.alloc_avg.block = 0;
    36                         stats->io.submit_q.helped = 0;
    37                         stats->io.submit_q.leader = 0;
    38                         stats->io.submit_q.busy   = 0;
    39                         stats->io.complete_q.completed_avg.val = 0;
    40                         stats->io.complete_q.completed_avg.cnt = 0;
    41                         stats->io.complete_q.blocks = 0;
     27                        stats->io.alloc.fast        = 0;
     28                        stats->io.alloc.slow        = 0;
     29                        stats->io.alloc.fail        = 0;
     30                        stats->io.alloc.revoke      = 0;
     31                        stats->io.alloc.block       = 0;
     32                        stats->io.submit.fast       = 0;
     33                        stats->io.submit.slow       = 0;
     34                        stats->io.flush.external    = 0;
     35                        stats->io.calls.count       = 0;
     36                        stats->io.calls.submitted   = 0;
     37                        stats->io.calls.completed   = 0;
     38                        stats->io.calls.blocks      = 0;
     39                        stats->io.calls.errors.busy = 0;
    4240                #endif
    4341        }
     
    6058
    6159                #if defined(CFA_HAVE_LINUX_IO_URING_H)
    62                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy     , proc->io.submit_q.submit_avg.rdy     , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.rdy      = 0;
    63                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm     , proc->io.submit_q.submit_avg.csm     , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.csm      = 0;
    64                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl     , proc->io.submit_q.submit_avg.avl     , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.avl      = 0;
    65                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt     , proc->io.submit_q.submit_avg.cnt     , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.cnt      = 0;
    66                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.val       , proc->io.submit_q.look_avg.val       , __ATOMIC_SEQ_CST ); proc->io.submit_q.look_avg.val        = 0;
    67                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt       , proc->io.submit_q.look_avg.cnt       , __ATOMIC_SEQ_CST ); proc->io.submit_q.look_avg.cnt        = 0;
    68                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.block     , proc->io.submit_q.look_avg.block     , __ATOMIC_SEQ_CST ); proc->io.submit_q.look_avg.block      = 0;
    69                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val      , proc->io.submit_q.alloc_avg.val      , __ATOMIC_SEQ_CST ); proc->io.submit_q.alloc_avg.val       = 0;
    70                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt      , proc->io.submit_q.alloc_avg.cnt      , __ATOMIC_SEQ_CST ); proc->io.submit_q.alloc_avg.cnt       = 0;
    71                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block    , proc->io.submit_q.alloc_avg.block    , __ATOMIC_SEQ_CST ); proc->io.submit_q.alloc_avg.block     = 0;
    72                         __atomic_fetch_add( &cltr->io.submit_q.helped             , proc->io.submit_q.helped             , __ATOMIC_SEQ_CST ); proc->io.submit_q.helped              = 0;
    73                         __atomic_fetch_add( &cltr->io.submit_q.leader             , proc->io.submit_q.leader             , __ATOMIC_SEQ_CST ); proc->io.submit_q.leader              = 0;
    74                         __atomic_fetch_add( &cltr->io.submit_q.busy               , proc->io.submit_q.busy               , __ATOMIC_SEQ_CST ); proc->io.submit_q.busy                = 0;
    75                         __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val, proc->io.complete_q.completed_avg.val, __ATOMIC_SEQ_CST ); proc->io.complete_q.completed_avg.val = 0;
    76                         __atomic_fetch_add( &cltr->io.complete_q.completed_avg.cnt, proc->io.complete_q.completed_avg.cnt, __ATOMIC_SEQ_CST ); proc->io.complete_q.completed_avg.cnt = 0;
    77                         __atomic_fetch_add( &cltr->io.complete_q.blocks           , proc->io.complete_q.blocks           , __ATOMIC_SEQ_CST ); proc->io.complete_q.blocks            = 0;
     60                        __atomic_fetch_add( &cltr->io.alloc.fast       , proc->io.alloc.fast       , __ATOMIC_SEQ_CST ); proc->io.alloc.fast        = 0;
     61                        __atomic_fetch_add( &cltr->io.alloc.slow       , proc->io.alloc.slow       , __ATOMIC_SEQ_CST ); proc->io.alloc.slow        = 0;
     62                        __atomic_fetch_add( &cltr->io.alloc.fail       , proc->io.alloc.fail       , __ATOMIC_SEQ_CST ); proc->io.alloc.fail        = 0;
     63                        __atomic_fetch_add( &cltr->io.alloc.revoke     , proc->io.alloc.revoke     , __ATOMIC_SEQ_CST ); proc->io.alloc.revoke      = 0;
     64                        __atomic_fetch_add( &cltr->io.alloc.block      , proc->io.alloc.block      , __ATOMIC_SEQ_CST ); proc->io.alloc.block       = 0;
     65                        __atomic_fetch_add( &cltr->io.submit.fast      , proc->io.submit.fast      , __ATOMIC_SEQ_CST ); proc->io.submit.fast       = 0;
     66                        __atomic_fetch_add( &cltr->io.submit.slow      , proc->io.submit.slow      , __ATOMIC_SEQ_CST ); proc->io.submit.slow       = 0;
     67                        __atomic_fetch_add( &cltr->io.flush.external   , proc->io.flush.external   , __ATOMIC_SEQ_CST ); proc->io.flush.external    = 0;
     68                        __atomic_fetch_add( &cltr->io.calls.count      , proc->io.calls.count      , __ATOMIC_SEQ_CST ); proc->io.calls.count       = 0;
     69                        __atomic_fetch_add( &cltr->io.calls.submitted  , proc->io.calls.submitted  , __ATOMIC_SEQ_CST ); proc->io.calls.submitted   = 0;
     70                        __atomic_fetch_add( &cltr->io.calls.completed  , proc->io.calls.completed  , __ATOMIC_SEQ_CST ); proc->io.calls.completed   = 0;
     71                        __atomic_fetch_add( &cltr->io.calls.blocks     , proc->io.calls.blocks     , __ATOMIC_SEQ_CST ); proc->io.calls.blocks      = 0;
     72                        __atomic_fetch_add( &cltr->io.calls.errors.busy, proc->io.calls.errors.busy, __ATOMIC_SEQ_CST ); proc->io.calls.errors.busy = 0;
    7873                #endif
    7974        }
     
    123118                #if defined(CFA_HAVE_LINUX_IO_URING_H)
    124119                        if( flags & CFA_STATS_IO ) {
    125                                 double avgrdy = ((double)io.submit_q.submit_avg.rdy) / io.submit_q.submit_avg.cnt;
    126                                 double avgcsm = ((double)io.submit_q.submit_avg.csm) / io.submit_q.submit_avg.cnt;
     120                                uint64_t total_allocs = io.alloc.fast + io.alloc.slow;
     121                                double avgfasta = ((double)io.alloc.fast) / total_allocs;
    127122
    128                                 double lavgv = 0;
    129                                 double lavgb = 0;
    130                                 if(io.submit_q.look_avg.cnt != 0) {
    131                                         lavgv = ((double)io.submit_q.look_avg.val  ) / io.submit_q.look_avg.cnt;
    132                                         lavgb = ((double)io.submit_q.look_avg.block) / io.submit_q.look_avg.cnt;
    133                                 }
     123                                uint64_t total_submits = io.submit.fast + io.submit.slow;
     124                                double avgfasts = ((double)io.submit.fast) / total_submits;
    134125
    135                                 double aavgv = 0;
    136                                 double aavgb = 0;
    137                                 if(io.submit_q.alloc_avg.cnt != 0) {
    138                                         aavgv = ((double)io.submit_q.alloc_avg.val  ) / io.submit_q.alloc_avg.cnt;
    139                                         aavgb = ((double)io.submit_q.alloc_avg.block) / io.submit_q.alloc_avg.cnt;
    140                                 }
     126                                double avgsubs = ((double)io.calls.submitted) / io.calls.count;
     127                                double avgcomp = ((double)io.calls.completed) / io.calls.count;
    141128
    142129                                __cfaabi_bits_print_safe( STDOUT_FILENO,
    143130                                        "----- %s \"%s\" (%p) - I/O Stats -----\n"
    144                                         "- total submit calls     : %'15" PRIu64 "\n"
    145                                         "- avg ready entries      : %'18.2lf\n"
    146                                         "- avg submitted entries  : %'18.2lf\n"
    147                                         "- total helped entries   : %'15" PRIu64 "\n"
    148                                         "- total leader entries   : %'15" PRIu64 "\n"
    149                                         "- total busy submit      : %'15" PRIu64 "\n"
    150                                         "- total ready search     : %'15" PRIu64 "\n"
    151                                         "- avg ready search len   : %'18.2lf\n"
    152                                         "- avg ready search block : %'18.2lf\n"
    153                                         "- total alloc search    : %'15" PRIu64 "\n"
    154                                         "- avg alloc search len   : %'18.2lf\n"
    155                                         "- avg alloc search block : %'18.2lf\n"
    156                                         "- total wait calls       : %'15" PRIu64 "\n"
    157                                         "- avg completion/wait    : %'18.2lf\n"
    158                                         "- total completion blocks: %'15" PRIu64 "\n"
     131                                        "- total allocations      : %'15" PRIu64 "\n"
     132                                        "-     fast allocations   : %'15" PRIu64 " (%'18.2lf) \n"
     133                                        "-     fast enomem        : %'15" PRIu64 "\n"
     134                                        "-     slow allocations   : %'15" PRIu64 "\n"
     135                                        "-     revokes for alloc  : %'15" PRIu64 "\n"
     136                                        "-     blocks  for alloc  : %'15" PRIu64 "\n"
     137                                        "- total submits          : %'15" PRIu64 "\n"
     138                                        "-     fast submits       : %'15" PRIu64 " (%'18.2lf) \n"
     139                                        "-     slow submits       : %'15" PRIu64 "\n"
     140                                        "- flush external submits : %'15" PRIu64 "\n"
     141                                        "- io_uring_enter calls   : %'15" PRIu64 "\n"
     142                                        "-     submits            : %'15" PRIu64 " (%'18.2lf) \n"
     143                                        "-     completes          : %'15" PRIu64 " (%'18.2lf) \n"
     144                                        "-     blocking calls     : %'15" PRIu64 "\n"
     145                                        "- io_uring_enter EBUSYs  : %'15" PRIu64 "\n"
    159146                                        "\n"
    160147                                        , type,  name, id
    161                                         , io.submit_q.submit_avg.cnt
    162                                         , avgrdy, avgcsm
    163                                         , io.submit_q.helped, io.submit_q.leader, io.submit_q.busy
    164                                         , io.submit_q.look_avg.cnt
    165                                         , lavgv, lavgb
    166                                         , io.submit_q.alloc_avg.cnt
    167                                         , aavgv, aavgb
    168                                         , io.complete_q.completed_avg.cnt
    169                                         , ((double)io.complete_q.completed_avg.val) / io.complete_q.completed_avg.cnt
    170                                         , io.complete_q.blocks
     148                                        , total_allocs
     149                                        , io.alloc.fast, avgfasta
     150                                        , io.alloc.fail
     151                                        , io.alloc.slow
     152                                        , io.alloc.revoke
     153                                        , io.alloc.block
     154                                        , total_submits
     155                                        , io.submit.fast, avgfasts
     156                                        , io.submit.slow
     157                                        , io.flush.external
     158                                        , io.calls.count
     159                                        , io.calls.submitted, avgsubs
     160                                        , io.calls.completed, avgcomp
     161                                        , io.calls.blocks
     162                                        , io.calls.errors.busy
    171163                                );
    172164                        }
  • libcfa/src/concurrency/stats.hfa

    r4f762d3 rd60d30e  
    6666                struct __attribute__((aligned(64))) __stats_io_t{
    6767                        struct {
     68                                volatile uint64_t fast;
     69                                volatile uint64_t slow;
     70                                volatile uint64_t fail;
     71                                volatile uint64_t revoke;
     72                                volatile uint64_t block;
     73                        } alloc;
     74                        struct {
     75                                volatile uint64_t fast;
     76                                volatile uint64_t slow;
     77                        } submit;
     78                        struct {
     79                                volatile uint64_t external;
     80                        } flush;
     81                        struct {
     82                                volatile uint64_t count;
     83                                volatile uint64_t submitted;
     84                                volatile uint64_t completed;
     85                                volatile uint64_t blocks;
    6886                                struct {
    69                                         volatile uint64_t rdy;
    70                                         volatile uint64_t csm;
    71                                         volatile uint64_t avl;
    72                                         volatile uint64_t cnt;
    73                                 } submit_avg;
    74                                 struct {
    75                                         volatile uint64_t val;
    76                                         volatile uint64_t cnt;
    77                                         volatile uint64_t block;
    78                                 } look_avg;
    79                                 struct {
    80                                         volatile uint64_t val;
    81                                         volatile uint64_t cnt;
    82                                         volatile uint64_t block;
    83                                 } alloc_avg;
    84                                 volatile uint64_t helped;
    85                                 volatile uint64_t leader;
    86                                 volatile uint64_t busy;
    87                         } submit_q;
    88                         struct {
    89                                 struct {
    90                                         volatile uint64_t val;
    91                                         volatile uint64_t cnt;
    92                                 } completed_avg;
    93                                 volatile uint64_t blocks;
    94                         } complete_q;
     87                                        volatile uint64_t busy;
     88                                } errors;
     89                        } calls;
    9590                };
    9691        #endif
Note: See TracChangeset for help on using the changeset viewer.