Skip to content

Commit 7bfc11b

Browse files
pupachaLiliDeng
authored andcommitted
ch_tests_tool: support using pmem for ch block tests
change kernel command line to create a pmem device which can be used for running block perf tests.
1 parent fa3e548 commit 7bfc11b

File tree

2 files changed

+92
-14
lines changed

2 files changed

+92
-14
lines changed

microsoft/testsuites/cloud_hypervisor/ch_tests.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None:
206206
# will not run it with data-disk and it would not add direct=on
207207
# if run_without_cache is not set to YES
208208
use_datadisk = variables.get("use_datadisk", "")
209-
disable_datadisk_cache = variables.get("disable_datadisk_cache", "")
209+
use_pmem = variables.get("ch_tests_use_pmem", "")
210+
pmem_config = variables.get("ch_tests_pmem_config", "")
211+
disable_disk_cache = variables.get("disable_disk_cache", "")
210212
block_size_kb = variables.get("block_size_kb", "")
211213

212214
if not ms_access_token:
@@ -229,10 +231,14 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None:
229231

230232
if block_size_kb:
231233
CloudHypervisorTests.block_size_kb = block_size_kb
234+
if use_pmem:
235+
CloudHypervisorTests.use_pmem = use_pmem
236+
if pmem_config:
237+
CloudHypervisorTests.pmem_config = pmem_config
232238
if use_datadisk:
233239
CloudHypervisorTests.use_datadisk = use_datadisk
234-
if disable_datadisk_cache:
235-
CloudHypervisorTests.disable_datadisk_cache = disable_datadisk_cache
240+
if disable_disk_cache:
241+
CloudHypervisorTests.disable_disk_cache = disable_disk_cache
236242

237243

238244
def get_test_list(variables: Dict[str, Any], var1: str, var2: str) -> Any:

microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from lisa.executable import Tool
1313
from lisa.features import SerialConsole
1414
from lisa.messages import TestStatus, send_sub_test_result_message
15-
from lisa.operating_system import CBLMariner
15+
from lisa.operating_system import CBLMariner, Ubuntu
1616
from lisa.testsuite import TestResult
1717
from lisa.tools import (
18+
Cat,
1819
Chmod,
1920
Chown,
2021
Dmesg,
@@ -25,9 +26,10 @@
2526
Lsblk,
2627
Mkdir,
2728
Modprobe,
29+
Sed,
2830
Whoami,
2931
)
30-
from lisa.util import LisaException, find_groups_in_lines
32+
from lisa.util import LisaException, UnsupportedDistroException, find_groups_in_lines
3133

3234

3335
@dataclass
@@ -63,7 +65,17 @@ class CloudHypervisorTests(Tool):
6365

6466
# Block perf related env var
6567
use_datadisk = ""
66-
disable_datadisk_cache = ""
68+
use_pmem = ""
69+
"""
70+
Following is the last usable entry in e820 table and is safest to use for
71+
pmem since its most likely to be free. 0x0000001000000000 is 64G.
72+
So, set it as default.
73+
74+
[ 0.000000] BIOS-e820: [mem 0x0000001000000000-0x00000040ffffffff] usable
75+
76+
"""
77+
pmem_config = "memmap=8G!64G"
78+
disable_disk_cache = ""
6779
block_size_kb = ""
6880

6981
cmd_path: PurePath
@@ -164,8 +176,16 @@ def run_metrics_tests(
164176
skip: Optional[List[str]] = None,
165177
subtest_timeout: Optional[int] = None,
166178
) -> None:
167-
if self.use_datadisk:
168-
self._set_data_disk()
179+
disk_name = ""
180+
if self.use_pmem:
181+
disk_name = self._get_pmem_for_block_tests()
182+
elif self.use_datadisk:
183+
disk_name = self._get_data_disk_for_block_tests()
184+
185+
if disk_name:
186+
self._log.debug(f"Using disk: {disk_name}, for block tests")
187+
self.env_vars["DATADISK_NAME"] = disk_name
188+
self._save_kernel_logs(log_path)
169189

