nvml-sys 0.0.6

A low-level FFI wrapper around the Persistent Memory Development Kit, PMDK (formerly NVML) and its libraries, including libpmem, libpmemobj and others. Currently tracks master after version 1.3.1.
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
/*
 * Copyright 2015-2017, Intel Corporation
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *      * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *
 *      * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *
 *      * Neither the name of the copyright holder nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * pmemobj_tx.cpp -- pmemobj_tx_alloc(), pmemobj_tx_free(),
 * pmemobj_tx_realloc(), pmemobj_tx_add_range() benchmarks.
 */
#include <cassert>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>

#include "benchmark.hpp"
#include "libpmemobj.h"

#define LAYOUT_NAME "benchmark"
#define FACTOR 1.2f
#define ALLOC_OVERHEAD 64
/*
 * operations number is limited to prevent stack overflow during
 * performing recursive functions.
 */
#define MAX_OPS 10000

TOID_DECLARE(struct item, 0);

struct obj_tx_bench;
struct obj_tx_worker;

int obj_tx_init(struct benchmark *bench, struct benchmark_args *args);
int obj_tx_exit(struct benchmark *bench, struct benchmark_args *args);

/*
 * type_num_mode -- type number mode
 */
enum type_num_mode {
	NUM_MODE_ONE,
	NUM_MODE_PER_THREAD,
	NUM_MODE_RAND,
	NUM_MODE_UNKNOWN
};

/*
 * op_mode -- operation type
 */
enum op_mode {
	OP_MODE_COMMIT,
	OP_MODE_ABORT,
	OP_MODE_ABORT_NESTED,
	OP_MODE_ONE_OBJ,
	OP_MODE_ONE_OBJ_NESTED,
	OP_MODE_ONE_OBJ_RANGE,
	OP_MODE_ONE_OBJ_NESTED_RANGE,
	OP_MODE_ALL_OBJ,
	OP_MODE_ALL_OBJ_NESTED,
	OP_MODE_UNKNOWN
};

/*
 * lib_mode -- operation type
 */
enum lib_mode {
	LIB_MODE_DRAM,
	LIB_MODE_OBJ_TX,
	LIB_MODE_OBJ_ATOMIC,
	LIB_MODE_NONE,
};

/*
 * nesting_mode -- nesting type
 */
enum nesting_mode {
	NESTING_MODE_SIM,
	NESTING_MODE_TX,
	NESTING_MODE_UNKNOWN,
};

/*
 * add_range_mode -- operation type for obj_add_range benchmark
 */
enum add_range_mode { ADD_RANGE_MODE_ONE_TX, ADD_RANGE_MODE_NESTED_TX };

/*
 * parse_mode -- parsing function type
 */
enum parse_mode { PARSE_OP_MODE, PARSE_OP_MODE_ADD_RANGE };

typedef size_t (*fn_type_num_t)(struct obj_tx_bench *obj_bench,
				size_t worker_idx, size_t op_idx);

typedef size_t (*fn_num_t)(size_t idx);

typedef int (*fn_op_t)(struct obj_tx_bench *obj_bench,
		       struct worker_info *worker, size_t idx);

typedef struct offset (*fn_os_off_t)(struct obj_tx_bench *obj_bench,
				     size_t idx);

typedef enum op_mode (*fn_parse_t)(const char *arg);

/*
 * obj_tx_args -- stores command line parsed arguments.
 */
struct obj_tx_args {

	/*
	 * operation which will be performed when flag io set to false.
	 *	modes for obj_tx_alloc, obj_tx_free and obj_tx_realloc:
	 *		- basic - transaction will be committed
	 *		- abort - 'external' transaction will be aborted.
	 *		- abort-nested - all nested transactions will be
	 *		  aborted.
	 *
	 *	modes for  obj_tx_add_range benchmark:
	 *		- basic - one object is added to undo log many times in
	 *		  one transaction.
	 *		- range - fields of one object are added to undo
	 *		  log many times in one transaction.
	 *		- all-obj - all objects are added to undo log in
	 *		  one transaction.
	 *		- range-nested - fields of one object are added to undo
	 *		  log many times in many nested transactions.
	 *		- one-obj-nested - one object is added to undo log many
	 *		  times in many nested transactions.
	 *		- all-obj-nested - all objects are added to undo log in
	 *		  many separate, nested transactions.
	 */
	char *operation;

	/*
	 * type number for each persistent object. There are three modes:
	 *		- one - all of objects have the same type number
	 *		- per-thread - all of object allocated by the same
	 *		  thread have the same type number
	 *		- rand - type numbers are assigned randomly for
	 *		  each persistent object
	 */
	char *type_num;

	/*
	 * define s which library will be used in main operations There are
	 * three modes in which benchmark can be run:
	 *		- tx - uses PMEM transactions
	 *		- pmem - uses PMEM without transactions
	 *		- dram - does not use PMEM
	 */
	char *lib;
	unsigned nested;    /* number of nested transactions */
	unsigned min_size;  /* minimum allocation size */
	unsigned min_rsize; /* minimum reallocation size */
	unsigned rsize;     /* reallocation size */
	bool change_type;   /* change type number in reallocation */
	size_t obj_size;    /* size of each allocated object */
	size_t n_ops;       /* number of operations */
	int parse_mode;     /* type of parsing function */
};

