Changeset 8b74fa7 for libcfa/src


Ignore:
Timestamp:
Oct 27, 2022, 11:20:19 AM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
a167c70c
Parents:
878cfcc
Message:

cluster now support 'set_concurrency' which addes/removes processors internal to clusters

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r878cfcc r8b74fa7  
    160160// P9_EMBEDDED( processor, dlink(processor) )
    161161static inline tytagref( dlink(processor), dlink(processor) ) ?`inner( processor & this ) {
    162     dlink(processor) & b = this.link;
    163     tytagref( dlink(processor), dlink(processor) ) result = { b };
    164     return result;
     162        dlink(processor) & b = this.link;
     163        tytagref( dlink(processor), dlink(processor) ) result = { b };
     164        return result;
    165165}
    166166
     
    269269                io_context_params params;
    270270        } io;
     271
     272        struct {
     273                struct processor ** procs;
     274                unsigned cnt;
     275        } managed;
    271276
    272277        #if !defined(__CFA_NO_STATISTICS__)
     
    298303static inline struct cluster   * active_cluster  () { return publicTLS_get( this_processor )->cltr; }
    299304
     305// set the number of internal processors
     306// these processors are in addition to any explicitly declared processors
     307unsigned set_concurrency( cluster & this, unsigned new_count );
     308
    300309#if !defined(__CFA_NO_STATISTICS__)
    301310        void print_stats_now( cluster & this, int flags );
  • libcfa/src/concurrency/kernel/startup.cfa

    r878cfcc r8b74fa7  
    1616#define __cforall_thread__
    1717#define _GNU_SOURCE
     18
     19// #define __CFA_DEBUG_PRINT_RUNTIME_CORE__
    1820
    1921// C Includes
     
    336338
    337339                /* paranoid */ verify( this.do_terminate == true );
    338                 __cfaabi_dbg_print_safe("Kernel : destroyed main processor context %p\n", &runner);
     340                __cfadbg_print_safe(runtime_core, "Kernel : destroyed main processor context %p\n", &runner);
    339341        }
    340342
     
    397399        (proc->runner){ proc, &info };
    398400
    399         __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage);
     401        __cfadbg_print_safe(runtime_core, "Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage);
    400402
    401403        //Set global state
     
    662664        io.params = io_params;
    663665
     666        managed.procs = 0p;
     667        managed.cnt = 0;
     668
    664669        doregister(this);
    665670
     
    677682
    678683void ^?{}(cluster & this) libcfa_public {
     684        set_concurrency( this, 0 );
     685
    679686        destroy(this.io.arbiter);
    680687
     
    848855}
    849856
     857unsigned set_concurrency( cluster & this, unsigned new ) libcfa_public {
     858        unsigned old = this.managed.cnt;
     859
     860        __cfadbg_print_safe(runtime_core, "Kernel : resizing cluster from %u to %u\n", old, (unsigned)new);
     861
     862        // Delete all the old unneeded procs
     863        if(old > new) for(i; (unsigned)new ~ old) {
     864                __cfadbg_print_safe(runtime_core, "Kernel : destroying %u\n", i);
     865                delete( this.managed.procs[i] );
     866        }
     867
     868        // Allocate new array (uses realloc and memcpies the data)
     869        this.managed.procs = alloc( new, this.managed.procs`realloc );
     870        this.managed.cnt = new;
     871
     872        // Create the desired new procs
     873        if(old < new) for(i; old ~ new) {
     874                __cfadbg_print_safe(runtime_core, "Kernel : constructing %u\n", i);
     875                (*(this.managed.procs[i] = alloc())){ this };
     876        }
     877
     878        // return the old count
     879        return old;
     880}
     881
    850882#if defined(__CFA_WITH_VERIFY__)
    851883static bool verify_fwd_bck_rng(void) {
Note: See TracChangeset for help on using the changeset viewer.