Ignore:
Timestamp:
Mar 27, 2018, 5:22:58 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
43725bd
Parents:
af1ed1ad
Message:

second draft of time package and incorporation into runtime kernel

Location:
src/libcfa/concurrency
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    raf1ed1ad r2a84d06d  
    1010// Created On       : Fri Jun 2 11:31:25 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:35:18 2017
    13 // Update Count     : 1
     12// Last Modified On : Tue Mar 27 14:12:11 2018
     13// Update Count     : 41
    1414//
    1515
     
    2727
    2828
    29 static inline void ?{}( itimerval & this, __cfa_time_t * alarm ) with( this ) {
    30         it_value.tv_sec = alarm->val / (1`cfa_s).val;                   // seconds
    31         it_value.tv_usec = max( (alarm->val % (1`cfa_s).val) / (1`cfa_us).val, 1000 ); // microseconds
    32         it_interval.tv_sec = 0;
    33         it_interval.tv_usec = 0;
    34 }
    35 
    36 static inline void ?{}( __cfa_time_t & this, timespec * curr ) {
    37         uint64_t secs  = curr->tv_sec;
    38         uint64_t nsecs = curr->tv_nsec;
    39         this.val = from_s(secs).val + nsecs;
     29static inline void ?{}( itimerval & this, Duration alarm ) with( this ) {
     30        it_value   { alarm };                                                           // seconds, microseconds
     31        it_interval{ 0 };
    4032}
    4133
     
    4436//=============================================================================================
    4537
    46 __cfa_time_t __kernel_get_time() {
     38Time __kernel_get_time() {
    4739        timespec curr;
    48         clock_gettime( CLOCK_REALTIME, &curr );
    49         return (__cfa_time_t){ &curr };
     40        clock_gettime( CLOCK_MONOTONIC_RAW, &curr );            // CLOCK_REALTIME
     41        return (Time){ curr };
    5042}
    5143
    52 void __kernel_set_timer( __cfa_time_t alarm ) {
    53         itimerval val = { &alarm };
    54         setitimer( ITIMER_REAL, &val, NULL );
     44void __kernel_set_timer( Duration alarm ) {
     45        setitimer( ITIMER_REAL, &(itimerval){ alarm }, NULL );
    5546}
    5647
     
    5950//=============================================================================================
    6051
    61 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s ) with( this ) {
     52void ?{}( alarm_node_t & this, thread_desc * thrd, Time alarm, Duration period ) with( this ) {
    6253        this.thrd = thrd;
    6354        this.alarm = alarm;
     
    6859}
    6960
    70 void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s ) with( this ) {
     61void ?{}( alarm_node_t & this, processor   * proc, Time alarm, Duration period ) with( this ) {
    7162        this.proc = proc;
    7263        this.alarm = alarm;
  • src/libcfa/concurrency/alarm.h

    raf1ed1ad r2a84d06d  
    1010// Created On       : Fri Jun 2 11:31:25 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:59:27 2017
    13 // Update Count     : 3
     12// Last Modified On : Mon Mar 26 16:25:41 2018
     13// Update Count     : 11
    1414//
    1515
     
    2121#include <assert.h>
    2222
    23 #include "bits/cfatime.h"
     23#include "time"
    2424
    2525struct thread_desc;
     
    3030//=============================================================================================
    3131
    32 __cfa_time_t __kernel_get_time();
    33 void __kernel_set_timer( __cfa_time_t alarm );
     32Time __kernel_get_time();
     33void __kernel_set_timer( Duration alarm );
    3434
    3535//=============================================================================================
     
    3838
    3939struct alarm_node_t {
    40         __cfa_time_t alarm;             // time when alarm goes off
    41         __cfa_time_t period;            // if > 0 => period of alarm
     40        Time alarm;                             // time when alarm goes off
     41        Duration period;                        // if > 0 => period of alarm
    4242        alarm_node_t * next;            // intrusive link list field
    4343
     
    5353typedef alarm_node_t ** __alarm_it_t;
    5454
    55 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s );
    56 void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s );
     55void ?{}( alarm_node_t & this, thread_desc * thrd, Time alarm, Duration period );
     56void ?{}( alarm_node_t & this, processor   * proc, Time alarm, Duration period );
    5757void ^?{}( alarm_node_t & this );
    5858
  • src/libcfa/concurrency/kernel

    raf1ed1ad r2a84d06d  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:58:39 2017
    13 // Update Count     : 2
     12// Last Modified On : Fri Mar 23 17:08:20 2018
     13// Update Count     : 3
    1414//
    1515
     
    1919
    2020#include "invoke.h"
    21 #include "bits/cfatime.h"
     21#include "time"
    2222
    2323extern "C" {
     
    4949
    5050        // Preemption rate on this cluster
    51         __cfa_time_t preemption_rate;
     51        Duration preemption_rate;
    5252};
    5353
    54 extern __cfa_time_t default_preemption();
     54extern Duration default_preemption();
    5555
    5656void ?{} (cluster & this);
  • src/libcfa/concurrency/preemption.c

    raf1ed1ad r2a84d06d  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  9 16:38:13 2018
    13 // Update Count     : 14
     12// Last Modified On : Tue Mar 27 11:28:51 2018
     13// Update Count     : 24
    1414//
    1515
     
    2727
    2828#if !defined(__CFA_DEFAULT_PREEMPTION__)
    29 #define __CFA_DEFAULT_PREEMPTION__ 10`cfa_ms
     29#define __CFA_DEFAULT_PREEMPTION__ 10`ms
    3030#endif
    3131
    32 __cfa_time_t default_preemption() __attribute__((weak)) {
     32Duration default_preemption() __attribute__((weak)) {
    3333        return __CFA_DEFAULT_PREEMPTION__;
    3434}
     
    7878
    7979// Get next expired node
    80 static inline alarm_node_t * get_expired( alarm_list_t * alarms, __cfa_time_t currtime ) {
     80static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) {
    8181        if( !alarms->head ) return NULL;                          // If no alarms return null
    8282        if( alarms->head->alarm >= currtime ) return NULL;        // If alarms head not expired return null
     
    8888        alarm_node_t * node = NULL;                     // Used in the while loop but cannot be declared in the while condition
    8989        alarm_list_t * alarms = &event_kernel->alarms;  // Local copy for ease of reading
    90         __cfa_time_t currtime = __kernel_get_time();    // Check current time once so we everything "happens at once"
     90        Time currtime = __kernel_get_time();                    // Check current time once so we everything "happens at once"
    9191
    9292        //Loop throught every thing expired
     
    102102
    103103                // Check if this is a periodic alarm
    104                 __cfa_time_t period = node->period;
     104                Duration period = node->period;
    105105                if( period > 0 ) {
    106106                        node->alarm = currtime + period;    // Alarm is periodic, add currtime to it (used cached current time)
     
    117117
    118118// Update the preemption of a processor and notify interested parties
    119 void update_preemption( processor * this, __cfa_time_t duration ) {
     119void update_preemption( processor * this, Duration duration ) {
    120120        alarm_node_t * alarm = this->preemption_alarm;
    121121
    122122        // Alarms need to be enabled
    123         if ( duration > 0 && !alarm->set ) {
     123        if ( duration > 0 && ! alarm->set ) {
    124124                alarm->alarm = __kernel_get_time() + duration;
    125125                alarm->period = duration;
     
    291291// Used by thread to control when they want to receive preemption signals
    292292void ?{}( preemption_scope & this, processor * proc ) {
    293         (this.alarm){ proc, 0`cfa_s, 0`cfa_s };
     293        (this.alarm){ proc, (Time){ 0 }, 0`s };
    294294        this.proc = proc;
    295295        this.proc->preemption_alarm = &this.alarm;
     
    301301        disable_interrupts();
    302302
    303         update_preemption( this.proc, 0`cfa_s );
     303        update_preemption( this.proc, 0`s );
    304304}
    305305
  • src/libcfa/concurrency/preemption.h

    raf1ed1ad r2a84d06d  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:34:25 2017
    13 // Update Count     : 1
     12// Last Modified On : Fri Mar 23 17:18:53 2018
     13// Update Count     : 2
    1414//
    1515
     
    2121void kernel_start_preemption();
    2222void kernel_stop_preemption();
    23 void update_preemption( processor * this, __cfa_time_t duration );
     23void update_preemption( processor * this, Duration duration );
    2424void tick_preemption();
    2525
Note: See TracChangeset for help on using the changeset viewer.