source: src/libcfa/concurrency/kernel@ 1dbc8590

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 1dbc8590 was 14a61b5, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Ground work for quiescing processors and update/remove TL_GET/TL_SETs. Still work to be done in both cases

  • Property mode set to 100644
File size: 3.8 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// Cluster
43struct cluster {
44 // Ready queue locks
45 __spinlock_t ready_queue_lock;
46
47 // Ready queue for threads
48 __queue_t(thread_desc) ready_queue;
49
50 // Name of the cluster
51 const char * name;
52
53 // Preemption rate on this cluster
54 Duration preemption_rate;
55
56 // List of idle processors
57 // __dllist_t(struct processor) idles;
58};
59
60extern struct cluster * mainCluster;
61extern Duration default_preemption();
62
63void ?{} (cluster & this, const char * name, Duration preemption_rate);
64void ^?{}(cluster & this);
65
66static inline void ?{} (cluster & this) { this{"Anonymous Cluster", default_preemption()}; }
67static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
68static inline void ?{} (cluster & this, const char * name) { this{name, default_preemption()}; }
69
70//-----------------------------------------------------------------------------
71// Processor
72enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
73
74//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
75struct FinishAction {
76 FinishOpCode action_code;
77 thread_desc * thrd;
78 __spinlock_t * lock;
79 __spinlock_t ** locks;
80 unsigned short lock_count;
81 thread_desc ** thrds;
82 unsigned short thrd_count;
83};
84static inline void ?{}(FinishAction & this) {
85 this.action_code = No_Action;
86 this.thrd = NULL;
87 this.lock = NULL;
88}
89static inline void ^?{}(FinishAction & this) {}
90
91// Processor
92coroutine processorCtx_t {
93 struct processor * proc;
94};
95
96// Wrapper around kernel threads
97struct processor {
98 // Main state
99 // Coroutine ctx who does keeps the state of the processor
100 struct processorCtx_t runner;
101
102 // Cluster from which to get threads
103 cluster * cltr;
104
105 // Name of the processor
106 const char * name;
107
108 // Handle to pthreads
109 pthread_t kernel_thread;
110
111 // Termination
112 // Set to true to notify the processor should terminate
113 volatile bool do_terminate;
114
115 // Termination synchronisation
116 semaphore terminated;
117
118 // RunThread data
119 // Action to do after a thread is ran
120 struct FinishAction finish;
121
122 // Preemption data
123 // Node which is added in the discrete event simulaiton
124 struct alarm_node_t * preemption_alarm;
125
126 // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
127 bool pending_preemption;
128
129 struct {
130 pthread_mutex_t lock;
131 pthread_cond_t cond;
132 } idle;
133
134#ifdef __CFA_DEBUG__
135 // Last function to enable preemption on this processor
136 const char * last_enable;
137#endif
138};
139
140void ?{}(processor & this, const char * name, cluster & cltr);
141void ^?{}(processor & this);
142
143static inline void ?{}(processor & this) { this{ "Anonymous Processor", *mainCluster}; }
144static inline void ?{}(processor & this, cluster & cltr) { this{ "Anonymous Processor", cltr}; }
145static inline void ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
146
147// Local Variables: //
148// mode: c //
149// tab-width: 4 //
150// End: //
Note: See TracBrowser for help on using the repository browser.