-
Notifications
You must be signed in to change notification settings - Fork 0
/
libgomp-timing.h
65 lines (55 loc) · 1.68 KB
/
libgomp-timing.h
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
#if _LIBGOMP_LIBGOMP_TIMING_
/* Header file for tracking library function execution time. */
#ifndef RDTSC
#define RDTSC() ({ \
unsigned int cycles_low; \
unsigned int cycles_high; \
asm volatile ( \
"RDTSC\n\t" \
"mov %%edx, %0\n\t" \
"mov %%eax, %1\n\t" \
: \
"=r" (cycles_high), "=r" (cycles_low) \
: \
: \
"%rax", "%rdx" \
); \
(((uint64_t) cycles_high << 32) | cycles_low); \
})
#endif
extern struct gomp_task_icv gomp_global_icv;
struct gomp_libgomp_time
{
uint64_t entry_time;
uint64_t gomp_time;
};
static inline __attribute__((always_inline)) void
gomp_init_libgomp_time (struct gomp_libgomp_time **libgomp_time)
{
if ((*libgomp_time) == NULL)
(*libgomp_time) = gomp_malloc (sizeof(struct gomp_libgomp_time));
memset((*libgomp_time), 0, sizeof(struct gomp_libgomp_time));
}
static inline __attribute__((always_inline)) void
gomp_print_libgomp_time (struct gomp_libgomp_time **libgomp_time, unsigned nthreads)
{
unsigned tid;
size_t length;
time_t rawtime;
struct tm *timeinfo;
char filename[128];
time(&rawtime);
timeinfo = localtime(&rawtime);
if (gomp_global_icv.ult_var)
length = strftime(filename, 128, "ult_omp_libgomp_time_%d-%m-%Y_%H-%M-%S-", timeinfo);
else
length = strftime(filename, 128, "bsl_omp_libgomp_time_%d-%m-%Y_%H-%M-%S-", timeinfo);
snprintf(&filename[length], (128 - length), "(%llu).txt", (unsigned long long int) RDTSC());
FILE *file = fopen(filename, "w");
for (tid = 0; tid < nthreads; tid++)
if (libgomp_time[tid] != NULL)
fprintf(file, "Thread: %u\nLIBGOMP-Time: %llu\n\n", tid, (unsigned long long int) libgomp_time[tid]->gomp_time);
fflush(file);
fclose(file);
}
#endif