Skip to content

Commit

Permalink
Tool to check supported hugepagesize
Browse files Browse the repository at this point in the history
  • Loading branch information
kanchansenlaskar committed Jun 10, 2024
1 parent 6efdb9b commit c09990a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lisa/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from .lsvmbus import Lsvmbus
from .make import Make
from .mdadm import Mdadm
from .hugepages import Hugepages
from .mkdir import Mkdir
from .mkfs import FileSystem, Mkfs, Mkfsext, Mkfsxfs
from .modinfo import Modinfo
Expand Down Expand Up @@ -158,6 +159,7 @@
"Iperf3",
"HibernationSetup",
"Hostname",
"Hugepages",
"Hwclock",
"HyperV",
"InterruptInspector",
Expand Down
32 changes: 32 additions & 0 deletions lisa/tools/hugepages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import re
from typing import Any, Set

from lisa.executable import Tool
from lisa.util import LisaException

PATTERN_HUGEPAGE = re.compile(
r"^hugepages-(?P<hugepage_size_in_kb>\d+)kB",
)

class Hugepages(Tool):
@property
def command(self) -> str:
return "ls /sys/devices/system/node/node*/hugepages"

@property
def can_install(self) -> bool:

This comment has been minimized.

Copy link
@mcgov

mcgov Jun 10, 2024

Collaborator

I would comment the tool a little more thoroughly. Explaining the limitations: since we rely on sysfs this only supports Linux and not BSD, not Windows.

I'm a little iffy on relying on sysfs to check the available hugepage sizes, maybe we could link to the Linux docs on hugepages or some Linux source 🤔

return False

def _initialize(self, *args: Any, **kwargs: Any) -> None:
self._command = "ls /sys/devices/system/node/node*/hugepages"
self._hugepage_sizes = set()

def get_hugepage_sizes_in_kB(self):
hugepage_size_dir_names = self.run("", shell=True)
# e.g. hugepages-16777216kB hugepages-2048kB hugepages-524288kB
for hugepage_size_dir_name in hugepage_size_dir_names.stdout.split():
matched_hugepage = PATTERN_HUGEPAGE.match(hugepage_size_dir_name)
self._hugepage_sizes.add(matched_hugepage.group("hugepage_size_in_kb"))
return self._hugepage_sizes
7 changes: 7 additions & 0 deletions microsoft/testsuites/dpdk/dpdkutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Lscpu,
Lsmod,
Lspci,
Hugepages,
Modprobe,
Mount,
Ntttcp,
Expand Down Expand Up @@ -99,6 +100,12 @@ def __init__(self, _node: Node, _testpmd: DpdkTestpmd) -> None:
def init_hugepages(node: Node, enable_gibibyte_hugepages: bool = False) -> None:
mount = node.tools[Mount]
if enable_gibibyte_hugepages:
hugepages = node.tools[Hugepages]
hugepage_sizes_in_kB = hugepages.get_hugepage_sizes_in_kB()
if "1048576" not in hugepage_sizes_in_kB:

This comment has been minimized.

Copy link
@squirrelsc

squirrelsc Jun 10, 2024

Member

It's hard to understand why check a magic number. Is it too large or too small? Do you have any reference?

raise SkippedException(
f"Supported hugepage sizes in kB: {hugepage_sizes_in_kB}. 1048576 kB is not available"
)
mount.mount(
name="nodev",
point="/mnt/huge-1G",
Expand Down

1 comment on commit c09990a

@mcgov
Copy link
Collaborator

@mcgov mcgov commented on c09990a Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the init procedure for hugepages into the tool too, we want to abstract both checks and usage into the tool so people don't need to deal with sysfs paths or mount commands. The advantage is we're giving them an API so we can improve or change the underlying implementation later, if needed.

Please sign in to comment.