]> code.ossystems Code Review - openembedded-core.git/commitdiff
package_ipk: Parallelise ipk creation
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 30 Mar 2017 21:02:45 +0000 (22:02 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 16 Jun 2017 09:58:25 +0000 (10:58 +0100)
Allow the creation of ipks to happen in parallel, making best use of resources
on multiprocessor systems.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/package_ipk.bbclass

index 8e69b5da365b9de2e3b0bcc940dee06a83e73e74..d58b824d3a154731abd58c5406f8825bfe93134d 100644 (file)
@@ -17,6 +17,8 @@ OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKA
 OPKGLIBDIR = "${localstatedir}/lib"
 
 python do_package_ipk () {
+    from multiprocessing import Process
+
     oldcwd = os.getcwd()
 
     workdir = d.getVar('WORKDIR')
@@ -37,11 +39,25 @@ python do_package_ipk () {
     if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
         os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
 
-    for pkg in packages.split():
-        ipk_write_pkg(pkg, d)
+    max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1)
+    launched = []
+    pkgs = packages.split()
+    while pkgs:
+        if len(launched) < max_process:
+            p = Process(target=ipk_write_pkg, args=(pkgs.pop(), d))
+            p.start()
+            launched.append(p)
+        for q in launched:
+            # The finished processes are joined when calling is_alive()
+            if not q.is_alive():
+                launched.remove(q)
+    for p in launched:
+        p.join()
 
     os.chdir(oldcwd)
 }
+do_package_ipk[vardeps] += "ipk_write_pkg"
+do_package_ipk[vardepsexclude] = "BB_NUMBER_THREADS"
 
 def ipk_write_pkg(pkg, d):
     import re, copy