pyocf: add sector size logic to Size class
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
parent
641fba1708
commit
31ab2b3fe6
@ -21,7 +21,7 @@ from enum import IntEnum
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
from ..utils import print_buffer
|
from ..utils import print_buffer, Size as S
|
||||||
|
|
||||||
|
|
||||||
class DataSeek(IntEnum):
|
class DataSeek(IntEnum):
|
||||||
|
@ -56,8 +56,12 @@ class Size:
|
|||||||
_MiB = _KiB * 1024
|
_MiB = _KiB * 1024
|
||||||
_GiB = _MiB * 1024
|
_GiB = _MiB * 1024
|
||||||
_TiB = _GiB * 1024
|
_TiB = _GiB * 1024
|
||||||
|
_SECTOR_SIZE = 512
|
||||||
|
|
||||||
def __init__(self, b: int):
|
def __init__(self, b: int, sector_aligned: bool = False):
|
||||||
|
if sector_aligned:
|
||||||
|
self.bytes = ((b + self._SECTOR_SIZE - 1) // self._SECTOR_SIZE) * self._SECTOR_SIZE
|
||||||
|
else:
|
||||||
self.bytes = b
|
self.bytes = b
|
||||||
|
|
||||||
def __int__(self):
|
def __int__(self):
|
||||||
@ -67,24 +71,28 @@ class Size:
|
|||||||
return self.bytes
|
return self.bytes
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_B(cls, value):
|
def from_B(cls, value, sector_aligned = False):
|
||||||
return cls(value)
|
return cls(value, sector_aligned)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_KiB(cls, value):
|
def from_KiB(cls, value, sector_aligned = False):
|
||||||
return cls(value * cls._KiB)
|
return cls(value * cls._KiB, sector_aligned)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_MiB(cls, value):
|
def from_MiB(cls, value, sector_aligned = False):
|
||||||
return cls(value * cls._MiB)
|
return cls(value * cls._MiB, sector_aligned)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_GiB(cls, value):
|
def from_GiB(cls, value, sector_aligned = False):
|
||||||
return cls(value * cls._GiB)
|
return cls(value * cls._GiB, sector_aligned)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_TiB(cls, value):
|
def from_TiB(cls, value, sector_aligned = False):
|
||||||
return cls(value * cls._TiB)
|
return cls(value * cls._TiB, sector_aligned)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_sector(cls, value):
|
||||||
|
return cls(value * cls._SECTOR_SIZE)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def B(self):
|
def B(self):
|
||||||
@ -106,6 +114,10 @@ class Size:
|
|||||||
def TiB(self):
|
def TiB(self):
|
||||||
return self.bytes / self._TiB
|
return self.bytes / self._TiB
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sectors(self):
|
||||||
|
return self.bytes // _SECTOR_SIZE
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.bytes < self._KiB:
|
if self.bytes < self._KiB:
|
||||||
return "{} B".format(self.B)
|
return "{} B".format(self.B)
|
||||||
|
@ -93,7 +93,7 @@ def test_wo_read_data_consistency(pyocf_ctx):
|
|||||||
# possible end sectors for test iteration
|
# possible end sectors for test iteration
|
||||||
end_sec = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 23]
|
end_sec = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 23]
|
||||||
|
|
||||||
SECTOR_SIZE = 512
|
SECTOR_SIZE = Size.from_sector(1).B
|
||||||
CACHELINE_SIZE = 4096
|
CACHELINE_SIZE = 4096
|
||||||
WORKSET_SIZE = 3 * CACHELINE_SIZE
|
WORKSET_SIZE = 3 * CACHELINE_SIZE
|
||||||
WORKSET_OFFSET = 1024 * CACHELINE_SIZE
|
WORKSET_OFFSET = 1024 * CACHELINE_SIZE
|
||||||
|
Loading…
Reference in New Issue
Block a user