/*
 * obj_tx_bench -- stores variables used in benchmark, passed within functions.
 */
static struct obj_tx_bench {
	PMEMobjpool *pop;	     /* handle to persistent pool */
	struct obj_tx_args *obj_args; /* pointer to benchmark arguments */
	size_t *random_types;	 /* array to store random type numbers */
	size_t *sizes;      /* array to store size of each allocation */
	size_t *resizes;    /* array to store size of each reallocation */
	size_t n_objs;      /* number of objects to allocate */
	int type_mode;      /* type number mode */
	int op_mode;	/* type of operation */
	int lib_mode;       /* type of operation used in initialization */
	int lib_op;	 /* type of main operation */
	int lib_op_free;    /* type of main operation */
	int nesting_mode;   /* type of nesting in main operation */
	fn_num_t n_oid;     /* returns object's number in array */
	fn_os_off_t fn_off; /* returns offset for proper operation */

	/*
	 * fn_type_num gets proper function assigned, depending on the
	 * value of the type_mode argument, which returns proper type number for
	 * each persistent object. Possible functions are:
	 *	- type_mode_one,
	 *	- type_mode_rand.
	 */
	fn_type_num_t fn_type_num;

	/*
	 * fn_op gets proper array with functions pointer assigned, depending on
	 * function which is tested by benchmark. Possible arrays are:
	 *	-alloc_op
	 *	-free_op
	 *	-realloc_op
	 */
	fn_op_t *fn_op;
} obj_bench;

/*
 * item -- TOID's structure
 */
struct item;

/*
 * obj_tx_worker - stores variables used by one thread.
 */
struct obj_tx_worker {
	TOID(struct item) * oids;
	char **items;
	unsigned tx_level;
	unsigned max_level;
};

/*
 * offset - stores offset data used in pmemobj_tx_add_range()
 */
struct offset {
	uint64_t off;
	size_t size;
};

/*
 * alloc_dram -- main operations for obj_tx_alloc benchmark in dram mode
 */
static int
alloc_dram(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	   size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	obj_worker->items[idx] = (char *)malloc(obj_bench->sizes[idx]);
	if (obj_worker->items[idx] == NULL) {
		perror("malloc");
		return -1;
	}
	return 0;
}

/*
 * alloc_pmem -- main operations for obj_tx_alloc benchmark in pmem mode
 */
static int
alloc_pmem(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	   size_t idx)
{
	size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	if (pmemobj_alloc(obj_bench->pop, &obj_worker->oids[idx].oid,
			  obj_bench->sizes[idx], type_num, NULL, NULL) != 0) {
		perror("pmemobj_alloc");
		return -1;
	}
	return 0;
}

/*
 * alloc_tx -- main operations for obj_tx_alloc benchmark in tx mode
 */
static int
alloc_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker, size_t idx)
{
	size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	obj_worker->oids[idx].oid = pmemobj_tx_xalloc(
		obj_bench->sizes[idx], type_num, POBJ_XALLOC_NO_FLUSH);
	if (OID_IS_NULL(obj_worker->oids[idx].oid)) {
		perror("pmemobj_tx_alloc");
		return -1;
	}
	return 0;
}

/*
 * free_dram -- main operations for obj_tx_free benchmark in dram mode
 */
static int
free_dram(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	  size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	free(obj_worker->items[idx]);
	return 0;
}

/*
 * free_pmem -- main operations for obj_tx_free benchmark in pmem mode
 */
static int
free_pmem(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	  size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	POBJ_FREE(&obj_worker->oids[idx]);
	return 0;
}

/*
 * free_tx -- main operations for obj_tx_free benchmark in tx mode
 */
static int
free_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker, size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	TX_FREE(obj_worker->oids[idx]);
	return 0;
}

/*
 * no_free -- exit operation for benchmarks obj_tx_alloc and obj_tx_free
 * if there is no need to free memory
 */
static int
no_free(struct obj_tx_bench *obj_bench, struct worker_info *worker, size_t idx)
{
	return 0;
}

/*
 * realloc_dram -- main operations for obj_tx_realloc benchmark in dram mode
 */
static int
realloc_dram(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	     size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	char *tmp = (char *)realloc(obj_worker->items[idx],
				    obj_bench->resizes[idx]);
	if (tmp == NULL) {
		perror("realloc");
		return -1;
	}
	obj_worker->items[idx] = tmp;
	return 0;
}

/*
 * realloc_pmem -- main operations for obj_tx_realloc benchmark in pmem mode
 */
static int
realloc_pmem(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	     size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
	if (obj_bench->obj_args->change_type)
		type_num++;
	if (pmemobj_realloc(obj_bench->pop, &obj_worker->oids[idx].oid,
			    obj_bench->resizes[idx], type_num) != 0) {
		perror("pmemobj_realloc");
		return -1;
	}
	return 0;
}

/*
 * realloc_tx -- main operations for obj_tx_realloc benchmark in tx mode
 */
