[2.8][PATCH 0/8] Patch review
Please review this set of changes for 2.8/scarthgap and have comments back by end of day Tuesday, June 4
Passed a-full on autobuilder:
https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/6993
with two exceptions, the first a known reproducibility issue also present on master:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=15491
and the second is a failure on meta-agl-core, which will require an update to the ptest-runner override in meta-agl once "ptest-runner: Bump to 2.4.4 (95f528c)" merges.
The following changes since commit b5159c0373e2e7d403aed16e096ad655f38b1fa7:
fetch2/gcp: Add missing runfetchcmd import (2024-05-28 15:27:08 +0100)
are available in the Git repository at:
https://git.openembedded.org/bitbake-contrib stable/2.8-nut
https://git.openembedded.org/bitbake-contrib/log/?h=stable/2.8-nut
Joshua Watt (3):
bb: Use namedtuple for Task data
hashserv: client: Add batch stream API
siggen: Enable batching of unihash queries
Richard Purdie (4):
runqueue: Add timing warnings around slow loops
runqueue: Allow rehash loop to exit in case of interrupts
runqueue: Process unihashes in parallel at init
runqueue: Improve rehash get_unihash parallelism
joshua Watt (1):
siggen/runqueue: Report which dependencies affect the taskhash
lib/bb/__init__.py | 12 +++++ lib/bb/cooker.py | 1 - lib/bb/runqueue.py | 99 +++++++++++++++++++++++++++----------- lib/bb/siggen.py | 11 +++-- lib/hashserv/client.py | 106 +++++++++++++++++++++++++++++++++++++---- lib/hashserv/tests.py | 75 +++++++++++++++++++++++++++++ 6 files changed, 263 insertions(+), 41 deletions(-)
Signature · 1 line
2.34.1
[bitbake][scarthgap][2.8][PATCH 4/8] runqueue: Process unihashes in parallel at init
From: Richard Purdie <[email protected]>
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.
The call to the function from cooker is unneeded since that function calls prepare() and hence this functionality will already have run, so drop that obsolete call.
--- lib/bb/cooker.py | 1 - lib/bb/runqueue.py | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-)
lib/bb/cooker.py +0 -1
@@ -1459,7 +1459,6 @@ class BBCooker: if t in task or getAllTaskSignatures: try: - rq.rqdata.prepare_task_hash(tid) sig.append([pn, t, rq.rqdata.get_task_unihash(tid)]) except KeyError: sig.append(self.getTaskSignatures(target, [t])[0])
lib/bb/runqueue.py +10 -8
@@ -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.34.1
[bitbake][scarthgap][2.8][PATCH 3/8] siggen/runqueue: Report which dependencies affect the taskhash
In reply to Steve SakomanFrom: joshua Watt <[email protected]>
Report which task dependencies in BB_TASKDEPDATA are included in the taskhash. This allows tasks to identify which tasks dependencies may change without the task re-running. Knowing this information is important for tasks that want to transfer information from dependencies (such as SPDX)
--- lib/bb/runqueue.py | 8 +++++--- lib/bb/siggen.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/bb/runqueue.py +5 -3
@@ -1302,7 +1302,7 @@ class RunQueueData: return len(self.runtaskentries) def prepare_task_hash(self, tid): - bb.parse.siggen.prep_taskhash(tid, self.runtaskentries[tid].depends, self.dataCaches) + 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)
@@ -2457,7 +2457,8 @@ class RunQueueExecute: unihash = self.rqdata.runtaskentries[task].unihash deps = self.filtermcdeps(task, mc, deps) hashfn = self.rqdata.dataCaches[mc].hashfn[taskfn] - taskdepdata_cache[task] = [pn, taskname, fn, deps, provides, taskhash, unihash, hashfn] + taskhash_deps = self.rqdata.runtaskentries[task].taskhash_deps + taskdepdata_cache[task] = [pn, taskname, fn, deps, provides, taskhash, unihash, hashfn, taskhash_deps] self.taskdepdata_cache = taskdepdata_cache
@@ -2836,7 +2837,8 @@ class RunQueueExecute: taskhash = self.rqdata.runtaskentries[revdep].hash unihash = self.rqdata.runtaskentries[revdep].unihash hashfn = self.rqdata.dataCaches[mc].hashfn[taskfn] - taskdepdata[revdep] = [pn, taskname, fn, deps, provides, taskhash, unihash, hashfn] + taskhash_deps = self.rqdata.runtaskentries[revdep].taskhash_deps + taskdepdata[revdep] = [pn, taskname, fn, deps, provides, taskhash, unihash, hashfn, taskhash_deps] for revdep2 in deps: if revdep2 not in taskdepdata: additional.append(revdep2)
lib/bb/siggen.py +1 -1
@@ -381,7 +381,7 @@ class SignatureGeneratorBasic(SignatureGenerator): self.taints[tid] = taint logger.warning("%s is tainted from a forced run" % tid) - return + return set(dep for _, dep in self.runtaskdeps[tid]) def get_taskhash(self, tid, deps, dataCaches):
Signature · 1 line
2.34.1
[bitbake][scarthgap][2.8][PATCH 2/8] runqueue: Allow rehash loop to exit in case of interrupts
In reply to Steve SakomanFrom: Richard Purdie <[email protected]>
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
@@ -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()
@@ -2601,6 +2602,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.34.1
[bitbake][scarthgap][2.8][PATCH 1/8] runqueue: Add timing warnings around slow loops
In reply to Steve SakomanFrom: Richard Purdie <[email protected]>
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
@@ -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()
@@ -2556,6 +2567,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()
@@ -2588,6 +2602,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.34.1
[bitbake][scarthgap][2.8][PATCH 7/8] hashserv: client: Add batch stream API
In reply to Steve SakomanFrom: Joshua Watt <[email protected]>
Changes the stream mode to do "batch" processing. This means that the sending and reciving of messages is done simultaneously so that messages can be sent as fast as possible without having to wait for each reply. This allows multiple messages to be in flight at once, reducing the effect of the round trip latency from the server.
--- lib/hashserv/client.py | 106 +++++++++++++++++++++++++++++++++++++---- lib/hashserv/tests.py | 75 +++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 9 deletions(-)
lib/hashserv/client.py +97 -9
@@ -5,6 +5,7 @@ import logging import socket +import asyncio import bb.asyncrpc import json from . import create_async_client
@@ -13,6 +14,66 @@ from . import create_async_client logger = logging.getLogger("hashserv.client") +class Batch(object): + def __init__(self): + self.done = False + self.cond = asyncio.Condition() + self.pending = [] + self.results = [] + self.sent_count = 0 + + async def recv(self, socket): + while True: + async with self.cond: + await self.cond.wait_for(lambda: self.pending or self.done) + + if not self.pending: + if self.done: + return + continue + + r = await socket.recv() + self.results.append(r) + + async with self.cond: + self.pending.pop(0) + + async def send(self, socket, msgs): + try: + # In the event of a restart due to a reconnect, all in-flight + # messages need to be resent first to keep to result count in sync + for m in self.pending: + await socket.send(m) + + for m in msgs: + # Add the message to the pending list before attempting to send + # it so that if the send fails it will be retried + async with self.cond: + self.pending.append(m) + self.cond.notify() + self.sent_count += 1 + + await socket.send(m) + + finally: + async with self.cond: + self.done = True + self.cond.notify() + + async def process(self, socket, msgs): + await asyncio.gather( + self.recv(socket), + self.send(socket, msgs), + ) + + if len(self.results) != self.sent_count: + raise ValueError( + f"Expected result count {len(self.results)}. Expected {self.sent_count}" + ) + + return self.results + + class AsyncClient(bb.asyncrpc.AsyncClient): MODE_NORMAL = 0 MODE_GET_STREAM = 1
@@ -36,11 +97,27 @@ class AsyncClient(bb.asyncrpc.AsyncClient): if become: await self.become_user(become) - async def send_stream(self, mode, msg): + async def send_stream_batch(self, mode, msgs): + """ + Does a "batch" process of stream messages. This sends the query + messages as fast as possible, and simultaneously attempts to read the + messages back. This helps to mitigate the effects of latency to the + hash equivalence server be allowing multiple queries to be "in-flight" + at once + + The implementation does more complicated tracking using a count of sent + messages so that `msgs` can be a generator function (i.e. its length is + unknown) + + """ + + b = Batch() + async def proc(): + nonlocal b + await self._set_mode(mode) - await self.socket.send(msg) - return await self.socket.recv() + return await b.process(self.socket, msgs) return await self._send_wrapper(proc)
@@ -89,10 +166,15 @@ class AsyncClient(bb.asyncrpc.AsyncClient): self.mode = new_mode async def get_unihash(self, method, taskhash): - r = await self.send_stream(self.MODE_GET_STREAM, "%s %s" % (method, taskhash)) - if not r: - return None - return r + r = await self.get_unihash_batch([(method, taskhash)]) + return r[0] + + async def get_unihash_batch(self, args): + result = await self.send_stream_batch( + self.MODE_GET_STREAM, + (f"{method} {taskhash}" for method, taskhash in args), + ) + return [r if r else None for r in result] async def report_unihash(self, taskhash, method, outhash, unihash, extra={}): m = extra.copy()
@@ -115,8 +197,12 @@ class AsyncClient(bb.asyncrpc.AsyncClient): ) async def unihash_exists(self, unihash): - r = await self.send_stream(self.MODE_EXIST_STREAM, unihash) - return r == "true" + r = await self.unihash_exists_batch([unihash]) + return r[0] + + async def unihash_exists_batch(self, unihashes): + result = await self.send_stream_batch(self.MODE_EXIST_STREAM, unihashes) + return [r == "true" for r in result] async def get_outhash(self, method, outhash, taskhash, with_unihash=True): return await self.invoke(
@@ -237,10 +323,12 @@ class Client(bb.asyncrpc.Client): "connect_tcp", "connect_websocket", "get_unihash", + "get_unihash_batch", "report_unihash", "report_unihash_equiv", "get_taskhash", "unihash_exists", + "unihash_exists_batch", "get_outhash", "get_stats", "reset_stats",
lib/hashserv/tests.py +75 -0
87 lines not on this page · raw message
Signature · 1 line
2.34.1
[bitbake][scarthgap][2.8][PATCH 5/8] runqueue: Improve rehash get_unihash parallelism
In reply to Steve SakomanFrom: Richard Purdie <[email protected]>
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
@@ -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.34.1
[bitbake][scarthgap][2.8][PATCH 8/8] siggen: Enable batching of unihash queries
In reply to Steve SakomanFrom: Joshua Watt <[email protected]>
Uses the batching API of the client to reduce the effect of latency when making multiple queries to the server
--- lib/bb/siggen.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
lib/bb/siggen.py +6 -3
@@ -726,10 +726,13 @@ class SignatureGeneratorUniHashMixIn(object): return result if self.max_parallel <= 1 or len(queries) <= 1: - # No parallelism required. Make the query serially with the single client + # No parallelism required. Make the query using a single client with self.client() as client: - for tid, args in queries.items(): - query_result[tid] = client.get_unihash(*args) + keys = list(queries.keys()) + unihashes = client.get_unihash_batch(queries[k] for k in keys) + + for idx, k in enumerate(keys): + query_result[k] = unihashes[idx] else: with self.client_pool() as client_pool: query_result = client_pool.get_unihashes(queries)
Signature · 1 line
2.34.1
[bitbake][scarthgap][2.8][PATCH 6/8] bb: Use namedtuple for Task data
In reply to Steve SakomanFrom: Joshua Watt <[email protected]>
Task dependency data is becoming unwieldy with the number of indices it contains. Convert it to use a named tuple instead, which allows members to be indexed by a named property or an index (which allows it to retain backward compatibility).
--- lib/bb/__init__.py | 12 ++++++++++++ lib/bb/runqueue.py | 45 +++++++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 18 deletions(-)
lib/bb/__init__.py +12 -0
@@ -36,6 +36,7 @@ class BBHandledException(Exception): import os import logging +from collections import namedtuple class NullHandler(logging.Handler):
@@ -227,3 +228,14 @@ def deprecate_import(current, modulename, fromlist, renames = None): setattr(sys.modules[current], newname, newobj) +TaskData = namedtuple("TaskData", [ + "pn", + "taskname", + "fn", + "deps", + "provides", + "taskhash", + "unihash", + "hashfn", + "taskhash_deps", +])
lib/bb/runqueue.py +27 -18
65 lines not on this page · raw message
Signature · 1 line
2.34.1