Skip to contentSkip to conversation

siggen/runqueue: Store whether the hash was present on the hashserver or not

PATCH In review Richard Purdie 1 participant 7 messages May 24, 2024 – May 28, 2024 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 siggen/runqueue: Store whether the hash was present on the hashserver or not

We need to be able to know if a unihash came from the hashequivalence server or not. Add this information to the cache data so we can use it in later code changes.

---
 lib/bb/runqueue.py |  2 +-
 lib/bb/siggen.py   | 32 ++++++++++++++++----------------
 2 files changed, 17 insertions(+), 17 deletions(-)
lib/bb/runqueue.py +1 -1
index 6b43f303d5..6c2034176e 100644
@@ -2530,7 +2530,7 @@ class RunQueueExecute:
                 for hashtid in torehash:
                     hashequiv_logger.verbose("Task %s unihash changed to %s" % (hashtid, unihash))
                     self.rqdata.runtaskentries[hashtid].unihash = unihash
-                    bb.parse.siggen.set_unihash(hashtid, unihash)
+                    bb.parse.siggen.set_unihash(hashtid, unihash, True)
                     toprocess.add(hashtid)
                 if torehash:
                     # Need to save after set_unihash above
lib/bb/siggen.py +16 -16
index 03dfda6f3c..e8fe806c36 100644
@@ -80,7 +80,7 @@ class SignatureGenerator(object):
         self.runtaskdeps = {}
         self.file_checksum_values = {}
         self.taints = {}
-        self.unitaskhashes = {}
+        self.hashserv_cache = {}
         self.tidtopn = {}
         self.setscenetasks = set()
 
@@ -184,19 +184,19 @@ class SignatureGenerator(object):
         return
 
     def get_taskdata(self):
-        return (self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes, self.tidtopn, self.setscenetasks)
+        return (self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.hashserv_cache, self.tidtopn, self.setscenetasks)
 
     def set_taskdata(self, data):
-        self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes, self.tidtopn, self.setscenetasks = data
+        self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.hashserv_cache, self.tidtopn, self.setscenetasks = data
 
     def reset(self, data):
         self.__init__(data)
 
     def get_taskhashes(self):
-        return self.taskhash, self.unihash, self.unitaskhashes, self.tidtopn
+        return self.taskhash, self.unihash, self.hashserv_cache, self.tidtopn
 
     def set_taskhashes(self, hashes):
-        self.taskhash, self.unihash, self.unitaskhashes, self.tidtopn = hashes
+        self.taskhash, self.unihash, self.hashserv_cache, self.tidtopn = hashes
 
     def save_unitaskhashes(self):
         return
@@ -238,8 +238,8 @@ class SignatureGeneratorBasic(SignatureGenerator):
         else:
             self.checksum_cache = None
 
-        self.unihash_cache = bb.cache.SimpleCache("3")
-        self.unitaskhashes = self.unihash_cache.init_cache(data, "bb_unihashes.dat", {})
+        self.unihash_cache = bb.cache.SimpleCache("4")
+        self.hashserv_cache = self.unihash_cache.init_cache(data, "bb_unihashes.dat", {})
         self.localdirsexclude = (data.getVar("BB_SIGNATURE_LOCAL_DIRS_EXCLUDE") or "CVS .bzr .git .hg .osc .p4 .repo .svn").split()
         self.tidtopn = {}
 
@@ -416,7 +416,7 @@ class SignatureGeneratorBasic(SignatureGenerator):
             bb.fetch2.fetcher_parse_done()
 
     def save_unitaskhashes(self):
-        self.unihash_cache.save(self.unitaskhashes)
+        self.unihash_cache.save(self.hashserv_cache)
 
     def copy_unitaskhashes(self, targetdir):
         self.unihash_cache.copyfile(targetdir)
@@ -630,10 +630,10 @@ class SignatureGeneratorUniHashMixIn(object):
 
         return super().get_stampfile_hash(tid)
 
-    def set_unihash(self, tid, unihash):
+    def set_unihash(self, tid, unihash, present):
         (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid)
         key = mc + ":" + self.tidtopn[tid] + ":" + taskname
-        self.unitaskhashes[key] = (self.taskhash[tid], unihash)
+        self.hashserv_cache[key] = (self.taskhash[tid], unihash, present)
         self.unihash[tid] = unihash
 
     def _get_unihash(self, tid, checkkey=None):
@@ -641,11 +641,11 @@ class SignatureGeneratorUniHashMixIn(object):
             return None
         (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid)
         key = mc + ":" + self.tidtopn[tid] + ":" + taskname
-        if key not in self.unitaskhashes:
+        if key not in self.hashserv_cache:
             return None
         if not checkkey:
             checkkey = self.taskhash[tid]
