The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
buddy.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <datatypes/array.h>
12 #include <datatypes/bitmap.h>
13 
14 #include <assert.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 #define B_TOTAL_EXP 17U
19 #define B_BLOCK_EXP 6U
20 #define B_LOG_INCREMENTAL_THRESHOLD 0.5
21 #define B_LOG_FREQUENCY 50
22 
24 struct mm_state { // todo incremental checkpoints
26  dyn_array(
28  struct mm_log {
30  array_count_t ref_i;
32  struct mm_checkpoint *c;
33  }
34  ) logs;
36  uint_fast32_t used_mem;
38  uint_least8_t longest[(1U << (B_TOTAL_EXP - B_BLOCK_EXP + 1))]; // last char is actually unused
40  unsigned char base_mem[1U << B_TOTAL_EXP];
41 #ifdef ROOTSIM_INCREMENTAL
42  uint_fast32_t dirty_mem;
47  // this tracks writes to the allocation tree
48  (1 << (B_TOTAL_EXP - 2 * B_BLOCK_EXP + 1)) +
49  // while this tracks writes to the actual memory buffer
50  (1 << (B_TOTAL_EXP - B_BLOCK_EXP))
51 
52  )
53  ];
54 #endif
55 };
56 
58 struct mm_checkpoint { // todo only log longest[] if changed, or incrementally
59 #ifdef ROOTSIM_INCREMENTAL
60  bool is_incremental;
65  // this tracks writes to the allocation tree
66  (1 << (B_TOTAL_EXP - 2 * B_BLOCK_EXP + 1)) +
67  // while this tracks writes to the actual memory buffer
68  (1 << (B_TOTAL_EXP - B_BLOCK_EXP))
69  )
70  ];
71 #endif
72  uint_fast32_t used_mem;
75  uint_least8_t longest[(1U << (B_TOTAL_EXP - B_BLOCK_EXP + 1))];
77  unsigned char base_mem[];
78 };
79 
80 static_assert(
81  offsetof(struct mm_state, longest) ==
82  offsetof(struct mm_state, base_mem) -
83  sizeof(((struct mm_state *)0)->longest),
84  "longest and base_mem are not contiguous, this will break incremental checkpointing");
85 
86 
mm_state
The checkpointable memory context assigned to a single LP.
Definition: buddy.h:24
block_bitmap
unsigned char block_bitmap
The type of a generic bitmap.
Definition: bitmap.h:22
bitmap.h
Bitmap data type.
mm_state::dirty_mem
uint_fast32_t dirty_mem
The bytes count of the memory dirtied by writes.
Definition: buddy.h:43
mm_state::dirty
block_bitmap dirty[bitmap_required_size((1<<(17U - 2 *6U+1))+(1<<(17U - 6U)))]
Keeps track of memory blocks which have been dirtied by a write.
Definition: buddy.h:53
mm_checkpoint::used_mem
uint_fast32_t used_mem
The used memory in bytes when this checkpoint was taken.
Definition: buddy.h:73
mm_state::dyn_array
dyn_array(struct mm_log { array_count_t ref_i;struct mm_checkpoint *c;}) logs
The array of checkpoints.
array.h
Dynamic array datatype.
mm_checkpoint::is_incremental
bool is_incremental
If set this checkpoint is incremental, else it is a full one.
Definition: buddy.h:61
bitmap_required_size
#define bitmap_required_size(requested_bits)
Computes the required size of a bitmap.
Definition: bitmap.h:56
array_count_t
uint_fast32_t array_count_t
The type used to handle dynamic arrays count of elements and capacity.
Definition: array.h:21
mm_state::longest
uint_least8_t longest[(1U<<(17U - 6U+1))]
The checkpointed binary tree representing the buddy system.
Definition: buddy.h:38
mm_checkpoint::dirty
block_bitmap dirty[bitmap_required_size((1<<(17U - 2 *6U+1))+(1<<(17U - 6U)))]
The checkpoint of the dirty bitmap.
Definition: buddy.h:70
mm_checkpoint::longest
uint_least8_t longest[(1U<<(17U - 6U+1))]
The checkpointed binary tree representing the buddy system.
Definition: buddy.h:75
mm_state::base_mem
unsigned char base_mem[1U<< 17U]
The memory buffer served to the model.
Definition: buddy.h:40
mm_checkpoint
A restorable checkpoint of the memory context assigned to a single LP.
Definition: buddy.h:58
mm_checkpoint::base_mem
unsigned char base_mem[]
The checkpointed memory buffer assigned to the model.
Definition: buddy.h:77
mm_state::used_mem
uint_fast32_t used_mem
The count of allocated bytes.
Definition: buddy.h:36