Re: [PATCH 39/52] tools/perf/build: Automatically build in parallel,based on number of CPUs in the syst
From: Ingo Molnar
Date: Tue Oct 08 2013 - 08:22:29 EST
* Pádraig Brady <P@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/