[75f3522] | 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_private.h -- |
---|
[75f3522] | 9 | // |
---|
| 10 | // Author : Thierry Delisle |
---|
| 11 | // Created On : Mon Feb 13 12:27:26 2017 |
---|
| 12 | // Last Modified By : Thierry Delisle |
---|
| 13 | // Last Modified On : -- |
---|
| 14 | // Update Count : 0 |
---|
| 15 | // |
---|
| 16 | |
---|
| 17 | #ifndef KERNEL_PRIVATE_H |
---|
| 18 | #define KERNEL_PRIVATE_H |
---|
| 19 | |
---|
[2ac095d] | 20 | #include "libhdr.h" |
---|
| 21 | |
---|
[75f3522] | 22 | #include "kernel" |
---|
[75a17f1] | 23 | #include "thread" |
---|
[75f3522] | 24 | |
---|
[fa21ac9] | 25 | #include "alarm.h" |
---|
| 26 | |
---|
[4aa2fb2] | 27 | |
---|
[75f3522] | 28 | //----------------------------------------------------------------------------- |
---|
| 29 | // Scheduler |
---|
[1c273d0] | 30 | |
---|
| 31 | extern "C" { |
---|
| 32 | void disable_interrupts(); |
---|
[969b3fe] | 33 | void enable_interrupts_noPoll(); |
---|
[2ac095d] | 34 | void enable_interrupts( DEBUG_CTX_PARAM ); |
---|
[1c273d0] | 35 | } |
---|
| 36 | |
---|
[348006f] | 37 | void ScheduleThread( thread_desc * ); |
---|
[1c273d0] | 38 | static inline void WakeThread( thread_desc * thrd ) { |
---|
| 39 | if( !thrd ) return; |
---|
| 40 | |
---|
| 41 | disable_interrupts(); |
---|
| 42 | ScheduleThread( thrd ); |
---|
[2ac095d] | 43 | enable_interrupts( DEBUG_CTX ); |
---|
[1c273d0] | 44 | } |
---|
[348006f] | 45 | thread_desc * nextThread(cluster * this); |
---|
[75f3522] | 46 | |
---|
[e60e0dc] | 47 | //Block current thread and release/wake-up the following resources |
---|
[82ff5845] | 48 | void BlockInternal(void); |
---|
| 49 | void BlockInternal(spinlock * lock); |
---|
| 50 | void BlockInternal(thread_desc * thrd); |
---|
| 51 | void BlockInternal(spinlock * lock, thread_desc * thrd); |
---|
| 52 | void BlockInternal(spinlock ** locks, unsigned short count); |
---|
| 53 | void BlockInternal(spinlock ** locks, unsigned short count, thread_desc ** thrds, unsigned short thrd_count); |
---|
[f2b12406] | 54 | void LeaveThread(spinlock * lock, thread_desc * thrd); |
---|
[db6f06a] | 55 | |
---|
[75f3522] | 56 | //----------------------------------------------------------------------------- |
---|
| 57 | // Processor |
---|
[fa21ac9] | 58 | coroutine processorCtx_t { |
---|
[75f3522] | 59 | processor * proc; |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | void main(processorCtx_t *); |
---|
[db6f06a] | 63 | void start(processor * this); |
---|
[348006f] | 64 | void runThread(processor * this, thread_desc * dst); |
---|
[db6f06a] | 65 | void finishRunning(processor * this); |
---|
[75f3522] | 66 | void spin(processor * this, unsigned int * spin_count); |
---|
| 67 | |
---|
[e60e0dc] | 68 | struct event_kernel_t { |
---|
[fa21ac9] | 69 | alarm_list_t alarms; |
---|
[e60e0dc] | 70 | spinlock lock; |
---|
[fa21ac9] | 71 | }; |
---|
| 72 | |
---|
[e60e0dc] | 73 | extern event_kernel_t * event_kernel; |
---|
| 74 | |
---|
[9cc0472] | 75 | extern thread_local coroutine_desc * volatile this_coroutine; |
---|
| 76 | extern thread_local thread_desc * volatile this_thread; |
---|
| 77 | extern thread_local processor * volatile this_processor; |
---|
| 78 | |
---|
[d6ff3ff] | 79 | extern volatile thread_local bool preemption_in_progress; |
---|
[4e6fb8e] | 80 | extern volatile thread_local unsigned short disable_preempt_count; |
---|
[c81ebf9] | 81 | |
---|
[75f3522] | 82 | //----------------------------------------------------------------------------- |
---|
| 83 | // Threads |
---|
| 84 | extern "C" { |
---|
| 85 | forall(dtype T | is_thread(T)) |
---|
| 86 | void CtxInvokeThread(T * this); |
---|
| 87 | } |
---|
| 88 | |
---|
[c3acb841] | 89 | extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst); |
---|
[75f3522] | 90 | |
---|
[969b3fe] | 91 | //----------------------------------------------------------------------------- |
---|
| 92 | // Utils |
---|
| 93 | #define KERNEL_STORAGE(T,X) static char storage_##X[sizeof(T)] |
---|
| 94 | |
---|
[75f3522] | 95 | #endif //KERNEL_PRIVATE_H |
---|
| 96 | |
---|
| 97 | // Local Variables: // |
---|
| 98 | // mode: c // |
---|
| 99 | // tab-width: 4 // |
---|
[4aa2fb2] | 100 | // End: // |
---|