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 | // |
---|
8 | // kernel -- |
---|
9 | // |
---|
10 | // Author : Thierry Delisle |
---|
11 | // Created On : Tue Jan 17 12:27:26 2017 |
---|
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 | |
---|
20 | #include <stdbool.h> |
---|
21 | |
---|
22 | #include "invoke.h" |
---|
23 | |
---|
24 | extern "C" { |
---|
25 | #include <pthread.h> |
---|
26 | } |
---|
27 | |
---|
28 | //----------------------------------------------------------------------------- |
---|
29 | // Locks |
---|
30 | bool try_lock ( spinlock * DEBUG_CTX_PARAM2 ); |
---|
31 | void lock ( spinlock * DEBUG_CTX_PARAM2 ); |
---|
32 | void lock_yield( spinlock * DEBUG_CTX_PARAM2 ); |
---|
33 | void unlock ( spinlock * ); |
---|
34 | |
---|
35 | struct semaphore { |
---|
36 | spinlock lock; |
---|
37 | int count; |
---|
38 | __thread_queue_t waiting; |
---|
39 | }; |
---|
40 | |
---|
41 | void ?{}(semaphore & this, int count = 1); |
---|
42 | void ^?{}(semaphore & this); |
---|
43 | void P(semaphore * this); |
---|
44 | void V(semaphore * this); |
---|
45 | |
---|
46 | |
---|
47 | //----------------------------------------------------------------------------- |
---|
48 | // Cluster |
---|
49 | struct cluster { |
---|
50 | __thread_queue_t ready_queue; |
---|
51 | spinlock lock; |
---|
52 | }; |
---|
53 | |
---|
54 | void ?{}(cluster & this); |
---|
55 | void ^?{}(cluster & this); |
---|
56 | |
---|
57 | //----------------------------------------------------------------------------- |
---|
58 | // Processor |
---|
59 | enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule }; |
---|
60 | |
---|
61 | //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) |
---|
62 | struct FinishAction { |
---|
63 | FinishOpCode action_code; |
---|
64 | thread_desc * thrd; |
---|
65 | spinlock * lock; |
---|
66 | spinlock ** locks; |
---|
67 | unsigned short lock_count; |
---|
68 | thread_desc ** thrds; |
---|
69 | unsigned short thrd_count; |
---|
70 | }; |
---|
71 | static inline void ?{}(FinishAction & this) { |
---|
72 | this.action_code = No_Action; |
---|
73 | this.thrd = NULL; |
---|
74 | this.lock = NULL; |
---|
75 | } |
---|
76 | static inline void ^?{}(FinishAction & this) {} |
---|
77 | |
---|
78 | struct processor { |
---|
79 | struct processorCtx_t * runner; |
---|
80 | cluster * cltr; |
---|
81 | pthread_t kernel_thread; |
---|
82 | |
---|
83 | semaphore terminated; |
---|
84 | volatile bool is_terminated; |
---|
85 | |
---|
86 | struct FinishAction finish; |
---|
87 | |
---|
88 | struct alarm_node_t * preemption_alarm; |
---|
89 | unsigned int preemption; |
---|
90 | |
---|
91 | bool pending_preemption; |
---|
92 | |
---|
93 | char * last_enable; |
---|
94 | }; |
---|
95 | |
---|
96 | void ?{}(processor & this); |
---|
97 | void ?{}(processor & this, cluster * cltr); |
---|
98 | void ^?{}(processor & this); |
---|
99 | |
---|
100 | #endif //KERNEL_H |
---|
101 | |
---|
102 | // Local Variables: // |
---|
103 | // mode: CFA // |
---|
104 | // tab-width: 6 // |
---|
105 | // End: // |
---|