X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FVhostUser.py;h=c6b9185e14d3a9cd70cf8f1c34db446b0d870b43;hp=22528b2b7f31bff0ba055fc08612334c23b168e4;hb=44dcb3113c8ade2e44543746abca861a89362c9b;hpb=e813695b481b745d5136f8cbd0152e62a4ec990c diff --git a/resources/libraries/python/VhostUser.py b/resources/libraries/python/VhostUser.py index 22528b2b7f..c6b9185e14 100644 --- a/resources/libraries/python/VhostUser.py +++ b/resources/libraries/python/VhostUser.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Cisco and/or its affiliates. +# Copyright (c) 2021 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -17,9 +17,11 @@ from enum import IntEnum from robot.api import logger +from resources.libraries.python.CpuUtils import CpuUtils from resources.libraries.python.PapiExecutor import PapiSocketExecutor from resources.libraries.python.topology import NodeType, Topology from resources.libraries.python.InterfaceUtil import InterfaceUtil +from resources.libraries.python.ssh import exec_cmd_no_error class VirtioFeaturesFlags(IntEnum): @@ -151,6 +153,26 @@ class VhostUser: logger.debug(f"Vhost-user details:\n{details}") return details + @staticmethod + def vhost_user_affinity(node, pf_key, skip_cnt=0): + """Set vhost-user affinity for the given node. + + :param node: Topology node. + :param pf_key: Interface key to compute numa location. + :param skip_cnt: Skip first "skip_cnt" CPUs. + :type node: dict + :type pf_key: str + :type skip_cnt: int + """ + pids, _ = exec_cmd_no_error( + node, f"grep -h vhost /proc/*/comm | uniq | xargs pidof") + + affinity = CpuUtils.get_affinity_vhost( + node, pf_key, skip_cnt=skip_cnt, cpu_cnt=len(pids.split(" "))) + + for cpu, pid in zip(affinity, pids.split(" ")): + exec_cmd_no_error(node, f"taskset -pc {cpu} {pid}", sudo=True) + class VirtioFeatureMask: """Virtio features utilities"""