[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 |
|
---|
| 20 | #include "kernel"
|
---|
[75a17f1] | 21 | #include "thread"
|
---|
[75f3522] | 22 |
|
---|
[fa21ac9] | 23 | #include "alarm.h"
|
---|
| 24 |
|
---|
[75f3522] | 25 | //-----------------------------------------------------------------------------
|
---|
| 26 | // Scheduler
|
---|
[348006f] | 27 | void ScheduleThread( thread_desc * );
|
---|
| 28 | thread_desc * nextThread(cluster * this);
|
---|
[75f3522] | 29 |
|
---|
[0c78741] | 30 | void ScheduleInternal(void);
|
---|
[db6f06a] | 31 | void ScheduleInternal(spinlock * lock);
|
---|
[348006f] | 32 | void ScheduleInternal(thread_desc * thrd);
|
---|
| 33 | void ScheduleInternal(spinlock * lock, thread_desc * thrd);
|
---|
[0c78741] | 34 | void ScheduleInternal(spinlock ** locks, unsigned short count);
|
---|
| 35 | void ScheduleInternal(spinlock ** locks, unsigned short count, thread_desc ** thrds, unsigned short thrd_count);
|
---|
[db6f06a] | 36 |
|
---|
[75f3522] | 37 | //-----------------------------------------------------------------------------
|
---|
| 38 | // Processor
|
---|
[fa21ac9] | 39 | coroutine processorCtx_t {
|
---|
[75f3522] | 40 | processor * proc;
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | void main(processorCtx_t *);
|
---|
[db6f06a] | 44 | void start(processor * this);
|
---|
[348006f] | 45 | void runThread(processor * this, thread_desc * dst);
|
---|
[db6f06a] | 46 | void finishRunning(processor * this);
|
---|
[75f3522] | 47 | void spin(processor * this, unsigned int * spin_count);
|
---|
| 48 |
|
---|
[fa21ac9] | 49 | struct system_proc_t {
|
---|
| 50 | processor proc;
|
---|
| 51 |
|
---|
| 52 | alarm_list_t alarms;
|
---|
| 53 | spinlock alarm_lock;
|
---|
[c81ebf9] | 54 |
|
---|
| 55 | bool pending_alarm;
|
---|
[fa21ac9] | 56 | };
|
---|
| 57 |
|
---|
| 58 | extern cluster * systemCluster;
|
---|
| 59 | extern system_proc_t * systemProcessor;
|
---|
[c81ebf9] | 60 | extern thread_local processor * this_processor;
|
---|
| 61 |
|
---|
| 62 | static inline void disable_interrupts() {
|
---|
| 63 | __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &this_processor->disable_preempt_count, 1, __ATOMIC_SEQ_CST );
|
---|
| 64 | assert( prev != (unsigned short) -1 );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | static inline void enable_interrupts_noRF() {
|
---|
| 68 | unsigned short prev = __atomic_fetch_add_2( &this_processor->disable_preempt_count, -1, __ATOMIC_SEQ_CST );
|
---|
| 69 | assert( prev != (unsigned short) 0 );
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | static inline void enable_interrupts() {
|
---|
| 73 | unsigned short prev = __atomic_fetch_add_2( &this_processor->disable_preempt_count, -1, __ATOMIC_SEQ_CST );
|
---|
| 74 | assert( prev != (unsigned short) 0 );
|
---|
| 75 | if( prev == 1 && this_processor->pending_preemption ) {
|
---|
| 76 | ScheduleInternal( this_processor->current_thread );
|
---|
| 77 | this_processor->pending_preemption = false;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
[fa21ac9] | 80 |
|
---|
[75f3522] | 81 | //-----------------------------------------------------------------------------
|
---|
| 82 | // Threads
|
---|
| 83 | extern "C" {
|
---|
| 84 | forall(dtype T | is_thread(T))
|
---|
| 85 | void CtxInvokeThread(T * this);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[c3acb841] | 88 | extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
|
---|
[75f3522] | 89 |
|
---|
| 90 | #endif //KERNEL_PRIVATE_H
|
---|
| 91 |
|
---|
| 92 | // Local Variables: //
|
---|
| 93 | // mode: c //
|
---|
| 94 | // tab-width: 4 //
|
---|
| 95 | // End: //
|
---|