static int
realloc_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	   size_t idx)
{
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
	if (obj_bench->obj_args->change_type)
		type_num++;
	obj_worker->oids[idx].oid = pmemobj_tx_realloc(
		obj_worker->oids[idx].oid, obj_bench->sizes[idx], type_num);
	if (OID_IS_NULL(obj_worker->oids[idx].oid)) {
		perror("pmemobj_tx_realloc");
		return -1;
	}
	return 0;
}

/*
 * add_range_nested_tx -- main operations of the obj_tx_add_range with nesting.
 */
static int
add_range_nested_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
		    size_t idx)
{
	int ret = 0;
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	TX_BEGIN(obj_bench->pop)
	{
		if (obj_bench->obj_args->n_ops != obj_worker->tx_level) {
			size_t n_oid = obj_bench->n_oid(obj_worker->tx_level);
			struct offset offset = obj_bench->fn_off(
				obj_bench, obj_worker->tx_level);
			pmemobj_tx_add_range(obj_worker->oids[n_oid].oid,
					     offset.off, offset.size);
			obj_worker->tx_level++;
			ret = add_range_nested_tx(obj_bench, worker, idx);
		}
	}
	TX_ONABORT
	{
		fprintf(stderr, "transaction failed\n");
		ret = -1;
	}
	TX_END
	return ret;
}

/*
 * add_range_tx -- main operations of the obj_tx_add_range without nesting.
 */
static int
add_range_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	     size_t idx)
{
	int ret = 0;
	size_t i = 0;
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	TX_BEGIN(obj_bench->pop)
	{
		for (i = 0; i < obj_bench->obj_args->n_ops; i++) {
			size_t n_oid = obj_bench->n_oid(i);
			struct offset offset = obj_bench->fn_off(obj_bench, i);
			ret = pmemobj_tx_add_range(obj_worker->oids[n_oid].oid,
						   offset.off, offset.size);
		}
	}
	TX_ONABORT
	{
		fprintf(stderr, "transaction failed\n");
		ret = -1;
	}
	TX_END
	return ret;
}

/*
 * obj_op_sim -- main function for benchmarks which simulates nested
 * transactions on dram or pmemobj atomic API by calling function recursively.
 */
static int
obj_op_sim(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	   size_t idx)
{
	int ret = 0;
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	if (obj_worker->max_level == obj_worker->tx_level) {
		ret = obj_bench->fn_op[obj_bench->lib_op](obj_bench, worker,
							  idx);
	} else {
		obj_worker->tx_level++;
		ret = obj_op_sim(obj_bench, worker, idx);
	}
	return ret;
}

/*
 * obj_op_tx -- main recursive function for transactional benchmarks
 */
static int
obj_op_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
	  size_t idx)
{
	volatile int ret = 0;
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	TX_BEGIN(obj_bench->pop)
	{
		if (obj_worker->max_level == obj_worker->tx_level) {
			ret = obj_bench->fn_op[obj_bench->lib_op](obj_bench,
								  worker, idx);
			if (obj_bench->op_mode == OP_MODE_ABORT_NESTED)
				pmemobj_tx_abort(-1);
		} else {
			obj_worker->tx_level++;
			ret = obj_op_tx(obj_bench, worker, idx);
			if (--obj_worker->tx_level == 0 &&
			    obj_bench->op_mode == OP_MODE_ABORT)
				pmemobj_tx_abort(-1);
		}
	}
	TX_ONABORT
	{
		if (obj_bench->op_mode != OP_MODE_ABORT &&
		    obj_bench->op_mode != OP_MODE_ABORT_NESTED) {
			fprintf(stderr, "transaction failed\n");
			ret = -1;
		}
	}
	TX_END
	return ret;
}

/*
 * type_mode_one -- always returns 0, as in the mode NUM_MODE_ONE
 * all of the persistent objects have the same type_number value.
 */
static size_t
type_mode_one(struct obj_tx_bench *obj_bench, size_t worker_idx, size_t op_idx)
{
	return 0;
}

/*
 * type_mode_per_thread -- always returns worker index to all of the persistent
 * object allocated by the same thread have the same type number.
 */
static size_t
type_mode_per_thread(struct obj_tx_bench *obj_bench, size_t worker_idx,
		     size_t op_idx)
{
	return worker_idx;
}

/*
 * type_mode_rand -- returns the value from the random_types array assigned
 * for the specific operation in a specific thread.
 */
static size_t
type_mode_rand(struct obj_tx_bench *obj_bench, size_t worker_idx, size_t op_idx)
{
	return obj_bench->random_types[op_idx];
}

/*
 * parse_op_mode_add_range -- parses command line "--operation" argument
 * and returns proper op_mode enum value for obj_tx_add_range.
 */
