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
49#define __STARPU_PERF_COUNTER_UPDATE_32BIT(OPNAME,OP,TYPENAME,TYPE) \
50static inline void _starpu_perf_counter_update_##OPNAME##_##TYPENAME(TYPE *ptr, TYPE value) \
52 STARPU_ASSERT(sizeof(TYPE) == sizeof(uint32_t)); \
53 typedef uint32_t __attribute__((__may_alias__)) alias_uint32_t; \
54 typedef TYPE __attribute__((__may_alias__)) alias_##TYPE; \
56 uint32_t raw_old = *(uint32_t *)ptr; \
58 while(value OP *(alias_##TYPE*)&raw_old) \
60 uint32_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP32((uint32_t *)ptr, raw_old, *(alias_uint32_t*)&value); \
61 if (raw_old_check == raw_old) \
63 raw_old = raw_old_check; \
67#define __STARPU_PERF_COUNTER_UPDATE_64BIT(OPNAME,OP,TYPENAME,TYPE) \
68static inline void _starpu_perf_counter_update_##OPNAME##_##TYPENAME(TYPE *ptr, TYPE value) \
70 STARPU_ASSERT(sizeof(TYPE) == sizeof(uint64_t)); \
71 typedef uint64_t __attribute__((__may_alias__)) alias_uint64_t; \
72 typedef TYPE __attribute__((__may_alias__)) alias_##TYPE; \
74 uint64_t raw_old = *(uint64_t *)ptr; \
76 while(value OP *(alias_##TYPE*)&raw_old) \
78 uint64_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP64((uint64_t *)ptr, raw_old, *(alias_uint64_t*)&value); \
79 if (raw_old_check == raw_old) \
81 raw_old = raw_old_check; \
86__STARPU_PERF_COUNTER_UPDATE_32BIT(max,>=,int32,int32_t);
87__STARPU_PERF_COUNTER_UPDATE_32BIT(max,>=,
float,
float);
88__STARPU_PERF_COUNTER_UPDATE_64BIT(max,>=,int64,int64_t);
89__STARPU_PERF_COUNTER_UPDATE_64BIT(max,>=,
double,
double);
92__STARPU_PERF_COUNTER_UPDATE_32BIT(min,<=,int32,int32_t);
93__STARPU_PERF_COUNTER_UPDATE_32BIT(min,<=,
float,
float);
94__STARPU_PERF_COUNTER_UPDATE_64BIT(min,<=,int64,int64_t);
95__STARPU_PERF_COUNTER_UPDATE_64BIT(min,<=,
double,
double);
97#undef __STARPU_PERF_COUNTER_UPDATE_32BIT
98#undef __STARPU_PERF_COUNTER_UPDATE_64BIT
103 STARPU_ASSERT(
sizeof(
float) ==
sizeof(uint32_t));
104 typedef uint32_t __attribute__((__may_alias__)) alias_uint32_t;
105 typedef float __attribute__((__may_alias__)) alias_float;
106 uint32_t raw_old = *(uint32_t *)ptr;
109 float value = acc_value + *(alias_float*)&raw_old;
110 uint32_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP32((uint32_t *)ptr, raw_old, *(alias_uint32_t*)&value);
111 if (raw_old_check == raw_old)
113 raw_old = raw_old_check;
116static inline void _starpu_perf_counter_update_acc_double(
double *ptr,
double acc_value)
118 STARPU_ASSERT(
sizeof(
double) ==
sizeof(uint64_t));
119 typedef uint64_t __attribute__((__may_alias__)) alias_uint64_t;
120 typedef double __attribute__((__may_alias__)) alias_double;
121 uint64_t raw_old = *(uint64_t *)ptr;
124 double value = acc_value + *(alias_double*)&raw_old;
125 uint64_t raw_old_check = STARPU_VAL_COMPARE_AND_SWAP64((uint64_t *)ptr, raw_old, *(alias_uint64_t*)&value);
126 if (raw_old_check == raw_old)
128 raw_old = raw_old_check;
137 enum starpu_perf_counter_type type;
142 enum starpu_perf_counter_scope scope;
164 enum starpu_perf_counter_scope scope;
174 int64_t total_submitted;
175 int64_t peak_submitted;
176 int64_t current_submitted;
178 int64_t current_ready;
179 int64_t total_executed;
180 double cumul_execution_time;
186static inline enum starpu_perf_counter_scope _starpu_perf_counter_id_get_scope(
const int counter_id)
188 STARPU_ASSERT(counter_id >= 0);
189 return counter_id & ((1 << _STARPU_PERF_COUNTER_ID_SCOPE_BITS) - 1);
192static inline int _starpu_perf_counter_id_get_index(
const int counter_id)
194 STARPU_ASSERT(counter_id >= 0);
195 return counter_id >> _STARPU_PERF_COUNTER_ID_SCOPE_BITS;
198static inline int _starpu_perf_counter_id_build(
const enum starpu_perf_counter_scope scope,
const int index)
201 STARPU_ASSERT(index >= 0);
202 return (index << _STARPU_PERF_COUNTER_ID_SCOPE_BITS) | scope;
209void _starpu_perf_counter_exit(
void);
211int _starpu_perf_counter_register(
enum starpu_perf_counter_scope scope,
const char *name,
enum starpu_perf_counter_type type,
const char *help);
212void _starpu_perf_counter_unregister_all_scopes(
void);
214void _starpu_perf_counter_register_updater(
enum starpu_perf_counter_scope scope,
void (*updater)(
struct starpu_perf_counter_sample *sample,
void *context));
216void _starpu_perf_counter_update_global_sample(
void);
217void _starpu_perf_counter_update_per_worker_sample(
unsigned workerid);
218void _starpu_perf_counter_update_per_codelet_sample(
struct starpu_codelet *cl);
220#define __STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(STRING, TYPE) \
221static inline void _starpu_perf_counter_sample_set_##STRING##_value(struct starpu_perf_counter_sample *sample, const int counter_id, const TYPE value) \
223 STARPU_ASSERT(starpu_perf_counter_get_type_id(counter_id) == starpu_perf_counter_type_##STRING); \
224 STARPU_ASSERT(sample->listener != NULL && sample->listener->set != NULL); \
225 STARPU_ASSERT(_starpu_perf_counter_id_get_scope(counter_id) == sample->listener->set->scope); \
227 const struct starpu_perf_counter_set * const set = sample->listener->set; \
228 const int index = _starpu_perf_counter_id_get_index(counter_id); \
229 STARPU_ASSERT(index < set->size); \
230 if (set->index_array[index] > 0) \
232 sample->value_array[index].STRING##_val = value; \
236__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(int32, int32_t);
237__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(int64, int64_t);
238__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(
float,
float);
239__STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE(
double,
double);
241#undef __STARPU_PERF_COUNTER_SAMPLE_SET_TYPED_VALUE
243#define __STARPU_PERF_COUNTER_REG(PREFIX, SCOPE, CTR, TYPESTRING, HELP) \
246 __##CTR = _starpu_perf_counter_register(SCOPE, \
247 PREFIX "." #CTR, starpu_perf_counter_type_ ## TYPESTRING, \
253extern int64_t _starpu_task__g_total_submitted__value;
254extern int64_t _starpu_task__g_peak_submitted__value;
255extern int64_t _starpu_task__g_current_submitted__value;
256extern int64_t _starpu_task__g_peak_ready__value;
257extern int64_t _starpu_task__g_current_ready__value;
260void _starpu__task_c__register_counters(
void);
266#define STARPU_ASSERT_PERF_KNOB_SCOPE_DEFINED(t) STARPU_ASSERT( \
267 (t == starpu_perf_knob_scope_global) \
268 || (t == starpu_perf_knob_scope_per_worker) \
269 || (t == starpu_perf_knob_scope_per_scheduler) \
272#define STARPU_ASSERT_PERF_KNOB_TYPE_DEFINED(t) STARPU_ASSERT( \
273 (t == starpu_perf_knob_type_int32) \
274 || (t == starpu_perf_knob_type_int64) \
275 || (t == starpu_perf_knob_type_float) \
276 || (t == starpu_perf_knob_type_double) \
279#define _STARPU_PERF_KNOBS_ID_SCOPE_BITS 4
285 enum starpu_perf_knob_type type;
297 enum starpu_perf_knob_scope scope;
310 enum starpu_perf_knob_type type;
314#define __STARPU_PERF_KNOB_REG(PREFIX, SCOPE, CTR, TYPESTRING, HELP) \
317 __##CTR = _starpu_perf_knob_register(SCOPE, \
318 PREFIX "." #CTR, starpu_perf_knob_type_ ## TYPESTRING, \
323static inline int _starpu_perf_knob_id_get_scope(
const int knob_id)
325 STARPU_ASSERT(knob_id >= 0);
326 return knob_id & ((1 << _STARPU_PERF_KNOBS_ID_SCOPE_BITS) - 1);
329static inline int _starpu_perf_knob_id_get_index(
const int knob_id)
331 STARPU_ASSERT(knob_id >= 0);
332 return knob_id >> _STARPU_PERF_KNOBS_ID_SCOPE_BITS;
335static inline int _starpu_perf_knob_id_build(
const enum starpu_perf_knob_scope scope,
const int index)
337 STARPU_ASSERT_PERF_KNOB_SCOPE_DEFINED(scope);
338 STARPU_ASSERT(index >= 0);
339 return (index << _STARPU_PERF_KNOBS_ID_SCOPE_BITS) | scope;
342void _starpu_perf_knob_init(
void);
343void _starpu_perf_knob_exit(
void);
350int _starpu_perf_knob_register(
struct starpu_perf_knob_group *group,
const char *name,
enum starpu_perf_knob_type type,
const char *help);
351void _starpu_perf_knob_unregister_all_scopes(
void);
354void _starpu__workers_c__register_knobs(
void);
355void _starpu__task_c__register_knobs(
void);
356void _starpu__dmda_c__register_knobs(
void);
357void _starpu__workers_c__unregister_knobs(
void);
358void _starpu__task_c__unregister_knobs(
void);
359void _starpu__dmda_c__unregister_knobs(
void);
361#pragma GCC visibility pop
#define STARPU_ASSERT_PERF_COUNTER_SCOPE_DEFINED(t)
Definition: knobs.h:31
static void _starpu_perf_counter_update_acc_float(float *ptr, float acc_value)
Definition: knobs.h:101
Definition: starpu_spinlock.h:82
Definition: workers.h:441
Definition: workers.h:155