HPCToolkit
lush-support.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_h
64 #define lush_support_h
65 
66 //************************* System Include Files ****************************
67 
68 #include <stdlib.h>
69 #include <stdint.h>
70 #include <stdbool.h>
71 #include <string.h>
72 
73 //*************************** User Include Files ****************************
74 
75 //*************************** Forward Declarations **************************
76 
77 #if defined(__cplusplus)
78 extern "C" {
79 #endif
80 
81 //*************************** Forward Declarations **************************
82 
83 // ---------------------------------------------------------
84 // LUSH metric id
85 // ---------------------------------------------------------
86 
87 #define lush_metricid_NULL (-1)
88 
89 
90 //***************************************************************************
91 // LUSH Agents
92 //***************************************************************************
93 
94 // ---------------------------------------------------------
95 // LUSH agent id
96 // ---------------------------------------------------------
97 
98 #define lush_agentid_NULL (0)
99 typedef int lush_agentid_t;
100 
101 
102 // ---------------------------------------------------------
103 // A LUSH agent
104 // ---------------------------------------------------------
105 
106 typedef struct lush_agent lush_agent_t;
107 
108 struct lush_agent {
109  lush_agentid_t id;
110  char* path;
111  void* dlhandle;
112 };
113 
114 
115 // ---------------------------------------------------------
116 // A pool of LUSH agents
117 // ---------------------------------------------------------
118 
120 
121 
122 //***************************************************************************
123 // LUSH association Types
124 //***************************************************************************
125 
126 // ---------------------------------------------------------
127 // bichord association classification: [p-chord <-> l-chord]
128 //
129 // - each association is a member of {0, 1, M} x {0, 1, M}
130 // - M represents "multi", i.e., { n | n >= 2 }
131 // ---------------------------------------------------------
132 
134  // Association classes
135 #define MKASSOC1(as, c1) ( ((as) << 4) | (c1) )
136 #define MKASSOC2(as, c1, c2) ( ((as) << 4) | (c1) | (c2) )
137 
140  LUSH_ASSOC_CLASS_a_to_0 = 0x01, // a-to-0
141  LUSH_ASSOC_CLASS_a_to_1 = 0x02, // a-to-1
142  LUSH_ASSOC_CLASS_1_to_a = 0x04, // 1-to-a
143 
144  // Associations
146 
149 
151  LUSH_ASSOC_CLASS_1_to_a), // 1-to-1
152 
154 
156 
157  // A special association for use during unwinding
159 
160 #undef MKASSOC1
161 #undef MKASSOC2
162 };
163 
165 
166 
168 
170  uint32_t bits;
171 
173  lush_assoc_t as : 8;
174  uint32_t len : 24; // (inclusive) length of path to root note: >= 1
175  } u;
176 };
177 
178 //
179 // lush assoc_info selectors, manipulators, constants
180 //
181 
183 
184 static inline unsigned
185 lush_assoc_class(lush_assoc_t as)
186 {
187  return ((as) & LUSH_ASSOC_CLASS_MASK);
188 }
189 
190 static inline bool
191 lush_assoc_is_a_to_0(lush_assoc_t as)
192 {
194 }
195 
196 static inline bool
197 lush_assoc_is_1_to_a(lush_assoc_t as)
198 {
200 }
201 
202 static inline bool
203 lush_assoc_is_a_to_1(lush_assoc_t as)
204 {
206 }
207 
208 static inline uint32_t
210 {
211  return (x).u.len;
212 }
213 
214 static inline lush_assoc_t
216 {
217  return x.u.as;
218 }
219 
220 //
221 // comparison ops, (mainly) for cct sibling splay tree operations
222 //
223 static inline bool
225 {
227 }
228 
229 static inline bool
230 lush_assoc_class_eq(lush_assoc_t x, lush_assoc_t y)
231 {
232  return ( ((x) == (y)) /* handles x == y == LUSH_ASSOC_NULL */
233  || (lush_assoc_class(x) & lush_assoc_class(y)) );
234 }
235 
236 static inline bool
238 {
240 }
241 
242 static inline bool
244 {
245  if (x.u.len < y.u.len) return true;
246  if (x.u.len > y.u.len) return false;
247  if (lush_assoc_class_eq(x.u.as, y.u.as)) return false;
248  return (x.u.as > y.u.as);
249 }
250 
251 static inline bool
253 {
254  return lush_assoc_info_lt(y, x);
255 }
256 
257 #if 0
258 static inline void
259 lush_assoc_info__set_assoc(lush_assoc_info_t& x, lush_assoc_t new_as)
260 {
261  x->u.as = (new_as);
262 }
263 #else
264 #define lush_assoc_info__set_assoc(/*lush_assoc_info_t*/ x, \
265  /*lush_assoc_t*/ new_as) \
266  (x).u.as = (new_as)
267 #endif
268 
269 #if 0
270 static inline void
272 {
273  x->.u.len = (new_len);
274 }
275 #else
276 #define lush_assoc_info__set_path_len(/*lush_assoc_info_t*/ x, \
277  /*uint32_t*/ new_len) \
278  (x).u.len = (new_len)
279 #endif
280 
281 
282 static inline bool
284 {
285  return (((x).u.as != LUSH_ASSOC_NULL) && ((x).u.len == 1));
286 }
287 
288 
289 #define LUSH_ASSOC_STR_MAX_LEN 6
290 
291 const char*
292 lush_assoc_tostr(lush_assoc_t as);
293 
294 
295 #define LUSH_ASSOC_INFO_STR_MIN_LEN (LUSH_ASSOC_STR_MAX_LEN + 26)
296 
297 const char*
298 lush_assoc_info_sprintf(char* str, lush_assoc_info_t as_info);
299 
300 
301 // ---------------------------------------------------------
302 // LUSH LIP: An opaque logical id
303 // ---------------------------------------------------------
304 
305 typedef union lush_lip lush_lip_t;
306 
307 union lush_lip {
308 #define LUSH_LIP_DATA1_SZ 16
309 #define LUSH_LIP_DATA8_SZ (LUSH_LIP_DATA1_SZ / 8)
310 
311  unsigned char data1[LUSH_LIP_DATA1_SZ];
312  uint64_t data8[LUSH_LIP_DATA8_SZ];
313 };
314 
316 
317 
318 static inline void
320 {
321  //memset(x, 0, sizeof(*x));
322  *x = lush_lip_NULL;
323 }
324 
325 
326 static inline bool
327 lush_lip_eq(const lush_lip_t* x, const lush_lip_t* y)
328 {
329  return ((x == y) || (x && y
330  && x->data8[0] == y->data8[0]
331  && x->data8[1] == y->data8[1]));
332 }
333 
334 static inline bool
335 lush_lip_lt(const lush_lip_t* x, const lush_lip_t* y)
336 {
337  if (x == y) {
338  return false;
339  }
340  if (! x) x = &lush_lip_NULL;
341  if (! y) y = &lush_lip_NULL;
342 
343  if (x->data8[0] < y->data8[0]) return true;
344  if (x->data8[0] > y->data8[0]) return false;
345  if (x->data8[1] < y->data8[1]) return true;
346  if (x->data8[1] > y->data8[1]) return false;
347  return false;
348 }
349 
350 static inline bool
351 lush_lip_gt(const lush_lip_t* x, const lush_lip_t* y)
352 {
353  return lush_lip_lt(y, x);
354 }
355 
356 #define LUSH_LIP_STR_MIN_LEN (20 * LUSH_LIP_DATA8_SZ) /* 0x + 16 + space */
357 
358 const char*
359 lush_lip_sprintf(char* str, const lush_lip_t* x);
360 
361 
362 // ---------------------------------------------------------
363 // Temporary interpreters for current set of agents
364 // ---------------------------------------------------------
365 
366 static inline uint16_t
368 {
369  return (uint16_t)x->data8[0];
370 }
371 
372 
373 static inline void
374 lush_lip_setLMId(lush_lip_t* x, uint16_t lmId)
375 {
376  x->data8[0] = (uint64_t)lmId;
377 }
378 
379 
380 static inline uint64_t
382 {
383  return (uint64_t)x->data8[1];
384 }
385 
386 
387 static inline void
388 lush_lip_setLMIP(lush_lip_t* x, uint64_t lm_ip)
389 {
390  x->data8[1] = lm_ip;
391 }
392 
393 
394 // **************************************************************************
395 
396 #if defined(__cplusplus)
397 } /* extern "C" */
398 #endif
399 
400 #endif /* lush_support_h */
static bool lush_assoc_info_eq(lush_assoc_info_t x, lush_assoc_info_t y)
Definition: lush-support.h:237
static void lush_lip_setLMId(lush_lip_t *x, uint16_t lmId)
Definition: lush-support.h:374
#define MKASSOC2(as, c1, c2)
Definition: lush-support.h:136
#define LUSH_LIP_DATA8_SZ
Definition: lush-support.h:309
lush_assoc_info_t lush_assoc_info_NULL
Definition: lush-support.c:83
static uint32_t lush_assoc_info__get_path_len(lush_assoc_info_t x)
Definition: lush-support.h:209
struct lush_assoc_info_u::lush_assoc_info_s u
lush_agentid_t id
Definition: lush-support.h:109
static uint16_t lush_lip_getLMId(const lush_lip_t *x)
Definition: lush-support.h:367
static bool lush_lip_lt(const lush_lip_t *x, const lush_lip_t *y)
Definition: lush-support.h:335
#define lush_assoc_info__set_path_len(x, new_len)
Definition: lush-support.h:276
static bool lush_assoc_info_is_root_note(lush_assoc_info_t x)
Definition: lush-support.h:283
#define MKASSOC1(as, c1)
Definition: lush-support.h:135
static bool lush_assoc_is_a_to_0(lush_assoc_t as)
Definition: lush-support.h:191
static bool lush_assoc_info_gt(lush_assoc_info_t x, lush_assoc_info_t y)
Definition: lush-support.h:252
static unsigned lush_assoc_class(lush_assoc_t as)
Definition: lush-support.h:185
#define lush_assoc_info__set_assoc(x, new_as)
Definition: lush-support.h:264
static void lush_lip_setLMIP(lush_lip_t *x, uint64_t lm_ip)
Definition: lush-support.h:388
static uint64_t lush_lip_getLMIP(const lush_lip_t *x)
Definition: lush-support.h:381
int lush_agentid_t
Definition: lush-support.h:99
char * path
Definition: lush-support.h:110
lush_lip_t lush_lip_NULL
Definition: lush-support.c:119
lush_assoc
Definition: lush-support.h:133
static void lush_lip_init(lush_lip_t *x)
Definition: lush-support.h:319
static lush_assoc_t lush_assoc_info__get_assoc(lush_assoc_info_t x)
Definition: lush-support.h:215
const char * lush_lip_sprintf(char *str, const lush_lip_t *x)
Definition: lush-support.c:122
static bool lush_lip_eq(const lush_lip_t *x, const lush_lip_t *y)
Definition: lush-support.h:327
enum lush_assoc lush_assoc_t
Definition: lush-support.h:164
static bool lush_assoc_is_a_to_1(lush_assoc_t as)
Definition: lush-support.h:203
static bool lush_assoc_info__path_len_eq(lush_assoc_info_t x, lush_assoc_info_t y)
Definition: lush-support.h:224
void * dlhandle
Definition: lush-support.h:111
const char * lush_assoc_tostr(lush_assoc_t as)
Definition: lush-support.c:86
static bool lush_assoc_class_eq(lush_assoc_t x, lush_assoc_t y)
Definition: lush-support.h:230
static bool lush_lip_gt(const lush_lip_t *x, const lush_lip_t *y)
Definition: lush-support.h:351
#define LUSH_LIP_DATA1_SZ
Definition: lush-support.h:308
uint64_t data8[LUSH_LIP_DATA8_SZ]
Definition: lush-support.h:312
static bool lush_assoc_info_lt(lush_assoc_info_t x, lush_assoc_info_t y)
Definition: lush-support.h:243
const char * lush_assoc_info_sprintf(char *str, lush_assoc_info_t as_info)
Definition: lush-support.c:101
static bool lush_assoc_is_1_to_a(lush_assoc_t as)
Definition: lush-support.h:197