-        (key, unihash) = self.unitaskhashes[key]
+        (key, unihash, present) = self.hashserv_cache[key]
         if key != checkkey:
             return None
         return unihash
@@ -754,12 +754,12 @@ class SignatureGeneratorUniHashMixIn(object):
                 # so it is reported it at debug level 2. If they differ, that
                 # is much more interesting, so it is reported at debug level 1
                 hashequiv_logger.bbdebug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server))
+                self.set_unihash(tid, unihash, True)
             else:
                 hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server))
                 unihash = taskhash
+                self.set_unihash(tid, unihash, False)
 
-
-            self.set_unihash(tid, unihash)
             self.unihash[tid] = unihash
             result[tid] = unihash
 
@@ -835,7 +835,7 @@ class SignatureGeneratorUniHashMixIn(object):
                 if new_unihash != unihash:
                     hashequiv_logger.debug('Task %s unihash changed %s -> %s by server %s' % (taskhash, unihash, new_unihash, self.server))
                     bb.event.fire(bb.runqueue.taskUniHashUpdate(mcfn + ':do_' + task, new_unihash), d)
-                    self.set_unihash(tid, new_unihash)
+                    self.set_unihash(tid, new_unihash, True)
                     d.setVar('BB_UNIHASH', new_unihash)
                 else:
                     hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server))
@@ -875,7 +875,7 @@ class SignatureGeneratorUniHashMixIn(object):
                 hashequiv_logger.verbose('Task %s unihash %s unchanged by server' % (tid, finalunihash))
             elif finalunihash == wanted_unihash:
                 hashequiv_logger.verbose('Task %s unihash changed %s -> %s as wanted' % (tid, current_unihash, finalunihash))
-                self.set_unihash(tid, finalunihash)
+                self.set_unihash(tid, finalunihash, True)
                 return True
             else:
                 # TODO: What to do here?
Signature · 1 line
2.40.1
#1 lore raw

PATCH 2/6 runqueue: Add timing warnings around slow loops

With hashserve enabled, there are two slow paths/loops, one at initial runqueue generation and also during the rehash process when new outhashes are found.

Add timing information at the hashserve log level for when these loops take longer than 30s or 60s overall. This will leave evidence in the logs when things are running particularly slowly.

---
 lib/bb/runqueue.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
lib/bb/runqueue.py +22 -0
index 6c2034176e..b0375fcb36 100644
@@ -1273,6 +1273,9 @@ class RunQueueData:
 
         bb.parse.siggen.set_setscene_tasks(self.runq_setscene_tids)
 
+        starttime = time.time()
+        lasttime = starttime
+
         # Iterate over the task list and call into the siggen code
         dealtwith = set()
         todeal = set(self.runtaskentries)
@@ -1284,6 +1287,14 @@ class RunQueueData:
                     self.prepare_task_hash(tid)
                 bb.event.check_for_interrupts(self.cooker.data)
 
+            if time.time() > (lasttime + 30):
+                lasttime = time.time()
+                hashequiv_logger.verbose("Initial setup loop progress: %s of %s in %s" % (len(todeal), len(self.runtaskentries), lasttime - starttime))
+
+        endtime = time.time()
+        if (endtime-starttime > 60):
+            hashequiv_logger.verbose("Initial setup loop took: %s" % (endtime-starttime))
+
         bb.parse.siggen.writeout_file_checksum_cache()
 
         #self.dump_data()
@@ -2557,6 +2568,9 @@ class RunQueueExecute:
             elif self.rqdata.runtaskentries[p].depends.isdisjoint(total):
                 next.add(p)
 
+        starttime = time.time()
+        lasttime = starttime
+
         # When an item doesn't have dependencies in total, we can process it. Drop items from total when handled
         while next:
             current = next.copy()
@@ -2589,6 +2603,14 @@ class RunQueueExecute:
                 total.remove(tid)
                 next.intersection_update(total)
 
+                if time.time() > (lasttime + 30):
+                    lasttime = time.time()
+                    hashequiv_logger.verbose("Rehash loop slow progress: %s in %s" % (len(total), lasttime - starttime))
+
+        endtime = time.time()
+        if (endtime-starttime > 60):
+            hashequiv_logger.verbose("Rehash loop took more than 60s: %s" % (endtime-starttime))
+
         if changed:
             for mc in self.rq.worker:
                 RunQueue.send_pickled_data(self.rq.worker[mc].process, bb.parse.siggen.get_taskhashes(), "newtaskhashes")
Signature · 1 line
2.40.1
#2 lore raw

PATCH 3/6 runqueue: Allow rehash loop to exit in case of interrupts

In reply to Richard Purdie

The initial hash serve loop exits in the case where interrupts are present but probably checks a bit too often. Tweak that and also allow the slow rehash loop to break on interrupt, improving bitbake Ctrl+C response.

