Skip to contentSkip to conversation

sstate.bbclass: track found files on mirrors with a counter

PATCH In review Jose Quaresma 2 participants 6 messages Aug 18, 2021 – Aug 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/4 sstate.bbclass: track found files on mirrors with a counter

We don't need extra python collections to count the found files on the sstate cache and sstate mirrors.
The main found collections provides all the files that were found, then we only need to count the files on sstate mirror

---
 meta/classes/sstate.bbclass | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
meta/classes/sstate.bbclass +6 -7
index 2175ace4c4..2575750247 100644
@@ -871,8 +871,6 @@ BB_HASHCHECK_FUNCTION = "sstate_checkhashes"
 
 def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True, **kwargs):
     found = set()
-    foundLocal = set()
-    foundNet = set()
     missed = set()
 
     def gethash(task):
@@ -905,12 +903,11 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
         if os.path.exists(sstatefile):
             bb.debug(2, "SState: Found valid sstate file %s" % sstatefile)
             found.add(tid)
-            foundLocal.add(tid)
-            continue
         else:
-            missed.add(tid)
             bb.debug(2, "SState: Looked for but didn't find file %s" % sstatefile)
+            missed.add(tid)
 
+    foundMirrors = 0
     mirrors = d.getVar("SSTATE_MIRRORS")
     if mirrors:
         # Copy the data object and override DL_DIR and SRC_URI
@@ -950,8 +947,9 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
                             connection_cache=thread_worker.connection_cache)
                 fetcher.checkstatus()
                 bb.debug(2, "SState: Successful fetch test for %s" % srcuri)
+                foundMirrors += 1
                 found.add(tid)
-                foundNet.add(tid)
+
                 if tid in missed:
                     missed.remove(tid)
             except:
@@ -1013,7 +1011,8 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
         match = 0
         if total:
             match = len(found) / total * 100
-        bb.plain("Sstate summary: Wanted %d Local %d Network %d Missed %d Current %d (%d%% match, %d%% complete)" % (total, len(foundLocal), len(foundNet),len(missed), currentcount, match, complete))
+        bb.plain("Sstate summary: Wanted %d Local %d Mirrors %d Missed %d Current %d (%d%% match, %d%% complete)" %
+            (total, len(found)-foundMirrors, foundMirrors, len(missed), currentcount, match, complete))
 
     if hasattr(bb.parse.siggen, "checkhashes"):
         bb.parse.siggen.checkhashes(sq_data, missed, found, d)
Signature · 1 line
2.33.0
#1 lore raw

PATCH v4 2/4 sstate.bbclass: only search on the mirrors for the missing files

On the first search we found some files on the local sstate cache. The missing files are know as well when this step finish. When we have sstate mirrors we don't need to iterate all files again because we already know what's missing.

---
 meta/classes/sstate.bbclass | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
meta/classes/sstate.bbclass +2 -7
index 2575750247..c3c145e7f3 100644
@@ -949,11 +949,8 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
                 bb.debug(2, "SState: Successful fetch test for %s" % srcuri)
                 foundMirrors += 1
                 found.add(tid)
-
-                if tid in missed:
-                    missed.remove(tid)
+                missed.remove(tid)
             except:
-                missed.add(tid)
                 bb.debug(2, "SState: Unsuccessful fetch test for %s" % srcuri)
                 pass
             if len(tasklist) >= min_tasks:
@@ -961,9 +958,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
 
         tasklist = []
         min_tasks = 100
-        for tid in sq_data['hash']:
-            if tid in found:
-                continue
+        for tid in missed:
             spec, extrapath, tname = getpathcomponents(tid, d)
             sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), tname, siginfo, d))
             tasklist.append((tid, sstatefile))
Signature · 1 line
2.33.0
#2 lore raw

PATCH v4 3/4 sstate.bbclass: get the number of threads from BB_NUMBER_THREADS

In reply to Jose Quaresma

- bitbake BB_NUMBER_THREADS uses cpu_count from oe utils that uses the python os.sched_getaffinity and it is more acurrate.

