]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/tools/pmreorder/memoryoperations.py
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / tools / pmreorder / memoryoperations.py
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2018, Intel Corporation
3
4 from utils import Rangeable
5 from utils import range_cmp
6 from utils import StackTrace
7 from sys import byteorder
8
9
10 class BaseOperation:
11 """
12 Base class for all memory operations.
13 """
14 pass
15
16
17 class Fence(BaseOperation):
18 """
19 Describes a fence operation.
20
21 The exact type of the memory barrier is not important,
22 it is interpreted as an SFENCE or MFENCE.
23 """
24 class Factory:
25 """
26 Internal factory class to be used in dynamic object creation.
27 """
28 def create(self, values):
29 """
30 Factory object creation method.
31
32 :param values: Ignored.
33 :type values: str
34 :return: New Fence object.
35 :rtype: Fence
36 """
37 return Fence()
38
39
40 class Store(BaseOperation, Rangeable):
41 """
42 Describes a store operation.
43
44 :ivar address: The virtual address at which to store the new value.
45 :type address: int
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.
49 :type size: int
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.
53 :type flushed: bool
54 """
55 def __init__(self, values):
56 """
57 Initializes the object based on the describing string.
58
59 :param values: Pre-formatted string describing the store.
60 :type values: str
61 :return: None
62 """
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)
67 self.new_value = \
68 int(params[2], 16).to_bytes(self.size, byteorder=byteorder)
69 if len(params) > 4:
70 self.trace = StackTrace(params[4:])
71 else:
72 self.trace = StackTrace(["No trace available", ])
73 self.old_value = None
74 self.flushed = False
75
76 def __str__(self):
77 return "addr: " + hex(self.address) + " size " + \
78 str(self.size) + " value " + str(self.new_value)
79
80 def get_base_address(self):
81 """
82 Override from :class:`utils.Rangeable`.
83
84 :return: Virtual address of the store.
85 :rtype: int
86 """
87 return self.address
88
89 def get_max_address(self):
90 """
91 Override from :class:`utils.Rangeable`.
92
93 :return: Virtual address of the first byte after the store.
94 :rtype: int
95 """
96 return self.address + self.size
97
98 class Factory():
99 """
100 Internal factory class to be used in dynamic object creation.
101 """
102 def create(self, values):
103 """
104 Factory object creation method.
105
106 :param values: Pre-formatted string describing the store.
107 :type values: str
108 :return: New Store object.
109 :rtype: Store
110 """
111 return Store(values)
112
113
114 class FlushBase(BaseOperation, Rangeable):
115 """
116 Base class for flush operations.
117 """
118 def is_in_flush(self, store_op):
119 """
120 Check if a given store is within the flush.
121
122 :param store_op: Store operation to check.
123 :return: True if store is in flush, false otherwise.
124 :rtype: bool
125 """
126 raise NotImplementedError
127
128
129 class Flush(FlushBase):
130 """
131 Describes a flush operation.
132
133 Examples of flush instructions are CLFLUSH, CLFLUSHOPT or CLWB.
134
135 :ivar _address: Virtual address of the flush.
136 :type _address: int
137 :ivar _size: The size of the flush in bytes (should be cache line aligned).
138 :type _size: int
139 """
140 def __init__(self, values):
141 """
142 Initializes the object based on the describing string.
143
144 :param values: Pre-formatted string describing the flush.
145 :type values: str
146 :return: None
147 """
148 params = values.split(";")
149 self._address = int(params[1], 16)
150 self._size = int(params[2], 16)
151
152 def is_in_flush(self, store_op):
153 """
154 Override from :class:`FlushBase`.
155
156 :param store_op: Store operation to check.
157 :return: True if store is in flush, false otherwise.
158 :rtype: bool
159 """
160 if range_cmp(store_op, self) == 0:
161 return True
162 else:
163 return False
164
165 def get_base_address(self):
166 """
167 Override from :class:`utils.Rangeable`.
168
169 :return: Virtual address of the flush.
170 :rtype: int
171 """
172 return self._address
173
174 def get_max_address(self):
175 """
176 Override from :class:`utils.Rangeable`.
177
178 :return: Virtual address of the first byte after the flush.
179 :rtype: int
180 """
181 return self._address + self._size
182
183 class Factory:
184 """
185 Internal factory class to be used in dynamic object creation.
186 """
187 def create(self, values):
188 """
189 Factory object creation method.
190
191 :param values: Pre-formatted string describing the flush.
192 :type values: str
193 :return: New Flush object.
194 :rtype: Flush
195 """
196 return Flush(values)
197
198
199 class ReorderBase(BaseOperation):
200 """
201 Base class for all reorder type classes.
202 """
203 pass
204
205
206 class NoReorderDoCheck(ReorderBase):
207 """
208 Describes the type of reordering engine to be used.
209
210 This marker class triggers writing the whole sequence of stores
211 between barriers.
212 """
213 class Factory:
214 """
215 Internal factory class to be used in dynamic object creation.
216 """
217 def create(self, values):
218 """
219 Factory object creation method.
220
221 :param values: Ignored.
222 :type values: str
223 :return: New NoReorderDoCheck object.
224 :rtype: NoReorderDoCheck
225 """
226 return NoReorderDoCheck()
227
228
229 class ReorderFull(ReorderBase):
230 """
231 Describes the type of reordering engine to be used.
232
233 This marker class triggers writing all possible sequences of stores
234 between barriers.
235 """
236 class Factory:
237 """
238 Internal factory class to be used in dynamic object creation.
239 """
240 def create(self, values):
241 """
242 Factory object creation method.
243
244 :param values: Ignored.
245 :type values: str
246 :return: New ReorderFull object.
247 :rtype: ReorderFull
248 """
249 return ReorderFull()
250
251
252 class ReorderAccumulative(ReorderBase):
253 """
254 Describes the type of reordering engine to be used.
255
256 This marker class triggers writing all
257 possible accumulative sequences of stores
258 between barriers.
259 """
260 class Factory:
261 """
262 Internal factory class to be used in dynamic object creation.
263 """
264 def create(self, values):
265 """
266 Factory object creation method.
267
268 :param values: Ignored.
269 :type values: str
270 :return: New ReorderAccumulative object.
271 :rtype: ReorderAccumulative
272 """
273 return ReorderAccumulative()
274
275
276 class ReorderReverseAccumulative(ReorderBase):
277 """
278 Describes the type of reordering engine to be used.
279
280 This marker class triggers writing all
281 possible reverted accumulative sequences of stores
282 between barriers.
283 """
284 class Factory:
285 """
286 Internal factory class to be used in dynamic object creation.
287 """
288 def create(self, values):
289 """
290 Factory object creation method.
291
292 :param values: Ignored.
293 :type values: str
294 :return: New ReorderReverseAccumulative object.
295 :rtype: ReorderReverseAccumulative
296 """
297 return ReorderReverseAccumulative()
298
299
300 class NoReorderNoCheck(ReorderBase):
301 """
302 Describes the type of reordering engine to be used.
303
304 This marker class triggers writing the whole sequence of stores
305 between barriers. It additionally marks that no consistency checking
306 is to be made.
307 """
308 class Factory:
309 """
310 Internal factory class to be used in dynamic object creation.
311 """
312 def create(self, values):
313 """
314 Factory object creation method.
315
316 :param values: Ignored.
317 :type values: str
318 :return: New NoReorderNoCheck object.
319 :rtype: NoReorderNoCheck
320 """
321 return NoReorderNoCheck()
322
323
324 class ReorderDefault(ReorderBase):
325 """
326 Describes the default reordering engine to be used.
327
328 This marker class triggers default reordering.
329 """
330 class Factory:
331 """
332 Internal factory class to be used in dynamic object creation.
333 """
334 def create(self, values):
335 """
336 Factory object creation method.
337
338 :param values: Ignored.
339 :type values: str
340 :return: ReorderDefault object.
341 :rtype: ReorderDefault
342 """
343 return ReorderDefault()
344
345
346 class ReorderPartial(ReorderBase):
347 """
348 Describes the type of reordering engine to be used.
349
350 This marker class triggers writing a subset of all possible
351 sequences of stores between barriers.
352
353 The type of partial reordering is chosen at runtime. Not yet
354 implemented.
355 """
356 class Factory:
357 """
358 Internal factory class to be used in dynamic object creation.
359 """
360 def create(self, values):
361 """
362 Factory object creation method.
363
364 :param values: Ignored.
365 :type values: str
366 :return: New ReorderPartial object.
367 :rtype: ReorderPartial
368 """
369 return ReorderPartial()
370
371
372 class Register_file(BaseOperation):
373 """
374 Describes the file to be mapped into processes address space.
375
376 :ivar name: The full name of the file.
377 :type name: str
378 :ivar address: The base address where the file was mapped.
379 :type address: int
380 :ivar size: The size of the mapping.
381 :type size: int
382 :ivar offset: The start offset of the mapping within the file.
383 :type offset: int
384 """
385 def __init__(self, values):
386 """
387 Initializes the object based on the describing string.
388
389 :param values: Pre-formatted string describing the flush.
390 :type values: str
391 :return: None
392 """
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)
398
399 class Factory():
400 """
401 Internal factory class to be used in dynamic object creation.
402 """
403 def create(self, values):
404 """
405 Factory object creation method.
406
407 :param values: Pre-formatted string
408 describing the file registration.
409 :type values: str
410 :return: New Register_file object.
411 :rtype: Register_file
412 """
413 return Register_file(values)