Skip to content

Commit

Permalink
move sysctl setting to tool
Browse files Browse the repository at this point in the history
  • Loading branch information
LiliDeng authored and squirrelsc committed Feb 7, 2022
1 parent 6ef5292 commit 2d9a63c
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 146 deletions.
87 changes: 58 additions & 29 deletions lisa/tools/lagscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
)
from lisa.util.process import ExecutableResult, Process

from .firewall import Firewall
from .git import Git
from .sysctl import Sysctl

if TYPE_CHECKING:
from lisa.environment import Environment
Expand Down Expand Up @@ -91,6 +93,7 @@ class Lagscope(Tool):
_average_pattern = re.compile(
r"([\w\W]*?)Average = (?P<average_latency_us>.+?)us", re.M
)
_busy_pool_keys = ["net.core.busy_poll", "net.core.busy_read"]

@property
def dependencies(self) -> List[Type[Tool]]:
Expand All @@ -104,35 +107,21 @@ def command(self) -> str:
def can_install(self) -> bool:
return True

def _install(self) -> bool:
self._install_dep_packages()
tool_path = self.get_tool_path()
git = self.node.tools[Git]
git.clone(self.repo, tool_path, ref=self.branch)
code_path = tool_path.joinpath("lagscope")
self.node.execute(
"./do-cmake.sh build",
cwd=code_path,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to run do-cmake.sh build",
)
self.node.execute(
"./do-cmake.sh install",
cwd=code_path,
sudo=True,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to run do-cmake.sh install",
)
self.node.execute(
"ln -sf /usr/local/bin/lagscope /usr/bin/lagscope",
sudo=True,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to create symlink to lagscope",
)
return self._check_exists()
def set_busy_poll(self) -> None:
# Busy polling helps reduce latency in the network receive path by
# allowing socket layer code to poll the receive queue of a network
# device, and disabling network interrupts. This removes delays caused
# by the interrupt and the resultant context switch. However, it also
# increases CPU utilization. Busy polling also prevents the CPU from
# sleeping, which can incur additional power consumption.
sysctl = self.node.tools[Sysctl]
for key in self._busy_pool_keys:
sysctl.write(key, "50")

def restore_busy_poll(self) -> None:
sysctl = self.node.tools[Sysctl]
for key in self._busy_pool_keys:
sysctl.write(key, self._original_settings[key])

def run_as_server(self, ip: str = "", daemon: bool = True) -> None:
# -r: run as a receiver
Expand Down Expand Up @@ -281,6 +270,46 @@ def create_latency_peformance_messages(
perf_message_list.append(message)
return perf_message_list

def _initialize(self, *args: Any, **kwargs: Any) -> None:
firewall = self.node.tools[Firewall]
firewall.stop()

# save the original value for recovering
self._original_settings: Dict[str, str] = {}
sysctl = self.node.tools[Sysctl]
for key in self._busy_pool_keys:
self._original_settings[key] = sysctl.get(key)

def _install(self) -> bool:
self._install_dep_packages()
tool_path = self.get_tool_path()
git = self.node.tools[Git]
git.clone(self.repo, tool_path, ref=self.branch)
code_path = tool_path.joinpath("lagscope")
self.node.execute(
"./do-cmake.sh build",
cwd=code_path,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to run do-cmake.sh build",
)
self.node.execute(
"./do-cmake.sh install",
cwd=code_path,
sudo=True,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to run do-cmake.sh install",
)
self.node.execute(
"ln -sf /usr/local/bin/lagscope /usr/bin/lagscope",
sudo=True,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to create symlink to lagscope",
)
return self._check_exists()

def _install_dep_packages(self) -> None:
posix_os: Posix = cast(Posix, self.node.os)
if isinstance(self.node.os, Redhat):
Expand Down
95 changes: 83 additions & 12 deletions lisa/tools/ntttcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
TransportProtocol,
create_message,
)
from lisa.tools import Gcc, Git, Make
from lisa.tools import Firewall, Gcc, Git, Make, Sed
from lisa.util import constants
from lisa.util.process import ExecutableResult, Process

from .sysctl import Sysctl

if TYPE_CHECKING:
from lisa.environment import Environment

Expand Down Expand Up @@ -111,6 +113,17 @@ class Ntttcp(Tool):
r"([\w\W]*?)cycles/byte.*:(?P<cycles_per_byte>.+)",
re.MULTILINE,
)
sys_list_tcp = [
{"kernel.pid_max": "122880"},
{"vm.max_map_count": "655300"},
{"net.ipv4.ip_local_port_range": "1024 65535"},
]
sys_list_udp = [
{"net.core.rmem_max": "67108864"},
{"net.core.rmem_default": "67108864"},
{"net.core.wmem_default": "67108864"},
{"net.core.wmem_max": "67108864"},
]

@property
def dependencies(self) -> List[Type[Tool]]:
Expand All @@ -124,17 +137,48 @@ def command(self) -> str:
def can_install(self) -> bool:
return True

