Skip to contentSkip to conversation

runqueue: Optimise taskname lookups in next_buildable_task

PATCH In review Richard Purdie 1 participant 3 messages Feb 10, 2024 – Feb 11, 2024 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 runqueue: Optimise taskname lookups in next_buildable_task

A quick profile of bitbake world showed 147 million calls to taskname_from_tid(). The next_buildable_task function is performance senstive so move the call inside the if block to reduce the number of calls and speed the code up.

---
 lib/bb/runqueue.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/runqueue.py +3 -3
index c8392346a8..95cab5132f 100644
@@ -270,11 +270,11 @@ class RunQueueScheduler(object):
         best = None
         bestprio = None
         for tid in buildable:
-            taskname = taskname_from_tid(tid)
-            if taskname in skip_buildable and skip_buildable[taskname] >= int(self.skip_maxthread[taskname]):
-                continue
             prio = self.rev_prio_map[tid]
             if bestprio is None or bestprio > prio:
+                taskname = taskname_from_tid(tid)
+                if taskname in skip_buildable and skip_buildable[taskname] >= int(self.skip_maxthread[taskname]):
+                    continue
                 stamp = self.stamps[tid]
                 if stamp in self.rq.build_stamps.values():
                     continue
Signature · 1 line
2.40.1
#1 lore raw

PATCH 2/2 runqueue: Optimise performance of setscene task execution

"time bitbake world -n" shows a lot of time being spent trying to execute the setscene tasks when many of them are being skipped due to not being present.

The challenge is the "return True" back into the mainloop restarts the search back at the start of the task list particularly when there are large numbers of deferred tasks due to hard dependencies.

In this case we can use continue to continue within the list at the expense of not returning so quickly to loop back through the main loop. This does significantly improve performance in real world usage scenarios and we can probably afford the potential loop starvation.

Thanks for the suggestion from Alexander Kanavin.

---
 lib/bb/runqueue.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/runqueue.py +3 -1
index 95cab5132f..85669b80ee 100644
@@ -2204,7 +2204,9 @@ class RunQueueExecute:
                     if nexttask in self.sqdata.outrightfail:
                         logger.debug2('No package found, so skipping setscene task %s', nexttask)
                         self.sq_task_failoutright(nexttask)
-                        return True
+                        # Technically we should return True here but that would then start the task list back at the start
+                        # which is really bad for performance ("time bitbake world -n"). Instead, keep our place in the tasklist.
+                        continue
                     if nexttask in self.sqdata.unskippable:
                         logger.debug2("Setscene task %s is unskippable" % nexttask)
                     task = nexttask
Signature · 1 line
2.40.1

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

#3 lore raw

Re: [bitbake-devel] [PATCH 2/2] runqueue: Optimise performance of setscene task execution

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

"time bitbake world -n" shows a lot of time being spent trying to execute the setscene tasks when many of them are being skipped due to not being present.

The challenge is the "return True" back into the mainloop restarts the search back at the start of the task list particularly when there are large numbers of deferred tasks due to hard dependencies.

In this case we can use continue to continue within the list at the expense of not returning so quickly to loop back through the main loop. This does significantly improve performance in real world usage scenarios and we can probably afford the potential loop starvation.

Thanks for the suggestion from Alexander Kanavin.

---
 lib/bb/runqueue.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/runqueue.py +0 -0
index 95cab5132f..85669b80ee 100644

lib/bb/runqueue.py class RunQueueExecute: · line 2212

Quoted 10 lines
lib/bb/runqueue.py +3 -1
@@ -2204,7 +2204,9 @@ class RunQueueExecute:
                     if nexttask in self.sqdata.outrightfail:
                         logger.debug2('No package found, so skipping setscene task %s', nexttask)
                         self.sq_task_failoutright(nexttask)
-                        return True
+                        # Technically we should return True here but that would then start the task list back at the start
+                        # which is really bad for performance ("time bitbake world -n"). Instead, keep our place in the tasklist.
+                        continue
                     if nexttask in self.sqdata.unskippable:
                         logger.debug2("Setscene task %s is unskippable" % nexttask)
                     task = nexttask

Sadly this doesn't work:

https://autobuilder.yoctoproject.org/typhoon/#/builders/80/builds/6354

Cheers,

Richard