+ 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 create_virtio_feature_mask(**kwargs):
+ """Create virtio feature mask with feature bits set according to kwargs.
+ :param kwargs: Key-value pairs of feature names and it's state
+ :type kwargs: dict
+ """
+ virtio_feature_mask = 0
+
+ if u"all" in kwargs and kwargs[u"all"] is True:
+ for virtio_feature_flag in VirtioFeaturesFlags:
+ virtio_feature_mask |= 1 << virtio_feature_flag.value
+ else:
+ for feature_name, enabled in kwargs.items():
+ virtio_feature_name = \
+ u"VIRTIO_NET_F_API_" + feature_name.upper()
+ if virtio_feature_name not in VirtioFeaturesFlags.__members__:
+ raise ValueError(u"Unsupported virtio feature flag name")
+ if enabled:
+ virtio_feature_mask |= \
+ 1 << VirtioFeaturesFlags[virtio_feature_name].value
+
+ return virtio_feature_mask
+
+ @staticmethod
+ def is_feature_enabled(virtio_feature_mask, virtio_feature_flag):
+ """Checks if concrete virtio feature is enabled within
+ virtio_feature_mask
+ :param virtio_feature_mask: Mask of enabled virtio features
+ :param virtio_feature_flag: Checked virtio feature
+ :type virtio_feature_mask: int
+ :type virtio_feature_flag: VirtioFeaturesFlags
+ """
+ feature_flag_bit = 1 << virtio_feature_flag.value
+ return (virtio_feature_mask & feature_flag_bit) > 0