[8118303] | 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 --
|
---|
[8118303] | 9 | //
|
---|
| 10 | // Author : Thierry Delisle
|
---|
[75f3522] | 11 | // Created On : Tue Jan 17 12:27:26 2017
|
---|
[8118303] | 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 |
|
---|
[c84e80a] | 20 | #include <stdbool.h>
|
---|
[8118303] | 21 |
|
---|
[bd98b58] | 22 | #include "invoke.h"
|
---|
| 23 |
|
---|
[8def349] | 24 | extern "C" {
|
---|
| 25 | #include <pthread.h>
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[db6f06a] | 28 | //-----------------------------------------------------------------------------
|
---|
| 29 | // Locks
|
---|
[b227f68] | 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 * );
|
---|
[db6f06a] | 34 |
|
---|
[bdeba0b] | 35 | struct semaphore {
|
---|
| 36 | spinlock lock;
|
---|
| 37 | int count;
|
---|
| 38 | __thread_queue_t waiting;
|
---|
[9c31349] | 39 | };
|
---|
| 40 |
|
---|
[bdeba0b] | 41 | void ?{}(semaphore * this, int count = 1);
|
---|
| 42 | void ^?{}(semaphore * this);
|
---|
| 43 | void P(semaphore * this);
|
---|
| 44 | void V(semaphore * this);
|
---|
[9c31349] | 45 |
|
---|
[db6f06a] | 46 |
|
---|
[bd98b58] | 47 | //-----------------------------------------------------------------------------
|
---|
| 48 | // Cluster
|
---|
| 49 | struct cluster {
|
---|
[5ea06d6] | 50 | __thread_queue_t ready_queue;
|
---|
[db6f06a] | 51 | spinlock lock;
|
---|
[bd98b58] | 52 | };
|
---|
| 53 |
|
---|
| 54 | void ?{}(cluster * this);
|
---|
| 55 | void ^?{}(cluster * this);
|
---|
| 56 |
|
---|
| 57 | //-----------------------------------------------------------------------------
|
---|
| 58 | // Processor
|
---|
[0c78741] | 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)
|
---|
[db6f06a] | 62 | struct FinishAction {
|
---|
| 63 | FinishOpCode action_code;
|
---|
[348006f] | 64 | thread_desc * thrd;
|
---|
[db6f06a] | 65 | spinlock * lock;
|
---|
[0c78741] | 66 | spinlock ** locks;
|
---|
| 67 | unsigned short lock_count;
|
---|
| 68 | thread_desc ** thrds;
|
---|
| 69 | unsigned short thrd_count;
|
---|
[8fcbb4c] | 70 | };
|
---|
[2ac095d] | 71 | static inline void ?{}(FinishAction * this) {
|
---|
[db6f06a] | 72 | this->action_code = No_Action;
|
---|
| 73 | this->thrd = NULL;
|
---|
| 74 | this->lock = NULL;
|
---|
| 75 | }
|
---|
| 76 | static inline void ^?{}(FinishAction * this) {}
|
---|
[8fcbb4c] | 77 |
|
---|
[c84e80a] | 78 | struct processor {
|
---|
[8fcbb4c] | 79 | struct processorCtx_t * runner;
|
---|
[bd98b58] | 80 | cluster * cltr;
|
---|
[8def349] | 81 | pthread_t kernel_thread;
|
---|
[2ac095d] | 82 |
|
---|
[bdeba0b] | 83 | semaphore terminated;
|
---|
[db6f06a] | 84 | volatile bool is_terminated;
|
---|
| 85 |
|
---|
| 86 | struct FinishAction finish;
|
---|
[c81ebf9] | 87 |
|
---|
| 88 | struct alarm_node_t * preemption_alarm;
|
---|
| 89 | unsigned int preemption;
|
---|
| 90 |
|
---|
| 91 | bool pending_preemption;
|
---|
[4e6fb8e] | 92 |
|
---|
| 93 | char * last_enable;
|
---|
[c84e80a] | 94 | };
|
---|
| 95 |
|
---|
[8def349] | 96 | void ?{}(processor * this);
|
---|
[bd98b58] | 97 | void ?{}(processor * this, cluster * cltr);
|
---|
[c84e80a] | 98 | void ^?{}(processor * this);
|
---|
| 99 |
|
---|
[8118303] | 100 | #endif //KERNEL_H
|
---|
| 101 |
|
---|
| 102 | // Local Variables: //
|
---|
[fa21ac9] | 103 | // mode: CFA //
|
---|
| 104 | // tab-width: 6 //
|
---|
[8118303] | 105 | // End: //
|
---|