static enum op_mode
parse_op_mode_add_range(const char *arg)
{
	if (strcmp(arg, "basic") == 0)
		return OP_MODE_ONE_OBJ;
	else if (strcmp(arg, "one-obj-nested") == 0)
		return OP_MODE_ONE_OBJ_NESTED;
	else if (strcmp(arg, "range") == 0)
		return OP_MODE_ONE_OBJ_RANGE;
	else if (strcmp(arg, "range-nested") == 0)
		return OP_MODE_ONE_OBJ_NESTED_RANGE;
	else if (strcmp(arg, "all-obj") == 0)
		return OP_MODE_ALL_OBJ;
	else if (strcmp(arg, "all-obj-nested") == 0)
		return OP_MODE_ALL_OBJ_NESTED;
	else
		return OP_MODE_UNKNOWN;
}

/*
 * parse_op_mode -- parses command line "--operation" argument
 * and returns proper op_mode enum value.
 */
static enum op_mode
parse_op_mode(const char *arg)
{
	if (strcmp(arg, "basic") == 0)
		return OP_MODE_COMMIT;
	else if (strcmp(arg, "abort") == 0)
		return OP_MODE_ABORT;
	else if (strcmp(arg, "abort-nested") == 0)
		return OP_MODE_ABORT_NESTED;
	else
		return OP_MODE_UNKNOWN;
}

static fn_op_t alloc_op[] = {alloc_dram, alloc_tx, alloc_pmem};

static fn_op_t free_op[] = {free_dram, free_tx, free_pmem, no_free};

static fn_op_t realloc_op[] = {realloc_dram, realloc_tx, realloc_pmem};

static fn_op_t add_range_op[] = {add_range_tx, add_range_nested_tx};

static fn_parse_t parse_op[] = {parse_op_mode, parse_op_mode_add_range};

static fn_op_t nestings[] = {obj_op_sim, obj_op_tx};

/*
 * parse_type_num_mode -- converts string to type_num_mode enum
 */
static enum type_num_mode
parse_type_num_mode(const char *arg)
{
	if (strcmp(arg, "one") == 0)
		return NUM_MODE_ONE;
	else if (strcmp(arg, "per-thread") == 0)
		return NUM_MODE_PER_THREAD;
	else if (strcmp(arg, "rand") == 0)
		return NUM_MODE_RAND;
	fprintf(stderr, "unknown type number\n");
	return NUM_MODE_UNKNOWN;
}

/*
 * parse_lib_mode -- converts string to type_num_mode enum
 */
static enum lib_mode
parse_lib_mode(const char *arg)
{
	if (strcmp(arg, "dram") == 0)
		return LIB_MODE_DRAM;
	else if (strcmp(arg, "pmem") == 0)
		return LIB_MODE_OBJ_ATOMIC;
	else if (strcmp(arg, "tx") == 0)
		return LIB_MODE_OBJ_TX;
	fprintf(stderr, "unknown lib mode\n");
	return LIB_MODE_NONE;
}

static fn_type_num_t type_num_fn[] = {type_mode_one, type_mode_per_thread,
				      type_mode_rand, NULL};

/*
 * one_num -- returns always the same number.
 */
static size_t
one_num(size_t idx)
{
	return 0;
}

/*
 * diff_num -- returns number given as argument.
 */
static size_t
diff_num(size_t idx)
{
	return idx;
}

/*
 * off_entire -- returns zero offset.
 */
static struct offset
off_entire(struct obj_tx_bench *obj_bench, size_t idx)
{
	struct offset offset;
	offset.off = 0;
	offset.size = obj_bench->sizes[obj_bench->n_oid(idx)];
	return offset;
}

/*
 * off_range -- returns offset for range in object.
 */
static struct offset
off_range(struct obj_tx_bench *obj_bench, size_t idx)
{
	struct offset offset;
	offset.size = obj_bench->sizes[0] / obj_bench->obj_args->n_ops;
	offset.off = offset.size * idx;
	return offset;
}

/*
 * rand_values -- allocates array and if range mode calculates random
 * values as allocation sizes for each object otherwise populates whole array
 * with max value. Used only when range flag set.
 */
static size_t *
rand_values(size_t min, size_t max, size_t n_ops)
{
	size_t size = max - min;
	size_t *sizes = (size_t *)calloc(n_ops, sizeof(size_t));
	if (sizes == NULL) {
		perror("calloc");
		return NULL;
	}
	for (size_t i = 0; i < n_ops; i++)
		sizes[i] = max;
	if (min) {
		if (min > max) {
			fprintf(stderr, "Invalid size\n");
			free(sizes);
			return NULL;
		}
		for (size_t i = 0; i < n_ops; i++)
			sizes[i] = (rand() % size) + min;
	}
	return sizes;
}

/*
 * obj_tx_add_range_op -- main operations of the obj_tx_add_range benchmark.
 */
static int
obj_tx_add_range_op(struct benchmark *bench, struct operation_info *info)
{
	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	struct obj_tx_worker *obj_worker =
		(struct obj_tx_worker *)info->worker->priv;
	if (add_range_op[obj_bench->lib_op](obj_bench, info->worker,
					    info->index) != 0)
		return -1;
	obj_worker->tx_level = 0;
	return 0;
}

/*
 * obj_tx_op -- main operation for obj_tx_alloc(), obj_tx_free() and
 * obj_tx_realloc() benchmarks.
 */
