* RE: [PATCH 39/52] tools/perf/build: Automatically build in parallel, based on number of CPUs in the syst
@ 2013-10-08 12:04 Pádraig Brady
2013-10-08 12:22 ` Ingo Molnar
0 siblings, 1 reply; 2+ messages in thread
From: Pádraig Brady @ 2013-10-08 12:04 UTC (permalink / raw)
To: Ingo Molnar, Linux Kernel Mailing List
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.
> + ifeq ($(JOBS),)
> + JOBS := 1
> + endif
> +endif
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 39/52] tools/perf/build: Automatically build in parallel, based on number of CPUs in the syst
2013-10-08 12:04 [PATCH 39/52] tools/perf/build: Automatically build in parallel, based on number of CPUs in the syst Pádraig Brady
@ 2013-10-08 12:22 ` Ingo Molnar
0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2013-10-08 12:22 UTC (permalink / raw)
To: Pádraig Brady
Cc: Linux Kernel Mailing List, Arnaldo Carvalho de Melo, jiri,
Peter Zijlstra, Namhyung Kim, David Ahern
* Pádraig Brady <P@draigBrady.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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-08 12:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-08 12:04 [PATCH 39/52] tools/perf/build: Automatically build in parallel, based on number of CPUs in the syst Pádraig Brady
2013-10-08 12:22 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox