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