static int
obj_tx_op(struct benchmark *bench, struct operation_info *info)
{
	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	struct obj_tx_worker *obj_worker =
		(struct obj_tx_worker *)info->worker->priv;
	int ret = nestings[obj_bench->nesting_mode](obj_bench, info->worker,
						    info->index);
	obj_worker->tx_level = 0;
	return ret;
}

/*
 * obj_tx_init_worker -- common part for the worker initialization functions
 * for transactional benchmarks.
 */
static int
obj_tx_init_worker(struct benchmark *bench, struct benchmark_args *args,
		   struct worker_info *worker)
{
	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	struct obj_tx_worker *obj_worker =
		(struct obj_tx_worker *)calloc(1, sizeof(struct obj_tx_worker));
	if (obj_worker == NULL) {
		perror("calloc");
		return -1;
	}
	worker->priv = obj_worker;
	obj_worker->tx_level = 0;
	obj_worker->max_level = obj_bench->obj_args->nested;
	if (obj_bench->lib_mode != LIB_MODE_DRAM)
		obj_worker->oids = (TOID(struct item) *)calloc(
			obj_bench->n_objs, sizeof(PMEMoid));
	else
		obj_worker->items =
			(char **)calloc(obj_bench->n_objs, sizeof(char *));
	if (obj_worker->oids == NULL && obj_worker->items == NULL) {
		free(obj_worker);
		perror("calloc");
		return -1;
	}
	return 0;
}

/*
 * obj_tx_free_init_worker_alloc_obj -- special part for the worker
 * initialization function for benchmarks which needs allocated objects
 * before operation.
 */
static int
obj_tx_init_worker_alloc_obj(struct benchmark *bench,
			     struct benchmark_args *args,
			     struct worker_info *worker)
{
	unsigned i;
	if (obj_tx_init_worker(bench, args, worker) != 0)
		return -1;

	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	for (i = 0; i < obj_bench->n_objs; i++) {
		if (alloc_op[obj_bench->lib_mode](obj_bench, worker, i) != 0)
			goto out;
	}
	return 0;
out:
	for (; i > 0; i--)
		free_op[obj_bench->lib_mode](obj_bench, worker, i - 1);
	if (obj_bench->lib_mode == LIB_MODE_DRAM)
		free(obj_worker->items);
	else
		free(obj_worker->oids);
	free(obj_worker);
	return -1;
}

/*
 * obj_tx_exit_worker -- common part for the worker de-initialization.
 */
static void
obj_tx_exit_worker(struct benchmark *bench, struct benchmark_args *args,
		   struct worker_info *worker)
{
	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	struct obj_tx_worker *obj_worker = (struct obj_tx_worker *)worker->priv;
	for (unsigned i = 0; i < obj_bench->n_objs; i++)
		free_op[obj_bench->lib_op_free](obj_bench, worker, i);

	if (obj_bench->lib_mode == LIB_MODE_DRAM)
		free(obj_worker->items);
	else
		free(obj_worker->oids);
	free(obj_worker);
}

/*
 * obj_tx_add_range_init -- specific part of the obj_tx_add_range
 * benchmark initialization.
 */
static int
obj_tx_add_range_init(struct benchmark *bench, struct benchmark_args *args)
{
	struct obj_tx_args *obj_args = (struct obj_tx_args *)args->opts;
	obj_args->parse_mode = PARSE_OP_MODE_ADD_RANGE;
	if (args->n_ops_per_thread > MAX_OPS)
		args->n_ops_per_thread = MAX_OPS;
	if (obj_tx_init(bench, args) != 0)
		return -1;

	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);

	obj_bench->n_oid = diff_num;
	if (obj_bench->op_mode < OP_MODE_ALL_OBJ) {
		obj_bench->n_oid = one_num;
		obj_bench->n_objs = 1;
	}
	obj_bench->fn_off = off_entire;
	if (obj_bench->op_mode == OP_MODE_ONE_OBJ_RANGE ||
	    obj_bench->op_mode == OP_MODE_ONE_OBJ_NESTED_RANGE) {
		obj_bench->fn_off = off_range;
		if (args->n_ops_per_thread > args->dsize)
			args->dsize = args->n_ops_per_thread;

		obj_bench->sizes[0] = args->dsize;
	}
	obj_bench->lib_op = (obj_bench->op_mode == OP_MODE_ONE_OBJ ||
			     obj_bench->op_mode == OP_MODE_ALL_OBJ)
		? ADD_RANGE_MODE_ONE_TX
		: ADD_RANGE_MODE_NESTED_TX;
	return 0;
}

/*
 * obj_tx_free_init -- specific part of the obj_tx_free initialization.
 */
static int
obj_tx_free_init(struct benchmark *bench, struct benchmark_args *args)
{
	if (obj_tx_init(bench, args) != 0)
		return -1;

	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	obj_bench->fn_op = free_op;

	/*
	 * Generally all objects which were allocated during worker
	 * initialization are released in main operation so there is no need to
	 * free them in exit operation. Only exception is situation where
	 * transaction (inside which object is releasing) is aborted.
	 * Then object is not released so there there is necessary to free it
	 * in exit operation.
	 */
	if (!(obj_bench->lib_op == LIB_MODE_OBJ_TX &&
	      obj_bench->op_mode != OP_MODE_COMMIT))
		obj_bench->lib_op_free = LIB_MODE_NONE;
	return 0;
}