170190
if ref:
171191
self.node.tools[Git].checkout(ref, self.repo_root)
@@ -265,10 +285,12 @@ def _install(self) -> bool:
265285
if self.use_ms_bz_image:
266286
self.env_vars["USE_MS_BZ_IMAGE"] = self.use_ms_bz_image
267287

268-
if self.use_datadisk:
288+
if self.use_pmem:
289+
self.env_vars["USE_DATADISK"] = self.use_pmem
290+
elif self.use_datadisk:
269291
self.env_vars["USE_DATADISK"] = self.use_datadisk
270-
if self.disable_datadisk_cache:
271-
self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_datadisk_cache
292+
if self.disable_disk_cache:
293+
self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_disk_cache
272294
if self.block_size_kb:
273295
self.env_vars["PERF_BLOCK_SIZE_KB"] = self.block_size_kb
274296
else:
@@ -497,7 +519,58 @@ def _configure_vdpa_devices(self, node: Node) -> None:
497519
node.tools[Chown].change_owner(file=PurePath(device_path), user=user)
498520
node.tools[Chmod].chmod(path=device_path, permission=permission, sudo=True)
499521

500-
def _set_data_disk(self) -> None:
522+
def _get_pmem_for_block_tests(self) -> str:
523+
lsblk = self.node.tools[Lsblk]
524+
sed = self.node.tools[Sed]
525+
cat = self.node.tools[Cat]
526+
527+
os_major_version = int(self.node.os.information.version.major)
528+
if isinstance(self.node.os, CBLMariner) and os_major_version == 2:
529+
grub_file = "/boot/mariner-mshv.cfg"
530+
match_line = "mariner_cmdline_mshv="
531+
regexp = "$"
532+
replacement = f" {self.pmem_config} "
533+
else:
534+
grub_file = "/etc/default/grub"
535+
match_line = "GRUB_CMDLINE_LINUX="
536+
regexp = '"$'
537+
replacement = f' {self.pmem_config} "'
538+
cat.read(file=grub_file, sudo=True, force_run=True)
539+
grub_cmdline = cat.read_with_filter(
540+
file=grub_file,
541+
grep_string=match_line,
542+
sudo=True,
543+
)
544+
if self.pmem_config not in grub_cmdline:
545+
sed.substitute(
546+
file=grub_file,
547+
match_lines=f"^{match_line}",
548+
regexp=regexp,
549+
replacement=replacement,
550+
sudo=True,
551+
)
552+
cat.read(file=grub_file, sudo=True, force_run=True)
553+
554+
if isinstance(self.node.os, CBLMariner):
555+
if os_major_version != 2:
556+
self.node.execute(
557+
"grub2-mkconfig -o /boot/grub2/grub.cfg", sudo=True, shell=True
558+
)
559+
elif isinstance(self.node.os, Ubuntu):
560+
self.node.execute("update-grub", sudo=True, shell=True)
561+
else:
562+
raise UnsupportedDistroException(
563+
self.node.os,
564+
"pmem for CH tests is supported only on Ubuntu and CBLMariner",
565+
)
566+
567+
lsblk.run(force_run=True)
568+
self.node.reboot(time_out=900)
569+
lsblk.run(force_run=True)
570+
571+
return "/dev/pmem0"
572+
573+
def _get_data_disk_for_block_tests(self) -> str:
501574
datadisk_name = ""
502575
lsblk = self.node.tools[Lsblk]
503576
disks = lsblk.get_disks()
@@ -512,8 +585,7 @@ def _set_data_disk(self) -> None:
512585
lsblk.run()
513586
if not datadisk_name:
514587
raise LisaException("No unmounted data disk (/dev/sdX) found")
515-
self._log.debug(f"Using data disk: {datadisk_name}")
516-
self.env_vars["DATADISK_NAME"] = datadisk_name
588+
return datadisk_name
517589

518590

519591
def extract_jsons(input_string: str) -> List[Any]:

0 commit comments

Comments
 (0)