From: Anatoly Burakov <anatoly.burakov@intel.com>
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
Subject: [dpdk-dev] [RFC 4/9] usertools/lib: support FreeBSD for platform info
Date: Mon, 25 Jun 2018 16:59:41 +0100 [thread overview]
Message-ID: <798fa82633f347495706e964fc44f6ab273d7baa.1529940601.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1529940601.git.anatoly.burakov@intel.com>
In-Reply-To: <cover.1529940601.git.anatoly.burakov@intel.com>
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 <anatoly.burakov@intel.com>
---
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
next prev parent reply other threads:[~2018-06-25 15:59 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-25 15:59 [dpdk-dev] [RFC 0/9] Modularize and enhance DPDK Python scripts Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 1/9] usertools: add DPDK config lib python library Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 2/9] usertools/lib: add platform info library Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 3/9] usertools/cpu_layout: rewrite to use DPDKConfigLib Anatoly Burakov
2018-06-25 15:59 ` Anatoly Burakov [this message]
2018-06-25 15:59 ` [dpdk-dev] [RFC 5/9] usertools/lib: add device information library Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 6/9] usertools/devbind: switch to using DPDKConfigLib Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 7/9] usertools/lib: add hugepage information library Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 8/9] usertools: add hugepage info script Anatoly Burakov
2018-06-25 15:59 ` [dpdk-dev] [RFC 9/9] usertools/lib: add GRUB utility library for hugepage config Anatoly Burakov
2018-06-26 1:09 ` Kevin Wilson
2018-06-26 9:05 ` Burakov, Anatoly
2018-08-14 10:11 ` [dpdk-dev] [RFC 0/9] Modularize and enhance DPDK Python scripts Burakov, Anatoly
2018-08-28 8:16 ` Burakov, Anatoly
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 " Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 1/9] usertools: add DPDK config lib python library Anatoly Burakov
2018-11-16 0:45 ` Stephen Hemminger
2018-11-16 11:49 ` Burakov, Anatoly
2018-11-16 14:09 ` Wiles, Keith
2018-11-16 14:13 ` Richardson, Bruce
2018-11-16 14:37 ` Burakov, Anatoly
2018-11-16 14:55 ` Thomas Monjalon
2018-11-16 15:41 ` Wiles, Keith
2018-11-16 15:43 ` Burakov, Anatoly
2018-11-16 15:58 ` Thomas Monjalon
2018-11-16 16:10 ` Bruce Richardson
2018-11-16 16:08 ` Bruce Richardson
2018-11-16 15:38 ` Wiles, Keith
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 2/9] usertools/lib: add platform info library Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 3/9] usertools/cpu_layout: rewrite to use DPDKConfigLib Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 4/9] usertools/lib: support FreeBSD for platform info Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 5/9] usertools/lib: add device information library Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 6/9] usertools/devbind: switch to using DPDKConfigLib Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 7/9] usertools/lib: add hugepage information library Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 8/9] usertools: add hugepage info script Anatoly Burakov
2018-11-15 15:47 ` [dpdk-dev] [RFC v2 9/9] usertools/lib: add GRUB utility library for hugepage config Anatoly Burakov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=798fa82633f347495706e964fc44f6ab273d7baa.1529940601.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=david.hunt@intel.com \
--cc=dev@dpdk.org \
--cc=john.mcnamara@intel.com \
--cc=mohammad.abdul.awal@intel.com \
--cc=pablo.de.lara.guarch@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).