grep -nH ^BB_NUMBER_THREADS meta/conf/bitbake.conf meta/conf/bitbake.conf:806:BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"

- multiprocessing.cpu_count() returns the number of CPUs on the host, not the number of usable CPUs on the host. If the user is using scheduler affinity then the number of usable CPUs may be less, so when determining how many cores we can use check the affinity instead.

---
 meta/classes/sstate.bbclass | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
meta/classes/sstate.bbclass +2 -3
index c3c145e7f3..e86c003726 100644
@@ -964,13 +964,12 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             tasklist.append((tid, sstatefile))
 
         if tasklist:
+            nproc = min(int(d.getVar("BB_NUMBER_THREADS")), len(tasklist))
+
             if len(tasklist) >= min_tasks:
                 msg = "Checking sstate mirror object availability"
                 bb.event.fire(bb.event.ProcessStarted(msg, len(tasklist)), d)
 
-            import multiprocessing
-            nproc = min(multiprocessing.cpu_count(), len(tasklist))
-
             bb.event.enable_threadlock()
             pool = oe.utils.ThreadedPool(nproc, len(tasklist),
                     worker_init=checkstatus_init, worker_end=checkstatus_end)
Signature · 1 line
2.33.0
#3 lore raw

PATCH v4 4/4 sstate.bbclass: sstate mirror progress bar cleanup

In reply to Jose Quaresma

We only has the progress bar when we have more than 100 objects. So check for this and store the result to show the progress bar.

---
 meta/classes/sstate.bbclass | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
meta/classes/sstate.bbclass +8 -4
index e86c003726..9c19002a11 100644
@@ -953,20 +953,24 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             except:
                 bb.debug(2, "SState: Unsuccessful fetch test for %s" % srcuri)
                 pass
-            if len(tasklist) >= min_tasks:
+
+            if progress:
                 bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - thread_worker.tasks.qsize()), d)
 
         tasklist = []
-        min_tasks = 100
         for tid in missed:
             spec, extrapath, tname = getpathcomponents(tid, d)
             sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), tname, siginfo, d))
             tasklist.append((tid, sstatefile))
 
+        progress = False
+        if len(tasklist) >= 100:
+            progress = True
+
         if tasklist:
             nproc = min(int(d.getVar("BB_NUMBER_THREADS")), len(tasklist))
 
-            if len(tasklist) >= min_tasks:
+            if progress:
                 msg = "Checking sstate mirror object availability"
                 bb.event.fire(bb.event.ProcessStarted(msg, len(tasklist)), d)
 
@@ -979,7 +983,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             pool.wait_completion()
             bb.event.disable_threadlock()
 
-            if len(tasklist) >= min_tasks:
+            if progress:
                 bb.event.fire(bb.event.ProcessFinished(msg), d)
 
     inheritlist = d.getVar("INHERIT")
Signature · 1 line
2.33.0
#4 lore raw
In reply to Jose Quaresma
Quoted 9 lines · Jose Quaresma

We don't need extra python collections to count the found files on the sstate cache and sstate mirrors.
The main found collections provides all the files that were found, then we only need to count the files on sstate mirror

---
 meta/classes/sstate.bbclass | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

I'm afraid there is still some change in this series causing problems.

https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/2464

Many of the failures in that build seem to be triggered only when this patch series is applied. I thought it was the locking issue but there appears to be something else.

Cheers,

Richard

#5 lore raw

I Richard

It's not being easy to integrate this series.
In September I will take a look again.

Richard Purdie <[email protected]> escreveu no dia quinta, 19/08/2021 à(s) 10:14:

Quoted 24 lines · Jose Quaresma
Quoted 9 lines

We don't need extra python collections to count the found files on the sstate cache and sstate mirrors.
The main found collections provides all the files that were found, then we only need to count the files on sstate mirror

---
 meta/classes/sstate.bbclass | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

I'm afraid there is still some change in this series causing problems.

https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/2464

Many of the failures in that build seem to be triggered only when this patch series is applied. I thought it was the locking issue but there appears to be something else.

Cheers,

Richard

Signature · 3 lines
Best regards,

José Quaresma