---
 lib/bb/runqueue.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/runqueue.py +3 -1
index b0375fcb36..586b11da2d 100644
@@ -1285,7 +1285,8 @@ class RunQueueData:
                     dealtwith.add(tid)
                     todeal.remove(tid)
                     self.prepare_task_hash(tid)
-                bb.event.check_for_interrupts(self.cooker.data)
+
+            bb.event.check_for_interrupts(self.cooker.data)
 
             if time.time() > (lasttime + 30):
                 lasttime = time.time()
@@ -2602,6 +2603,7 @@ class RunQueueExecute:
                 next |= self.rqdata.runtaskentries[tid].revdeps
                 total.remove(tid)
                 next.intersection_update(total)
+                bb.event.check_for_interrupts(self.cooker.data)
 
                 if time.time() > (lasttime + 30):
                     lasttime = time.time()
Signature · 1 line
2.40.1
#3 lore raw

PATCH 4/6 runqueue: Process unihashes in parallel at init

In reply to Richard Purdie

Improve the runqueue init code to call unihash queries in parallel since this is faster and more efficient, particularly on slower links with longer round trip times.

---
 lib/bb/runqueue.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/bb/runqueue.py +10 -8
index 586b11da2d..411c47eff9 100644
@@ -1280,11 +1280,18 @@ class RunQueueData:
         dealtwith = set()
         todeal = set(self.runtaskentries)
         while todeal:
+            ready = set()
             for tid in todeal.copy():
                 if not (self.runtaskentries[tid].depends - dealtwith):
-                    dealtwith.add(tid)
-                    todeal.remove(tid)
-                    self.prepare_task_hash(tid)
+                    self.runtaskentries[tid].taskhash_deps = bb.parse.siggen.prep_taskhash(tid, self.runtaskentries[tid].depends, self.dataCaches)
+                    # get_taskhash for a given tid *must* be called before get_unihash* below
+                    self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, self.runtaskentries[tid].depends, self.dataCaches)
+                    ready.add(tid)
+            unihashes = bb.parse.siggen.get_unihashes(ready)
+            for tid in ready:
+                dealtwith.add(tid)
+                todeal.remove(tid)
+                self.runtaskentries[tid].unihash = unihashes[tid]
 
             bb.event.check_for_interrupts(self.cooker.data)
 
@@ -1301,11 +1308,6 @@ class RunQueueData:
         #self.dump_data()
         return len(self.runtaskentries)
 
