public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset
@ 2015-01-17 10:45 Michał Górny
  2015-01-18  4:22 ` Zac Medico
  0 siblings, 1 reply; 9+ messages in thread
From: Michał Górny @ 2015-01-17 10:45 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

Default MAKEOPTS job number to (number of CPUs + 1) when it is not
provided in the ebuild environment.

Suggested-By: Daniel Robbins <drobbins@funtoo.org>
---
 pym/portage/package/ebuild/doebuild.py |  8 +++++++-
 pym/portage/util/cpuinfo.py            | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 pym/portage/util/cpuinfo.py

diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
index bf97660..f43dddc 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2013 Gentoo Foundation
+# Copyright 2010-2015 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import unicode_literals
@@ -66,6 +66,7 @@ from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs
 from portage.util import apply_recursive_permissions, \
 	apply_secpass_permissions, noiselimit, normalize_path, \
 	writemsg, writemsg_stdout, write_atomic
+from portage.util.cpuinfo import get_cpu_count
 from portage.util.lafilefixer import rewrite_lafile	
 from portage.versions import _pkgsplit
 from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
@@ -463,6 +464,11 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
 				mysettings["PATH"] = os.path.join(os.sep, eprefix_lstrip,
 					 "usr", libdir, "ccache", "bin") + ":" + mysettings["PATH"]
 
+		if 'MAKEOPTS' not in mysettings:
+			nproc = get_cpu_count()
+			if nproc:
+				mysettings['MAKEOPTS'] = '-j%d' % (nproc + 1)
+
 		if not eapi_exports_KV(eapi):
 			# Discard KV for EAPIs that don't support it. Cached KV is restored
 			# from the backupenv whenever config.reset() is called.
diff --git a/pym/portage/util/cpuinfo.py b/pym/portage/util/cpuinfo.py
new file mode 100644
index 0000000..157e2e7
--- /dev/null
+++ b/pym/portage/util/cpuinfo.py
@@ -0,0 +1,19 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+__all__ = ['get_cpu_count']
+
+import multiprocessing
+
+
+def get_cpu_count():
+	"""
+	Try to obtain the number of CPUs available.
+
+	@return: Number of CPUs or None if unable to obtain.
+	"""
+
+	try:
+		return multiprocessing.cpu_count()
+	except NotImplementedError:
+		return None
-- 
2.2.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-17 10:45 [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset Michał Górny
@ 2015-01-18  4:22 ` Zac Medico
  2015-01-18  4:48   ` Zac Medico
  0 siblings, 1 reply; 9+ messages in thread
From: Zac Medico @ 2015-01-18  4:22 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

On 01/17/2015 02:45 AM, Michał Górny wrote:
> Default MAKEOPTS job number to (number of CPUs + 1) when it is not
> provided in the ebuild environment.
> 
> Suggested-By: Daniel Robbins <drobbins@funtoo.org>
> ---
>  pym/portage/package/ebuild/doebuild.py |  8 +++++++-
>  pym/portage/util/cpuinfo.py            | 19 +++++++++++++++++++
>  2 files changed, 26 insertions(+), 1 deletion(-)
>  create mode 100644 pym/portage/util/cpuinfo.py

LGTM.
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-18  4:22 ` Zac Medico
@ 2015-01-18  4:48   ` Zac Medico
  2015-01-18  5:10     ` Tim Harder
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Zac Medico @ 2015-01-18  4:48 UTC (permalink / raw
  To: Zac Medico, gentoo-portage-dev; +Cc: Michał Górny

On 01/17/2015 08:22 PM, Zac Medico wrote:
> On 01/17/2015 02:45 AM, Michał Górny wrote:
>> Default MAKEOPTS job number to (number of CPUs + 1) when it is not
>> provided in the ebuild environment.
>>
>> Suggested-By: Daniel Robbins <drobbins@funtoo.org>
>> ---
>>  pym/portage/package/ebuild/doebuild.py |  8 +++++++-
>>  pym/portage/util/cpuinfo.py            | 19 +++++++++++++++++++
>>  2 files changed, 26 insertions(+), 1 deletion(-)
>>  create mode 100644 pym/portage/util/cpuinfo.py
> 
> LGTM.
> 

Actually, Arfrever tells me that the multiprocessing module is not
available if python is built without threading support. So, we need to
handle the ImportError and either do nothing or parse /proc/cpuinfo or
something like that.
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-18  4:48   ` Zac Medico
@ 2015-01-18  5:10     ` Tim Harder
  2015-01-18  9:30     ` Michał Górny
  2015-01-18 10:38     ` [gentoo-portage-dev] [PATCH v2] " Michał Górny
  2 siblings, 0 replies; 9+ messages in thread
From: Tim Harder @ 2015-01-18  5:10 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico, Michał Górny

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

On 2015-01-17 23:48, Zac Medico wrote:
> Actually, Arfrever tells me that the multiprocessing module is not
> available if python is built without threading support. So, we need to
> handle the ImportError and either do nothing or parse /proc/cpuinfo or
> something like that.

Feel free to borrow/steal/copy the relevant methods from
snakeoil.process since we parse /proc/cpuinfo there probably how you
want. Patches/pull reqs welcome if you have improvements.

Thanks,
Tim

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-18  4:48   ` Zac Medico
  2015-01-18  5:10     ` Tim Harder
@ 2015-01-18  9:30     ` Michał Górny
  2015-01-18 10:38     ` [gentoo-portage-dev] [PATCH v2] " Michał Górny
  2 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2015-01-18  9:30 UTC (permalink / raw
  To: Zac Medico; +Cc: gentoo-portage-dev

[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]

Dnia 2015-01-17, o godz. 20:48:11
Zac Medico <zmedico@gentoo.org> napisał(a):

> On 01/17/2015 08:22 PM, Zac Medico wrote:
> > On 01/17/2015 02:45 AM, Michał Górny wrote:
> >> Default MAKEOPTS job number to (number of CPUs + 1) when it is not
> >> provided in the ebuild environment.
> >>
> >> Suggested-By: Daniel Robbins <drobbins@funtoo.org>
> >> ---
> >>  pym/portage/package/ebuild/doebuild.py |  8 +++++++-
> >>  pym/portage/util/cpuinfo.py            | 19 +++++++++++++++++++
> >>  2 files changed, 26 insertions(+), 1 deletion(-)
> >>  create mode 100644 pym/portage/util/cpuinfo.py
> > 
> > LGTM.
> > 
> 
> Actually, Arfrever tells me that the multiprocessing module is not
> available if python is built without threading support. So, we need to
> handle the ImportError and either do nothing or parse /proc/cpuinfo or
> something like that.

I don't think there's a point in having more complexity for a use case
that doesn't really get used. Except maybe for the few 'USE=-*' people
who aren't cautious enough but they're going to be hit by some failure
sooner or later.

I'm going to remove the flag on the Python end after verifying
the USE-deps.

-- 
Best regards,
Michał Górny

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 949 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [gentoo-portage-dev] [PATCH v2] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-18  4:48   ` Zac Medico
  2015-01-18  5:10     ` Tim Harder
  2015-01-18  9:30     ` Michał Górny
@ 2015-01-18 10:38     ` Michał Górny
  2015-01-18 16:58       ` Brian Dolbec
  2 siblings, 1 reply; 9+ messages in thread
From: Michał Górny @ 2015-01-18 10:38 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

Default MAKEOPTS job number to (number of CPUs + 1) when it is not
provided in the ebuild environment.

Suggested-By: Daniel Robbins <drobbins@funtoo.org>
---
 pym/portage/package/ebuild/doebuild.py |  8 +++++++-
 pym/portage/util/cpuinfo.py            | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 pym/portage/util/cpuinfo.py

diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
index bf97660..f43dddc 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2013 Gentoo Foundation
+# Copyright 2010-2015 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import unicode_literals
@@ -66,6 +66,7 @@ from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs
 from portage.util import apply_recursive_permissions, \
 	apply_secpass_permissions, noiselimit, normalize_path, \
 	writemsg, writemsg_stdout, write_atomic
+from portage.util.cpuinfo import get_cpu_count
 from portage.util.lafilefixer import rewrite_lafile	
 from portage.versions import _pkgsplit
 from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
@@ -463,6 +464,11 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
 				mysettings["PATH"] = os.path.join(os.sep, eprefix_lstrip,
 					 "usr", libdir, "ccache", "bin") + ":" + mysettings["PATH"]
 
+		if 'MAKEOPTS' not in mysettings:
+			nproc = get_cpu_count()
+			if nproc:
+				mysettings['MAKEOPTS'] = '-j%d' % (nproc + 1)
+
 		if not eapi_exports_KV(eapi):
 			# Discard KV for EAPIs that don't support it. Cached KV is restored
 			# from the backupenv whenever config.reset() is called.
diff --git a/pym/portage/util/cpuinfo.py b/pym/portage/util/cpuinfo.py
new file mode 100644
index 0000000..669e707
--- /dev/null
+++ b/pym/portage/util/cpuinfo.py
@@ -0,0 +1,18 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+__all__ = ['get_cpu_count']
+
+
+def get_cpu_count():
+	"""
+	Try to obtain the number of CPUs available.
+
+	@return: Number of CPUs or None if unable to obtain.
+	"""
+
+	try:
+		import multiprocessing
+		return multiprocessing.cpu_count()
+	except (ImportError, NotImplementedError):
+		return None
-- 
2.2.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-18 10:38     ` [gentoo-portage-dev] [PATCH v2] " Michał Górny
@ 2015-01-18 16:58       ` Brian Dolbec
  2015-01-29  3:06         ` Rick "Zero_Chaos" Farina
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Dolbec @ 2015-01-18 16:58 UTC (permalink / raw
  To: gentoo-portage-dev

On Sun, 18 Jan 2015 11:38:38 +0100
Michał Górny <mgorny@gentoo.org> wrote:

> Default MAKEOPTS job number to (number of CPUs + 1) when it is not
> provided in the ebuild environment.
> 
> Suggested-By: Daniel Robbins <drobbins@funtoo.org>
> ---
>  pym/portage/package/ebuild/doebuild.py |  8 +++++++-
>  pym/portage/util/cpuinfo.py            | 18 ++++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>  create mode 100644 pym/portage/util/cpuinfo.py
>


looks good, merge please

-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-18 16:58       ` Brian Dolbec
@ 2015-01-29  3:06         ` Rick "Zero_Chaos" Farina
  2015-01-30  7:05           ` Zac Medico
  0 siblings, 1 reply; 9+ messages in thread
From: Rick "Zero_Chaos" Farina @ 2015-01-29  3:06 UTC (permalink / raw
  To: gentoo-portage-dev

[-- Attachment #1: Type: text/plain, Size: 896 bytes --]

On 01/18/2015 11:58 AM, Brian Dolbec wrote:
> On Sun, 18 Jan 2015 11:38:38 +0100
> Michał Górny <mgorny@gentoo.org> wrote:
> 
>> Default MAKEOPTS job number to (number of CPUs + 1) when it is not
>> provided in the ebuild environment.
>>
>> Suggested-By: Daniel Robbins <drobbins@funtoo.org>
>> ---
>>  pym/portage/package/ebuild/doebuild.py |  8 +++++++-
>>  pym/portage/util/cpuinfo.py            | 18 ++++++++++++++++++
>>  2 files changed, 25 insertions(+), 1 deletion(-)
>>  create mode 100644 pym/portage/util/cpuinfo.py
>>
> 
> 
> looks good, merge please
> 
I realize I'm a little bit late here, but after extensive testing with
multiple different schedulers that NUMCPU provides equivalent
performance, or even outperforms NUMCPU+1.  I think that changes from 1
cpu to NUMCPU is good enough, and we don't need to test thrashing the
scheduler.

Thanks,
Zero


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] Default MAKEOPTS to -j(ncpus+1) when unset
  2015-01-29  3:06         ` Rick "Zero_Chaos" Farina
@ 2015-01-30  7:05           ` Zac Medico
  0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2015-01-30  7:05 UTC (permalink / raw
  To: gentoo-portage-dev

On 01/28/2015 07:06 PM, Rick "Zero_Chaos" Farina wrote:
> On 01/18/2015 11:58 AM, Brian Dolbec wrote:
>> On Sun, 18 Jan 2015 11:38:38 +0100
>> Michał Górny <mgorny@gentoo.org> wrote:
>>
>>> Default MAKEOPTS job number to (number of CPUs + 1) when it is not
>>> provided in the ebuild environment.
>>>
>>> Suggested-By: Daniel Robbins <drobbins@funtoo.org>
>>> ---
>>>  pym/portage/package/ebuild/doebuild.py |  8 +++++++-
>>>  pym/portage/util/cpuinfo.py            | 18 ++++++++++++++++++
>>>  2 files changed, 25 insertions(+), 1 deletion(-)
>>>  create mode 100644 pym/portage/util/cpuinfo.py
>>>
>>
>>
>> looks good, merge please
>>
> I realize I'm a little bit late here, but after extensive testing with
> multiple different schedulers that NUMCPU provides equivalent
> performance, or even outperforms NUMCPU+1.  I think that changes from 1
> cpu to NUMCPU is good enough, and we don't need to test thrashing the
> scheduler.

Yeah, that's what I was thinking when the patch was submitted, but I
forgot to mention it.
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-01-30  7:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-17 10:45 [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset Michał Górny
2015-01-18  4:22 ` Zac Medico
2015-01-18  4:48   ` Zac Medico
2015-01-18  5:10     ` Tim Harder
2015-01-18  9:30     ` Michał Górny
2015-01-18 10:38     ` [gentoo-portage-dev] [PATCH v2] " Michał Górny
2015-01-18 16:58       ` Brian Dolbec
2015-01-29  3:06         ` Rick "Zero_Chaos" Farina
2015-01-30  7:05           ` Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox