HPCToolkit
lush-support-rt.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_support_rt_h
64 #define lush_support_rt_h
65 
66 //************************* System Include Files ****************************
67 
68 #include <stdlib.h>
69 #include <stdbool.h>
70 #include <stdint.h>
71 #include <string.h>
72 
73 //*************************** User Include Files ****************************
74 
76 
77 #include <unwind/common/unwind.h>
78 
79 #include <memory/hpcrun-malloc.h>
81 
82 
83 //*************************** Forward Declarations **************************
84 
85 // A macro to automatically declare function pointers types for each
86 // routine
87 #define LUSHI_DECL(RET, FN, ARGS) \
88  RET FN ARGS; \
89  typedef RET (* FN ## _fn_t) ARGS
90 
91 
92 //***************************************************************************
93 // LUSH Unwind Types
94 //***************************************************************************
95 
96 
97 // ---------------------------------------------------------
98 // LUSH step
99 // ---------------------------------------------------------
100 
101 typedef enum lush_step lush_step_t;
102 
103 enum lush_step {
105 
106  LUSH_STEP_CONT, // cursor represents valid chord/note
107  LUSH_STEP_END_CHORD, // prev note was the end of the chord
108  LUSH_STEP_END_PROJ, // prev chord was the end of the projection
109  LUSH_STEP_ERROR // error during the step
110 };
111 
112 
113 // ---------------------------------------------------------
114 // LUSH LIP: An opaque logical id
115 // ---------------------------------------------------------
116 
117 // N.B.: Currently, this routine belongs here and not in lush-support.h!
118 static inline lush_lip_t*
120 {
121  lush_lip_t* x_clone = hpcrun_malloc(sizeof(lush_lip_t));
122  memcpy(x_clone, x, sizeof(lush_lip_t));
123  return x_clone;
124 }
125 
126 
127 // ---------------------------------------------------------
128 // LUSH l-cursor: space for a logical cursor
129 // ---------------------------------------------------------
130 
132 
133 struct lush_lcursor {
134  unsigned char data[64];
135 };
136 
137 
138 // ---------------------------------------------------------
139 // LUSH cursor
140 // ---------------------------------------------------------
141 
143 
146 
147  //fixme: do we want this?
148  //LUSH_CURSOR_FLAGS_MASK = 0x00000000,
149  //LUSH_CURSOR_FLAGS_MASK_AGENT = 0x00000000,
150 
151  // projections
152  LUSH_CURSOR_FLAGS_BEG_PPROJ = 0x00000001, // cursor @ beg of p-projection
153  LUSH_CURSOR_FLAGS_END_PPROJ = 0x00000002, // cursor @ end of p-projection
154  LUSH_CURSOR_FLAGS_END_LPROJ = 0x00000004, // cursor @ end of l-projection
155 
156  // chords
157  LUSH_CURSOR_FLAGS_BEG_PCHORD = 0x00000010, // cursor @ beg of p-chord
158  LUSH_CURSOR_FLAGS_END_PCHORD = 0x00000020, // cursor @ end of p-chord
159  LUSH_CURSOR_FLAGS_END_LCHORD = 0x00000040 // cursor @ end of l-chord
160 };
161 
162 
163 typedef struct lush_cursor lush_cursor_t;
164 
165 struct lush_cursor {
166  // meta info
167  unsigned flags; // lush_cursor_flags
168  lush_assoc_info_t as_info; // bichord's physical-logical association
169  lush_agentid_t aid; // agent id (if any) owning this cursor
170  lush_agentid_t aid_prev; // previous agent id (excluding identity agent)
171  lush_agent_pool_t* apool; // agent pool
172 
173  // physical cursor
175 
176  // logical cursor
179  // active marker FIXME
180 };
181 
182 
183 static inline bool
185 {
186  return (cursor->flags & f);
187 }
188 
189 
190 static inline void
192 {
193  cursor->flags = (cursor->flags | f);
194 }
195 
196 
197 static inline void
199 {
200  cursor->flags = (cursor->flags & ~f);
201 }
202 
203 
204 static inline lush_assoc_t
206 {
207  return lush_assoc_info__get_assoc(cursor->as_info);
208 }
209 
210 
211 static inline void
213 {
214  lush_assoc_info__set_assoc(cursor->as_info, as);
215 }
216 
217 
218 static inline lush_agentid_t
220 {
221  return cursor->aid;
222 }
223 
224 
225 static inline void
227 {
228  cursor->aid = aid;
229 }
230 
231 
232 static inline lush_agentid_t
234 {
235  return cursor->aid_prev;
236 }
237 
238 
239 static inline void
241 {
242  cursor->aid_prev = aid;
243 }
244 
245 
246 static inline ip_normalized_t
248 {
249  ip_normalized_t ip_norm;
250  if (hpcrun_unw_get_ip_norm_reg(&cursor->pcursor, &ip_norm) < 0) {
251  // FIXME
252  }
253  return ip_norm;
254 }
255 
256 
257 static inline void*
259 {
260  void* ip_unnorm;
261  if (hpcrun_unw_get_ip_unnorm_reg(&cursor->pcursor, &ip_unnorm) < 0) {
262  // FIXME
263  }
264  return ip_unnorm;
265 }
266 
267 
268 static inline lush_lip_t*
270 {
271  return &cursor->lip;
272 }
273 
274 
275 static inline hpcrun_unw_cursor_t*
277 {
278  return &cursor->pcursor;
279 }
280 
281 
282 static inline lush_lcursor_t*
284 {
285  return &cursor->lcursor;
286 }
287 
288 
289 // **************************************************************************
290 
291 #endif /* lush_support_rt_h */
static lush_lip_t * lush_cursor_get_lip(lush_cursor_t *cursor)
lush_agent_pool_t * apool
lush_lip_t lip
static lush_agentid_t lush_cursor_get_aid_prev(lush_cursor_t *cursor)
lush_agentid_t aid_prev
unsigned char data[64]
lush_assoc_info_t as_info
hpcrun_unw_cursor_t pcursor
static void lush_cursor_unset_flag(lush_cursor_t *cursor, lush_cursor_flags_t f)
static void * lush_cursor_get_ip_unnorm(lush_cursor_t *cursor)
lush_step
#define lush_assoc_info__set_assoc(x, new_as)
Definition: lush-support.h:264
static ip_normalized_t lush_cursor_get_ip_norm(lush_cursor_t *cursor)
static void lush_cursor_set_aid(lush_cursor_t *cursor, lush_agentid_t aid)
int lush_agentid_t
Definition: lush-support.h:99
static void lush_cursor_set_aid_prev(lush_cursor_t *cursor, lush_agentid_t aid)
static bool lush_cursor_is_flag(lush_cursor_t *cursor, lush_cursor_flags_t f)
lush_cursor_flags
lush_lcursor_t lcursor
void * hpcrun_malloc(size_t size)
Definition: mem.c:275
static lush_assoc_t lush_assoc_info__get_assoc(lush_assoc_info_t x)
Definition: lush-support.h:215
enum lush_step lush_step_t
static void lush_cursor_set_assoc(lush_cursor_t *cursor, lush_assoc_t as)
enum lush_assoc lush_assoc_t
Definition: lush-support.h:164
static void lush_cursor_set_flag(lush_cursor_t *cursor, lush_cursor_flags_t f)
static lush_assoc_t lush_cursor_get_assoc(lush_cursor_t *cursor)
enum lush_cursor_flags lush_cursor_flags_t
static lush_agentid_t lush_cursor_get_aid(lush_cursor_t *cursor)
lush_agentid_t aid
static hpcrun_unw_cursor_t * lush_cursor_get_pcursor(lush_cursor_t *cursor)
unsigned flags
int hpcrun_unw_get_ip_norm_reg(hpcrun_unw_cursor_t *c, ip_normalized_t *reg_value)
int hpcrun_unw_get_ip_unnorm_reg(hpcrun_unw_cursor_t *c, void **reg_value)
static lush_lip_t * lush_lip_clone(lush_lip_t *x)
static lush_lcursor_t * lush_cursor_get_lcursor(lush_cursor_t *cursor)