-    def prepare_task_hash(self, tid):
-        self.runtaskentries[tid].taskhash_deps = bb.parse.siggen.prep_taskhash(tid, self.runtaskentries[tid].depends, self.dataCaches)
-        self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, self.runtaskentries[tid].depends, self.dataCaches)
-        self.runtaskentries[tid].unihash = bb.parse.siggen.get_unihash(tid)
-
     def dump_data(self):
         """
         Dump some debug information on the internal data structures
Signature · 1 line
2.40.1
#4 lore raw

PATCH 5/6 runqueue: Improve rehash get_unihash parallelism

In reply to Richard Purdie

Improve the rehash code to query unihashes in parallel since this is more efficient on slower links.

---
 lib/bb/runqueue.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
lib/bb/runqueue.py +10 -2
index 411c47eff9..5626ffcccb 100644
@@ -2578,13 +2578,21 @@ class RunQueueExecute:
         while next:
             current = next.copy()
             next = set()
+            ready = {}
             for tid in current:
                 if self.rqdata.runtaskentries[p].depends and not self.rqdata.runtaskentries[tid].depends.isdisjoint(total):
                     continue
+                # get_taskhash for a given tid *must* be called before get_unihash* below
+                ready[tid] = bb.parse.siggen.get_taskhash(tid, self.rqdata.runtaskentries[tid].depends, self.rqdata.dataCaches)
+
+            unihashes = bb.parse.siggen.get_unihashes(ready.keys())
+
+            for tid in ready:
                 orighash = self.rqdata.runtaskentries[tid].hash
-                newhash = bb.parse.siggen.get_taskhash(tid, self.rqdata.runtaskentries[tid].depends, self.rqdata.dataCaches)
+                newhash = ready[tid]
                 origuni = self.rqdata.runtaskentries[tid].unihash
-                newuni = bb.parse.siggen.get_unihash(tid)
+                newuni = unihashes[tid]
+
                 # FIXME, need to check it can come from sstate at all for determinism?
                 remapped = False
                 if newuni == origuni:
Signature · 1 line
2.40.1
#5 lore raw

PATCH 6/6 siggen/runqueue: Allow skipping of rehash if not present on hashserve

In reply to Richard Purdie

If a unihash isn't present on the hashserver, it is extremely unlikely any following unihashes would be either. Use this information to skip unihash checks in that scenario where there is low matching to allow the build to proceed more quickly. This significantly improves performance on the low match scenario.

---
 lib/bb/runqueue.py | 35 ++++++++++++++++++++++++++----
 lib/bb/siggen.py   | 54 +++++++++++++++++++++++++---------------------
 2 files changed, 61 insertions(+), 28 deletions(-)
lib/bb/runqueue.py +31 -4
index 5626ffcccb..0fb9edc77e 100644
@@ -472,6 +472,7 @@ class RunQueueData:
         self.reset()
 
     def reset(self):
+        self.hashserve_valid = set()
         self.runtaskentries = {}
 
     def runq_depends_names(self, ids):
@@ -1287,11 +1288,23 @@ class RunQueueData:
                     # get_taskhash for a given tid *must* be called before get_unihash* below
                     self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(tid, self.runtaskentries[tid].depends, self.dataCaches)
                     ready.add(tid)
-            unihashes = bb.parse.siggen.get_unihashes(ready)
+
+            ready2 = set()
+            for tid in ready:
+                if self.runtaskentries[tid].depends.issubset(self.hashserve_valid):
+                    ready2.add(tid)
+            unihashes = bb.parse.siggen.get_unihashes(ready2)
             for tid in ready:
                 dealtwith.add(tid)
                 todeal.remove(tid)
-                self.runtaskentries[tid].unihash = unihashes[tid]
+                if tid in unihashes:
+                    self.runtaskentries[tid].unihash, present = unihashes[tid]
+                    if present:
+                        self.hashserve_valid.add(tid)
+                else:
+                    taskhash = self.runtaskentries[tid].hash
+                    bb.parse.siggen.set_unihash(tid, taskhash, False)
+                    self.runtaskentries[tid].unihash = taskhash
 
             bb.event.check_for_interrupts(self.cooker.data)
 
@@ -2585,13 +2598,25 @@ class RunQueueExecute:
                 # get_taskhash for a given tid *must* be called before get_unihash* below
                 ready[tid] = bb.parse.siggen.get_taskhash(tid, self.rqdata.runtaskentries[tid].depends, self.rqdata.dataCaches)
 
-            unihashes = bb.parse.siggen.get_unihashes(ready.keys())
+            toquery = set()
+            for tid in ready:
+                if self.rqdata.runtaskentries[tid].depends.issubset(self.rqdata.hashserve_valid):
+                    toquery.add(tid)
+
+            unihashes = bb.parse.siggen.get_unihashes(toquery)
 
             for tid in ready:
                 orighash = self.rqdata.runtaskentries[tid].hash
                 newhash = ready[tid]
                 origuni = self.rqdata.runtaskentries[tid].unihash
-                newuni = unihashes[tid]
+
+                if tid in unihashes:
+                    newuni, present = unihashes[tid]
+                    if present:
+                        self.rqdata.hashserve_valid.add(tid)
+                else:
+                    bb.parse.siggen.set_unihash(tid, origuni, False)
+                    newuni = origuni
 
                 # FIXME, need to check it can come from sstate at all for determinism?
                 remapped = False
@@ -2623,6 +2648,8 @@ class RunQueueExecute:
         if (endtime-starttime > 60):
             hashequiv_logger.verbose("Rehash loop took more than 60s: %s" % (endtime-starttime))
 
+        bb.parse.siggen.save_unitaskhashes()
+
         if changed:
             for mc in self.rq.worker:
                 RunQueue.send_pickled_data(self.rq.worker[mc].process, bb.parse.siggen.get_taskhashes(), "newtaskhashes")
lib/bb/siggen.py +30 -24

124 lines not on this page · raw message

Signature · 1 line
2.40.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [bitbake-devel] [PATCH 6/6] siggen/runqueue: Allow skipping of rehash if not present on hashserve

Quoted 11 lines · Richard Purdie via lists.openembedded.org

If a unihash isn't present on the hashserver, it is extremely unlikely any following unihashes would be either. Use this information to skip unihash checks in that scenario where there is low matching to allow the build to proceed more quickly. This significantly improves performance on the low match scenario.

---
 lib/bb/runqueue.py | 35 ++++++++++++++++++++++++++---- lib/bb/siggen.py   | 54 +++++++++++++++++++++++++---------------------

 2 files changed, 61 insertions(+), 28 deletions(-)

This patch isn't stable and there are also what looks like problems in the hashserve client parallel code with connection closed errors.

I'm going to split the series, trying to get the basic bits working with MAX_PARALLEL=1 then look at the parallel queries and the skips separately.

I will note the performance impact of these problems on the testing infrastructure is dire but only really visible when the logging patch in this series is applied.

Cheers,

Richard