source: src/libcfa/concurrency/kernel@ a83ffa4

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since a83ffa4 was de94a60, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

some more work on kernel doubly linked lists and fixed segfault in abort message

  • Property mode set to 100644
File size: 4.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// kernel --
8//
9// Author : Thierry Delisle
10// Created On : Tue Jan 17 12:27:26 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Apr 10 14:46:49 2018
13// Update Count : 10
14//
15
16#pragma once
17
18#include <stdbool.h>
19
20#include "invoke.h"
21#include "time_t.h"
22
23extern "C" {
24#include <pthread.h>
25}
26
27//-----------------------------------------------------------------------------
28// Locks
29struct semaphore {
30 __spinlock_t lock;
31 int count;
32 __queue_t(thread_desc) waiting;
33};
34
35void ?{}(semaphore & this, int count = 1);
36void ^?{}(semaphore & this);
37void P (semaphore & this);
38void V (semaphore & this);
39
40
41//-----------------------------------------------------------------------------
42// Processor
43extern struct cluster * mainCluster;
44
45enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
46
47//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
48struct FinishAction {
49 FinishOpCode action_code;
50 thread_desc * thrd;
51 __spinlock_t * lock;
52 __spinlock_t ** locks;
53 unsigned short lock_count;
54 thread_desc ** thrds;
55 unsigned short thrd_count;
56};
57static inline void ?{}(FinishAction & this) {
58 this.action_code = No_Action;
59 this.thrd = NULL;
60 this.lock = NULL;
61}
62static inline void ^?{}(FinishAction & this) {}
63
64// Processor
65coroutine processorCtx_t {
66 struct processor * proc;
67};
68
69// Wrapper around kernel threads
70struct processor {
71 // Main state
72 // Coroutine ctx who does keeps the state of the processor
73 struct processorCtx_t runner;
74
75 // Cluster from which to get threads
76 struct cluster * cltr;
77
78 // Name of the processor
79 const char * name;
80
81 // Handle to pthreads
82 pthread_t kernel_thread;
83
84 // Termination
85 // Set to true to notify the processor should terminate
86 volatile bool do_terminate;
87
88 // Termination synchronisation
89 semaphore terminated;
90
91 // RunThread data
92 // Action to do after a thread is ran
93 struct FinishAction finish;
94
95 // Preemption data
96 // Node which is added in the discrete event simulaiton
97 struct alarm_node_t * preemption_alarm;
98
99 // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
100 bool pending_preemption;
101
102 // Idle lock
103
104 // Link lists fields
105 struct {
106 struct processor * next;
107 struct processor * prev;
108 } node;
109
110#ifdef __CFA_DEBUG__
111 // Last function to enable preemption on this processor
112 const char * last_enable;
113#endif
114};
115
116void ?{}(processor & this, const char * name, struct cluster & cltr);
117void ^?{}(processor & this);
118
119static inline void ?{}(processor & this) { this{ "Anonymous Processor", *mainCluster}; }
120static inline void ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr}; }
121static inline void ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
122
123static inline [processor *&, processor *& ] __get( processor & this ) {
124 return this.node.[next, prev];
125}
126
127//-----------------------------------------------------------------------------
128// Cluster
129struct cluster {
130 // Ready queue locks
131 __spinlock_t ready_queue_lock;
132
133 // Ready queue for threads
134 __queue_t(thread_desc) ready_queue;
135
136 // Name of the cluster
137 const char * name;
138
139 // Preemption rate on this cluster
140 Duration preemption_rate;
141
142 // List of processors
143 __spinlock_t proc_list_lock;
144 __dllist_t(struct processor) procs;
145 __dllist_t(struct processor) idles;
146
147 // Link lists fields
148 struct {
149 cluster * next;
150 cluster * prev;
151 } node;
152};
153extern Duration default_preemption();
154
155void ?{} (cluster & this, const char * name, Duration preemption_rate);
156void ^?{}(cluster & this);
157
158static inline void ?{} (cluster & this) { this{"Anonymous Cluster", default_preemption()}; }
159static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
160static inline void ?{} (cluster & this, const char * name) { this{name, default_preemption()}; }
161
162static inline [cluster *&, cluster *& ] __get( cluster & this ) {
163 return this.node.[next, prev];
164}
165
166// Local Variables: //
167// mode: c //
168// tab-width: 4 //
169// End: //
Note: See TracBrowser for help on using the repository browser.