| 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 *
|
|---|
| 31 | #ifdef __CFA_DEBUG__
|
|---|
| 32 | , const char * caller
|
|---|
| 33 | #endif
|
|---|
| 34 | );
|
|---|
| 35 |
|
|---|
| 36 | void lock( spinlock *
|
|---|
| 37 | #ifdef __CFA_DEBUG__
|
|---|
| 38 | , const char * caller
|
|---|
| 39 | #endif
|
|---|
| 40 | );
|
|---|
| 41 |
|
|---|
| 42 | void unlock( spinlock * );
|
|---|
| 43 |
|
|---|
| 44 | struct signal_once {
|
|---|
| 45 | volatile bool cond;
|
|---|
| 46 | struct spinlock lock;
|
|---|
| 47 | struct __thread_queue_t blocked;
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | void ?{}(signal_once * this);
|
|---|
| 51 | void ^?{}(signal_once * this);
|
|---|
| 52 |
|
|---|
| 53 | void wait( signal_once * );
|
|---|
| 54 | void signal( signal_once * );
|
|---|
| 55 |
|
|---|
| 56 | //-----------------------------------------------------------------------------
|
|---|
| 57 | // Cluster
|
|---|
| 58 | struct cluster {
|
|---|
| 59 | __thread_queue_t ready_queue;
|
|---|
| 60 | spinlock lock;
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | void ?{}(cluster * this);
|
|---|
| 64 | void ^?{}(cluster * this);
|
|---|
| 65 |
|
|---|
| 66 | //-----------------------------------------------------------------------------
|
|---|
| 67 | // Processor
|
|---|
| 68 | enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
|
|---|
| 69 |
|
|---|
| 70 | //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
|
|---|
| 71 | struct FinishAction {
|
|---|
| 72 | FinishOpCode action_code;
|
|---|
| 73 | thread_desc * thrd;
|
|---|
| 74 | spinlock * lock;
|
|---|
| 75 | spinlock ** locks;
|
|---|
| 76 | unsigned short lock_count;
|
|---|
| 77 | thread_desc ** thrds;
|
|---|
| 78 | unsigned short thrd_count;
|
|---|
| 79 | };
|
|---|
| 80 | static inline void ?{}(FinishAction * this) {
|
|---|
| 81 | this->action_code = No_Action;
|
|---|
| 82 | this->thrd = NULL;
|
|---|
| 83 | this->lock = NULL;
|
|---|
| 84 | }
|
|---|
| 85 | static inline void ^?{}(FinishAction * this) {}
|
|---|
| 86 |
|
|---|
| 87 | struct processor {
|
|---|
| 88 | struct processorCtx_t * runner;
|
|---|
| 89 | cluster * cltr;
|
|---|
| 90 | pthread_t kernel_thread;
|
|---|
| 91 |
|
|---|
| 92 | signal_once terminated;
|
|---|
| 93 | volatile bool is_terminated;
|
|---|
| 94 |
|
|---|
| 95 | struct FinishAction finish;
|
|---|
| 96 |
|
|---|
| 97 | struct alarm_node_t * preemption_alarm;
|
|---|
| 98 | unsigned int preemption;
|
|---|
| 99 |
|
|---|
| 100 | bool pending_preemption;
|
|---|
| 101 |
|
|---|
| 102 | char * last_enable;
|
|---|
| 103 | };
|
|---|
| 104 |
|
|---|
| 105 | void ?{}(processor * this);
|
|---|
| 106 | void ?{}(processor * this, cluster * cltr);
|
|---|
| 107 | void ^?{}(processor * this);
|
|---|
| 108 |
|
|---|
| 109 | #endif //KERNEL_H
|
|---|
| 110 |
|
|---|
| 111 | // Local Variables: //
|
|---|
| 112 | // mode: CFA //
|
|---|
| 113 | // tab-width: 6 //
|
|---|
| 114 | // End: //
|
|---|