Author: marek Date: 2010-06-24 17:03:13 +0200 (Thu, 24 Jun 2010) New Revision: 1719
Modified: trunk/batman-adv/Makefile Log: batman-adv: Use nproc to get number of available processors
The current way of getting the number of cpus uses different assumptions which may or may not be true in the future: * /proc/cpuinfo exists * cpuinfo provides a list of all processing units * all processing units are available for the current process and its childs * the word 'processor' is only used in the cpu index and 'model name' lines * cpu index is strict monotonic increasing * lowest cpu index is 0 and highest cpu index is n-1 (n is the number of processing units)
At least the number of available processing units for the current process can be shown to be wrong. on current systems by assigning a singe cpu to a process and its childs:
$ numactl --physcpubind=0 nproc 1
$ numactl --physcpubind=0 sh -c 'NUM_CPUS=`cat /proc/cpuinfo | grep -v "model name" | grep processor | tail -1 | awk -F" " '''{print $$3}'''`;echo `expr $NUM_CPUS + 1`' 4
nproc is part of coreutils since version 8.1. On systems without nproc it will just assume that a single processing unit is available.
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de
Modified: trunk/batman-adv/Makefile =================================================================== --- trunk/batman-adv/Makefile 2010-06-21 13:30:31 UTC (rev 1718) +++ trunk/batman-adv/Makefile 2010-06-24 15:03:13 UTC (rev 1719) @@ -41,7 +41,7 @@ fi; \ fi)
-NUM_CPUS = $(shell NUM_CPUS=`cat /proc/cpuinfo | grep -v 'model name' | grep processor | tail -1 | awk -F' ' '{print $$3}'`;echo `expr $$NUM_CPUS + 1`) +NUM_CPUS = $(shell nproc 2> /dev/null || echo 1)
include $(PWD)/Makefile.kbuild