Changeset 320ec6fc


Ignore:
Timestamp:
Jul 24, 2020, 1:11:39 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:
39fc03e
Parents:
f4ec4a90
Message:

Changed ready_queue_(grow/shrink) to take a target instead of going incrementing

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

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

    rf4ec4a90 r320ec6fc  
    242242        #endif
    243243
    244         __atomic_fetch_add( &cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
     244        int target = __atomic_add_fetch( &cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
    245245
    246246        id = doregister((__processor_id_t*)&this);
     
    250250
    251251                // Adjust the ready queue size
    252                 ready_queue_grow( cltr );
     252                ready_queue_grow( cltr, target );
    253253
    254254        // Unlock the RWlock
     
    260260// Not a ctor, it just preps the destruction but should not destroy members
    261261void deinit(processor & this) {
     262
     263        int target = __atomic_sub_fetch( &this.cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
     264
    262265        // Lock the RWlock so no-one pushes/pops while we are changing the queue
    263266        uint_fast32_t last_size = ready_mutate_lock();
    264267
    265268                // Adjust the ready queue size
    266                 ready_queue_shrink( this.cltr );
     269                ready_queue_shrink( this.cltr, target );
    267270
    268271                // Make sure we aren't on the idle queue
     
    305308
    306309        deinit( this );
    307 
    308         __atomic_fetch_sub( &cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
    309310}
    310311
     
    936937
    937938                /* paranoid */ verify( this.do_terminate == true );
    938                 __atomic_fetch_sub( &cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
    939939                __cfaabi_dbg_print_safe("Kernel : destroyed main processor context %p\n", &runner);
    940940        }
  • libcfa/src/concurrency/kernel_private.hfa

    rf4ec4a90 r320ec6fc  
    274274//-----------------------------------------------------------------------
    275275// Increase the width of the ready queue (number of lanes) by 4
    276 void ready_queue_grow  (struct cluster * cltr);
     276void ready_queue_grow  (struct cluster * cltr, int target);
    277277
    278278//-----------------------------------------------------------------------
    279279// Decrease the width of the ready queue (number of lanes) by 4
    280 void ready_queue_shrink(struct cluster * cltr);
     280void ready_queue_shrink(struct cluster * cltr, int target);
    281281
    282282//-----------------------------------------------------------------------
  • libcfa/src/concurrency/ready_queue.cfa

    rf4ec4a90 r320ec6fc  
    3737#endif
    3838
    39 #define BIAS 64
     39#define BIAS 16
    4040
    4141// returns the maximum number of processors the RWLock support
     
    500500
    501501// Grow the ready queue
    502 void ready_queue_grow  (struct cluster * cltr) {
     502void ready_queue_grow  (struct cluster * cltr, int target) {
    503503        /* paranoid */ verify( ready_mutate_islocked() );
    504504        __cfadbg_print_safe(ready_queue, "Kernel : Growing ready queue\n");
     
    515515                // increase count
    516516                ncount += 4;
     517                /* paranoid */ verify( ncount == target * 4 || target < 2 );
    517518
    518519                // Allocate new array (uses realloc and memcpies the data)
     
    550551
    551552// Shrink the ready queue
    552 void ready_queue_shrink(struct cluster * cltr) {
     553void ready_queue_shrink(struct cluster * cltr, int target) {
    553554        /* paranoid */ verify( ready_mutate_islocked() );
    554555        __cfadbg_print_safe(ready_queue, "Kernel : Shrinking ready queue\n");
     
    566567                // reduce the actual count so push doesn't use the old queues
    567568                lanes.count -= 4;
    568                 verify(ocount > lanes.count);
     569                /* paranoid */ verify( ocount > lanes.count );
     570                /* paranoid */ verify( lanes.count == target * 4 || target < 2 );
    569571
    570572                // for printing count the number of displaced threads
  • libcfa/src/concurrency/snzi.hfa

    rf4ec4a90 r320ec6fc  
    148148
    149149static inline void arrive( __snzi_t & this, int idx) {
     150        idx >>= 2;
    150151        idx &= this.mask;
    151152        arrive( this.nodes[idx] );
     
    153154
    154155static inline void depart( __snzi_t & this, int idx) {
     156        idx >>= 2;
    155157        idx &= this.mask;
    156158        depart( this.nodes[idx] );
Note: See TracChangeset for help on using the changeset viewer.