Changeset c9c1c1c


Ignore:
Timestamp:
Jan 30, 2022, 1:16:50 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
473d1da0, 8e5e945
Parents:
ac6fc48
Message:

Minor changes to kernel main loop and fixed stats.

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    rac6fc48 rc9c1c1c  
    4242
    4343#if !defined(__CFA_NO_STATISTICS__)
    44         #define __STATS( ...) __VA_ARGS__
     44        #define __STATS_DEF( ...) __VA_ARGS__
    4545#else
    46         #define __STATS( ...)
     46        #define __STATS_DEF( ...)
    4747#endif
    4848
     
    122122static thread$ * __next_thread(cluster * this);
    123123static thread$ * __next_thread_slow(cluster * this);
     124static thread$ * __next_thread_search(cluster * this);
    124125static inline bool __must_unpark( thread$ * thrd ) __attribute((nonnull(1)));
    125126static void __run_thread(processor * this, thread$ * dst);
     
    194195
    195196                        if( !readyThread ) {
    196                                 __tls_stats()->io.flush.idle++;
     197                                __IO_STATS__(true, io.flush.idle++; )
    197198                                __cfa_io_flush( this, 0 );
    198199
     200                                readyThread = __next_thread( this->cltr );
     201                        }
     202
     203                        if( !readyThread ) for(5) {
     204                                __IO_STATS__(true, io.flush.idle++; )
     205
    199206                                readyThread = __next_thread_slow( this->cltr );
     207
     208                                if( readyThread ) break;
     209
     210                                __cfa_io_flush( this, 0 );
    200211                        }
    201212
     
    209220
    210221                                // Confirm the ready-queue is empty
    211                                 readyThread = __next_thread_slow( this->cltr );
     222                                readyThread = __next_thread_search( this->cltr );
    212223                                if( readyThread ) {
    213224                                        // A thread was found, cancel the halt
    214225                                        mark_awake(this->cltr->procs, * this);
    215226
    216                                         #if !defined(__CFA_NO_STATISTICS__)
    217                                                 __tls_stats()->ready.sleep.cancels++;
    218                                         #endif
     227                                        __STATS__(true, ready.sleep.cancels++; )
    219228
    220229                                        // continue the mai loop
     
    243252
    244253                        if(this->io.pending && !this->io.dirty) {
    245                                 __tls_stats()->io.flush.dirty++;
     254                                __IO_STATS__(true, io.flush.dirty++; )
    246255                                __cfa_io_flush( this, 0 );
    247256                        }
     
    356365                                break RUNNING;
    357366                        case TICKET_UNBLOCK:
    358                                 #if !defined(__CFA_NO_STATISTICS__)
    359                                         __tls_stats()->ready.threads.threads++;
    360                                 #endif
     367                                __STATS__(true, ready.threads.threads++; )
    361368                                // This is case 2, the racy case, someone tried to run this thread before it finished blocking
    362369                                // In this case, just run it again.
     
    373380        __cfadbg_print_safe(runtime_core, "Kernel : core %p finished running thread %p\n", this, thrd_dst);
    374381
    375         #if !defined(__CFA_NO_STATISTICS__)
    376                 __tls_stats()->ready.threads.threads--;
    377         #endif
     382        __STATS__(true, ready.threads.threads--; )
    378383
    379384        /* paranoid */ verify( ! __preemption_enabled() );
     
    386391        thread$ * thrd_src = kernelTLS().this_thread;
    387392
    388         __STATS( thrd_src->last_proc = kernelTLS().this_processor; )
     393        __STATS_DEF( thrd_src->last_proc = kernelTLS().this_processor; )
    389394
    390395        // Run the thread on this processor
     
    438443        // Dereference the thread now because once we push it, there is not guaranteed it's still valid.
    439444        struct cluster * cl = thrd->curr_cluster;
    440         __STATS(bool outside = hint == UNPARK_LOCAL && thrd->last_proc && thrd->last_proc != kernelTLS().this_processor; )
     445        __STATS_DEF(bool outside = hint == UNPARK_LOCAL && thrd->last_proc && thrd->last_proc != kernelTLS().this_processor; )
    441446
    442447        // push the thread to the cluster ready-queue
     
    489494
    490495        ready_schedule_lock();
    491                 thread$ * thrd;
    492                 for(25) {
    493                         thrd = pop_slow( this );
    494                         if(thrd) goto RET;
    495                 }
    496                 thrd = pop_search( this );
    497 
    498                 RET:
     496                thread$ * thrd = pop_slow( this );
     497        ready_schedule_unlock();
     498
     499        /* paranoid */ verify( ! __preemption_enabled() );
     500        return thrd;
     501}
     502
     503// KERNEL ONLY
     504static inline thread$ * __next_thread_search(cluster * this) with( *this ) {
     505        /* paranoid */ verify( ! __preemption_enabled() );
     506
     507        ready_schedule_lock();
     508                thread$ * thrd = pop_search( this );
    499509        ready_schedule_unlock();
    500510
     
    738748
    739749static bool mark_idle(__cluster_proc_list & this, processor & proc) {
    740         #if !defined(__CFA_NO_STATISTICS__)
    741                 __tls_stats()->ready.sleep.halts++;
    742         #endif
     750        __STATS__(true, ready.sleep.halts++; )
    743751
    744752        proc.idle_wctx.fd = 0;
  • libcfa/src/concurrency/kernel/fwd.hfa

    rac6fc48 rc9c1c1c  
    396396                                if( !(in_kernel) ) enable_interrupts(); \
    397397                        }
     398                        #if defined(CFA_HAVE_LINUX_IO_URING_H)
     399                                #define __IO_STATS__(in_kernel, ...) { \
     400                                        if( !(in_kernel) ) disable_interrupts(); \
     401                                        with( *__tls_stats() ) { \
     402                                                __VA_ARGS__ \
     403                                        } \
     404                                        if( !(in_kernel) ) enable_interrupts(); \
     405                                }
     406                        #else
     407                                #define __IO_STATS__(in_kernel, ...)
     408                        #endif
    398409                #else
    399410                        #define __STATS__(in_kernel, ...)
     411                        #define __IO_STATS__(in_kernel, ...)
    400412                #endif
    401413        }
Note: See TracChangeset for help on using the changeset viewer.