From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id AC7DF2BEB for ; Mon, 25 Jun 2018 17:59:51 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jun 2018 08:59:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,270,1526367600"; d="scan'208";a="67552569" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 25 Jun 2018 08:59:47 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w5PFxlt4032509; Mon, 25 Jun 2018 16:59:47 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w5PFxljA026604; Mon, 25 Jun 2018 16:59:47 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w5PFxlZk026599; Mon, 25 Jun 2018 16:59:47 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: john.mcnamara@intel.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com, david.hunt@intel.com, mohammad.abdul.awal@intel.com Date: Mon, 25 Jun 2018 16:59:41 +0100 Message-Id: <798fa82633f347495706e964fc44f6ab273d7baa.1529940601.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [RFC 4/9] usertools/lib: support FreeBSD for platform info X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jun 2018 15:59:52 -0000 This enables FreeBSD support for PlatformInfo part of the DPDKConfigLib script, thereby enabling FreeBSD support for the cpu_layout script. Signed-off-by: Anatoly Burakov --- usertools/DPDKConfigLib/PlatformInfo.py | 81 ++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/usertools/DPDKConfigLib/PlatformInfo.py b/usertools/DPDKConfigLib/PlatformInfo.py index 734d22026..4ca507a37 100755 --- a/usertools/DPDKConfigLib/PlatformInfo.py +++ b/usertools/DPDKConfigLib/PlatformInfo.py @@ -6,6 +6,15 @@ from .Util import * import re import glob +import platform +import subprocess +import string +import xml.etree.ElementTree # for FreeBSD topology parsing +try: + import queue # python 3 +except ImportError: + import Queue as queue # python 2 + __SYSFS_CPU_INFO_PATH = "/sys/devices/system/cpu" __SYSFS_IOMMU_CLASS_PATH = "/sys/class/iommu" @@ -26,6 +35,9 @@ __HT_CPU_FLAGS = ["ht"] +__SYSCTL_TOPOLOGY_CMDLINE = ['sysctl', '-b', 'kern.sched.topology_spec'] +__SYSCTL_MEM_CMDLINE = ['sysctl', 'hw.realmem'] + def _parse_cpuinfo(pinfo): core_info_list = [] @@ -107,6 +119,56 @@ def _iommu_is_enabled(): pass +def _parse_sysctl_cpu_topology(pinfo): + output = subprocess.check_output(__SYSCTL_TOPOLOGY_CMDLINE) + + # output from sysctl contains null terminator, remove it + raw_xml = output[:-1] + tree = xml.etree.ElementTree.fromstring(raw_xml) + groups = queue.Queue() + + # put first group onto the queue + for e in tree.findall('group'): + groups.put(e) + + # per-level list of cores + levels = {} + + while not groups.empty(): + group = groups.get() + level = int(group.get('level')) + cpus = [int(cpu) for cpu in group.find('cpu').text.split(",")] + cur_value = levels.setdefault(level, []) + + # store discovered cpu's + cur_value.append(cpus) + levels[level] = cur_value + + children = group.find('children') + if children is not None: + for c in children.findall('group'): + groups.put(c) + + # find deepest level + max_level = max(levels.keys()) + + # for each group in the deepest level, take first CPU and make it physical + # core id + for cpus in levels[max_level]: + pinfo.core_map[pinfo.numa_nodes[0], cpus[0]] = cpus + + # also make note of hyperthreading + if len(cpus) > 1: + pinfo.hyperthreading_supported = True + + +def _parse_sysctl_ram_size(): + output = subprocess.check_output(__SYSCTL_MEM_CMDLINE) + _, mem_str = kv_split(output, ':') + mem_amount = int(mem_str) / 1024 # kilobytes + return mem_amount + + class PlatformInfo: def __init__(self): self.update() @@ -125,6 +187,19 @@ def reset(self): def update(self): self.reset() - _parse_cpuinfo(self) - _parse_meminfo(self) - self.hugepage_sizes_enabled = _find_enabled_hugepage_sizes() + system = platform.system() + if system == 'Linux': + _parse_cpuinfo(self) + _parse_meminfo(self) + self.hugepage_sizes_enabled = _find_enabled_hugepage_sizes() + elif system == 'FreeBSD': + # DPDK doesn't support NUMA on FreeBSD + self.numa_nodes = [0] + # find number of threads + _parse_sysctl_cpu_topology(self) + # find RAM size + self.ram_size = _parse_sysctl_ram_size() + # DPDK doesn't use hugepages on FreeBSD + self.hugepage_sizes_supported = [] + self.hugepage_sizes_enabled = [] + self.default_hugepage_size = 0 -- 2.17.1