-
Notifications
You must be signed in to change notification settings - Fork 0
/
pm_instr.h
528 lines (482 loc) · 20.6 KB
/
pm_instr.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
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
/*
* Macros to instrument PM reads and writes
* Author : Nalli, S.
* Contact: nalli@wisc.edu
*
* The value returned by code surrounded by {}
* is the value returned by last statement in
* the block. These macros do not perform any
* operations on the persistent variable itself,
* and hence do not introduce any extra accesses
* to persistent memory.
*
*/
#ifndef PM_INSTR_H
#define PM_INSTR_H
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define LOC1 __func__ /* str ["0"]: can be __func__, __FILE__ */
#define LOC2 __LINE__ /* int [0] : can be __LINE__ */
#define m_out stdout
#define m_err stderr
#define TSTR_SZ 128
#define MAX_TBUF_SZ 2*512*1024*1024 /* bytes */
/*
Currently, the buffer is 1gb in size since that is the
maximum allowed by mmap. mmap64 fails for some reason and isn't
supported on all systems. If a circular buffer is used, then after
a point every insertion into the buffer will be followed by a drain
operation which will move one entry into storage after compression.
This not only increases the latency of an insertion affecting runtime
performance, but underutilizes the capacity of gzip to compress larger
blocks and possibly unnecessary disk I/O. In short, please batch movement
of data between buffer and storage.
*/
extern __thread struct timeval mtm_time;
extern __thread int mtm_tid;
extern __thread char tstr[TSTR_SZ];
extern __thread int tsz;
extern __thread unsigned long long tbuf_ptr;
extern __thread int reg_write;
extern __thread unsigned long long n_epoch;
extern char *tbuf;
extern unsigned long long tbuf_sz;
extern pthread_spinlock_t tbuf_lock;
extern pthread_spinlock_t tot_epoch_lock;
extern int mtm_enable_trace;
extern int mtm_debug_buffer;
extern int trace_marker, tracing_on;
extern struct timeval glb_time;
extern unsigned long long start_buf_drain, end_buf_drain, buf_drain_period;
extern unsigned long long glb_tv_sec, glb_tv_usec, glb_start_time;
extern unsigned long long tot_epoch;
extern void __pm_trace_print(char* format, ...);
extern unsigned long long get_epoch_count(void);
extern unsigned long long get_tot_epoch_count(void);
#define PSEGMENT_RESERVED_REGION_START 0x0000100000000000
#define PSEGMENT_RESERVED_REGION_SIZE 0x0000010000000000 /* 1 TB */
#define PSEGMENT_RESERVED_REGION_END (PSEGMENT_RESERVED_REGION_START + \
PSEGMENT_RESERVED_REGION_SIZE)
/******************************************************************************/
#ifdef _ENABLE_TRACE
/* Customer user-mode, blocking tracer */
#define time_since_start \
({ \
gettimeofday(&mtm_time, NULL); \
(((1000000*mtm_time.tv_sec + \
mtm_time.tv_usec) \
- (glb_start_time)) - buf_drain_period); \
})
#define TENTRY_ID \
(mtm_tid == -1 ? \
({mtm_tid = syscall(SYS_gettid); mtm_tid;}) : mtm_tid), \
(time_since_start)
#define pm_trace_print(format, args ...) \
{ \
if(mtm_enable_trace) { \
pthread_spin_lock(&tbuf_lock); \
sprintf(tstr, format, args); \
tsz = strlen(tstr); \
if((unsigned long long)tsz < MAX_TBUF_SZ - tbuf_sz) \
{ \
memcpy(tbuf+tbuf_sz, \
tstr, tsz); \
tbuf_sz += (unsigned long long)tsz; \
} \
else { \
tbuf_ptr = 0; \
if(mtm_debug_buffer) \
{ \
fprintf(m_err, \
"start_buf_drain - %llu us\n", \
(start_buf_drain = time_since_start)); \
} \
while(tbuf_ptr < tbuf_sz) \
{ \
tbuf_ptr = tbuf_ptr + 1 + \
fprintf(m_out,"%s", \
tbuf + tbuf_ptr); \
} \
tbuf_sz = 0; \
memset(tbuf,'\0', MAX_TBUF_SZ); \
if(mtm_debug_buffer) \
{ \
fprintf(m_err, \
"end_buf_drain - %llu us\n", \
(end_buf_drain = time_since_start)); \
} \
memcpy(tbuf, tstr, tsz); \
tbuf_sz += (unsigned long long)tsz; \
buf_drain_period += (end_buf_drain - \
start_buf_drain) + 1; \
} \
pthread_spin_unlock(&tbuf_lock); \
} \
}
#elif _ENABLE_FTRACE
/* Standard kernel-mode, non-blocking tracer. */
#define TENTRY_ID (int)0 ,(unsigned long long)0
#define pm_trace_print(format, args ...) \
{ \
if(mtm_enable_trace) { \
sprintf(tstr, format, args); \
tsz = strlen(tstr); \
write(trace_marker, tstr+4, tsz-4); \
} \
}
#else
#define TENTRY_ID (int)0 /* this is the first arg */
#define pm_trace_print(format, args ...) \
{ \
__pm_trace_print(format, args); \
}
#endif
/******************************************************************************/
#define PM_TRACE pm_trace_print
/* Cacheable PM write */
#define PM_WRT_MARKER "PM_W"
#define PM_DWRT_MARKER "PM_DW" /* Cache-able data write */
#define PM_DI_MARKER "PM_DI" /* Non-temporal data write */
/* Cacheable PM read */
#define PM_RD_MARKER "PM_R"
/* Un-cacheable PM store */
#define PM_NTI "PM_I"
/* PM flush */
#define PM_FLUSH_MARKER "PM_L"
/* PM Delimiters */
#define PM_TX_START "PM_XS"
#define PM_FENCE_MARKER "PM_N"
#define PM_COMMIT_MARKER "PM_C"
#define PM_BARRIER_MARKER "PM_B"
#define PM_TX_END "PM_XE"
/* PM Write macros */
/* PM Write to variable */
#define PM_STORE(pm_dst, bytes) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
(pm_dst), \
bytes, \
LOC1, \
LOC2); \
})
#define PM_STORE_DW(pm_dst, bytes) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_DWRT_MARKER, \
(pm_dst), \
bytes, \
LOC1, \
LOC2); \
})
#define PM_WRITE(pm_dst) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
\
pm_dst; \
})
#define PM_WRITE_DW(pm_dst) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_DWRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
\
pm_dst; \
})
#define PM_EQU(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst = y; \
})
#define PM_EQU_DW(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_DWRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst = y; \
})
#define PM_EQU_DI(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_DI_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst = y; \
})
#define PM_OR_EQU(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst |= y; \
})
#define PM_AND_EQU(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst &= y; \
})
#define PM_ADD_EQU(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst += y; \
})
#define PM_SUB_EQU(pm_dst, y) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_dst), \
sizeof((pm_dst)), \
LOC1, \
LOC2); \
pm_dst -= y; \
})
/* PM Writes to a range of memory */
#define PM_MEMSET(pm_dst, val, sz) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
(pm_dst), \
(unsigned long)sz, \
LOC1, \
LOC2); \
memset(pm_dst, val, sz); \
})
#define PM_DMEMSET(pm_dst, val, sz) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_DWRT_MARKER, \
(pm_dst), \
(unsigned long)sz, \
LOC1, \
LOC2); \
memset(pm_dst, val, sz); \
})
#define PM_MEMCPY(pm_dst, src, sz) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
(pm_dst), \
(unsigned long)sz, \
LOC1, \
LOC2); \
memcpy(pm_dst, src, sz); \
})
#define PM_DMEMCPY(pm_dst, src, sz) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_DWRT_MARKER, \
(pm_dst), \
(unsigned long)sz, \
LOC1, \
LOC2); \
memcpy(pm_dst, src, sz); \
})
#define PM_STRCPY(pm_dst, src) \
({ \
PM_TRACE("%d:%llu:%s:%p:%u:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
(pm_dst), \
(int)strlen((src)), \
LOC1, \
LOC2); \
strcpy(pm_dst, src); \
})
#define PM_STRNCPY(pm_dst, src, len) \
({ \
PM_TRACE("%d:%llu:%s:%p:%u:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
(pm_dst), \
(int)len, \
LOC1, \
LOC2); \
strncpy(pm_dst, src, len); \
})
#define PM_MOVNTI(pm_dst, count, copied) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%lu:%s:%d\n", \
TENTRY_ID, \
PM_NTI, \
(pm_dst), \
(unsigned long)copied, \
(unsigned long)count, \
LOC1, \
LOC2 \
); \
0; \
})
/* PM Read macros */
/* Return the data of persistent variable */
#define PM_READ(pm_src) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_RD_MARKER, \
&(pm_src), \
sizeof((pm_src)), \
LOC1, \
LOC2); \
(pm_src); \
})
/* Return the address of persistent variable */
#define PM_READ_P(pm_src) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_RD_MARKER, \
&(pm_src), \
sizeof((pm_src)), \
LOC1, \
LOC2); \
&(pm_src); \
})
/* Return the address of persistent variable */
#define PM_RD_WR_P(pm_src) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_RD_MARKER, \
&(pm_src), \
sizeof((pm_src)), \
LOC1, \
LOC2); \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_WRT_MARKER, \
&(pm_src), \
sizeof((pm_src)), \
LOC1, \
LOC2); \
&(pm_src); \
})
/* PM Reads to a range of memory */
#define PM_MEMCMP(pm_dst, src, sz) \
({ \
PM_TRACE("%d:%llu:%s:%p:%lu:%s:%d\n", \
TENTRY_ID, \
PM_RD_MARKER, \
(pm_dst), \
(unsigned long)sz, \
LOC1, \
LOC2); \
memcmp(pm_dst, src, sz); \
})
#define start_epoch() ({;})
#define end_epoch() ({;})
#define start_txn() \
({ \
PM_TRACE("%d:%llu:%s:%s:%d\n", \
TENTRY_ID, \
PM_TX_START, \
LOC1, \
LOC2); \
})
#define end_txn() \
({ \
PM_TRACE("%d:%llu:%s:%s:%d\n", \
TENTRY_ID, \
PM_TX_END, \
LOC1, \
LOC2); \
})
#define PM_START_TX start_txn
#define PM_END_TX end_txn
/******************************************************************************/
/* PM Persist operations
* (done/copied) followed by count to maintain
* uniformity with other macros
*/
#define PM_FLUSH(pm_dst, count, done) \
({ \
PM_TRACE("%d:%llu:%s:%p:%u:%u:%s:%d\n", \
TENTRY_ID, \
PM_FLUSH_MARKER, \
(pm_dst), \
done, \
count, \
LOC1, \
LOC2 \
); \
})
#define PM_COMMIT() \
({ \
PM_TRACE("%d:%llu:%s:%s:%d\n", \
TENTRY_ID, \
PM_COMMIT_MARKER, \
LOC1, \
LOC2); \
})
#define PM_BARRIER() \
({ \
PM_TRACE("%d:%llu:%s:%s:%d\n", \
TENTRY_ID, \
PM_BARRIER_MARKER, \
LOC1, \
LOC2); \
})
#define PM_FENCE() \
({ \
PM_TRACE("%d:%llu:%s:%s:%d\n", \
TENTRY_ID, \
PM_FENCE_MARKER, \
LOC1, \
LOC2); \
})
#endif /* PM_INSTR_H */