[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20131008122219.GA2678@gmail.com>
Date: Tue, 8 Oct 2013 14:22:19 +0200
From: Ingo Molnar <mingo@...nel.org>
To: Pádraig Brady <P@...igBrady.com>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Arnaldo Carvalho de Melo <acme@...radead.org>,
jiri@...il.com, Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Namhyung Kim <namhyung@...nel.org>,
David Ahern <dsahern@...il.com>
Subject: Re: [PATCH 39/52] tools/perf/build: Automatically build in parallel,
based on number of CPUs in the syst
* Pádraig Brady <P@...igBrady.com> wrote:
> On 10/08/2013 10:02 AM, Ingo Molnar wrote:
> > +ifeq ($(JOBS),)
> > + JOBS := $(shell grep -c ^processor /proc/cpuinfo 2>/dev/null)
>
> nproc is probably ubiquitous enough to use now
> (available since coreutils 8.1 (end of 2009))
>
> As well as being more concise, it will take
> account of offline CPUs etc.
/proc/cpuinfo takes account of offline CPUs as well:
# grep -c ^processor /proc/cpuinfo 2>/dev/null
16
# echo 0 > /sys/devices/system/cpu/cpu11/online
# grep -c ^processor /proc/cpuinfo 2>/dev/null
15
# echo 1 > /sys/devices/system/cpu/cpu11/online
# grep -c ^processor /proc/cpuinfo 2>/dev/null
16
But nproc is indeed a better choice:
1)
It is scheduler syscall based and will thus will work in limited
environments as well, for example when /proc is not mounted.
2)
It will also properly detect affinity-limited environments:
# taskset 1 nproc
1
3)
It is also faster than grepping /proc/cpuinfo:
# perf stat --null --repeat 100 nproc >/dev/null
Performance counter stats for 'nproc' (100 runs):
0.000652928 seconds time elapsed ( +- 0.53% )
versus:
# perf stat --null --repeat 100 grep -c ^processor /proc/cpuinfo >/dev/null
Performance counter stats for 'grep -c ^processor /proc/cpuinfo' (100 runs):
0.001037034 seconds time elapsed ( +- 0.32% )
so with 0.652 msecs versus 1.037 msecs it's about 60% faster than grep.
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists