X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FCpuUtils.py;h=170cbe6b2eb011c72d1d644f628796e3686f9266;hp=70177f5d9ae1beee8321a9be3c56242800f6e9c5;hb=f0e964d35af36f0923c6ae0421e74d94022cadba;hpb=3a2c37ffa4755d89247684935fd27d8868fbfe4b diff --git a/resources/libraries/python/CpuUtils.py b/resources/libraries/python/CpuUtils.py index 70177f5d9a..170cbe6b2e 100644 --- a/resources/libraries/python/CpuUtils.py +++ b/resources/libraries/python/CpuUtils.py @@ -84,6 +84,29 @@ class CpuUtils: [CpuUtils.__str2int(x) for x in line.split(u",")] ) + @staticmethod + def worker_count_from_cores_and_smt(phy_cores, smt_used): + """Simple conversion utility, needs smt from caller. + + The implementation assumes we pack 1 or 2 workers per core, + depending on hyperthreading. + + Some keywords use None to indicate no core/worker limit, + so this converts None to None. + + :param phy_cores: How many physical cores to use for workers. + :param smt_used: Whether symmetric multithreading is used. + :type phy_cores: Optional[int] + :type smt_used: bool + :returns: How many VPP workers fit into the given number of cores. + :rtype: Optional[int] + """ + if phy_cores is None: + return None + workers_per_core = CpuUtils.NR_OF_THREADS if smt_used else 1 + workers = phy_cores * workers_per_core + return workers + @staticmethod def cpu_node_count(node): """Return count of numa nodes.