-# 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:
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):
:returns: SW interface index.
:rtype: int
"""
- cmd = u"create_vhost_user_if"
+ cmd = u"create_vhost_user_if_v2"
err_msg = f"Failed to create Vhost-user interface " \
f"on host {node[u'host']}"
if virtio_feature_mask is None:
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"""
@staticmethod
def is_feature_enabled(virtio_feature_mask, virtio_feature_flag):
"""Checks if concrete virtio feature is enabled within
- virtio_feature_mask
+ virtio_feature_mask
:param virtio_feature_mask: Mask of enabled virtio features
:param virtio_feature_flag: Checked virtio feature
:type virtio_feature_mask: int