[8118303] | 1 | // -*- Mode: CFA -*- |
---|
| 2 | // |
---|
| 3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 4 | // |
---|
| 5 | // The contents of this file are covered under the licence agreement in the |
---|
| 6 | // file "LICENCE" distributed with Cforall. |
---|
| 7 | // |
---|
[75a17f1] | 8 | // kernel -- |
---|
[8118303] | 9 | // |
---|
| 10 | // Author : Thierry Delisle |
---|
[75f3522] | 11 | // Created On : Tue Jan 17 12:27:26 2017 |
---|
[8118303] | 12 | // Last Modified By : Thierry Delisle |
---|
| 13 | // Last Modified On : -- |
---|
| 14 | // Update Count : 0 |
---|
| 15 | // |
---|
| 16 | |
---|
| 17 | #ifndef KERNEL_H |
---|
| 18 | #define KERNEL_H |
---|
| 19 | |
---|
[c84e80a] | 20 | #include <stdbool.h> |
---|
[8118303] | 21 | |
---|
[bd98b58] | 22 | #include "invoke.h" |
---|
| 23 | |
---|
[8def349] | 24 | extern "C" { |
---|
| 25 | #include <pthread.h> |
---|
| 26 | } |
---|
| 27 | |
---|
[db6f06a] | 28 | //----------------------------------------------------------------------------- |
---|
| 29 | // Locks |
---|
[1c273d0] | 30 | bool try_lock( spinlock * |
---|
| 31 | #ifdef __CFA_DEBUG__ |
---|
| 32 | , const char * caller |
---|
| 33 | #endif |
---|
| 34 | ); |
---|
| 35 | |
---|
| 36 | void lock( spinlock * |
---|
| 37 | #ifdef __CFA_DEBUG__ |
---|
| 38 | , const char * caller |
---|
| 39 | #endif |
---|
| 40 | ); |
---|
| 41 | |
---|
[db6f06a] | 42 | void unlock( spinlock * ); |
---|
| 43 | |
---|
[9c31349] | 44 | struct signal_once { |
---|
[5ea06d6] | 45 | volatile bool cond; |
---|
[9c31349] | 46 | struct spinlock lock; |
---|
[5ea06d6] | 47 | struct __thread_queue_t blocked; |
---|
[9c31349] | 48 | }; |
---|
| 49 | |
---|
| 50 | void ?{}(signal_once * this); |
---|
| 51 | void ^?{}(signal_once * this); |
---|
| 52 | |
---|
[db6f06a] | 53 | void wait( signal_once * ); |
---|
| 54 | void signal( signal_once * ); |
---|
| 55 | |
---|
[bd98b58] | 56 | //----------------------------------------------------------------------------- |
---|
| 57 | // Cluster |
---|
| 58 | struct cluster { |
---|
[5ea06d6] | 59 | __thread_queue_t ready_queue; |
---|
[db6f06a] | 60 | spinlock lock; |
---|
[bd98b58] | 61 | }; |
---|
| 62 | |
---|
| 63 | void ?{}(cluster * this); |
---|
| 64 | void ^?{}(cluster * this); |
---|
| 65 | |
---|
| 66 | //----------------------------------------------------------------------------- |
---|
| 67 | // Processor |
---|
[0c78741] | 68 | enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule }; |
---|
| 69 | |
---|
| 70 | //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) |
---|
[db6f06a] | 71 | struct FinishAction { |
---|
| 72 | FinishOpCode action_code; |
---|
[348006f] | 73 | thread_desc * thrd; |
---|
[db6f06a] | 74 | spinlock * lock; |
---|
[0c78741] | 75 | spinlock ** locks; |
---|
| 76 | unsigned short lock_count; |
---|
| 77 | thread_desc ** thrds; |
---|
| 78 | unsigned short thrd_count; |
---|
[8fcbb4c] | 79 | }; |
---|
[db6f06a] | 80 | static inline void ?{}(FinishAction * this) { |
---|
| 81 | this->action_code = No_Action; |
---|
| 82 | this->thrd = NULL; |
---|
| 83 | this->lock = NULL; |
---|
| 84 | } |
---|
| 85 | static inline void ^?{}(FinishAction * this) {} |
---|
[8fcbb4c] | 86 | |
---|
[c84e80a] | 87 | struct processor { |
---|
[8fcbb4c] | 88 | struct processorCtx_t * runner; |
---|
[bd98b58] | 89 | cluster * cltr; |
---|
[8def349] | 90 | pthread_t kernel_thread; |
---|
[db6f06a] | 91 | |
---|
| 92 | signal_once terminated; |
---|
| 93 | volatile bool is_terminated; |
---|
| 94 | |
---|
| 95 | struct FinishAction finish; |
---|
[c81ebf9] | 96 | |
---|
| 97 | struct alarm_node_t * preemption_alarm; |
---|
| 98 | unsigned int preemption; |
---|
| 99 | |
---|
| 100 | bool pending_preemption; |
---|
[4e6fb8e] | 101 | |
---|
| 102 | char * last_enable; |
---|
[c84e80a] | 103 | }; |
---|
| 104 | |
---|
[8def349] | 105 | void ?{}(processor * this); |
---|
[bd98b58] | 106 | void ?{}(processor * this, cluster * cltr); |
---|
[c84e80a] | 107 | void ^?{}(processor * this); |
---|
| 108 | |
---|
[8118303] | 109 | #endif //KERNEL_H |
---|
| 110 | |
---|
| 111 | // Local Variables: // |
---|
[fa21ac9] | 112 | // mode: CFA // |
---|
| 113 | // tab-width: 6 // |
---|
[8118303] | 114 | // End: // |
---|