Ignore:
Timestamp:
Aug 14, 2017, 2:03:39 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
74b007ba
Parents:
fd344aa (diff), 54cd58b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into references

File:
1 edited

Legend:

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

    rfd344aa r9236060  
    1 //                              -*- Mode: CFA -*-
    21//
    32// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     
    109// Author           : Thierry Delisle
    1110// Created On       : Fri Jun 2 11:31:25 2017
    12 // Last Modified By : Thierry Delisle
    13 // Last Modified On : --
    14 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul 21 22:35:18 2017
     13// Update Count     : 1
    1514//
    1615
     
    3130
    3231//=============================================================================================
     32// time type
     33//=============================================================================================
     34
     35#define one_second         1_000_000_000ul
     36#define one_milisecond         1_000_000ul
     37#define one_microsecond            1_000ul
     38#define one_nanosecond                 1ul
     39
     40__cfa_time_t zero_time = { 0 };
     41
     42void ?{}( __cfa_time_t & this ) { this.val = 0; }
     43void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
     44
     45void ?{}( itimerval & this, __cfa_time_t * alarm ) {
     46        this.it_value.tv_sec = alarm->val / one_second;                 // seconds
     47        this.it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds
     48        this.it_interval.tv_sec = 0;
     49        this.it_interval.tv_usec = 0;
     50}
     51
     52
     53void ?{}( __cfa_time_t & this, timespec * curr ) {
     54        uint64_t secs  = curr->tv_sec;
     55        uint64_t nsecs = curr->tv_nsec;
     56        this.val = (secs * one_second) + nsecs;
     57}
     58
     59__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
     60        this.val = 0;
     61        return this;
     62}
     63
     64__cfa_time_t from_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
     65__cfa_time_t from_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
     66__cfa_time_t from_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
     67__cfa_time_t from_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
     68
     69//=============================================================================================
    3370// Clock logic
    3471//=============================================================================================
     
    3774        timespec curr;
    3875        clock_gettime( CLOCK_REALTIME, &curr );
    39         __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
    40         // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );
    41         return curr_time;
     76        return (__cfa_time_t){ &curr };
    4277}
    4378
    4479void __kernel_set_timer( __cfa_time_t alarm ) {
    45         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );
    46         itimerval val;
    47         val.it_value.tv_sec = alarm / TIMEGRAN;                 // seconds
    48         val.it_value.tv_usec = (alarm % TIMEGRAN) / ( TIMEGRAN / 1_000_000L ); // microseconds
    49         val.it_interval.tv_sec = 0;
    50         val.it_interval.tv_usec = 0;
     80        itimerval val = { &alarm };
    5181        setitimer( ITIMER_REAL, &val, NULL );
    5282}
     
    5686//=============================================================================================
    5787
    58 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = 0, __cfa_time_t period = 0 ) {
     88void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
    5989        this.thrd = thrd;
    6090        this.alarm = alarm;
     
    6595}
    6696
    67 void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = 0, __cfa_time_t period = 0 ) {
     97void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) {
    6898        this.proc = proc;
    6999        this.alarm = alarm;
     
    153183
    154184void register_self( alarm_node_t * this ) {
     185        alarm_list_t * alarms = &event_kernel->alarms;
     186
    155187        disable_interrupts();
    156         verify( !systemProcessor->pending_alarm );
    157         lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
     188        lock( &event_kernel->lock DEBUG_CTX2 );
    158189        {
    159                 verify( validate( &systemProcessor->alarms ) );
    160                 bool first = !systemProcessor->alarms.head;
    161 
    162                 insert( &systemProcessor->alarms, this );
    163                 if( systemProcessor->pending_alarm ) {
    164                         tick_preemption();
     190                verify( validate( alarms ) );
     191                bool first = !alarms->head;
     192
     193                insert( alarms, this );
     194                if( first ) {
     195                        __kernel_set_timer( alarms->head->alarm - __kernel_get_time() );
    165196                }
    166                 if( first ) {
    167                         __kernel_set_timer( systemProcessor->alarms.head->alarm - __kernel_get_time() );
    168                 }
    169         }
    170         unlock( &systemProcessor->alarm_lock );
     197        }
     198        unlock( &event_kernel->lock );
    171199        this->set = true;
    172200        enable_interrupts( DEBUG_CTX );
     
    174202
    175203void unregister_self( alarm_node_t * this ) {
    176         // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : unregister %p start\n", this );
    177204        disable_interrupts();
    178         lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
     205        lock( &event_kernel->lock DEBUG_CTX2 );
    179206        {
    180                 verify( validate( &systemProcessor->alarms ) );
    181                 remove( &systemProcessor->alarms, this );
    182         }
    183         unlock( &systemProcessor->alarm_lock );
     207                verify( validate( &event_kernel->alarms ) );
     208                remove( &event_kernel->alarms, this );
     209        }
     210        unlock( &event_kernel->lock );
    184211        enable_interrupts( DEBUG_CTX );
    185212        this->set = false;
    186         // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Kernel : unregister %p end\n", this );
    187 }
     213}
     214
     215// Local Variables: //
     216// mode: c //
     217// tab-width: 4 //
     218// End: //
Note: See TracChangeset for help on using the changeset viewer.