Changeset 39fc03e


Ignore:
Timestamp:
Jul 24, 2020, 3:42:32 PM (14 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
7458fea
Parents:
320ec6fc
Message:

Fixed ready_queue working with 0/1 processors on cluster

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r320ec6fc r39fc03e  
    324324        threads{ __get };
    325325
     326        doregister(this);
     327
     328        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     329        uint_fast32_t last_size = ready_mutate_lock();
     330
     331                // Adjust the ready queue size
     332                ready_queue_grow( &this, 0 );
     333
     334        // Unlock the RWlock
     335        ready_mutate_unlock( last_size );
     336
     337
    326338        __kernel_io_startup( this, io_flags, &this == mainCluster );
    327 
    328         doregister(this);
    329339}
    330340
    331341void ^?{}(cluster & this) {
    332342        __kernel_io_shutdown( this, &this == mainCluster );
     343
     344        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     345        uint_fast32_t last_size = ready_mutate_lock();
     346
     347                // Adjust the ready queue size
     348                ready_queue_shrink( &this, 0 );
     349
     350        // Unlock the RWlock
     351        ready_mutate_unlock( last_size );
    333352
    334353        #if !defined(__CFA_NO_STATISTICS__)
  • libcfa/src/concurrency/ready_queue.cfa

    r320ec6fc r39fc03e  
    191191
    192192void ^?{}(__ready_queue_t & this) with (this) {
    193         verify( 0 == lanes.count );
     193        verify( 1 == lanes.count );
    194194        verify( !query( snzi ) );
    195195        free(lanes.data);
     
    484484}
    485485
    486 #warning remove when alloc is fixed
    487 forall( dtype T | sized(T) )
    488 static inline T * correct_alloc( T ptr[], size_t dim ) {
    489         if( dim == 0 ) {
    490                 free(ptr);
    491                 return 0p;
    492         }
    493         T * temp = alloc( dim );
    494         if(ptr) {
    495                 memcpy( temp, ptr, dim * sizeof(T));
    496                 free(ptr);
    497         }
    498         return temp;
    499 }
    500 
    501486// Grow the ready queue
    502487void ready_queue_grow  (struct cluster * cltr, int target) {
     
    511496                ^(snzi){};
    512497
    513                 size_t ncount = lanes.count;
    514 
    515                 // increase count
    516                 ncount += 4;
    517                 /* paranoid */ verify( ncount == target * 4 || target < 2 );
     498                // Find new count
     499                // Make sure we always have atleast 1 list
     500                size_t ncount = target >= 2 ? target * 4: 1;
    518501
    519502                // Allocate new array (uses realloc and memcpies the data)
    520                 lanes.data = correct_alloc(lanes.data, ncount);
     503                lanes.data = alloc(lanes.data, ncount);
    521504
    522505                // Fix the moved data
     
    561544                ^(snzi){};
    562545
     546                // Remember old count
    563547                size_t ocount = lanes.count;
    564                 // Check that we have some space left
    565                 if(ocount < 4) abort("Program attempted to destroy more Ready Queues than were created");
    566 
    567                 // reduce the actual count so push doesn't use the old queues
    568                 lanes.count -= 4;
    569                 /* paranoid */ verify( ocount > lanes.count );
     548
     549                // Find new count
     550                // Make sure we always have atleast 1 list
     551                lanes.count = target >= 2 ? target * 4: 1;
     552                /* paranoid */ verify( ocount >= lanes.count );
    570553                /* paranoid */ verify( lanes.count == target * 4 || target < 2 );
    571554
     
    606589
    607590                // Allocate new array (uses realloc and memcpies the data)
    608                 lanes.data = correct_alloc(lanes.data, lanes.count);
     591                lanes.data = alloc(lanes.data, lanes.count);
    609592
    610593                // Fix the moved data
Note: See TracChangeset for help on using the changeset viewer.