Use rio in promotion policy tests

Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
Jan Musial 2021-08-31 12:21:40 +02:00
parent a6d8bd0470
commit cd0551e72e

View File

@ -6,6 +6,7 @@
from ctypes import c_int from ctypes import c_int
import pytest import pytest
import math import math
from datetime import timedelta
from pyocf.types.cache import Cache, PromotionPolicy, NhitParams from pyocf.types.cache import Cache, PromotionPolicy, NhitParams
from pyocf.types.core import Core from pyocf.types.core import Core
@ -14,6 +15,7 @@ from pyocf.types.data import Data
from pyocf.types.io import IoDir from pyocf.types.io import IoDir
from pyocf.utils import Size from pyocf.utils import Size
from pyocf.types.shared import OcfCompletion from pyocf.types.shared import OcfCompletion
from pyocf.rio import Rio, ReadWrite
@pytest.mark.parametrize("promotion_policy", PromotionPolicy) @pytest.mark.parametrize("promotion_policy", PromotionPolicy)
@ -62,49 +64,35 @@ def test_change_to_nhit_and_back_io_in_flight(pyocf_ctx):
cache.add_core(core) cache.add_core(core)
# Step 2 # Step 2
completions = [] r = (
for i in range(2000): Rio()
comp = OcfCompletion([("error", c_int)]) .target(core)
write_data = Data(4096) .njobs(10)
io = core.new_io( .bs(Size.from_KiB(4))
cache.get_default_queue(), i * 4096, write_data.size, IoDir.WRITE, 0, 0 .readwrite(ReadWrite.RANDWRITE)
) .size(core_device.size)
completions += [comp] .time_based()
io.set_data(write_data) .time(timedelta(minutes=1))
io.callback = comp.callback .qd(10)
io.submit() .run_async()
)
# Step 3 # Step 3
cache.set_promotion_policy(PromotionPolicy.NHIT) cache.set_promotion_policy(PromotionPolicy.NHIT)
# Step 4 # Step 4
for c in completions: r.abort()
c.wait() assert r.error_count == 0, "No IO's should fail when turning NHIT policy on"
assert not c.results["error"], "No IO's should fail when turning NHIT policy on"
# Step 5 # Step 5
completions = [] r.run_async()
for i in range(2000):
comp = OcfCompletion([("error", c_int)])
write_data = Data(4096)
io = core.new_io(
cache.get_default_queue(), i * 4096, write_data.size, IoDir.WRITE, 0, 0
)
completions += [comp]
io.set_data(write_data)
io.callback = comp.callback
io.submit()
# Step 6 # Step 6
cache.set_promotion_policy(PromotionPolicy.ALWAYS) cache.set_promotion_policy(PromotionPolicy.ALWAYS)
# Step 7 # Step 7
for c in completions: r.abort()
c.wait() assert r.error_count == 0, "No IO's should fail when turning NHIT policy off"
assert not c.results[
"error"
], "No IO's should fail when turning NHIT policy off"
def fill_cache(cache, fill_ratio): def fill_cache(cache, fill_ratio):
""" """
@ -116,47 +104,19 @@ def fill_cache(cache, fill_ratio):
cache_lines = cache.get_stats()["conf"]["size"] cache_lines = cache.get_stats()["conf"]["size"]
bytes_to_fill = cache_lines.bytes * fill_ratio bytes_to_fill = Size(round(cache_lines.bytes * fill_ratio))
max_io_size = cache.device.get_max_io_size().bytes
ios_to_issue = math.floor(bytes_to_fill / max_io_size)
core = cache.cores[0] core = cache.cores[0]
completions = []
for i in range(ios_to_issue):
comp = OcfCompletion([("error", c_int)])
write_data = Data(max_io_size)
io = core.new_io(
cache.get_default_queue(),
i * max_io_size,
write_data.size,
IoDir.WRITE,
0,
0,
)
io.set_data(write_data)
io.callback = comp.callback
completions += [comp]
io.submit()
if bytes_to_fill % max_io_size: r = (
comp = OcfCompletion([("error", c_int)]) Rio()
write_data = Data(Size.from_B(bytes_to_fill % max_io_size, sector_aligned=True)) .target(core)
io = core.new_io( .readwrite(ReadWrite.RANDWRITE)
cache.get_default_queue(), .size(bytes_to_fill)
ios_to_issue * max_io_size, .bs(Size(512))
write_data.size, .qd(10)
IoDir.WRITE, .run()
0, )
0,
)
io.set_data(write_data)
io.callback = comp.callback
completions += [comp]
io.submit()
for c in completions:
c.wait()
@pytest.mark.parametrize("fill_percentage", [0, 1, 50, 99]) @pytest.mark.parametrize("fill_percentage", [0, 1, 50, 99])
@ -194,33 +154,27 @@ def test_promoted_after_hits_various_thresholds(
# Step 3 # Step 3
fill_cache(cache, fill_percentage / 100) fill_cache(cache, fill_percentage / 100)
cache.settle()
stats = cache.get_stats() stats = cache.get_stats()
cache_lines = stats["conf"]["size"] cache_lines = stats["conf"]["size"]
assert stats["usage"]["occupancy"]["fraction"] // 10 == fill_percentage * 10 assert stats["usage"]["occupancy"]["fraction"] // 10 == fill_percentage * 10
filled_occupancy = stats["usage"]["occupancy"]["value"] filled_occupancy = stats["usage"]["occupancy"]["value"]
# Step 4 # Step 4
last_core_line = int(core_device.size) - cache_lines.line_size last_core_line = Size(int(core_device.size) - cache_lines.line_size)
completions = [] r = (
Rio()
.readwrite(ReadWrite.WRITE)
.bs(Size(4096))
.offset(last_core_line)
.target(core)
.size(Size(4096) + last_core_line)
)
for i in range(insertion_threshold - 1): for i in range(insertion_threshold - 1):
comp = OcfCompletion([("error", c_int)]) r.run()
write_data = Data(cache_lines.line_size)
io = core.new_io(
cache.get_default_queue(),
last_core_line,
write_data.size,
IoDir.WRITE,
0,
0,
)
completions += [comp]
io.set_data(write_data)
io.callback = comp.callback
io.submit()
for c in completions:
c.wait()
cache.settle()
stats = cache.get_stats() stats = cache.get_stats()
threshold_reached_occupancy = stats["usage"]["occupancy"]["value"] threshold_reached_occupancy = stats["usage"]["occupancy"]["value"]
assert threshold_reached_occupancy == filled_occupancy, ( assert threshold_reached_occupancy == filled_occupancy, (
@ -229,20 +183,13 @@ def test_promoted_after_hits_various_thresholds(
) )
# Step 5 # Step 5
comp = OcfCompletion([("error", c_int)]) r.run()
write_data = Data(cache_lines.line_size)
io = core.new_io(
cache.get_default_queue(), last_core_line, write_data.size, IoDir.WRITE, 0, 0
)
io.set_data(write_data)
io.callback = comp.callback
io.submit()
comp.wait()
cache.settle()
stats = cache.get_stats()
assert ( assert (
threshold_reached_occupancy threshold_reached_occupancy
== cache.get_stats()["usage"]["occupancy"]["value"] - 1 == stats["usage"]["occupancy"]["value"] - 1
), "Previous request should be promoted and occupancy should rise" ), "Previous request should be promoted and occupancy should rise"
@ -268,14 +215,7 @@ def test_partial_hit_promotion(pyocf_ctx):
cache.add_core(core) cache.add_core(core)
# Step 2 # Step 2
comp = OcfCompletion([("error", c_int)]) r = Rio().readwrite(ReadWrite.READ).bs(Size(512)).size(Size(512)).target(core).run()
write_data = Data(Size.from_sector(1))
io = core.new_io(cache.get_default_queue(), 0, write_data.size, IoDir.READ, 0, 0)
io.set_data(write_data)
io.callback = comp.callback
io.submit()
comp.wait()
stats = cache.get_stats() stats = cache.get_stats()
cache_lines = stats["conf"]["size"] cache_lines = stats["conf"]["size"]
@ -291,14 +231,10 @@ def test_partial_hit_promotion(pyocf_ctx):
) )
# Step 4 # Step 4
comp = OcfCompletion([("error", c_int)]) req_size = Size(2 * cache_lines.line_size)
write_data = Data(2 * cache_lines.line_size) r.size(req_size).bs(req_size).readwrite(ReadWrite.WRITE).run()
io = core.new_io(cache.get_default_queue(), 0, write_data.size, IoDir.WRITE, 0, 0)
io.set_data(write_data)
io.callback = comp.callback
io.submit()
comp.wait()
cache.settle()
stats = cache.get_stats() stats = cache.get_stats()
assert ( assert (
stats["usage"]["occupancy"]["value"] == 2 stats["usage"]["occupancy"]["value"] == 2