26#include <common/config.h>
28#pragma GCC visibility push(hidden)
31#define STARPU_ASSERT_PERF_COUNTER_SCOPE_DEFINED(t) STARPU_ASSERT( \
32 (t == starpu_perf_counter_scope_global) \
33 || (t == starpu_perf_counter_scope_per_worker) \
34 || (t == starpu_perf_counter_scope_per_codelet) \
37#define STARPU_ASSERT_PERF_COUNTER_TYPE_DEFINED(t) STARPU_ASSERT( \
38 (t == starpu_perf_counter_type_int32) \
39 || (t == starpu_perf_counter_type_int64) \
40 || (t == starpu_perf_counter_type_float) \
41 || (t == starpu_perf_counter_type_double) \
44#define _STARPU_PERF_COUNTER_ID_SCOPE_BITS 4
46#if defined(STARPU_VAL_COMPARE_AND_SWAP64) && defined (STARPU_ATOMIC_ADD64)
47#define STARPU_PERF_COUNTER_64
53#define __STARPU_PERF_COUNTER_UPDATE_32BIT(OPNAME,OP,TYPENAME,TYPE) \
54static inline void _starpu_perf_counter_update_##OPNAME##_##TYPENAME(TYPE *ptr, TYPE value) \
56 STARPU_ASSERT(sizeof(TYPE) == sizeof(uint32_t)); \
57 typedef uint32_t __attribute__((__may_alias__)) alias_uint32_t; \
58 typedef TYPE __attribute__((__may_alias__)) alias_##TYPE; \
60 uint32_t raw_old = *(uint32_t *)ptr; \
62 while(value OP *(alias_##TYPE*)&raw_old) \
64 uint32_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP32((uint32_t *)ptr, raw_old, *(alias_uint32_t*)&value); \
65 if (raw_old_check == raw_old) \
67 raw_old = raw_old_check; \
71#ifdef STARPU_PERF_COUNTER_64
72typedef int64_t starpu_perf_counter_int64_t;
73typedef double starpu_perf_counter_double;
74#define __STARPU_PERF_COUNTER_UPDATE_64BIT(OPNAME,OP,TYPENAME,TYPE) \
75static inline void _starpu_perf_counter_update_##OPNAME##_##TYPENAME(TYPE *ptr, TYPE value) \
77 STARPU_ASSERT(sizeof(TYPE) == sizeof(uint64_t)); \
78 typedef uint64_t __attribute__((__may_alias__)) alias_uint64_t; \
79 typedef TYPE __attribute__((__may_alias__)) alias_##TYPE; \
81 uint64_t raw_old = *(uint64_t *)ptr; \
83 while(value OP *(alias_##TYPE*)&raw_old) \
85 uint64_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP64((uint64_t *)ptr, raw_old, *(alias_uint64_t*)&value); \
86 if (raw_old_check == raw_old) \
88 raw_old = raw_old_check; \
93typedef int32_t starpu_perf_counter_int64_t;
94typedef float starpu_perf_counter_double;
95#define __STARPU_PERF_COUNTER_UPDATE_64BIT(OPNAME,OP,TYPENAME,TYPE) \
96 __STARPU_PERF_COUNTER_UPDATE_32BIT(OPNAME,OP,TYPENAME,TYPE)
100__STARPU_PERF_COUNTER_UPDATE_32BIT(max,>=,int32,int32_t);
101__STARPU_PERF_COUNTER_UPDATE_32BIT(max,>=,
float,
float);
102__STARPU_PERF_COUNTER_UPDATE_64BIT(max,>=,int64,starpu_perf_counter_int64_t);
103__STARPU_PERF_COUNTER_UPDATE_64BIT(max,>=,
double,starpu_perf_counter_double);
106__STARPU_PERF_COUNTER_UPDATE_32BIT(min,<=,int32,int32_t);
107__STARPU_PERF_COUNTER_UPDATE_32BIT(min,<=,
float,
float);
108__STARPU_PERF_COUNTER_UPDATE_64BIT(min,<=,int64,starpu_perf_counter_int64_t);
109__STARPU_PERF_COUNTER_UPDATE_64BIT(min,<=,
double,starpu_perf_counter_double);
111#undef __STARPU_PERF_COUNTER_UPDATE_32BIT
112#undef __STARPU_PERF_COUNTER_UPDATE_64BIT
115#define __STARPU_PERF_COUNTER_UPDATE_ACC_FLOAT(TYPENAME, TYPE) \
116static inline void _starpu_perf_counter_update_acc_##TYPENAME(TYPE *ptr, TYPE acc_value) \
118 STARPU_ASSERT(sizeof(TYPE) == sizeof(uint32_t)); \
119 typedef uint32_t __attribute__((__may_alias__)) alias_uint32_t; \
120 typedef TYPE __attribute__((__may_alias__)) alias_float; \
121 uint32_t raw_old = *(uint32_t *)ptr; \
124 TYPE value = acc_value + *(alias_float*)&raw_old; \
125 uint32_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP32((uint32_t *)ptr, raw_old, *(alias_uint32_t*)&value); \
126 if (raw_old_check == raw_old) \
128 raw_old = raw_old_check; \
133#ifdef STARPU_PERF_COUNTER_64
134static inline void _starpu_perf_counter_update_acc_double(
double *ptr,
double acc_value)
136 STARPU_ASSERT(
sizeof(
double) ==
sizeof(uint64_t));
137 typedef uint64_t __attribute__((__may_alias__)) alias_uint64_t;
138 typedef double __attribute__((__may_alias__)) alias_double;
139 uint64_t raw_old = *(uint64_t *)ptr;
142 double value = acc_value + *(alias_double*)&raw_old;
143 uint64_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP64((uint64_t *)ptr, raw_old, *(alias_uint64_t*)&value);
144 if (raw_old_check == raw_old)
146 raw_old = raw_old_check;
153#ifdef STARPU_ATOMIC_ADD64
154#define STARPU_PERF_COUNTER_ADD64(ptr, val) STARPU_ATOMIC_ADD64((ptr), (val))
156#define STARPU_PERF_COUNTER_ADD64(ptr, val) STARPU_ATOMIC_ADD((ptr), (val))
164 enum starpu_perf_counter_type type;
169 enum starpu_perf_counter_scope scope;
177 starpu_perf_counter_int64_t int64_val;
179 starpu_perf_counter_double double_val;
191 enum starpu_perf_counter_scope scope;
201 starpu_perf_counter_int64_t total_submitted;
202 starpu_perf_counter_int64_t peak_submitted;
203 starpu_perf_counter_int64_t current_submitted;
204 starpu_perf_counter_int64_t peak_ready;
205 starpu_perf_counter_int64_t current_ready;
206 starpu_perf_counter_int64_t total_executed;
207 starpu_perf_counter_double cumul_execution_time;
213static inline enum starpu_perf_counter_scope _starpu_perf_counter_id_get_scope(
const int counter_id)
215 STARPU_ASSERT(counter_id >= 0);
216 return counter_id & ((1 << _STARPU_PERF_COUNTER_ID_SCOPE_BITS) - 1);
219static inline int _starpu_perf_counter_id_get_index(
const int counter_id)
221 STARPU_ASSERT(counter_id >= 0);
222 return counter_id >> _STARPU_PERF_COUNTER_ID_SCOPE_BITS;
225static inline int _starpu_perf_counter_id_build(
const enum starpu_perf_counter_scope scope,
const int index)
228 STARPU_ASSERT(index >= 0);
229 return (index << _STARPU_PERF_COUNTER_ID_SCOPE_BITS) | scope;
236void _starpu_perf_counter_exit(
void);
238int _starpu_perf_counter_register(
enum starpu_perf_counter_scope scope,
const char *name,
enum starpu_perf_counter_type type,
const char *help);
239void _starpu_perf_counter_unregister_all_scopes(
void);
241void _starpu_perf_counter_register_updater(
enum starpu_perf_counter_scope scope,
void (*updater)(
struct starpu_perf_counter_sample *sample,
void *context));
243void _starpu_perf_counter_update_global_sample(
void);
244void _starpu_perf_counter_update_per_worker_sample(
unsigned workerid);
245void _starpu_perf_counter_update_per_codelet_sample(
struct starpu_codelet *cl);
247#define __STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(STRING, TYPE) \
248static inline void _starpu_perf_counter_sample_set_##STRING##_value(struct starpu_perf_counter_sample *sample, const int counter_id, const TYPE value) \
250 STARPU_ASSERT(starpu_perf_counter_get_type_id(counter_id) == starpu_perf_counter_type_##STRING); \
251 STARPU_ASSERT(sample->listener != NULL && sample->listener->set != NULL); \
252 STARPU_ASSERT(_starpu_perf_counter_id_get_scope(counter_id) == sample->listener->set->scope); \
254 const struct starpu_perf_counter_set * const set = sample->listener->set; \
255 const int index = _starpu_perf_counter_id_get_index(counter_id); \
256 STARPU_ASSERT(index < set->size); \
257 if (set->index_array[index] > 0) \
259 sample->value_array[index].STRING##_val = value; \
263__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(int32, int32_t);
264__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(int64, starpu_perf_counter_int64_t);
265__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(
float,
float);
266__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(
double, starpu_perf_counter_double);
268#undef __STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE
270#define __STARPU_PERF_COUNTER_REG(PREFIX, SCOPE, CTR, TYPESTRING, HELP) \
273 __##CTR = _starpu_perf_counter_register(SCOPE, \
274 PREFIX "." #CTR, starpu_perf_counter_type_ ## TYPESTRING, \
280extern starpu_perf_counter_int64_t _starpu_task__g_total_submitted__value;
281extern starpu_perf_counter_int64_t _starpu_task__g_peak_submitted__value;
282extern starpu_perf_counter_int64_t _starpu_task__g_current_submitted__value;
283extern starpu_perf_counter_int64_t _starpu_task__g_peak_ready__value;
284extern starpu_perf_counter_int64_t _starpu_task__g_current_ready__value;
287void _starpu__task_c__register_counters(
void);
293#define STARPU_ASSERT_PERF_KNOB_SCOPE_DEFINED(t) STARPU_ASSERT( \
294 (t == starpu_perf_knob_scope_global) \
295 || (t == starpu_perf_knob_scope_per_worker) \
296 || (t == starpu_perf_knob_scope_per_scheduler) \
299#define STARPU_ASSERT_PERF_KNOB_TYPE_DEFINED(t) STARPU_ASSERT( \
300 (t == starpu_perf_knob_type_int32) \
301 || (t == starpu_perf_knob_type_int64) \
302 || (t == starpu_perf_knob_type_float) \
303 || (t == starpu_perf_knob_type_double) \
306#define _STARPU_PERF_KNOBS_ID_SCOPE_BITS 4
312 enum starpu_perf_knob_type type;
316 starpu_perf_counter_int64_t val_int64_t;
318 starpu_perf_counter_double val_double;
324 enum starpu_perf_knob_scope scope;
337 enum starpu_perf_knob_type type;
341#define __STARPU_PERF_KNOB_REG(PREFIX, SCOPE, CTR, TYPESTRING, HELP) \
344 __##CTR = _starpu_perf_knob_register(SCOPE, \
345 PREFIX "." #CTR, starpu_perf_knob_type_ ## TYPESTRING, \
350static inline int _starpu_perf_knob_id_get_scope(
const int knob_id)
352 STARPU_ASSERT(knob_id >= 0);
353 return knob_id & ((1 << _STARPU_PERF_KNOBS_ID_SCOPE_BITS) - 1);
356static inline int _starpu_perf_knob_id_get_index(
const int knob_id)
358 STARPU_ASSERT(knob_id >= 0);
359 return knob_id >> _STARPU_PERF_KNOBS_ID_SCOPE_BITS;
362static inline int _starpu_perf_knob_id_build(
const enum starpu_perf_knob_scope scope,
const int index)
364 STARPU_ASSERT_PERF_KNOB_SCOPE_DEFINED(scope);
365 STARPU_ASSERT(index >= 0);
366 return (index << _STARPU_PERF_KNOBS_ID_SCOPE_BITS) | scope;
369void _starpu_perf_knob_init(
void);
370void _starpu_perf_knob_exit(
void);
377int _starpu_perf_knob_register(
struct starpu_perf_knob_group *group,
const char *name,
enum starpu_perf_knob_type type,
const char *help);
378void _starpu_perf_knob_unregister_all_scopes(
void);
381void _starpu__workers_c__register_knobs(
void);
382void _starpu__task_c__register_knobs(
void);
383void _starpu__dmda_c__register_knobs(
void);
384void _starpu__workers_c__unregister_knobs(
void);
385void _starpu__task_c__unregister_knobs(
void);
386void _starpu__dmda_c__unregister_knobs(
void);
388#pragma GCC visibility pop
#define __STARPU_PERF_COUNTER_UPDATE_ACC_FLOAT(TYPENAME, TYPE)
Definition: knobs.h:115
#define STARPU_ASSERT_PERF_COUNTER_SCOPE_DEFINED(t)
Definition: knobs.h:31
Definition: starpu_spinlock.h:82
Definition: workers.h:441
Definition: workers.h:155