The implementation of non-Posix compliant parts of Linux remote sessions.
| 45 | |
| 46 | |
| 47 | class LinuxSession(PosixSession): |
| 48 | """ |
| 49 | The implementation of non-Posix compliant parts of Linux remote sessions. |
| 50 | """ |
| 51 | |
| 52 | @staticmethod |
| 53 | def _get_privileged_command(command: str) -> str: |
| 54 | return f"sudo -- sh -c '{command}'" |
| 55 | |
| 56 | def get_remote_cpus(self, use_first_core: bool) -> list[LogicalCore]: |
| 57 | cpu_info = self.send_command("lscpu -p=CPU,CORE,SOCKET,NODE|grep -v \\#").stdout |
| 58 | lcores = [] |
| 59 | for cpu_line in cpu_info.splitlines(): |
| 60 | lcore, core, socket, node = map(int, cpu_line.split(",")) |
| 61 | if core == 0 and socket == 0 and not use_first_core: |
| 62 | self._logger.info("Not using the first physical core.") |
| 63 | continue |
| 64 | lcores.append(LogicalCore(lcore, core, socket, node)) |
| 65 | return lcores |
| 66 | |
| 67 | def get_dpdk_file_prefix(self, dpdk_prefix) -> str: |
| 68 | return dpdk_prefix |
| 69 | |
| 70 | def setup_hugepages(self, hugepage_amount: int, force_first_numa: bool) -> None: |
| 71 | self._logger.info("Getting Hugepage information.") |
| 72 | hugepage_size = self._get_hugepage_size() |
| 73 | hugepages_total = self._get_hugepages_total() |
| 74 | self._numa_nodes = self._get_numa_nodes() |
| 75 | |
| 76 | if force_first_numa or hugepages_total != hugepage_amount: |
| 77 | # when forcing numa, we need to clear existing hugepages regardless |
| 78 | # of size, so they can be moved to the first numa node |
| 79 | self._configure_huge_pages(hugepage_amount, hugepage_size, force_first_numa) |
| 80 | else: |
| 81 | self._logger.info("Hugepages already configured.") |
| 82 | self._mount_huge_pages() |
| 83 | |
| 84 | def _get_hugepage_size(self) -> int: |
| 85 | hugepage_size = self.send_command("awk '/Hugepagesize/ {print $2}' /proc/meminfo").stdout |
| 86 | return int(hugepage_size) |
| 87 | |
| 88 | def _get_hugepages_total(self) -> int: |
| 89 | hugepages_total = self.send_command( |
| 90 | "awk '/HugePages_Total/ { print $2 }' /proc/meminfo" |
| 91 | ).stdout |
| 92 | return int(hugepages_total) |
| 93 | |
| 94 | def _get_numa_nodes(self) -> list[int]: |
| 95 | try: |
| 96 | numa_count = self.send_command( |
| 97 | "cat /sys/devices/system/node/online", verify=True |
| 98 | ).stdout |
| 99 | numa_range = expand_range(numa_count) |
| 100 | except RemoteCommandExecutionError: |
| 101 | # the file doesn't exist, meaning the node doesn't support numa |
| 102 | numa_range = [] |
| 103 | return numa_range |
| 104 |