]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/tools/pmreorder/memoryoperations.py
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2018, Intel Corporation
4 from utils
import Rangeable
5 from utils
import range_cmp
6 from utils
import StackTrace
7 from sys
import byteorder
12 Base class for all memory operations.
17 class Fence(BaseOperation
):
19 Describes a fence operation.
21 The exact type of the memory barrier is not important,
22 it is interpreted as an SFENCE or MFENCE.
26 Internal factory class to be used in dynamic object creation.
28 def create(self
, values
):
30 Factory object creation method.
32 :param values: Ignored.
34 :return: New Fence object.
40 class Store(BaseOperation
, Rangeable
):
42 Describes a store operation.
44 :ivar address: The virtual address at which to store the new value.
46 :ivar new_value: The new value to be written.
47 :type new_value: bytearray
48 :ivar size: The size of the store in bytes.
50 :ivar old_value: The old value read from the file.
51 :type old_value: bytearray
52 :ivar flushed: Indicates whether the store has been flushed.
55 def __init__(self
, values
):
57 Initializes the object based on the describing string.
59 :param values: Pre-formatted string describing the store.
63 params
= values
.split(";")
64 # calculate the offset given the registered file mapping
65 self
.address
= int(params
[1], 16)
66 self
.size
= int(params
[3], 16)
68 int(params
[2], 16).to_bytes(self
.size
, byteorder
=byteorder
)
70 self
.trace
= StackTrace(params
[4:])
72 self
.trace
= StackTrace(["No trace available", ])
77 return "addr: " + hex(self
.address
) + " size " + \
78 str(self
.size
) + " value " + str(self
.new_value
)
80 def get_base_address(self
):
82 Override from :class:`utils.Rangeable`.
84 :return: Virtual address of the store.
89 def get_max_address(self
):
91 Override from :class:`utils.Rangeable`.
93 :return: Virtual address of the first byte after the store.
96 return self
.address
+ self
.size
100 Internal factory class to be used in dynamic object creation.
102 def create(self
, values
):
104 Factory object creation method.
106 :param values: Pre-formatted string describing the store.
108 :return: New Store object.
114 class FlushBase(BaseOperation
, Rangeable
):
116 Base class for flush operations.
118 def is_in_flush(self
, store_op
):
120 Check if a given store is within the flush.
122 :param store_op: Store operation to check.
123 :return: True if store is in flush, false otherwise.
126 raise NotImplementedError
129 class Flush(FlushBase
):
131 Describes a flush operation.
133 Examples of flush instructions are CLFLUSH, CLFLUSHOPT or CLWB.
135 :ivar _address: Virtual address of the flush.
137 :ivar _size: The size of the flush in bytes (should be cache line aligned).
140 def __init__(self
, values
):
142 Initializes the object based on the describing string.
144 :param values: Pre-formatted string describing the flush.
148 params
= values
.split(";")
149 self
._address
= int(params
[1], 16)
150 self
._size
= int(params
[2], 16)
152 def is_in_flush(self
, store_op
):
154 Override from :class:`FlushBase`.
156 :param store_op: Store operation to check.
157 :return: True if store is in flush, false otherwise.
160 if range_cmp(store_op
, self
) == 0:
165 def get_base_address(self
):
167 Override from :class:`utils.Rangeable`.
169 :return: Virtual address of the flush.
174 def get_max_address(self
):
176 Override from :class:`utils.Rangeable`.
178 :return: Virtual address of the first byte after the flush.
181 return self
._address
+ self
._size
185 Internal factory class to be used in dynamic object creation.
187 def create(self
, values
):
189 Factory object creation method.
191 :param values: Pre-formatted string describing the flush.
193 :return: New Flush object.
199 class ReorderBase(BaseOperation
):
201 Base class for all reorder type classes.
206 class NoReorderDoCheck(ReorderBase
):
208 Describes the type of reordering engine to be used.
210 This marker class triggers writing the whole sequence of stores
215 Internal factory class to be used in dynamic object creation.
217 def create(self
, values
):
219 Factory object creation method.
221 :param values: Ignored.
223 :return: New NoReorderDoCheck object.
224 :rtype: NoReorderDoCheck
226 return NoReorderDoCheck()
229 class ReorderFull(ReorderBase
):
231 Describes the type of reordering engine to be used.
233 This marker class triggers writing all possible sequences of stores
238 Internal factory class to be used in dynamic object creation.
240 def create(self
, values
):
242 Factory object creation method.
244 :param values: Ignored.
246 :return: New ReorderFull object.
252 class ReorderAccumulative(ReorderBase
):
254 Describes the type of reordering engine to be used.
256 This marker class triggers writing all
257 possible accumulative sequences of stores
262 Internal factory class to be used in dynamic object creation.
264 def create(self
, values
):
266 Factory object creation method.
268 :param values: Ignored.
270 :return: New ReorderAccumulative object.
271 :rtype: ReorderAccumulative
273 return ReorderAccumulative()
276 class ReorderReverseAccumulative(ReorderBase
):
278 Describes the type of reordering engine to be used.
280 This marker class triggers writing all
281 possible reverted accumulative sequences of stores
286 Internal factory class to be used in dynamic object creation.
288 def create(self
, values
):
290 Factory object creation method.
292 :param values: Ignored.
294 :return: New ReorderReverseAccumulative object.
295 :rtype: ReorderReverseAccumulative
297 return ReorderReverseAccumulative()
300 class NoReorderNoCheck(ReorderBase
):
302 Describes the type of reordering engine to be used.
304 This marker class triggers writing the whole sequence of stores
305 between barriers. It additionally marks that no consistency checking
310 Internal factory class to be used in dynamic object creation.
312 def create(self
, values
):
314 Factory object creation method.
316 :param values: Ignored.
318 :return: New NoReorderNoCheck object.
319 :rtype: NoReorderNoCheck
321 return NoReorderNoCheck()
324 class ReorderDefault(ReorderBase
):
326 Describes the default reordering engine to be used.
328 This marker class triggers default reordering.
332 Internal factory class to be used in dynamic object creation.
334 def create(self
, values
):
336 Factory object creation method.
338 :param values: Ignored.
340 :return: ReorderDefault object.
341 :rtype: ReorderDefault
343 return ReorderDefault()
346 class ReorderPartial(ReorderBase
):
348 Describes the type of reordering engine to be used.
350 This marker class triggers writing a subset of all possible
351 sequences of stores between barriers.
353 The type of partial reordering is chosen at runtime. Not yet
358 Internal factory class to be used in dynamic object creation.
360 def create(self
, values
):
362 Factory object creation method.
364 :param values: Ignored.
366 :return: New ReorderPartial object.
367 :rtype: ReorderPartial
369 return ReorderPartial()
372 class Register_file(BaseOperation
):
374 Describes the file to be mapped into processes address space.
376 :ivar name: The full name of the file.
378 :ivar address: The base address where the file was mapped.
380 :ivar size: The size of the mapping.
382 :ivar offset: The start offset of the mapping within the file.
385 def __init__(self
, values
):
387 Initializes the object based on the describing string.
389 :param values: Pre-formatted string describing the flush.
393 params
= values
.split(";")
394 self
.name
= params
[1]
395 self
.address
= int(params
[2], 16)
396 self
.size
= int(params
[3], 16)
397 self
.offset
= int(params
[4], 16)
401 Internal factory class to be used in dynamic object creation.
403 def create(self
, values
):
405 Factory object creation method.
407 :param values: Pre-formatted string
408 describing the file registration.
410 :return: New Register_file object.
411 :rtype: Register_file
413 return Register_file(values
)