-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_substrate.c
599 lines (535 loc) · 18 KB
/
test_substrate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/****************************************************
*
* Test the functionality of Score-P
* Checks for:
* - increasing timestamps
* - are locations defined?
* - is stack ok? (ONLY MAX_STACK elements on stack allowed)
* - are communicators defined?
* - are asynchronous MPI send/receives finished or canceled (ONLY the first MAX_MPI_REQUESTS!)
* - are locations only activated when being not active
* - are locations only deactivated when being active
* - are only defined regions entered/exited
* - are flushes correctly used
* - are tasks finished
*
****************************************************/
#include <assert.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <scorep/SCOREP_PublicTypes.h>
#include <scorep/SCOREP_PublicHandles.h>
#include <scorep/SCOREP_SubstratePlugins.h>
#include <scorep/SCOREP_SubstrateEvents.h>
/** The maximal number of locations per process */
#define MAX_LOCATIONS 1000
/** The maximal stack size */
#define MAX_STACK 100
/** The number of handles (strings/regions) that can be defined */
#define MAX_HANDLES 1000000
/** The number of asynchronous MPI communications that are checked */
#define MAX_MPI_REQUESTS 100000
/**
* Information about a single location
*/
struct location_info
{
/** handle */
const struct SCOREP_Location* location;
/** current stack */
/** see also MAX_STACK */
SCOREP_RegionHandle stack[MAX_STACK];
uint16_t stack_depth;
/** last timestamp that has been set */
uint64_t last_timestamp;
/** is this location enabled? */
int enabled;
/** is this location currently flushing? */
int flush_enabled;
/** number of rewind regions */
int nr_rewind;
/** current requests (finished requests are set to -1) */
/** see also MAX_MPI_REQUESTS */
SCOREP_MpiRequestId requests[MAX_MPI_REQUESTS];
uint32_t nr_requests;
/** location is active */
int active;
/** current active number of tasks */
uint64_t nr_tasks;
};
/**
* information about handles (per process)
*/
struct handle_info
{
/** handle for region/string/... */
SCOREP_AnyHandle handle;
/** type of handle */
SCOREP_HandleType type;
};
/** lock for locations */
pthread_mutex_t location_lock;
/** locations of this process */
/** see also MAX_LOCATIONS */
static struct location_info locations[MAX_LOCATIONS];
/** number of locations */
static uint16_t nr_infos=0;
/** lock for handles */
pthread_mutex_t handle_lock;
/** handles of this process */
/** see also MAX_HANDLES */
static struct handle_info registered_handles[MAX_HANDLES];
/** number of handles */
static uint32_t nr_defined_handles=0;
/** define default variables for events */
#define VARIABLES \
uint16_t index=0; \
uint32_t handle_index = 0; \
uint32_t request_index = 0
/** check whether a location is defined
* sets index
* */
#define CHECK_LOCATION(LOCATION) \
do \
{ \
for (index=0;index<nr_infos;index++) \
{ \
if (LOCATION==locations[index].location) \
{ \
break; \
} \
} \
assert(index!=nr_infos); \
} while (0)
/** check whether the timestamp of locations[index] is increasing
* uses locations[index] and timestamp
* */
#define CHECK_TIMESTAMP \
do{ \
assert( locations[index].last_timestamp <= timestamp ); \
locations[index].last_timestamp = timestamp; \
} \
while (0)
/** check whether a handle HANDLE is defined and of type TYPE
* sets handle_index
* */
#define CHECK_HANDLE_DEFINED(TYPE,HANDLE) \
do \
{ \
for (handle_index=0;handle_index<nr_defined_handles;handle_index++) \
{ \
if (HANDLE==registered_handles[handle_index].handle && registered_handles[handle_index].type == TYPE) \
{ \
break; \
} \
} \
assert(handle_index!=nr_defined_handles); \
} while (0)
/** check whether a request is registered
* uses index, requestId
* sets request_index
* TODO: do this per process, not per location?
* */
#define CHECK_REQUEST \
do \
{ \
for (request_index=0;request_index<locations[index].nr_requests;request_index++) \
{ \
if (locations[index].requests[request_index] == requestId) \
{ \
break; \
} \
} \
/* not found */ \
assert (request_index != locations[index].nr_requests); \
} while (0)
static void test_substrate_EnableRecording(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert disabled */
assert(!locations[index].enabled);
/* set enabled */
locations[index].enabled=1;
}
static void test_substrate_DisableRecording(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert enabled */
assert(locations[index].enabled);
/* set disabled */
locations[index].enabled=0;
}
static void test_substrate_OnTracingBufferFlushBegin(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert disabled */
assert(!locations[index].flush_enabled);
/* set enabled */
locations[index].flush_enabled=1;
}
static void test_substrate_OnTracingBufferFlushEnd(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert enabled */
assert(locations[index].flush_enabled);
/* set disabled */
locations[index].flush_enabled=0;
}
static void test_substrate_EnterRegion(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert stack size not exceeded */
assert(locations[index].stack_depth < ( MAX_STACK - 1 ) );
/* add region to stack */
locations[index].stack[locations[index].stack_depth] = regionHandle;
/* increase stack size */
locations[index].stack_depth++;
}
static void test_substrate_ExitRegion(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
uint64_t* metricValues )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert exited region = region on top of stack */
assert(locations[index].stack[locations[index].stack_depth-1] == regionHandle );
/* decrease stack size */
locations[index].stack_depth--;
}
static void test_substrate_EnterRewindRegion(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* increase number of rewind regions */
locations[index].nr_rewind++;
}
void test_substrate_ExitRewindRegion(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_RegionHandle regionHandle,
bool doRewind )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_REGION,regionHandle);
/* assert there are rewind regions */
assert(locations[index].nr_rewind!=0);
/* decrease number of rewind regions (at finalize they should be 0) */
locations[index].nr_rewind--;
}
static void test_substrate_MpiSend(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRank destinationRank,
SCOREP_InterimCommunicatorHandle communicatorHandle,
uint32_t tag,
uint64_t bytesSent )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_INTERIM_COMMUNICATOR,communicatorHandle);
}
static void test_substrate_MpiRecv(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRank sourceRank,
SCOREP_InterimCommunicatorHandle communicatorHandle,
uint32_t tag,
uint64_t bytesReceived )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_INTERIM_COMMUNICATOR,communicatorHandle);
}
static void test_substrate_MpiCollectiveBegin(
struct SCOREP_Location* location,
uint64_t timestamp )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
}
static void test_substrate_MpiCollectiveEnd(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_InterimCommunicatorHandle communicatorHandle,
SCOREP_MpiRank rootRank,
SCOREP_CollectiveType collectiveType,
uint64_t bytesSent,
uint64_t bytesReceived )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_INTERIM_COMMUNICATOR,communicatorHandle);
}
static void test_substrate_MpiIsendComplete(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRequestId requestId )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_REQUEST;
/* finish the request */
locations[index].requests[request_index] = -1;
}
static void test_substrate_MpiIrecvRequest(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRequestId requestId )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
/* register request */
locations[index].requests[locations[index].nr_requests++]=requestId;
}
static void test_substrate_MpiRequestTested(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRequestId requestId )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_REQUEST;
}
static void test_substrate_MpiRequestCancelled(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRequestId requestId )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_REQUEST;
/* finish request */
locations[index].requests[request_index] = -1;
}
static void test_substrate_MpiIsend(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRank destinationRank,
SCOREP_InterimCommunicatorHandle communicatorHandle,
uint32_t tag,
uint64_t bytesSent,
SCOREP_MpiRequestId requestId )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_INTERIM_COMMUNICATOR,communicatorHandle);
/* register request */
locations[index].requests[locations[index].nr_requests++]=requestId;
}
static void test_substrate_MpiIrecv(
struct SCOREP_Location* location,
uint64_t timestamp,
SCOREP_MpiRank sourceRank,
SCOREP_InterimCommunicatorHandle communicatorHandle,
uint32_t tag,
uint64_t bytesReceived,
SCOREP_MpiRequestId requestId )
{
VARIABLES;
CHECK_LOCATION(location);
CHECK_TIMESTAMP;
CHECK_HANDLE_DEFINED(SCOREP_HANDLE_TYPE_INTERIM_COMMUNICATOR,communicatorHandle);
CHECK_REQUEST;
/* finish request */
locations[index].requests[request_index] = -1;
}
static int test_early_init( void )
{
/** initialize muteces for arrays */
pthread_mutex_init(&location_lock,NULL);
pthread_mutex_init(&handle_lock,NULL);
/** return no problems */
return 0;
}
static void test_late_init( size_t pluginId )
{
}
static void test_finalize( void )
{
VARIABLES;
for (index = 0; index < nr_infos; index ++)
{
/* location should be deleted */
assert(locations[index].location == SCOREP_MOVABLE_NULL);
/* location should have stack size 0 */
assert(locations[index].stack_depth == 0);
/* location should be disabled */
assert(!locations[index].enabled);
/* location should be inactive */
assert(!locations[index].active);
/* location should be not flushing */
assert(!locations[index].flush_enabled);
/* location should have finished all tasks */
assert(locations[index].nr_tasks == 0);
/* location should have finished all requests */
for (request_index=0;request_index<locations[index].nr_requests;request_index++)
assert(locations[index].requests[request_index]==-1);
/* location should have no open rewinds */
assert(locations[index].nr_rewind == 0);
}
}
static void test_create_location( const struct SCOREP_Location* location,
const struct SCOREP_Location* parentLocation )
{
VARIABLES;
/* check if parent is registered or root of locations */
if (parentLocation != SCOREP_MOVABLE_NULL)
CHECK_LOCATION(parentLocation);
/* register location */
pthread_mutex_lock(&location_lock);
locations[nr_infos++].location=location;
pthread_mutex_unlock(&location_lock);
}
static void test_delete_location( const struct SCOREP_Location* location )
{
VARIABLES;
CHECK_LOCATION(location);
/* unregister location */
pthread_mutex_lock(&location_lock);
locations[index].location = SCOREP_MOVABLE_NULL;
pthread_mutex_unlock(&location_lock);
}
static void test_activate_location( const struct SCOREP_Location* location,
const struct SCOREP_Location* parentLocation,
uint32_t forkSequenceCount )
{
VARIABLES;
CHECK_LOCATION(location);
/* check and set active */
assert(!locations[index].active);
locations[index].active=1;
}
static void test_deactivate_location( const struct SCOREP_Location* location,
const struct SCOREP_Location* parentLocation )
{
VARIABLES;
CHECK_LOCATION(location);
/* check and set inactive */
assert(locations[index].active);
locations[index].active=0;
}
static void test_core_task_create( const struct SCOREP_Location* location,
SCOREP_TaskHandle taskHandle )
{
VARIABLES;
CHECK_LOCATION(location);
locations[index].nr_tasks++;
}
static void test_core_task_complete( const struct SCOREP_Location* location,
SCOREP_TaskHandle taskHandle )
{
VARIABLES;
CHECK_LOCATION(location);
assert(locations[index].nr_tasks != 0);
locations[index].nr_tasks--;
}
static void test_define_handle( SCOREP_AnyHandle handle,
SCOREP_HandleType type )
{
assert(handle);
pthread_mutex_lock(&handle_lock);
registered_handles[nr_defined_handles].handle=handle;
registered_handles[nr_defined_handles].type=type;
nr_defined_handles++;
pthread_mutex_unlock(&handle_lock);
}
static uint32_t test_get_event_functions(
SCOREP_Substrates_Mode mode,
SCOREP_Substrates_Callback** functions )
{
SCOREP_Substrates_Callback* ret_fun=calloc(SCOREP_SUBSTRATES_NUM_EVENTS,
sizeof(SCOREP_Substrates_Callback));
ret_fun[SCOREP_EVENT_ENABLE_RECORDING] = (SCOREP_Substrates_Callback)test_substrate_EnableRecording;
ret_fun[SCOREP_EVENT_DISABLE_RECORDING] = (SCOREP_Substrates_Callback)test_substrate_DisableRecording;
ret_fun[SCOREP_EVENT_ON_TRACING_BUFFER_FLUSH_BEGIN] = (SCOREP_Substrates_Callback)test_substrate_OnTracingBufferFlushBegin;
ret_fun[SCOREP_EVENT_ON_TRACING_BUFFER_FLUSH_END] = (SCOREP_Substrates_Callback)test_substrate_OnTracingBufferFlushEnd;
ret_fun[SCOREP_EVENT_ENTER_REGION] = (SCOREP_Substrates_Callback)test_substrate_EnterRegion;
ret_fun[SCOREP_EVENT_EXIT_REGION] = (SCOREP_Substrates_Callback)test_substrate_ExitRegion;
ret_fun[SCOREP_EVENT_ENTER_REWIND_REGION] = (SCOREP_Substrates_Callback)test_substrate_EnterRewindRegion;
ret_fun[SCOREP_EVENT_EXIT_REWIND_REGION] = (SCOREP_Substrates_Callback)test_substrate_ExitRewindRegion;
ret_fun[SCOREP_EVENT_MPI_SEND] = (SCOREP_Substrates_Callback)test_substrate_MpiSend;
ret_fun[SCOREP_EVENT_MPI_RECV] = (SCOREP_Substrates_Callback)test_substrate_MpiRecv;
ret_fun[SCOREP_EVENT_MPI_COLLECTIVE_BEGIN] = (SCOREP_Substrates_Callback)test_substrate_MpiCollectiveBegin;
ret_fun[SCOREP_EVENT_MPI_COLLECTIVE_END] = (SCOREP_Substrates_Callback)test_substrate_MpiCollectiveEnd;
ret_fun[SCOREP_EVENT_MPI_ISEND_COMPLETE] = (SCOREP_Substrates_Callback)test_substrate_MpiIsendComplete;
ret_fun[SCOREP_EVENT_MPI_IRECV_REQUEST] = (SCOREP_Substrates_Callback)test_substrate_MpiIrecvRequest;
ret_fun[SCOREP_EVENT_MPI_REQUEST_TESTED] = (SCOREP_Substrates_Callback)test_substrate_MpiRequestTested;
ret_fun[SCOREP_EVENT_MPI_REQUEST_CANCELLED] = (SCOREP_Substrates_Callback)test_substrate_MpiRequestCancelled;
ret_fun[SCOREP_EVENT_MPI_ISEND] = (SCOREP_Substrates_Callback)test_substrate_MpiIsend;
ret_fun[SCOREP_EVENT_MPI_IRECV] = (SCOREP_Substrates_Callback)test_substrate_MpiIrecv;
*functions=ret_fun;
return SCOREP_SUBSTRATES_NUM_EVENTS;
}
SCOREP_SUBSTRATE_PLUGIN_ENTRY(test)
{
SCOREP_SubstratePluginInfo info;
memset(&info,0,sizeof(SCOREP_SubstratePluginInfo));
info.init=test_early_init;
info.assign_id=test_late_init;
info.finalize=test_finalize;
info.create_location=test_create_location;
info.delete_location=test_delete_location;
info.activate_cpu_location=test_activate_location;
info.deactivate_cpu_location=test_deactivate_location;
info.core_task_create=test_core_task_create;
info.core_task_complete=test_core_task_complete;
info.new_definition_handle=test_define_handle;
info.get_event_functions=test_get_event_functions;
return info;
}