Changeset 1c6e1ec for libcfa/src


Ignore:
Timestamp:
Mar 22, 2021, 5:28:35 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
357fae8
Parents:
304de00
Message:

Cforall now uses CFA_DEFAULT_PREEMPTION environment variable to override the default preemption.

File:
1 edited

Legend:

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

    r304de00 r1c6e1ec  
    1515
    1616#define __cforall_thread__
     17// #define __CFA_DEBUG_PRINT_PREEMPTION__
    1718
    1819#include "preemption.hfa"
     
    2829#include "kernel_private.hfa"
    2930
     31
    3032#if !defined(__CFA_DEFAULT_PREEMPTION__)
    3133#define __CFA_DEFAULT_PREEMPTION__ 10`ms
    3234#endif
    3335
    34 Duration default_preemption() __attribute__((weak)) {
    35         return __CFA_DEFAULT_PREEMPTION__;
     36__attribute__((weak)) Duration default_preemption() {
     37        const char * preempt_rate_s = getenv("CFA_DEFAULT_PROCESSORS");
     38        if(!preempt_rate_s) {
     39                __cfadbg_print_safe(preemption, "No CFA_DEFAULT_PROCESSORS in ENV\n");
     40                return __CFA_DEFAULT_PREEMPTION__;
     41        }
     42
     43        char * endptr = 0p;
     44        long int preempt_rate_l = strtol(preempt_rate_s, &endptr, 10);
     45        if(preempt_rate_l < 0 || preempt_rate_l > 65535) {
     46                __cfadbg_print_safe(preemption, "CFA_DEFAULT_PROCESSORS out of range : %ld\n", preempt_rate_l);
     47                return __CFA_DEFAULT_PREEMPTION__;
     48        }
     49        if('\0' != *endptr) {
     50                __cfadbg_print_safe(preemption, "CFA_DEFAULT_PROCESSORS not a decimal number : %s\n", preempt_rate_s);
     51                return __CFA_DEFAULT_PREEMPTION__;
     52        }
     53
     54        return preempt_rate_l`ms;
    3655}
    3756
     
    125144        // If there are still alarms pending, reset the timer
    126145        if( & (*alarms)`first ) {
    127                 __cfadbg_print_buffer_decl(preemption, " KERNEL: @%ju(%ju) resetting alarm to %ju.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv);
    128146                Duration delta = (*alarms)`first.alarm - currtime;
    129147                Duration capped = max(delta, 50`us);
    130                 // itimerval tim  = { caped };
    131                 // __cfaabi_dbg_print_buffer_local( "    Values are %lu, %lu, %lu %lu.\n", delta.tv, caped.tv, tim.it_value.tv_sec, tim.it_value.tv_usec);
    132 
    133148                __kernel_set_timer( capped );
    134149        }
Note: See TracChangeset for help on using the changeset viewer.