Ignore:
Timestamp:
Sep 23, 2021, 2:18:01 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
75c7252
Parents:
fcd65ca
Message:

Unpark now takes a hint on locality.

File:
1 edited

Legend:

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

    rfcd65ca r24e321c  
    290290//-----------------------------------------------------------------------
    291291#if defined(USE_CPU_WORK_STEALING)
    292         __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool push_local) with (cltr->ready_queue) {
     292        __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
    293293                __cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
    294294
     
    450450        }
    451451
    452         __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool push_local) with (cltr->ready_queue) {
     452        __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
    453453                __cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
    454454
    455                 const bool external = !push_local || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
     455                const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
    456456                /* paranoid */ verify(external || kernelTLS().this_processor->rdq.id < lanes.count );
    457457
     
    537537#endif
    538538#if defined(USE_WORK_STEALING)
    539         __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool push_local) with (cltr->ready_queue) {
     539        __attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
    540540                __cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
    541541
    542542                // #define USE_PREFERRED
    543543                #if !defined(USE_PREFERRED)
    544                 const bool external = !push_local || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
     544                const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
    545545                /* paranoid */ verify(external || kernelTLS().this_processor->rdq.id < lanes.count );
    546546                #else
    547547                        unsigned preferred = thrd->preferred;
    548                         const bool external = push_local || (!kernelTLS().this_processor) || preferred == -1u || thrd->curr_cluster != cltr;
     548                        const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || preferred == -1u || thrd->curr_cluster != cltr;
    549549                        /* paranoid */ verifyf(external || preferred < lanes.count, "Invalid preferred queue %u for %u lanes", preferred, lanes.count );
    550550
     
    687687        #endif
    688688
    689         thrd->preferred = w;
     689        #if defined(USE_CPU_WORK_STEALING)
     690                thrd->preferred = w / READYQ_SHARD_FACTOR;
     691        #else
     692                thrd->preferred = w;
     693        #endif
    690694
    691695        // return the popped thread
     
    713717
    714718//-----------------------------------------------------------------------
     719// get preferred ready for new thread
     720unsigned ready_queue_new_preferred() {
     721        unsigned pref = 0;
     722        if(struct thread$ * thrd = publicTLS_get( this_thread )) {
     723                pref = thrd->preferred;
     724        }
     725        else {
     726                #if defined(USE_CPU_WORK_STEALING)
     727                        pref = __kernel_getcpu();
     728                #endif
     729        }
     730
     731        #if defined(USE_CPU_WORK_STEALING)
     732                /* paranoid */ verify(pref >= 0);
     733                /* paranoid */ verify(pref < cpu_info.hthrd_count);
     734        #endif
     735
     736        return pref;
     737}
     738
     739//-----------------------------------------------------------------------
    715740// Check that all the intrusive queues in the data structure are still consistent
    716741static void check( __ready_queue_t & q ) with (q) {
Note: See TracChangeset for help on using the changeset viewer.