From mboxrd@z Thu Jan 1 00:00:00 1970 From: Deck Pickard Subject: [PATCH 3/4] guix: Add schedule module. Date: Sat, 22 Nov 2014 23:35:28 +0100 Message-ID: References: <4957115194234589715@unknownmsgid> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1135ed8ea1bdb105087a2d1a Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XsJH9-0006oZ-FX for guix-devel@gnu.org; Sat, 22 Nov 2014 17:35:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XsJH7-0003oc-3a for guix-devel@gnu.org; Sat, 22 Nov 2014 17:35:31 -0500 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:61805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XsJH6-0003oV-Og for guix-devel@gnu.org; Sat, 22 Nov 2014 17:35:29 -0500 Received: by mail-wi0-f171.google.com with SMTP id bs8so2439556wib.4 for ; Sat, 22 Nov 2014 14:35:28 -0800 (PST) In-Reply-To: List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --001a1135ed8ea1bdb105087a2d1a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable * guix/schedule.scm: New file. To handle --cores and --max-jobs options in 'guix build'. * Makefile.am (MODULES): Add *this. --- Makefile.am | 1 + guix/schedule.scm | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 guix/schedule.scm diff --git a/Makefile.am b/Makefile.am index 5c4ce90..1806a05 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ MODULES =3D \ guix/ftp-client.scm \ guix/http-client.scm \ guix/gnupg.scm \ + guix/schedule.scm \ guix/store.scm \ guix/svn-download.scm \ guix/ui.scm \ diff --git a/guix/schedule.scm b/guix/schedule.scm new file mode 100644 index 0000000..26c7b6b --- /dev/null +++ b/guix/schedule.scm @@ -0,0 +1,102 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2014 Nebulieu +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix schedule) + #:use-module (guix records) + #:export (schedule? + schedule + schedule-name + schedule-max-cores + schedule-max-jobs + schedule-override-cores? + schedule-override-jobs? + + make-schedule-sane)) + +(define-record-type* + schedule make-schedule + schedule? + (name schedule-name ; symbol + (default 'serial)) + (max-cores schedule-max-cores ; non-negative integer + (default 0)) ; use all available horse-power + (max-jobs schedule-max-jobs ; non-negative integer + (default 1)) ; there can be only one + ;; unused, for now, rethink "unified" override + (override-cores? schedule-override-cores? ; boolean + (default #t)) + (override-jobs? schedule-override-jobs? ; boolean + (default #t))) + +; will rather need one `make-schedule-with-name` and switch on 'symbol +(define (make-schedule-serial) + (schedule)) +; redundant for now... + +; macro? +(define (real-schedule symname cores jobs + override-c override-j) + (schedule + (name symname) + (max-cores cores) + (max-jobs jobs) + (override-cores? override-c) + (override-jobs? override-j))) + +; better name? +(define (>1 num) + (if (< num 1) + 1 + num)) + +;; TODO: increase number of jobs with spare cores??? perhaps in real-schedule +(define* (make-schedule-sane #:key max-cores max-jobs) + (let ((sym-name 'serial-sane) + ;; should overriding one override both (think: yes, e.g. + ;; setting cores to max with guix-daemon default [max-jobs =3D 0] + ;; will again lead to the N^2 phenomenon... + (override-cores (and max-cores #t)) + (override-jobs (and max-jobs #t)) + ;; scheduling needs be centralized (think: override always) + (max-threads (min (current-processor-count) + (total-processor-count)))) + (let ((default-max-cores (>1 (- max-threads 1))) + (default-max-jobs 1) + (validate (lambda (arg default) + (if (or (not arg) + (not (integer? arg))) + default + (or (and (=3D arg 0) max-threads) + (and (< arg 0) default) + arg))))) + ;; perhaps we shouldn't be so symmetrical? + (let ((cores (validate max-cores default-max-cores)) + (jobs (validate max-jobs default-max-jobs))) + ;; cut-off + (let loop ((c (min cores max-threads)) + (j (min jobs max-threads))) + (let ((threads (* c j))) + (if (<=3D threads max-threads) + (real-schedule sym-name c j + override-cores override-jobs) + ;; maximize cores at the cost of jobs... + (let ((j- (>1 (- j 1)))) + (if (<=3D (* c j-) max-threads) + (real-schedule sym-name c j- + override-cores override-jobs) + (loop (>1 (- c 1)) j-)))))))))) --=20 2.1.2 --001a1135ed8ea1bdb105087a2d1a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

