Ignore:
Timestamp:
Dec 13, 2019, 1:45:49 PM (5 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:
75ca7f4
Parents:
983edfd
Message:

new ready queue seems to work but halting does not, had to be disabled

Location:
libcfa/src/concurrency
Files:
5 edited

Legend:

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

    r983edfd rc84b4be  
    556556
    557557        with( *thrd->curr_cluster ) {
    558                 if(was_empty) {
    559                         lock      (proc_list_lock __cfaabi_dbg_ctx2);
    560                         if(idles) {
    561                                 wake_fast(idles.head);
    562                         }
    563                         unlock    (proc_list_lock);
    564                 }
    565                 else if( struct processor * idle = idles.head ) {
    566                         wake_fast(idle);
    567                 }
     558                // if(was_empty) {
     559                //      lock      (proc_list_lock __cfaabi_dbg_ctx2);
     560                //      if(idles) {
     561                //              wake_fast(idles.head);
     562                //      }
     563                //      unlock    (proc_list_lock);
     564                // }
     565                // else if( struct processor * idle = idles.head ) {
     566                //      wake_fast(idle);
     567                // }
    568568        }
    569569
     
    825825//=============================================================================================
    826826static void halt(processor * this) with( *this ) {
    827         // verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    828 
    829         with( *cltr ) {
    830                 lock      (proc_list_lock __cfaabi_dbg_ctx2);
    831                 push_front(idles, *this);
    832                 unlock    (proc_list_lock);
    833         }
    834 
    835         __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
    836 
    837         wait( idleLock );
    838 
    839         __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
    840 
    841         with( *cltr ) {
    842                 lock      (proc_list_lock __cfaabi_dbg_ctx2);
    843                 remove    (idles, *this);
    844                 unlock    (proc_list_lock);
    845         }
     827        // // verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
     828
     829        // with( *cltr ) {
     830        //      lock      (proc_list_lock __cfaabi_dbg_ctx2);
     831        //      push_front(idles, *this);
     832        //      unlock    (proc_list_lock);
     833        // }
     834
     835        // __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
     836
     837        // wait( idleLock );
     838
     839        // __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
     840
     841        // with( *cltr ) {
     842        //      lock      (proc_list_lock __cfaabi_dbg_ctx2);
     843        //      remove    (idles, *this);
     844        //      unlock    (proc_list_lock);
     845        // }
    846846}
    847847
  • libcfa/src/concurrency/kernel.hfa

    r983edfd rc84b4be  
    194194        volatile bool lock;
    195195        unsigned int last_id;
     196        unsigned int count;
    196197
    197198        // anchor for the head and the tail of the queue
  • libcfa/src/concurrency/monitor.cfa

    r983edfd rc84b4be  
    816816        }
    817817
    818         __cfaabi_dbg_print_safe( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? node->waiting_thread : 0p );
     818        __cfaabi_dbg_print_safe( "Kernel :  Runing %i (%p)\n", ready2run, ready2run ? (thread_desc*)node->waiting_thread : (thread_desc*)0p );
    819819        return ready2run ? node->waiting_thread : 0p;
    820820}
  • libcfa/src/concurrency/preemption.cfa

    r983edfd rc84b4be  
    120120        // If there are still alarms pending, reset the timer
    121121        if( alarms->head ) {
    122                 __cfaabi_dbg_print_buffer_decl( " KERNEL: @%ju(%ju) resetting alarm to %ju.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv);
     122                // __cfaabi_dbg_print_buffer_decl( " KERNEL: @%ju(%ju) resetting alarm to %ju.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv);
    123123                Duration delta = alarms->head->alarm - currtime;
    124124                Duration caped = max(delta, 50`us);
  • libcfa/src/concurrency/ready_queue.cfa

    r983edfd rc84b4be  
    240240        this.lock = false;
    241241        this.last_id = -1u;
     242        this.count = 0u;
    242243
    243244        this.before.link.prev = 0p;
     
    283284        /* paranoid */ verify(tail(this)->link.next == 0p );
    284285        /* paranoid */ verify(tail(this)->link.prev == head(this) );
     286        /* paranoid */ verify(this.count == 0u );
    285287}
    286288
     
    292294        verify(node->link.next == 0p);
    293295        verify(node->link.prev == 0p);
     296
     297        this.count++;
    294298
    295299        if(this.before.link.ts == 0l) {
     
    345349        }
    346350
     351        this.count--;
    347352        /* paranoid */ verify(node);
    348353
     
    693698void ready_queue_grow  (struct cluster * cltr) {
    694699        uint_fast32_t last_size = ready_mutate_lock( *cltr );
     700        __cfaabi_dbg_print_safe("Kernel : Growing ready queue\n");
    695701        check( cltr->ready_queue );
    696702
     
    723729        // Make sure that everything is consistent
    724730        check( cltr->ready_queue );
     731        __cfaabi_dbg_print_safe("Kernel : Growing ready queue done\n");
    725732        ready_mutate_unlock( *cltr, last_size );
    726733}
     
    728735void ready_queue_shrink(struct cluster * cltr) {
    729736        uint_fast32_t last_size = ready_mutate_lock( *cltr );
     737        __cfaabi_dbg_print_safe("Kernel : Shrinking ready queue\n");
    730738        with( cltr->ready_queue ) {
     739                #if defined(__CFA_WITH_VERIFY__)
     740                        size_t nthreads = 0;
     741                        for( idx; (size_t)list.count ) {
     742                                nthreads += list.data[idx].count;
     743                        }
     744                #endif
     745
    731746                size_t ocount = list.count;
    732747                // Check that we have some space left
     
    737752                // redistribute old data
    738753                verify(ocount > list.count);
     754                __attribute__((unused)) size_t displaced = 0;
    739755                for( idx; (size_t)list.count ~ ocount) {
    740756                        // This is not strictly needed but makes checking invariants much easier
     
    747763                                verify(thrd);
    748764                                push(cltr, thrd);
     765                                displaced++;
    749766                        }
    750767
     
    755772                        ^(list.data[idx]){};
    756773                }
     774
     775                __cfaabi_dbg_print_safe("Kernel : Shrinking ready queue displaced %zu threads\n", displaced);
    757776
    758777                // clear the now unused masks
     
    776795
    777796                        empty.count = 0;
    778                         for( i ; lword ) {
     797                        for( i ; 0 ~= lword ) {
    779798                                empty.count += __builtin_popcountl(empty.mask[i]);
    780799                        }
     
    788807                        fix(list.data[idx]);
    789808                }
     809
     810                #if defined(__CFA_WITH_VERIFY__)
     811                        for( idx; (size_t)list.count ) {
     812                                nthreads -= list.data[idx].count;
     813                        }
     814                        assertf(nthreads == 0, "Shrinking changed number of threads");
     815                #endif
    790816        }
    791817
    792818        // Make sure that everything is consistent
    793819        check( cltr->ready_queue );
     820        __cfaabi_dbg_print_safe("Kernel : Shrinking ready queue done\n");
    794821        ready_mutate_unlock( *cltr, last_size );
    795822}
Note: See TracChangeset for help on using the changeset viewer.