X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=resources%2Flibraries%2Fpython%2FCpuUtils.py;h=e4fff010f1ac79fa70fdc9de254488b5ad5f85bc;hb=HEAD;hp=5f43e211a233d77da345b8e179be528024cf5901;hpb=9c926fdd75cc1d65faa1ee50ce9133e754fdd498;p=csit.git diff --git a/resources/libraries/python/CpuUtils.py b/resources/libraries/python/CpuUtils.py index 5f43e211a2..518469bd31 100644 --- a/resources/libraries/python/CpuUtils.py +++ b/resources/libraries/python/CpuUtils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Cisco and/or its affiliates. +# Copyright (c) 2024 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: @@ -13,6 +13,8 @@ """CPU utilities library.""" +from random import choice + from robot.libraries.BuiltIn import BuiltIn from resources.libraries.python.Constants import Constants @@ -245,6 +247,9 @@ class CpuUtils: """Return list of DUT node related list of CPU numbers. The main computing unit is physical core count. + On SMT enabled DUTs, both sibling logical cores are used, + unless Robot variable \${smt_used} is set to False. + :param node: DUT node. :param cpu_node: Numa node number. :param nf_chains: Number of NF chains. @@ -276,6 +281,7 @@ class CpuUtils: raise RuntimeError(u"NodeID is out of range!") smt_used = CpuUtils.is_smt_enabled(node[u"cpuinfo"]) + smt_used = BuiltIn().get_variable_value("\${smt_used}", smt_used) cpu_list = CpuUtils.cpu_list_per_node(node, cpu_node, smt_used) # CPU thread sibling offset. sib = len(cpu_list) // CpuUtils.NR_OF_THREADS @@ -388,7 +394,7 @@ class CpuUtils: @staticmethod def get_affinity_trex( - node, if_key, tg_mtc=1, tg_dtc=1, tg_ltc=1): + node, if_key, tg_mtc=1, tg_dtc=1, tg_ltc=1, tg_dtc_offset=0): """Get affinity for T-Rex. Result will be used to pin T-Rex threads. :param node: TG node. @@ -396,11 +402,13 @@ class CpuUtils: :param tg_mtc: TG main thread count. :param tg_dtc: TG dataplane thread count. :param tg_ltc: TG latency thread count. + :param tg_dtc_offset: TG dataplane thread offset. :type node: dict :type if_key: str :type tg_mtc: int :type tg_dtc: int :type tg_ltc: int + :type tg_dtc_offset: int :returns: List of CPUs allocated to T-Rex including numa node. :rtype: int, int, int, list """ @@ -412,12 +420,11 @@ class CpuUtils: smt_used=False) threads = CpuUtils.cpu_slice_of_list_per_node( - node, cpu_node, skip_cnt=tg_mtc, cpu_cnt=tg_dtc, - smt_used=False) + node, cpu_node, skip_cnt=tg_mtc + tg_ltc + tg_dtc_offset, + cpu_cnt=tg_dtc, smt_used=False) latency_thread_id = CpuUtils.cpu_slice_of_list_per_node( - node, cpu_node, skip_cnt=tg_mtc + tg_dtc, cpu_cnt=tg_ltc, - smt_used=False) + node, cpu_node, skip_cnt=tg_mtc, cpu_cnt=tg_ltc, smt_used=False) return master_thread_id[0], latency_thread_id[0], cpu_node, threads @@ -521,15 +528,15 @@ class CpuUtils: continue # Number of Data Plane physical cores. dp_cores_count = BuiltIn().get_variable_value( - f"${{dp_cores_count}}", phy_cores + "${dp_cores_count}", phy_cores ) # Number of Feature Plane physical cores. fp_cores_count = BuiltIn().get_variable_value( - f"${{fp_cores_count}}", phy_cores - dp_cores_count + "${fp_cores_count}", phy_cores - dp_cores_count ) # Ratio between RX queues and data plane threads. rxq_ratio = BuiltIn().get_variable_value( - f"${{rxq_ratio}}", 1 + "${rxq_ratio}", 1 ) dut_pf_keys = BuiltIn().get_variable_value( @@ -537,7 +544,7 @@ class CpuUtils: ) # SMT override in case of non standard test cases. smt_used = BuiltIn().get_variable_value( - f"${{smt_used}}", CpuUtils.is_smt_enabled(node["cpuinfo"]) + "${smt_used}", CpuUtils.is_smt_enabled(node["cpuinfo"]) ) cpu_node = Topology.get_interfaces_numa_node(node, *dut_pf_keys) @@ -545,9 +552,10 @@ class CpuUtils: cpu_main = CpuUtils.cpu_list_per_node_str( node, cpu_node, skip_cnt=skip_cnt, - cpu_cnt=Constants.CPU_CNT_MAIN, + cpu_cnt=Constants.CPU_CNT_MAIN if phy_cores else 0, smt_used=False ) + cpu_main = cpu_main if phy_cores else choice(cpu_main.split(",")) skip_cnt += Constants.CPU_CNT_MAIN cpu_dp = CpuUtils.cpu_list_per_node_str( node, cpu_node,