- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.hfa
rdd4e2d7 r13c5e19 23 23 #include "coroutine.hfa" 24 24 25 #include "containers/stackLockFree.hfa" 26 25 27 extern "C" { 26 28 #include <pthread.h> … … 47 49 extern struct cluster * mainCluster; 48 50 49 // Processor 51 // Processor id, required for scheduling threads 52 struct __processor_id_t { 53 unsigned id; 54 55 #if !defined(__CFA_NO_STATISTICS__) 56 struct __stats_t * stats; 57 #endif 58 }; 59 50 60 coroutine processorCtx_t { 51 61 struct processor * proc; … … 53 63 54 64 // Wrapper around kernel threads 55 struct processor {65 struct __attribute__((aligned(128))) processor { 56 66 // Main state 67 inline __processor_id_t; 68 69 // Cluster from which to get threads 70 struct cluster * cltr; 71 72 // Set to true to notify the processor should terminate 73 volatile bool do_terminate; 74 57 75 // Coroutine ctx who does keeps the state of the processor 58 76 struct processorCtx_t runner; 59 60 // Cluster from which to get threads61 struct cluster * cltr;62 77 63 78 // Name of the processor … … 81 96 __bin_sem_t idle; 82 97 83 // Termination84 // Set to true to notify the processor should terminate85 volatile bool do_terminate;86 87 98 // Termination synchronisation (user semaphore) 88 99 semaphore terminated; … … 92 103 93 104 // Link lists fields 94 struct __dbg_node_proc { 95 struct processor * next; 96 struct processor * prev; 97 } node; 105 Link(processor) link; 98 106 99 107 #ifdef __CFA_DEBUG__ … … 110 118 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster }; } 111 119 112 static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }120 static inline Link(processor) * ?`next( processor * this ) { return &this->link; } 113 121 114 122 //----------------------------------------------------------------------------- … … 121 129 #define CFA_CLUSTER_IO_BUFFLEN_OFFSET 16 122 130 131 132 //----------------------------------------------------------------------------- 133 // Cluster Tools 134 135 // Intrusives lanes which are used by the relaxed ready queue 136 struct __attribute__((aligned(128))) __intrusive_lane_t; 137 void ?{}(__intrusive_lane_t & this); 138 void ^?{}(__intrusive_lane_t & this); 139 140 // Counter used for wether or not the lanes are all empty 141 struct __attribute__((aligned(128))) __snzi_node_t; 142 struct __snzi_t { 143 unsigned mask; 144 int root; 145 __snzi_node_t * nodes; 146 }; 147 148 void ?{}( __snzi_t & this, unsigned depth ); 149 void ^?{}( __snzi_t & this ); 150 151 //TODO adjust cache size to ARCHITECTURE 152 // Structure holding the relaxed ready queue 153 struct __ready_queue_t { 154 // Data tracking how many/which lanes are used 155 // Aligned to 128 for cache locality 156 __snzi_t snzi; 157 158 // Data tracking the actual lanes 159 // On a seperate cacheline from the used struct since 160 // used can change on each push/pop but this data 161 // only changes on shrink/grow 162 struct { 163 // Arary of lanes 164 __intrusive_lane_t * volatile data; 165 166 // Number of lanes (empty or not) 167 volatile size_t count; 168 } lanes; 169 }; 170 171 void ?{}(__ready_queue_t & this); 172 void ^?{}(__ready_queue_t & this); 173 123 174 //----------------------------------------------------------------------------- 124 175 // Cluster 125 struct cluster { 126 // Ready queue locks 127 __spinlock_t ready_queue_lock; 128 176 struct __attribute__((aligned(128))) cluster { 129 177 // Ready queue for threads 130 __ queue_t($thread)ready_queue;178 __ready_queue_t ready_queue; 131 179 132 180 // Name of the cluster … … 136 184 Duration preemption_rate; 137 185 138 // List of processors 139 __spinlock_t idle_lock; 140 __dllist_t(struct processor) procs; 141 __dllist_t(struct processor) idles; 142 unsigned int nprocessors; 186 // List of idle processors 187 StackLF(processor) idles; 188 volatile unsigned int nprocessors; 143 189 144 190 // List of threads … … 157 203 #if !defined(__CFA_NO_STATISTICS__) 158 204 bool print_stats; 205 struct __stats_t * stats; 159 206 #endif 160 207 };
Note:
See TracChangeset
for help on using the changeset viewer.