HPCToolkit
agent-cilk.h
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // LUSH: Logical Unwind Support for HPCToolkit
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 // Author:
59 // Nathan Tallent, Rice University.
60 //
61 //***************************************************************************
62 
63 #ifndef lush_agents_agent_cilk_h
64 #define lush_agents_agent_cilk_h
65 
66 //************************* System Include Files ****************************
67 
68 #include <stdlib.h>
69 #include <stdint.h>
70 #include <stdbool.h>
71 
72 //*************************** Cilk Include Files ****************************
73 
74 #include <cilk/cilk.h> /* Cilk (installed) */
75 #include <cilk/cilk-internal.h> /* Cilk (not installed) */
76 
77 //*************************** User Include Files ****************************
78 
79 #include <lush/lushi.h>
80 #include <lush/lushi-cb.h>
81 
82 //*************************** Forward Declarations **************************
83 
84 #if defined(__cplusplus)
85 extern "C" {
86 #endif
87 
88 //*************************** Forward Declarations **************************
89 
90 
91 // **************************************************************************
92 //
93 // **************************************************************************
94 
95 typedef union cilk_ip cilk_ip_t;
96 
97 union cilk_ip {
98  // ------------------------------------------------------------
99  // LUSH type
100  // ------------------------------------------------------------
102 
103  // ------------------------------------------------------------
104  // superimposed with:
105  // ------------------------------------------------------------
106  struct {
107  // NOTE: coordinate with lush_lip_getLMId() and lush_lip_getLMIP()
108  uint64_t lm_id;
109  uint64_t lm_ip;
110  } u;
111 };
112 
113 
114 static inline void
115 cilk_ip_set(cilk_ip_t* x, ip_normalized_t ip /*uint32_t status*/)
116 {
117  lush_lip_setLMId(&(x->official_lip), (uint64_t)ip.lm_id);
118  lush_lip_setLMIP(&(x->official_lip), (uint64_t)ip.lm_ip);
119  //x->u.status = status;
120 }
121 
122 
123 // **************************************************************************
124 //
125 // **************************************************************************
126 
127 // ---------------------------------------------------------
128 //
129 // ---------------------------------------------------------
130 
131 typedef enum unw_ty_e unw_ty_t;
132 
133 enum unw_ty_e {
135  UnwTy_Master, // master (non-worker thread)
136 
137  UnwTy_WorkerLcl, // worker: user context is fully on local stack
138  UnwTy_Worker // worker: user context is partially on cactus stack
139 };
140 
141 static inline bool
142 unw_ty_is_master(unw_ty_t ty)
143 {
144  return (ty == UnwTy_Master);
145 }
146 
147 static inline bool
148 unw_ty_is_worker(unw_ty_t ty)
149 {
150  return ((ty == UnwTy_WorkerLcl) || (ty == UnwTy_Worker));
151 }
152 
153 
154 // ---------------------------------------------------------
155 //
156 // ---------------------------------------------------------
157 
158 typedef enum unw_seg_e unw_seg_t;
159 
160 enum unw_seg_e {
161  // Segments of a Cilk physical stack
162  // NOTE: ordering is important (inner to outer contexts)
164  UnwSeg_CilkRT, // Cilk runtime support
165  UnwSeg_User, // User code
166  UnwSeg_CilkSched // Cilk scheduler
167 };
168 
169 
170 // ---------------------------------------------------------
171 //
172 // ---------------------------------------------------------
173 
174 typedef enum unw_flg_e unw_flg_t;
175 
176 enum unw_flg_e {
177  UnwFlg_NULL = 0x00,
178  UnwFlg_SeenUser = 0x01, // user code has been seen (inter)
179  UnwFlg_HaveLCtxt = 0x02, // logical context has been obtained (inter)
180  UnwFlg_BegLNote = 0x04, // past beginning note of an lchord
181 };
182 
183 
184 // **************************************************************************
185 
187 
188 union cilk_cursor {
189  // ------------------------------------------------------------
190  // LUSH type
191  // ------------------------------------------------------------
193 
194  // ------------------------------------------------------------
195  // superimposed with:
196  // ------------------------------------------------------------
197  struct {
198  // ---------------------------------
199  // inter-bichord data (valid for the whole of one logical unwind)
200  // ---------------------------------
201  unw_ty_t ty : 8; // type of current unwind
202  unw_seg_t prev_seg: 8; // ty of prev bi-chord
203  unw_flg_t flg : 8; // unwind flags
204  unsigned xxx : 8; // UNUSED
205  CilkWorkerState* cilk_worker_state;
206  Closure* cilk_closure; // modified during traversal
207 
208  // ---------------------------------
209  // intra-bichord data (valid for only one bichord)
210  // ---------------------------------
211  void* ref_ip; // reference physical ip (unnormalized)
212  ip_normalized_t ref_ip_norm; // reference physical ip (normalized)
213 
214  } u;
215 };
216 
217 
218 static inline bool
219 csr_is_flag(cilk_cursor_t* csr, unw_flg_t flg)
220 {
221  return (csr->u.flg & flg);
222 }
223 
224 static inline void
225 csr_set_flag(cilk_cursor_t* csr, unw_flg_t flg)
226 {
227  csr->u.flg = (csr->u.flg | flg);
228 }
229 
230 static inline void
231 csr_unset_flag(cilk_cursor_t* csr, unw_flg_t flg)
232 {
233  csr->u.flg = (csr->u.flg & ~flg);
234 }
235 
236 
237 // NOTE: Local work (innermost) is pushed and popped from the BOTTOM
238 // or the TAIL of the deque while thieves steal from the TOP or HEAD
239 // (outermost).
240 static inline Closure*
241 CILKWS_CL_DEQ_TOP(CilkWorkerState* x)
242 {
243  return x->context->Cilk_RO_params->deques[x->self].top; // outermost!
244 }
245 
246 static inline Closure*
247 CILKWS_CL_DEQ_BOT(CilkWorkerState* x)
248 {
249  return x->context->Cilk_RO_params->deques[x->self].bottom; // innermost!
250 }
251 
252 static inline volatile CilkStackFrame**
253 CILKWS_FRAME_DEQ_HEAD(CilkWorkerState* x)
254 {
255  return x->cache.head; // outermost!
256 }
257 
258 static inline volatile CilkStackFrame**
259 CILKWS_FRAME_DEQ_TAIL(CilkWorkerState* x)
260 {
261  return x->cache.tail; // innermost!
262 }
263 
264 static inline void* /* void (*) () */
265 CILKFRM_PROC(CilkStackFrame* x) {
266  return x->sig[0].inlet;
267 }
268 
269 
270 // **************************************************************************
271 
272 #if defined(__cplusplus)
273 } /* extern "C" */
274 #endif
275 
276 #endif /* lush_agents_agent_cilk_h */
unw_ty_e
Definition: agent-cilk.h:133
static void lush_lip_setLMId(lush_lip_t *x, uint16_t lmId)
Definition: lush-support.h:374
static volatile CilkStackFrame ** CILKWS_FRAME_DEQ_TAIL(CilkWorkerState *x)
Definition: agent-cilk.h:259
unw_flg_e
Definition: agent-cilk.h:176
unw_ty_t ty
Definition: agent-cilk.h:201
enum unw_flg_e unw_flg_t
Definition: agent-cilk.h:174
unw_flg_t flg
Definition: agent-cilk.h:203
static bool unw_ty_is_worker(unw_ty_t ty)
Definition: agent-cilk.h:148
struct cilk_cursor::@13 u
static void cilk_ip_set(cilk_ip_t *x, ip_normalized_t ip)
Definition: agent-cilk.h:115
uint64_t lm_ip
Definition: agent-cilk.h:109
static void csr_unset_flag(cilk_cursor_t *csr, unw_flg_t flg)
Definition: agent-cilk.h:231
uintptr_t lm_ip
Definition: ip-normalized.h:78
unw_seg_e
Definition: agent-cilk.h:160
static Closure * CILKWS_CL_DEQ_BOT(CilkWorkerState *x)
Definition: agent-cilk.h:247
enum unw_seg_e unw_seg_t
Definition: agent-cilk.h:158
struct cilk_ip::@12 u
ip_normalized_t ref_ip_norm
Definition: agent-cilk.h:212
static void lush_lip_setLMIP(lush_lip_t *x, uint64_t lm_ip)
Definition: lush-support.h:388
lush_lip_t official_lip
Definition: agent-cilk.h:101
void * ref_ip
Definition: agent-cilk.h:211
static volatile CilkStackFrame ** CILKWS_FRAME_DEQ_HEAD(CilkWorkerState *x)
Definition: agent-cilk.h:253
static void csr_set_flag(cilk_cursor_t *csr, unw_flg_t flg)
Definition: agent-cilk.h:225
CilkWorkerState * cilk_worker_state
Definition: agent-cilk.h:205
static Closure * CILKWS_CL_DEQ_TOP(CilkWorkerState *x)
Definition: agent-cilk.h:241
static void * CILKFRM_PROC(CilkStackFrame *x)
Definition: agent-cilk.h:265
unsigned xxx
Definition: agent-cilk.h:204
Closure * cilk_closure
Definition: agent-cilk.h:206
uint64_t lm_id
Definition: agent-cilk.h:108
unw_seg_t prev_seg
Definition: agent-cilk.h:202
lush_lcursor_t official_cursor
Definition: agent-cilk.h:192
static bool csr_is_flag(cilk_cursor_t *csr, unw_flg_t flg)
Definition: agent-cilk.h:219
static bool unw_ty_is_master(unw_ty_t ty)
Definition: agent-cilk.h:142
enum unw_ty_e unw_ty_t
Definition: agent-cilk.h:131