On Tue, Oct 27, 2020 at 03:50:46PM +0000, Juraj Linkeš wrote: > > > > -----Original Message----- > > From: Bruce Richardson <bruce.richard...@intel.com> > > Sent: Tuesday, October 27, 2020 12:21 PM > > To: Juraj Linkeš <juraj.lin...@pantheon.tech> > > Cc: ruifeng.w...@arm.com; honnappa.nagaraha...@arm.com; > > phil.y...@arm.com; vcchu...@amazon.com; dharmik.thak...@arm.com; > > jerinjac...@gmail.com; hemant.agra...@nxp.com; dev@dpdk.org > > Subject: Re: [PATCH v4 3/6] build: optional NUMA and cpu counts detection > > > > On Fri, Oct 23, 2020 at 04:48:05PM +0200, Juraj Linkeš wrote: > > > Add an option to automatically discover the host's numa and cpu counts > > > and use those values for a non cross-build. > > > Give users the option to override the per-arch default values or > > > values from cross files by specifying them on the command line with > > > -Dmax_lcores and -Dmax_numa_nodes. > > > > > > Signed-off-by: Juraj Linkeš <juraj.lin...@pantheon.tech> > > > --- > > > buildtools/get_cpu_count.py | 7 ++++++ > > > buildtools/get_numa_count.py | 22 +++++++++++++++++ > > > buildtools/meson.build | 2 ++ > > > config/meson.build | 48 ++++++++++++++++++++++++++++++++++-- > > > meson_options.txt | 8 +++--- > > > 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 > > > buildtools/get_cpu_count.py create mode 100644 > > > buildtools/get_numa_count.py > > > > > > diff --git a/buildtools/get_cpu_count.py b/buildtools/get_cpu_count.py > > > new file mode 100644 index 000000000..386f85f8b > > > --- /dev/null > > > +++ b/buildtools/get_cpu_count.py > > > @@ -0,0 +1,7 @@ > > > +#!/usr/bin/python3 > > > +# SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2020 > > > +PANTHEON.tech s.r.o. > > > + > > > +import os > > > + > > > +print(os.cpu_count()) > > > diff --git a/buildtools/get_numa_count.py > > > b/buildtools/get_numa_count.py new file mode 100644 index > > > 000000000..f0c49973a > > > --- /dev/null > > > +++ b/buildtools/get_numa_count.py > > > @@ -0,0 +1,22 @@ > > > +#!/usr/bin/python3 > > > +# SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2020 > > > +PANTHEON.tech s.r.o. > > > + > > > +import ctypes > > > +import glob > > > +import os > > > +import subprocess > > > + > > > +if os.name == 'posix': > > > + if os.path.isdir('/sys/devices/system/node'): > > > + print(len(glob.glob('/sys/devices/system/node/node*'))) > > > + else: > > > + print(subprocess.run(['sysctl', 'vm.ndomains'], > > > +capture_output=True).stdout) > > > > I think you can shorten this, by just calling subprocess.run and not > > capturing > > anything, in which case the stdout will be printed as normal. > > > > subprocess.run(['sysctl', 'vm.ndomains']) > > > > This will also print out the resulting object (e.g. > CompletedProcess(args=['ls', '-ls', '/sys/devices/system/node'], > returncode=0)), but an assignment will take care of that. I'll make the > change. >
Not unless you are running interactively in the python3 REPL. For example: $ cat test_meminfo.py #! /usr/bin/env python3 from subprocess import run run(['cat', '/proc/meminfo']) $ python3 test_meminfo.py | tail -n 5 Hugepagesize: 2048 kB Hugetlb: 17825792 kB DirectMap4k: 1056788 kB DirectMap2M: 9758720 kB DirectMap1G: 88080384 kB $