def _install(self) -> bool:
tool_path = self.get_tool_path()
git = self.node.tools[Git]
git.clone(self.repo, tool_path)
make = self.node.tools[Make]
code_path = tool_path.joinpath("ntttcp-for-linux/src")
make.make_install(cwd=code_path)
self.node.execute(
"ln -s /usr/local/bin/ntttcp /usr/bin/ntttcp", sudo=True, cwd=code_path
).assert_exit_code()
return self._check_exists()
def set_sys_variables(self, udp_mode: bool = False) -> None:
sysctl = self.node.tools[Sysctl]
sys_list = self.sys_list_tcp
if udp_mode:
sys_list = self.sys_list_udp
for sys in sys_list:
for variable, value in sys.items():
sysctl.write(variable, value)

def restore_sys_variables(self, udp_mode: bool = False) -> None:
original_settings = self._original_settings_tcp
if udp_mode:
original_settings = self._original_settings_udp
sysctl = self.node.tools[Sysctl]
for variable_list in original_settings:
# restore back to the original value after testing
for variable, value in variable_list.items():
sysctl.write(variable, value)

def set_tasks_max(self) -> None:
if self.node.shell.exists(
self.node.get_pure_path(
"/usr/lib/systemd/system/user-.slice.d/10-defaults.conf"
)
):
self.node.tools[Sed].substitute(
regexp="TasksMax.*",
replacement="TasksMax=122880",
file="/usr/lib/systemd/system/user-.slice.d/10-defaults.conf",
sudo=True,
)
elif self.node.shell.exists(
self.node.get_pure_path("/etc/systemd/logind.conf")
):
self.node.tools[Sed].append(
"UserTasksMax=122880", "/etc/systemd/logind.conf", sudo=True
)
else:
self._log.debug(
"no config file exist for systemd, either there is no systemd"
" service or the config file location is incorrect."
)

def help(self) -> ExecutableResult:
return self.run("-h")
Expand Down Expand Up @@ -377,3 +421,30 @@ def create_ntttcp_udp_performance_message(
test_case_name,
other_fields,
)

def _initialize(self, *args: Any, **kwargs: Any) -> None:
firewall = self.node.tools[Firewall]
firewall.stop()

# save the original value for recovering
self._original_settings_tcp: List[Dict[str, str]] = []
self._original_settings_udp: List[Dict[str, str]] = []
sysctl = self.node.tools[Sysctl]
for tcp_sys in self.sys_list_tcp:
for variable, _ in tcp_sys.items():
self._original_settings_tcp.append({variable: sysctl.get(variable)})
for udp_sys in self.sys_list_udp:
for variable, _ in udp_sys.items():
self._original_settings_udp.append({variable: sysctl.get(variable)})

def _install(self) -> bool:
tool_path = self.get_tool_path()
git = self.node.tools[Git]
git.clone(self.repo, tool_path)
make = self.node.tools[Make]
code_path = tool_path.joinpath("ntttcp-for-linux/src")
make.make_install(cwd=code_path)
self.node.execute(
"ln -s /usr/local/bin/ntttcp /usr/bin/ntttcp", sudo=True, cwd=code_path
).assert_exit_code()
return self._check_exists()
39 changes: 3 additions & 36 deletions microsoft/testsuites/performance/common.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import pathlib
import inspect
import pathlib
from typing import Any, Dict, List, Optional

from lisa import Logger, Node, notifier
from lisa import Node, notifier
from lisa.environment import Environment
from lisa.messages import DiskPerformanceMessage, DiskSetupType, DiskType
from lisa.schema import NetworkDataPath
from lisa.tools import FIOMODES, Fdisk, Fio, FIOResult, Kill, Mdadm, Sed, Sysctl
from lisa.tools import FIOMODES, Fdisk, Fio, FIOResult, Kill, Mdadm


def run_perf_test(
Expand Down Expand Up @@ -74,39 +74,6 @@ def run_perf_test(
notifier.notify(fio_message)


def restore_sysctl_setting(
nodes: List[Node], perf_tuning: Dict[str, List[Dict[str, str]]]
) -> None:
for node in nodes:
sysctl = node.tools[Sysctl]
for variable_list in perf_tuning[node.name]:
# restore back to the original value after testing
for variable, value in variable_list.items():
sysctl.write(variable, value)


def set_systemd_tasks_max(nodes: List[Node], log: Logger) -> None:
for node in nodes:
if node.shell.exists(
node.get_pure_path("/usr/lib/systemd/system/user-.slice.d/10-defaults.conf")
):
node.tools[Sed].substitute(
regexp="TasksMax.*",
replacement="TasksMax=122880",
file="/usr/lib/systemd/system/user-.slice.d/10-defaults.conf",
sudo=True,
)
elif node.shell.exists(node.get_pure_path("/etc/systemd/logind.conf")):
node.tools[Sed].append(
"UserTasksMax=122880", "/etc/systemd/logind.conf", sudo=True
)
else:
log.debug(
"no config file exist for systemd, either there is no systemd"
" service or the config file location is incorrect."
)


def get_nic_datapath(node: Node) -> str:
data_path: str = ""
assert (
Expand Down
Loading

0 comments on commit 2d9a63c

Please sign in to comment.