| [6cff9f3] | 1 | //
 | 
|---|
 | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
 | 
|---|
 | 3 | //
 | 
|---|
 | 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
 | 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
 | 6 | //
 | 
|---|
 | 7 | // alarm.h --
 | 
|---|
 | 8 | //
 | 
|---|
 | 9 | // Author           : Thierry Delisle
 | 
|---|
 | 10 | // Created On       : Fri Jun 2 11:31:25 2017
 | 
|---|
| [91c389a] | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| [6b0b624] | 12 | // Last Modified On : Sat Jul 22 09:59:27 2017
 | 
|---|
 | 13 | // Update Count     : 3
 | 
|---|
| [6cff9f3] | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
| [6b0b624] | 16 | #pragma once
 | 
|---|
| [6cff9f3] | 17 | 
 | 
|---|
| [c81ebf9] | 18 | #include <stdbool.h>
 | 
|---|
| [8cb529e] | 19 | #include <stdint.h>
 | 
|---|
| [c81ebf9] | 20 | 
 | 
|---|
| [91c389a] | 21 | #include <assert.h>
 | 
|---|
| [6cff9f3] | 22 | 
 | 
|---|
 | 23 | struct thread_desc;
 | 
|---|
 | 24 | struct processor;
 | 
|---|
 | 25 | 
 | 
|---|
| [969b3fe] | 26 | struct timespec;
 | 
|---|
 | 27 | struct itimerval;
 | 
|---|
 | 28 | 
 | 
|---|
| [c81ebf9] | 29 | //=============================================================================================
 | 
|---|
| [969b3fe] | 30 | // time type
 | 
|---|
| [c81ebf9] | 31 | //=============================================================================================
 | 
|---|
 | 32 | 
 | 
|---|
| [969b3fe] | 33 | struct __cfa_time_t {
 | 
|---|
 | 34 |         uint64_t val;
 | 
|---|
 | 35 | };
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | // ctors
 | 
|---|
| [9236060] | 38 | void ?{}( __cfa_time_t & this );
 | 
|---|
 | 39 | void ?{}( __cfa_time_t & this, zero_t zero );
 | 
|---|
 | 40 | void ?{}( __cfa_time_t & this, timespec * curr );
 | 
|---|
 | 41 | void ?{}( itimerval & this, __cfa_time_t * alarm );
 | 
|---|
| [969b3fe] | 42 | 
 | 
|---|
| [9236060] | 43 | __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs );
 | 
|---|
| [969b3fe] | 44 | 
 | 
|---|
 | 45 | // logical ops
 | 
|---|
 | 46 | static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; }
 | 
|---|
 | 47 | static inline bool ?!=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val != rhs.val; }
 | 
|---|
 | 48 | static inline bool ?>? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >  rhs.val; }
 | 
|---|
 | 49 | static inline bool ?<? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <  rhs.val; }
 | 
|---|
 | 50 | static inline bool ?>=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >= rhs.val; }
 | 
|---|
 | 51 | static inline bool ?<=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <= rhs.val; }
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; }
 | 
|---|
 | 54 | static inline bool ?!=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val != rhs; }
 | 
|---|
 | 55 | static inline bool ?>? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >  rhs; }
 | 
|---|
 | 56 | static inline bool ?<? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <  rhs; }
 | 
|---|
 | 57 | static inline bool ?>=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >= rhs; }
 | 
|---|
 | 58 | static inline bool ?<=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <= rhs; }
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 | // addition/substract
 | 
|---|
 | 61 | static inline __cfa_time_t ?+?( __cfa_time_t lhs, __cfa_time_t rhs ) {
 | 
|---|
 | 62 |         __cfa_time_t ret;
 | 
|---|
 | 63 |         ret.val = lhs.val + rhs.val;
 | 
|---|
 | 64 |         return ret;
 | 
|---|
 | 65 | }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | static inline __cfa_time_t ?-?( __cfa_time_t lhs, __cfa_time_t rhs ) {
 | 
|---|
 | 68 |         __cfa_time_t ret;
 | 
|---|
 | 69 |         ret.val = lhs.val - rhs.val;
 | 
|---|
 | 70 |         return ret;
 | 
|---|
 | 71 | }
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | __cfa_time_t from_s ( uint64_t );
 | 