/*
 * obj_tx_alloc_init -- specific part of the obj_tx_alloc initialization.
 */
static int
obj_tx_alloc_init(struct benchmark *bench, struct benchmark_args *args)
{
	if (obj_tx_init(bench, args) != 0)
		return -1;

	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	obj_bench->fn_op = alloc_op;

	/*
	 * Generally all objects which will be allocated during main operation
	 * need to be released. Only exception is situation where transaction
	 * (inside which object is allocating) is aborted. Then object is not
	 * allocated so there is no need to free it in exit operation.
	 */
	if (obj_bench->lib_op == LIB_MODE_OBJ_TX &&
	    obj_bench->op_mode != OP_MODE_COMMIT)
		obj_bench->lib_op_free = LIB_MODE_NONE;
	return 0;
}

/*
 * obj_tx_realloc_init -- specific part of the obj_tx_realloc initialization.
 */
static int
obj_tx_realloc_init(struct benchmark *bench, struct benchmark_args *args)
{
	if (obj_tx_init(bench, args) != 0)
		return -1;

	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	obj_bench->resizes =
		rand_values(obj_bench->obj_args->min_rsize,
			    obj_bench->obj_args->rsize, args->n_ops_per_thread);
	if (obj_bench->resizes == NULL) {
		obj_tx_exit(bench, args);
		return -1;
	}
	obj_bench->fn_op = realloc_op;
	return 0;
}

/*
 * obj_tx_init -- common part of the benchmark initialization for transactional
 * benchmarks in their init functions. Parses command line arguments, set
 * variables and creates persistent pool.
 */
int
obj_tx_init(struct benchmark *bench, struct benchmark_args *args)
{
	assert(bench != NULL);
	assert(args != NULL);
	assert(args->opts != NULL);

	pmembench_set_priv(bench, &obj_bench);

	obj_bench.obj_args = (struct obj_tx_args *)args->opts;
	obj_bench.obj_args->obj_size = args->dsize;
	obj_bench.obj_args->n_ops = args->n_ops_per_thread;
	obj_bench.n_objs = args->n_ops_per_thread;

	obj_bench.lib_op = obj_bench.obj_args->lib != NULL
		? parse_lib_mode(obj_bench.obj_args->lib)
		: LIB_MODE_OBJ_ATOMIC;

	if (obj_bench.lib_op == LIB_MODE_NONE)
		return -1;

	obj_bench.lib_mode = obj_bench.lib_op == LIB_MODE_DRAM
		? LIB_MODE_DRAM
		: LIB_MODE_OBJ_ATOMIC;

	obj_bench.lib_op_free = obj_bench.lib_mode;

	obj_bench.nesting_mode = obj_bench.lib_op == LIB_MODE_OBJ_TX
		? NESTING_MODE_TX
		: NESTING_MODE_SIM;

	/*
	 * Multiplication by FACTOR prevents from out of memory error
	 * as the actual size of the allocated persistent objects
	 * is always larger than requested.
	 */
	size_t dsize = obj_bench.obj_args->rsize > args->dsize
		? obj_bench.obj_args->rsize
		: args->dsize;
	size_t psize = args->n_ops_per_thread * (dsize + ALLOC_OVERHEAD) *
		args->n_threads;

	psize += PMEMOBJ_MIN_POOL;
	psize = (size_t)(psize * FACTOR);

	/*
	 * When adding all allocated objects to undo log there is necessary
	 * to prepare larger pool to prevent out of memory error.
	 */
	if (obj_bench.op_mode == OP_MODE_ALL_OBJ ||
	    obj_bench.op_mode == OP_MODE_ALL_OBJ_NESTED)
		psize *= 2;

	obj_bench.op_mode = parse_op[obj_bench.obj_args->parse_mode](
		obj_bench.obj_args->operation);
	if (obj_bench.op_mode == OP_MODE_UNKNOWN) {
		fprintf(stderr, "operation mode unknown\n");
		return -1;
	}

	obj_bench.type_mode = parse_type_num_mode(obj_bench.obj_args->type_num);
	if (obj_bench.type_mode == NUM_MODE_UNKNOWN)
		return -1;

	obj_bench.fn_type_num = type_num_fn[obj_bench.type_mode];
	if (obj_bench.type_mode == NUM_MODE_RAND) {
		obj_bench.random_types =
			rand_values(1, UINT32_MAX, args->n_ops_per_thread);
		if (obj_bench.random_types == NULL)
			return -1;
	}
	obj_bench.sizes = rand_values(obj_bench.obj_args->min_size,
				      obj_bench.obj_args->obj_size,
				      args->n_ops_per_thread);
	if (obj_bench.sizes == NULL)
		goto free_random_types;

	if (obj_bench.lib_mode == LIB_MODE_DRAM)
		return 0;

	/* Create pmemobj pool. */
	if (args->is_poolset) {
		if (args->fsize < psize) {
			fprintf(stderr, "insufficient size of poolset\n");
			goto free_all;
		}

		psize = 0;
	}
	obj_bench.pop =
		pmemobj_create(args->fname, LAYOUT_NAME, psize, args->fmode);
	if (obj_bench.pop == NULL) {
		perror("pmemobj_create");
		goto free_all;
	}

	return 0;
free_all:
	free(obj_bench.sizes);
free_random_types:
	if (obj_bench.type_mode == NUM_MODE_RAND)
		free(obj_bench.random_types);
	return -1;
}

