runqueue: Simplify some convoluted logic
PATCH 1/7 runqueue: Simplify some convoluted logic
This was left from when task IDs complicated the code, simplify.
--- lib/bb/runqueue.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
lib/bb/runqueue.py +1 -6
@@ -1908,12 +1908,7 @@ class RunQueueExecute: if nexttask in self.sqdata.unskippable: logger.debug(2, "Setscene task %s is unskippable" % nexttask) if nexttask not in self.sqdata.unskippable and len(self.sqdata.sq_revdeps[nexttask]) > 0 and self.sqdata.sq_revdeps[nexttask].issubset(self.scenequeue_covered) and self.check_dependencies(nexttask, self.sqdata.sq_revdeps[nexttask]): - fn = fn_from_tid(nexttask) - foundtarget = False - - if nexttask in self.rqdata.target_tids: - foundtarget = True - if not foundtarget: + if nexttask not in self.rqdata.target_tids: logger.debug(2, "Skipping setscene for task %s" % nexttask) self.sq_task_skip(nexttask) self.scenequeue_notneeded.add(nexttask)
Signature · 1 line
2.20.1
PATCH 2/7 runqueue: Streamline outright setscene failure handling
With the recent codebase changes we can just call the outrightfail function immediately, removing some intermediate data structures.
--- lib/bb/runqueue.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
lib/bb/runqueue.py +1 -6
@@ -1913,9 +1913,6 @@ class RunQueueExecute: self.sq_task_skip(nexttask) self.scenequeue_notneeded.add(nexttask) return True - if nexttask in self.sqdata.outrightfail: - self.sq_task_failoutright(nexttask) - return True task = nexttask break if task is not None:
@@ -2330,8 +2327,6 @@ class SQData(object): self.stamps = {} # Setscene tasks directly depended upon by the build self.unskippable = set() - # List of setscene tasks which aren't present - self.outrightfail = [] # A list of normal tasks a setscene task covers self.sq_covered_tasks = {}
@@ -2553,7 +2548,7 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): for tid in sqdata.sq_revdeps: if tid not in valid_new and tid not in noexec: logger.debug(2, 'No package found, so skipping setscene task %s', tid) - sqdata.outrightfail.append(tid) + sqrq.sq_task_failoutright(tid) class TaskFailure(Exception): """
Signature · 1 line
2.20.1
Re: [PATCH 2/7] runqueue: Streamline outright setscene failure handling
Quoted 32 lines · Richard Purdie
With the recent codebase changes we can just call the outrightfail function immediately, removing some intermediate data structures.
Signed-off-by Richard Purdie <[email protected]>--- lib/bb/runqueue.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)lib/bb/runqueue.py +0
-5@@ -1913,9 +1913,6 @@ class RunQueueExecute: self.sq_task_skip(nexttask) self.scenequeue_notneeded.add(nexttask) return True - if nexttask in self.sqdata.outrightfail: - self.sq_task_failoutright(nexttask) - return True task = nexttask break if task is not None:@@ -2330,8 +2327,6 @@ class SQData(object): self.stamps = {} # Setscene tasks directly depended upon by the build self.unskippable = set() - # List of setscene tasks which aren't present - self.outrightfail = [] # A list of normal tasks a setscene task covers self.sq_covered_tasks = {}
lib/bb/runqueue.py def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): · line 2554
Quoted 8 lines
lib/bb/runqueue.py +1
-1@@ -2553,7 +2548,7 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): for tid in sqdata.sq_revdeps: if tid not in valid_new and tid not in noexec: logger.debug(2, 'No package found, so skipping setscene task %s', tid) - sqdata.outrightfail.append(tid) + sqrq.sq_task_failoutright(tid) class TaskFailure(Exception): """
I'm going to NAK my own patch. There is logic inbetween these two points which may end up covering the task without it needing to run. In particular do_shared_workdir in the kernel never has a valid sstate artefact and this change causes eSDK to break *if and only if* that task hasn't already been run in a given build directory.
This did result in a single failure on the autobuilder but shows how much fun this code is.
I'll ponder this further, its likely going to be better to pass around the "valid" list and totally streamline and rewrite some horrible code here.
Cheers,
Richard
PATCH 3/7 runqueue: Whitespace fix
In reply to Richard PurdieFix some unwanted extra indentation.
--- lib/bb/runqueue.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
lib/bb/runqueue.py +19 -19
@@ -2438,29 +2438,29 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): # e.g. do_sometask_setscene[depends] = "targetname:do_someothertask_setscene" # Note that anything explicitly depended upon will have its reverse dependencies removed to avoid circular dependencies for tid in rqdata.runq_setscene_tids: - (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) - realtid = tid + "_setscene" - idepends = rqdata.taskData[mc].taskentries[realtid].idepends - sqdata.stamps[tid] = bb.build.stampfile(taskname + "_setscene", rqdata.dataCaches[mc], taskfn, noextra=True) - for (depname, idependtask) in idepends: + (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) + realtid = tid + "_setscene" + idepends = rqdata.taskData[mc].taskentries[realtid].idepends + sqdata.stamps[tid] = bb.build.stampfile(taskname + "_setscene", rqdata.dataCaches[mc], taskfn, noextra=True) + for (depname, idependtask) in idepends: - if depname not in rqdata.taskData[mc].build_targets: - continue + if depname not in rqdata.taskData[mc].build_targets: + continue - depfn = rqdata.taskData[mc].build_targets[depname][0] - if depfn is None: - continue - deptid = depfn + ":" + idependtask.replace("_setscene", "") - if deptid not in rqdata.runtaskentries: - bb.msg.fatal("RunQueue", "Task %s depends upon non-existent task %s:%s" % (realtid, depfn, idependtask)) + depfn = rqdata.taskData[mc].build_targets[depname][0] + if depfn is None: + continue + deptid = depfn + ":" + idependtask.replace("_setscene", "") + if deptid not in rqdata.runtaskentries: + bb.msg.fatal("RunQueue", "Task %s depends upon non-existent task %s:%s" % (realtid, depfn, idependtask)) - if not deptid in sqdata.sq_harddeps: - sqdata.sq_harddeps[deptid] = set() - sqdata.sq_harddeps[deptid].add(tid) + if not deptid in sqdata.sq_harddeps: + sqdata.sq_harddeps[deptid] = set() + sqdata.sq_harddeps[deptid].add(tid) - sq_revdeps_squash[tid].add(deptid) - # Have to zero this to avoid circular dependencies - sq_revdeps_squash[deptid] = set() + sq_revdeps_squash[tid].add(deptid) + # Have to zero this to avoid circular dependencies + sq_revdeps_squash[deptid] = set() rqdata.init_progress_reporter.next_stage()
Signature · 1 line
2.20.1
PATCH 4/7 siggen: Use unique hashes for tasks
In reply to Richard PurdieNow that runqueue optimises based on task hash, we need to ensure tasks have unique hashes even in the simplest siggen mode. Use the task name to calculate a unique hash.
This fixes runqueue tests when hash optimisations are added.
--- lib/bb/siggen.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/bb/siggen.py +3 -2
@@ -49,8 +49,9 @@ class SignatureGenerator(object): return self.taskhash[task] def get_taskhash(self, fn, task, deps, dataCache): - self.taskhash[fn + "." + task] = "0" - return self.taskhash[fn + "." + task] + k = fn + "." + task + self.taskhash[k] = hashlib.sha256(k.encode("utf-8")).hexdigest() + return self.taskhash[k] def writeout_file_checksum_cache(self): """Write/update the file checksum cache onto disk"""
Signature · 1 line
2.20.1
PATCH 5/7 runqueue: Abstract hash verification function
In reply to Richard PurdiePull the common pieces of the hash verification code into a single function and reduce code duplication.
--- lib/bb/runqueue.py | 82 ++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 40 deletions(-)
lib/bb/runqueue.py +42 -40
@@ -1376,10 +1376,43 @@ class RunQueue: cache[tid] = iscurrent return iscurrent - def validate_hash(self, *, sq_fn, sq_task, sq_hash, sq_hashfn, siginfo, sq_unihash, d): + def validate_hashes(self, tocheck, data, presentcount=None, siginfo=False): + valid = set() + if self.hashvalidate: + sq_hash = [] + sq_hashfn = [] + sq_unihash = [] + sq_fn = [] + sq_taskname = [] + sq_task = [] + for tid in tocheck: + (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) + + sq_fn.append(fn) + sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn]) + sq_hash.append(self.rqdata.runtaskentries[tid].hash) + sq_unihash.append(self.rqdata.runtaskentries[tid].unihash) + sq_taskname.append(taskname) + sq_task.append(tid) + + if presentcount is not None: + data.setVar("BB_SETSCENE_STAMPCURRENT_COUNT", presentcount) + + valid_ids = self.validate_hash(sq_fn, sq_taskname, sq_hash, sq_hashfn, siginfo, sq_unihash, data, presentcount) + + if presentcount is not None: + data.delVar("BB_SETSCENE_STAMPCURRENT_COUNT") + + for v in valid_ids: + valid.add(sq_task[v]) + + return valid + + def validate_hash(self, sq_fn, sq_task, sq_hash, sq_hashfn, siginfo, sq_unihash, d, presentcount): locs = {"sq_fn" : sq_fn, "sq_task" : sq_task, "sq_hash" : sq_hash, "sq_hashfn" : sq_hashfn, "sq_unihash" : sq_unihash, "siginfo" : siginfo, "d" : d} + # Backwards compatibility hashvalidate_args = ("(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=siginfo, sq_unihash=sq_unihash)", "(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=siginfo)", "(sq_fn, sq_task, sq_hash, sq_hashfn, d)")
@@ -1564,16 +1597,8 @@ class RunQueue: def print_diffscenetasks(self): - valid = [] - sq_hash = [] - sq_hashfn = [] - sq_unihash = [] - sq_fn = [] - sq_taskname = [] - sq_task = [] noexec = [] - stamppresent = [] - valid_new = set() + tocheck = set() for tid in self.rqdata.runtaskentries: (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
@@ -1583,18 +1608,9 @@ class RunQueue: noexec.append(tid) continue - sq_fn.append(fn) - sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn]) - sq_hash.append(self.rqdata.runtaskentries[tid].hash) - sq_unihash.append(self.rqdata.runtaskentries[tid].unihash) - sq_taskname.append(taskname) - sq_task.append(tid) + tocheck.add(tid) - valid = self.validate_hash(sq_fn=sq_fn, sq_task=sq_taskname, sq_hash=sq_hash, sq_hashfn=sq_hashfn, - siginfo=True, sq_unihash=sq_unihash, d=self.cooker.data) - - for v in valid: - valid_new.add(sq_task[v]) + valid_new = self.validate_hashes(tocheck, self.cooker.data, None, True) # Tasks which are both setscene and noexec never care about dependencies # We therefore find tasks which are setscene and noexec and mark their
@@ -2496,14 +2512,10 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): rqdata.init_progress_reporter.finish() if rq.hashvalidate: - sq_hash = [] - sq_hashfn = [] - sq_unihash = [] - sq_fn = [] - sq_taskname = [] - sq_task = [] noexec = [] stamppresent = [] + tocheck = set() + for tid in sqdata.sq_revdeps: (mc, fn, taskname, taskfn) = split_tid_mcfn(tid)
@@ -2527,23 +2539,13 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): sqrq.sq_task_skip(tid) continue - sq_fn.append(fn) - sq_hashfn.append(rqdata.dataCaches[mc].hashfn[taskfn]) - sq_hash.append(rqdata.runtaskentries[tid].hash) - sq_unihash.append(rqdata.runtaskentries[tid].unihash) - sq_taskname.append(taskname) - sq_task.append(tid) - - cooker.data.setVar("BB_SETSCENE_STAMPCURRENT_COUNT", len(stamppresent)) - - valid = rq.validate_hash(sq_fn=sq_fn, sq_task=sq_taskname, sq_hash=sq_hash, sq_hashfn=sq_hashfn, - siginfo=False, sq_unihash=sq_unihash, d=cooker.data) + tocheck.add(tid) - cooker.data.delVar("BB_SETSCENE_STAMPCURRENT_COUNT") + valid = rq.validate_hashes(tocheck, cooker.data, len(stamppresent), False) valid_new = stamppresent for v in valid: - valid_new.append(sq_task[v]) + valid_new.append(v) for tid in sqdata.sq_revdeps: if tid not in valid_new and tid not in noexec:
Signature · 1 line
2.20.1
PATCH 6/7 runqueue: Optimise multiconfig with overlapping setscene
In reply to Richard Purdie--- lib/bb/runqueue.py | 33 ++++++++++++++++--- .../tests/runqueue-tests/classes/base.bbclass | 19 ++++++++++- lib/bb/tests/runqueue-tests/conf/bitbake.conf | 9 +++-- .../runqueue-tests/conf/multiconfig/mc1.conf | 1 + .../runqueue-tests/conf/multiconfig/mc2.conf | 1 + lib/bb/tests/runqueue.py | 19 +++++++++++ 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 lib/bb/tests/runqueue-tests/conf/multiconfig/mc1.conf create mode 100644 lib/bb/tests/runqueue-tests/conf/multiconfig/mc2.conf
lib/bb/runqueue.py +29 -4
@@ -1717,6 +1717,8 @@ class RunQueueExecute: self.build_stamps = {} self.build_stamps2 = [] self.failed_tids = [] + self.pending_hashes = {} + self.sq_deferred = set() self.stampcache = {}
@@ -1884,6 +1886,10 @@ class RunQueueExecute: if alldeps: self.setbuildable(revdep) logger.debug(1, "Marking task %s as buildable", revdep) + if task in self.rqdata.runq_setscene_tids: + h = self.rqdata.runtaskentries[task].hash + if h in self.pending_hashes: + del self.pending_hashes[h] def task_complete(self, task): self.stats.taskCompleted()
@@ -1921,14 +1927,25 @@ class RunQueueExecute: # Find the next setscene to run for nexttask in self.rqdata.runq_setscene_tids: if nexttask in self.sq_buildable and nexttask not in self.sq_running and self.sqdata.stamps[nexttask] not in self.build_stamps.values(): - if nexttask in self.sqdata.unskippable: - logger.debug(2, "Setscene task %s is unskippable" % nexttask) if nexttask not in self.sqdata.unskippable and len(self.sqdata.sq_revdeps[nexttask]) > 0 and self.sqdata.sq_revdeps[nexttask].issubset(self.scenequeue_covered) and self.check_dependencies(nexttask, self.sqdata.sq_revdeps[nexttask]): if nexttask not in self.rqdata.target_tids: logger.debug(2, "Skipping setscene for task %s" % nexttask) self.sq_task_skip(nexttask) self.scenequeue_notneeded.add(nexttask) return True + if self.rqdata.runtaskentries[nexttask].hash in self.pending_hashes: + # This setscene task has a hash matching something we're currently building, so wait + continue + if nexttask in self.sq_deferred: + logger.debug(1, "Task %s no longer deferred" % nexttask) + self.sq_deferred.remove(nexttask) + valid = self.rq.validate_hashes(set([nexttask]), self.cooker.data, None, False) + if not valid: + logger.debug(1, "%s didn't become valid, skipping setscene" % nexttask) + self.sq_task_failoutright(nexttask) + return True + if nexttask in self.sqdata.unskippable: + logger.debug(2, "Setscene task %s is unskippable" % nexttask) task = nexttask break if task is not None:
@@ -1979,7 +1996,7 @@ class RunQueueExecute: if self.can_start_task(): return True - if not self.sq_live and not self.sqdone: + if not self.sq_live and not self.sqdone and not self.sq_deferred: logger.info("Setscene tasks completed") logger.debug(1, 'We could skip tasks %s', "\n".join(sorted(self.scenequeue_covered)))
@@ -2248,6 +2265,8 @@ class RunQueueExecute: bb.event.fire(sceneQueueTaskFailed(task, self.sq_stats, result, self), self.cfgData) self.scenequeue_notcovered.add(task) self.tasks_notcovered.add(task) + h = self.rqdata.runtaskentries[task].hash + self.pending_hashes[h] = task self.scenequeue_updatecounters(task, True) self.sq_check_taskfail(task)
@@ -2258,6 +2277,8 @@ class RunQueueExecute: self.sq_stats.taskCompleted() self.scenequeue_notcovered.add(task) self.tasks_notcovered.add(task) + h = self.rqdata.runtaskentries[task].hash + self.pending_hashes[h] = task self.scenequeue_updatecounters(task, True) def sq_task_skip(self, task):
@@ -2548,7 +2569,11 @@ def build_scenequeue_data(sqdata, rqdata, rq, cooker, stampcache, sqrq): valid_new.append(v) for tid in sqdata.sq_revdeps: - if tid not in valid_new and tid not in noexec: + if tid not in valid_new and tid not in noexec and tid not in sqrq.scenequeue_notcovered: + if rqdata.runtaskentries[tid].hash in sqrq.pending_hashes: + logger.debug(1, "Deferring %s due to %s" % (tid, sqrq.pending_hashes[rqdata.runtaskentries[tid].hash])) + sqrq.sq_deferred.add(tid) + continue logger.debug(2, 'No package found, so skipping setscene task %s', tid) sqrq.sq_task_failoutright(tid)
lib/bb/tests/runqueue-tests/classes/base.bbclass +18 -1
@@ -4,7 +4,9 @@ SSTATEVALID ??= "" def stamptask(d): import time - thistask = d.expand("${PN}:${BB_CURRENTTASK}") + thistask = d.expand("${PN}:${BB_CURRENTTASK}") + if d.getVar("BB_CURRENT_MC") != "default": + thistask = d.expand("${BB_CURRENT_MC}:${PN}:${BB_CURRENTTASK}") if thistask in d.getVar("SLOWTASKS").split(): bb.note("Slowing task %s" % thistask) time.sleep(0.5)
@@ -13,48 +15,63 @@ def stamptask(d): f.write(thistask + "\n") python do_fetch() { + # fetch stamptask(d) } python do_unpack() { + # unpack stamptask(d) } python do_patch() { + # patch stamptask(d) } python do_populate_lic() { + # populate_lic stamptask(d) } python do_prepare_recipe_sysroot() { + # prepare_recipe_sysroot stamptask(d) } python do_configure() { + # configure stamptask(d) } python do_compile() { + # compile stamptask(d) } python do_install() { + # install stamptask(d) } python do_populate_sysroot() { + # populate_sysroot stamptask(d) } python do_package() { + # package stamptask(d) } python do_package_write_ipk() { + # package_write_ipk stamptask(d) } python do_package_write_rpm() { + # package_write_rpm stamptask(d) } python do_packagedata() { + # packagedata stamptask(d) } python do_package_qa() { + # package_qa stamptask(d) } python do_build() { + # build stamptask(d) } do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot"
lib/bb/tests/runqueue-tests/conf/bitbake.conf +7 -2
@@ -5,6 +5,11 @@ BBFILES = "${COREBASE}/recipes/*.bb" PROVIDES = "${PN}" PN = "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[0]}" export PATH -STAMP = "${TOPDIR}/stamps/${PN}" -T = "${TOPDIR}/workdir/${PN}/temp" +TMPDIR ??= "${TOPDIR}" +STAMP = "${TMPDIR}/stamps/${PN}" +T = "${TMPDIR}/workdir/${PN}/temp" BB_NUMBER_THREADS = "4" + +BB_HASHBASE_WHITELIST = "BB_CURRENT_MC" + +include conf/multiconfig/${BB_CURRENT_MC}.conf
lib/bb/tests/runqueue-tests/conf/multiconfig/mc1.conf new file +1 -0
@@ -0,0 +1 @@ +TMPDIR = "${TOPDIR}/mc1/"
lib/bb/tests/runqueue-tests/conf/multiconfig/mc2.conf new file +1 -0
@@ -0,0 +1 @@ +TMPDIR = "${TOPDIR}/mc2/"
lib/bb/tests/runqueue.py +19 -0
@@ -189,3 +189,22 @@ class RunQueueTests(unittest.TestCase): 'b1:packagedata_setscene', 'b1:package_qa_setscene', 'b1:populate_sysroot_setscene'] self.assertEqual(set(tasks), set(expected)) + def test_multiconfig_setscene_optimise(self): + with tempfile.TemporaryDirectory(prefix="runqueuetest") as tempdir: + extraenv = { + "BBMULTICONFIG" : "mc1 mc2", + "BB_SIGNATURE_HANDLER" : "basic" + } + cmd = ["bitbake", "b1", "mc:mc1:b1", "mc:mc2:b1"] + setscenetasks = ['package_write_ipk_setscene', 'package_write_rpm_setscene', 'packagedata_setscene', + 'populate_sysroot_setscene', 'package_qa_setscene'] + sstatevalid = "" + tasks = self.run_bitbakecmd(cmd, tempdir, sstatevalid, extraenv=extraenv) + expected = ['a1:' + x for x in self.alltasks] + ['b1:' + x for x in self.alltasks] + \ + ['mc1:b1:' + x for x in setscenetasks] + ['mc1:a1:' + x for x in setscenetasks] + \ + ['mc2:b1:' + x for x in setscenetasks] + ['mc2:a1:' + x for x in setscenetasks] + \ + ['mc1:b1:build', 'mc2:b1:build'] + for x in ['mc1:a1:package_qa_setscene', 'mc2:a1:package_qa_setscene', 'a1:build', 'a1:package_qa']: + expected.remove(x) + self.assertEqual(set(tasks), set(expected)) +
Signature · 1 line
2.20.1
PATCH 7/7 tests/runqueue: Allow common sstate tasks to become valid
In reply to Richard PurdieAs the logic in bitbake improves, the logic in the tests needs to as well.
Afer we built a task for the first time, allow its setscene hash verification status to change, mirroring what would happen in a multiconfig build.
--- lib/bb/tests/runqueue-tests/classes/base.bbclass | 6 ++++++ 1 file changed, 6 insertions(+)
lib/bb/tests/runqueue-tests/classes/base.bbclass +6 -0
@@ -5,6 +5,9 @@ def stamptask(d): import time thistask = d.expand("${PN}:${BB_CURRENTTASK}") + with open(d.expand("${TOPDIR}/%s.run") % thistask, "a+") as f: + f.write("\n") + if d.getVar("BB_CURRENT_MC") != "default": thistask = d.expand("${BB_CURRENT_MC}:${PN}:${BB_CURRENTTASK}") if thistask in d.getVar("SLOWTASKS").split():
@@ -225,6 +228,9 @@ def sstate_checkhashes(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=False, *, if n in valid: bb.note("SState: Found valid sstate for %s" % n) ret.append(task) + elif os.path.exists(d.expand("${TOPDIR}/%s.run" % n.replace("do_", ""))): + bb.note("SState: Found valid sstate for %s (already run)" % n) + ret.append(task) else: missed.append(task) bb.note("SState: Found no valid sstate for %s" % n)
Signature · 1 line
2.20.1