|---|
 | 74 | __cfa_time_t from_ms( uint64_t );
 | 
|---|
 | 75 | __cfa_time_t from_us( uint64_t );
 | 
|---|
 | 76 | __cfa_time_t from_ns( uint64_t );
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | extern __cfa_time_t zero_time;
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | //=============================================================================================
 | 
|---|
 | 81 | // Clock logic
 | 
|---|
 | 82 | //=============================================================================================
 | 
|---|
| [c81ebf9] | 83 | 
 | 
|---|
 | 84 | __cfa_time_t __kernel_get_time();
 | 
|---|
 | 85 | void __kernel_set_timer( __cfa_time_t alarm );
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | //=============================================================================================
 | 
|---|
 | 88 | // Alarm logic
 | 
|---|
 | 89 | //=============================================================================================
 | 
|---|
 | 90 | 
 | 
|---|
| [6cff9f3] | 91 | struct alarm_node_t {
 | 
|---|
| [c81ebf9] | 92 |         __cfa_time_t alarm;             // time when alarm goes off
 | 
|---|
 | 93 |         __cfa_time_t period;            // if > 0 => period of alarm
 | 
|---|
 | 94 |         alarm_node_t * next;            // intrusive link list field
 | 
|---|
| [6cff9f3] | 95 | 
 | 
|---|
 | 96 |         union {
 | 
|---|
 | 97 |                 thread_desc * thrd;     // thrd who created event
 | 
|---|
 | 98 |                 processor * proc;               // proc who created event
 | 
|---|
 | 99 |         };
 | 
|---|
| [c81ebf9] | 100 | 
 | 
|---|
 | 101 |         bool set                :1;             // whether or not the alarm has be registered
 | 
|---|
 | 102 |         bool kernel_alarm       :1;             // true if this is not a user defined alarm
 | 
|---|
| [6cff9f3] | 103 | };
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | typedef alarm_node_t ** __alarm_it_t;
 | 
|---|
 | 106 | 
 | 
|---|
| [9236060] | 107 | void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
 | 
|---|
 | 108 | void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
 | 
|---|
| [242a902] | 109 | void ^?{}( alarm_node_t & this );
 | 
|---|
| [6cff9f3] | 110 | 
 | 
|---|
 | 111 | struct alarm_list_t {
 | 
|---|
 | 112 |         alarm_node_t * head;
 | 
|---|
 | 113 |         __alarm_it_t tail;
 | 
|---|
 | 114 | };
 | 
|---|
 | 115 | 
 | 
|---|
| [242a902] | 116 | static inline void ?{}( alarm_list_t & this ) {
 | 
|---|
 | 117 |         this.head = 0;
 | 
|---|
 | 118 |         this.tail = &this.head;
 | 
|---|
| [6cff9f3] | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 | void insert( alarm_list_t * this, alarm_node_t * n );
 | 
|---|
 | 122 | alarm_node_t * pop( alarm_list_t * this );
 | 
|---|
 | 123 | 
 | 
|---|
| [c81ebf9] | 124 | void register_self  ( alarm_node_t * this );
 | 
|---|
 | 125 | void unregister_self( alarm_node_t * this );
 | 
|---|
 | 126 | 
 | 
|---|
| [6cff9f3] | 127 | // Local Variables: //
 | 
|---|
| [6b0b624] | 128 | // mode: c //
 | 
|---|
| [6cff9f3] | 129 | // tab-width: 6 //
 | 
|---|
| [242a902] | 130 | // End: //
 | 
|---|