/*
 * obj_tx_exit -- common part for the exit function of the transactional
 * benchmarks in their exit functions.
 */
int
obj_tx_exit(struct benchmark *bench, struct benchmark_args *args)
{
	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	if (obj_bench->lib_mode != LIB_MODE_DRAM)
		pmemobj_close(obj_bench->pop);

	free(obj_bench->sizes);
	if (obj_bench->type_mode == NUM_MODE_RAND)
		free(obj_bench->random_types);
	return 0;
}

/*
 * obj_tx_realloc_exit -- common part for the exit function of the transactional
 * benchmarks in their exit functions.
 */
static int
obj_tx_realloc_exit(struct benchmark *bench, struct benchmark_args *args)
{
	struct obj_tx_bench *obj_bench =
		(struct obj_tx_bench *)pmembench_get_priv(bench);
	free(obj_bench->resizes);
	return obj_tx_exit(bench, args);
}

/* Array defining common command line arguments. */
static struct benchmark_clo obj_tx_clo[8];

static struct benchmark_info obj_tx_alloc;
static struct benchmark_info obj_tx_free;
static struct benchmark_info obj_tx_realloc;
static struct benchmark_info obj_tx_add_range;

CONSTRUCTOR(pmemobj_tx_costructor)
void
pmemobj_tx_costructor(void)
{
	obj_tx_clo[0].opt_short = 'T';
	obj_tx_clo[0].opt_long = "type-number";
	obj_tx_clo[0].descr = "Type number - one, rand, per-thread";
	obj_tx_clo[0].def = "one";
	obj_tx_clo[0].type = CLO_TYPE_STR;
	obj_tx_clo[0].off = clo_field_offset(struct obj_tx_args, type_num);

	obj_tx_clo[1].opt_short = 'O';
	obj_tx_clo[1].opt_long = "operation";
	obj_tx_clo[1].descr = "Type of operation";
	obj_tx_clo[1].def = "basic";
	obj_tx_clo[1].off = clo_field_offset(struct obj_tx_args, operation);
	obj_tx_clo[1].type = CLO_TYPE_STR;

	obj_tx_clo[2].opt_short = 'm';
	obj_tx_clo[2].opt_long = "min-size";
	obj_tx_clo[2].type = CLO_TYPE_UINT;
	obj_tx_clo[2].descr = "Minimum allocation size";
	obj_tx_clo[2].off = clo_field_offset(struct obj_tx_args, min_size);
	obj_tx_clo[2].def = "0";
	obj_tx_clo[2].type_uint.size =
		clo_field_size(struct obj_tx_args, min_size);
	obj_tx_clo[2].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
	obj_tx_clo[2].type_uint.min = 0;
	obj_tx_clo[2].type_uint.max = UINT_MAX;
	/*
	 * nclos field in benchmark_info structures is decremented to make this
	 * options available only for obj_tx_alloc, obj_tx_free and
	 * obj_tx_realloc benchmarks.
	 */
	obj_tx_clo[3].opt_short = 'L';
	obj_tx_clo[3].opt_long = "lib";
	obj_tx_clo[3].descr = "Type of library";
	obj_tx_clo[3].def = "tx";
	obj_tx_clo[3].off = clo_field_offset(struct obj_tx_args, lib);
	obj_tx_clo[3].type = CLO_TYPE_STR;

	obj_tx_clo[4].opt_short = 'N';
	obj_tx_clo[4].opt_long = "nestings";
	obj_tx_clo[4].type = CLO_TYPE_UINT;
	obj_tx_clo[4].descr = "Number of nested transactions";
	obj_tx_clo[4].off = clo_field_offset(struct obj_tx_args, nested);
	obj_tx_clo[4].def = "0";
	obj_tx_clo[4].type_uint.size =
		clo_field_size(struct obj_tx_args, nested);
	obj_tx_clo[4].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
	obj_tx_clo[4].type_uint.min = 0;
	obj_tx_clo[4].type_uint.max = MAX_OPS;

	obj_tx_clo[5].opt_short = 'r';
	obj_tx_clo[5].opt_long = "min-rsize";
	obj_tx_clo[5].type = CLO_TYPE_UINT;
	obj_tx_clo[5].descr = "Minimum reallocation size";
	obj_tx_clo[5].off = clo_field_offset(struct obj_tx_args, min_rsize);
	obj_tx_clo[5].def = "0";
	obj_tx_clo[5].type_uint.size =
		clo_field_size(struct obj_tx_args, min_rsize);
	obj_tx_clo[5].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
	obj_tx_clo[5].type_uint.min = 0;
	obj_tx_clo[5].type_uint.max = UINT_MAX;

	obj_tx_clo[6].opt_short = 'R';
	obj_tx_clo[6].opt_long = "realloc-size";
	obj_tx_clo[6].type = CLO_TYPE_UINT;
	obj_tx_clo[6].descr = "Reallocation size";
	obj_tx_clo[6].off = clo_field_offset(struct obj_tx_args, rsize);
	obj_tx_clo[6].def = "1";
	obj_tx_clo[6].type_uint.size =
		clo_field_size(struct obj_tx_args, rsize);
	obj_tx_clo[6].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
	obj_tx_clo[6].type_uint.min = 1;
	obj_tx_clo[6].type_uint.max = ULONG_MAX;

	obj_tx_clo[7].opt_short = 'c';
	obj_tx_clo[7].opt_long = "changed-type";
	obj_tx_clo[7].descr = "Use another type number in "
			      "reallocation than in allocation";
	obj_tx_clo[7].type = CLO_TYPE_FLAG;
	obj_tx_clo[7].off = clo_field_offset(struct obj_tx_args, change_type);

	obj_tx_alloc.name = "obj_tx_alloc";
	obj_tx_alloc.brief = "pmemobj_tx_alloc() benchmark";
	obj_tx_alloc.init = obj_tx_alloc_init;
	obj_tx_alloc.exit = obj_tx_exit;
	obj_tx_alloc.multithread = true;
	obj_tx_alloc.multiops = true;
	obj_tx_alloc.init_worker = obj_tx_init_worker;
	obj_tx_alloc.free_worker = obj_tx_exit_worker;
	obj_tx_alloc.operation = obj_tx_op;
	obj_tx_alloc.measure_time = true;
	obj_tx_alloc.clos = obj_tx_clo;
	obj_tx_alloc.nclos = ARRAY_SIZE(obj_tx_clo) - 3;
	obj_tx_alloc.opts_size = sizeof(struct obj_tx_args);
	obj_tx_alloc.rm_file = true;
	obj_tx_alloc.allow_poolset = true;
	REGISTER_BENCHMARK(obj_tx_alloc);

	obj_tx_free.name = "obj_tx_free";
	obj_tx_free.brief = "pmemobj_tx_free() benchmark";
	obj_tx_free.init = obj_tx_free_init;
	obj_tx_free.exit = obj_tx_exit;
	obj_tx_free.multithread = true;
	obj_tx_free.multiops = true;
	obj_tx_free.init_worker = obj_tx_init_worker_alloc_obj;
	obj_tx_free.free_worker = obj_tx_exit_worker;
	obj_tx_free.operation = obj_tx_op;
	obj_tx_free.measure_time = true;
	obj_tx_free.clos = obj_tx_clo;
	obj_tx_free.nclos = ARRAY_SIZE(obj_tx_clo) - 3;
	obj_tx_free.opts_size = sizeof(struct obj_tx_args);
	obj_tx_free.rm_file = true;
	obj_tx_free.allow_poolset = true;
	REGISTER_BENCHMARK(obj_tx_free);

	obj_tx_realloc.name = "obj_tx_realloc";
	obj_tx_realloc.brief = "pmemobj_tx_realloc() benchmark";
	obj_tx_realloc.init = obj_tx_realloc_init;
	obj_tx_realloc.exit = obj_tx_realloc_exit;
	obj_tx_realloc.multithread = true;
	obj_tx_realloc.multiops = true;
	obj_tx_realloc.init_worker = obj_tx_init_worker_alloc_obj;
	obj_tx_realloc.free_worker = obj_tx_exit_worker;
	obj_tx_realloc.operation = obj_tx_op;
	obj_tx_realloc.measure_time = true;
	obj_tx_realloc.clos = obj_tx_clo;
	obj_tx_realloc.nclos = ARRAY_SIZE(obj_tx_clo);
	obj_tx_realloc.opts_size = sizeof(struct obj_tx_args);
	obj_tx_realloc.rm_file = true;
	obj_tx_realloc.allow_poolset = true;
	REGISTER_BENCHMARK(obj_tx_realloc);

	obj_tx_add_range.name = "obj_tx_add_range";
	obj_tx_add_range.brief = "pmemobj_tx_add_range() benchmark";
	obj_tx_add_range.init = obj_tx_add_range_init;
	obj_tx_add_range.exit = obj_tx_exit;
	obj_tx_add_range.multithread = true;
	obj_tx_add_range.multiops = false;
	obj_tx_add_range.init_worker = obj_tx_init_worker_alloc_obj;
	obj_tx_add_range.free_worker = obj_tx_exit_worker;
	obj_tx_add_range.operation = obj_tx_add_range_op;
	obj_tx_add_range.measure_time = true;
	obj_tx_add_range.clos = obj_tx_clo;
	obj_tx_add_range.nclos = ARRAY_SIZE(obj_tx_clo) - 5;
	obj_tx_add_range.opts_size = sizeof(struct obj_tx_args);
	obj_tx_add_range.rm_file = true;
	obj_tx_add_range.allow_poolset = true;
	REGISTER_BENCHMARK(obj_tx_add_range);
}