* guix/schedule.scm: New file. To handle --cores and --max-j= obs
options in 'guix build'.
* Makefile.am (MODULES): Add *this.
---
Makefile.am | 1 +
guix/schedule.scm | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++= +++
2 files changed, 103 insertions(+)
create mode 100644 guix/schedule.scm

diff --git a/Makefile.am b/Makefile.am
index 5c4ce90..1806a05 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -56,6 +56,7 @@ MODULES =3D \
guix/ftp-client.scm \
guix/http-client.scm \
guix/gnupg.scm \
+ guix/schedule.scm \
guix/store.scm \
guix/svn-download.scm \
guix/ui.scm \
diff --git a/guix/schedule.scm b/guix/schedule.scm
new file mode 100644
index 0000000..26c7b6b
--- /dev/null
+++ b/guix/schedule.scm
@@ -0,0 +1,102 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright =C2=A9 2014 Nebulieu <nebu@kipple>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at<= br> +;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix schedule)
+ #:use-module (guix records)
+ #:export (schedule?
+ schedule
+ schedule-name
+ schedule-max-cores
+ schedule-max-jobs
+ schedule-override-cores?
+ schedule-override-jobs?
+
+ make-schedule-sane))
+
+(define-record-type* <schedule>
+ schedule make-schedule
+ schedule?
+ (name schedule-name ; symbol
+ (default 'serial))
+ (max-cores schedule-max-cores ; non-negative integer
+ (default 0)) ; use all available horse-power
+ (max-jobs schedule-max-jobs ; non-negative integer
+ (default 1)) ; there can be only one
+ ;; unused, for now, rethink "unified" override
+ (override-cores? schedule-override-cores? ; boolean
+ (default #t))
+ (override-jobs? schedule-override-jobs? ; boolean
+ (default #t)))
+
+; will rather need one `make-schedule-with-name` and switch on 'symbol=
+(define (make-schedule-serial)
+ (schedule))
+; redundant for now...
+
+; macro?
+(define (real-schedule symname cores jobs
+ override-c override-j)
+ (schedule
+ (name symname)
+ (max-cores cores)
+ (max-jobs jobs)
+ (override-cores? override-c)
+ (override-jobs? override-j)))
+
+; better name?
+(define (>1 num)
+ (if (< num 1)
+ 1
+ num))
+
+;; TODO: increase number of jobs with spare cores??? perhaps in real-sched= ule
+(define* (make-schedule-sane #:key max-cores max-jobs)
+ (let ((sym-name 'serial-sane)
+ ;; should overriding one override both (think: yes, e.g.
+ ;; setting cores to max with guix-daemon default [max-jobs =3D 0]
+ ;; will again lead to the N^2 phenomenon...
+ (override-cores (and max-cores #t))
+ (override-jobs (and max-jobs #t))
+ ;; scheduling needs be centralized (think: override always)
+ (max-threads (min (current-processor-count)
+ (total-processor-count))))
+ (let ((default-max-cores (>1 (- max-threads 1)))
+ (default-max-jobs 1)
+ (validate (lambda (arg default)
+ (if (or (not arg)
+ (not (integer? arg)))
+ default
+ (or (and (=3D arg 0) max-threads)
+ (and (< arg 0) default)
+ arg)))))
+ ;; perhaps we shouldn't be so symmetrical?
+ (let ((cores (validate max-cores default-max-cores))
+ (jobs (validate max-jobs default-max-jobs)))
+ ;; cut-off
+ (let loop ((c (min cores max-threads))
+ (j (min jobs max-threads)))
+ (let ((threads (* c j)))
+ (if (<=3D threads max-threads)
+ (real-schedule sym-name c j
+ override-cores override-jobs)
+ ;; maximize cores at the cost of jobs...
+ (let ((j- (>1 (- j 1))))
+ (if (<=3D (* c j-) max-threads)
+ (real-schedule sym-name c j-
+ override-cores override-jobs)
+ (loop (>1 (- c 1)) j-))))))))))
--
2.1.2

--001a1135ed8ea1bdb105087a2d1a--