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 | // kernel -- |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Tue Jan 17 12:27:26 2017 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sat Jul 22 09:58:39 2017 |
---|
13 | // Update Count : 2 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <stdbool.h> |
---|
19 | |
---|
20 | #include "invoke.h" |
---|
21 | |
---|
22 | extern "C" { |
---|
23 | #include <pthread.h> |
---|
24 | } |
---|
25 | |
---|
26 | //----------------------------------------------------------------------------- |
---|
27 | // Locks |
---|
28 | struct semaphore { |
---|
29 | __spinlock_t lock; |
---|
30 | int count; |
---|
31 | __queue_t(thread_desc) waiting; |
---|
32 | }; |
---|
33 | |
---|
34 | void ?{}(semaphore & this, int count = 1); |
---|
35 | void ^?{}(semaphore & this); |
---|
36 | void P (semaphore & this); |
---|
37 | void V (semaphore & this); |
---|
38 | |
---|
39 | |
---|
40 | //----------------------------------------------------------------------------- |
---|
41 | // Cluster |
---|
42 | struct cluster { |
---|
43 | // Ready queue locks |
---|
44 | __spinlock_t ready_queue_lock; |
---|
45 | |
---|
46 | // Ready queue for threads |
---|
47 | __queue_t(thread_desc) ready_queue; |
---|
48 | |
---|
49 | // Preemption rate on this cluster |
---|
50 | unsigned long long int preemption; |
---|
51 | }; |
---|
52 | |
---|
53 | void ?{} (cluster & this); |
---|
54 | void ^?{}(cluster & this); |
---|
55 | |
---|
56 | //----------------------------------------------------------------------------- |
---|
57 | // Processor |
---|
58 | enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule }; |
---|
59 | |
---|
60 | //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) |
---|
61 | struct FinishAction { |
---|
62 | FinishOpCode action_code; |
---|
63 | thread_desc * thrd; |
---|
64 | __spinlock_t * lock; |
---|
65 | __spinlock_t ** locks; |
---|
66 | unsigned short lock_count; |
---|
67 | thread_desc ** thrds; |
---|
68 | unsigned short thrd_count; |
---|
69 | }; |
---|
70 | static inline void ?{}(FinishAction & this) { |
---|
71 | this.action_code = No_Action; |
---|
72 | this.thrd = NULL; |
---|
73 | this.lock = NULL; |
---|
74 | } |
---|
75 | static inline void ^?{}(FinishAction & this) {} |
---|
76 | |
---|
77 | // Processor |
---|
78 | // Wrapper around kernel threads |
---|
79 | struct processor { |
---|
80 | // Main state |
---|
81 | // Coroutine ctx who does keeps the state of the processor |
---|
82 | struct processorCtx_t * runner; |
---|
83 | |
---|
84 | // Cluster from which to get threads |
---|
85 | cluster * cltr; |
---|
86 | |
---|
87 | // Handle to pthreads |
---|
88 | pthread_t kernel_thread; |
---|
89 | |
---|
90 | // Termination |
---|
91 | // Set to true to notify the processor should terminate |
---|
92 | volatile bool do_terminate; |
---|
93 | |
---|
94 | // Termination synchronisation |
---|
95 | semaphore terminated; |
---|
96 | |
---|
97 | // RunThread data |
---|
98 | // Action to do after a thread is ran |
---|
99 | struct FinishAction finish; |
---|
100 | |
---|
101 | // Preemption data |
---|
102 | // Node which is added in the discrete event simulaiton |
---|
103 | struct alarm_node_t * preemption_alarm; |
---|
104 | |
---|
105 | // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible |
---|
106 | bool pending_preemption; |
---|
107 | |
---|
108 | #ifdef __CFA_DEBUG__ |
---|
109 | // Last function to enable preemption on this processor |
---|
110 | const char * last_enable; |
---|
111 | #endif |
---|
112 | }; |
---|
113 | |
---|
114 | void ?{}(processor & this); |
---|
115 | void ?{}(processor & this, cluster * cltr); |
---|
116 | void ^?{}(processor & this); |
---|
117 | |
---|
118 | // Local Variables: // |
---|
119 | // mode: c // |
---|
120 | // tab-width: 4 // |
---|
121 | // End: // |
---|