Skip to contentSkip to conversation

runqueue task race debugging notes

DISCUSSION Richard Purdie 1 participant 1 message Mar 6, 2021

lore
Share & tools
lore
#0 lore raw

Hi All,

I wanted to write down a few notes about debugging the weird kernel do_shared_workdir issue Steve and I have been chasing after seeing it occasionally in master and dunfell. Sending it publicly so there is a record and someone may find it interesting.

The symptom of the bug is that linux-yocto:do_compile_kernelmodules gets run, as does make-mod-scripts:do_configure yet linux-yocto:do_shared_workdir does not. There are very clear dependencies between the tasks so the question is why the dependencies are "ignored".

In runqueue there are effectively two dependency trees, "setscene" dependencies and normal task dependencies. The setscene dependencies are run first and can "cover" normal tasks meaning they don't need to run. For added fun, hash-equivalence means that dependencies can become available during a build do the whole thing has to dynamically adapt to a changing situation, where for example "real" tasks might be running which a newly available setscene could "cover".

do_shared_workdir is an odd task in that it is a setscene task but it never has any sstate object so it is never available. Why?
http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=f5f2467e4bdd1a3fda9b443712d32502645ebe3e

Anyhow, the basic problem is how to debug why this is breaking. We do have an autobuilder test target which fails about 50% of the time. It looks very much like some kind of timing window where there is an opportunity for things to break if they happen at the right time.

I've spent several days trying to reproduce and staring at the code trying to guess what was wrong. In the end the way I found of "reproducing" signs of the problem was:

a) Change the self.holdoff_need_update = True call sites to call update_holdofftasks() directly.

The code knows that call is (was?) expensive so only runs it when needed. Running it directly helps ensure all the data structures are up to date and aids debugging. It made no difference to the bug.

b) Add debugging to update_holdofftasks() to spot a "race":

if "XXX/linux-yocto_5.10.bb:do_shared_workdir" in covered and \
        "XXX/linux-yocto_5.10.bb:do_compile_kernelmodules" not in covered:
    logger.warn("Bingo, race")
    for a in ['XXX/kernel-devsrc.bb:do_package', 'XXX/linux-yocto_5.10.bb:do_package', 
              'XXX/make-mod-scripts_1.0.bb:do_populate_sysroot', 
              'XXX/linux-yocto_5.10.bb:do_populate_sysroot', 
              'XXX/linux-yocto_5.10.bb:do_deploy',
              'XXX/make-mod-scripts_1.0.bb:do_package', 
              'XXX/build-appliance-image_15.0.0.bb:do_package']:
        if a not in covered:
             logger.warn(a

If you run that with "bitbake build-appliance-image", even on a build directory where the build had already completed, there is a small period where it prints the "Bingo, race" message.

There never should be any point where do_compile_kernelmodules can run without do_shared_workdir having run first so the fact it prints the message at all is a clear bug and would explain our race and build failure. In the real world, the task timing would have to execute at the right moment to trigger the failure.

Above, you can see more debugging I added to prove why it was breaking. I'd hacked:

sqdata.multiconfigs = set()
for tid in sqdata.sq_revdeps:
if tid == "XXX/linux-yocto_5.10.bb:do_shared_workdir":
bb.warn(str(sqdata.sq_revdeps[tid]))
sqdata.multiconfigs.add(mc_from_tid(tid))
if len(sqdata.sq_revdeps[tid]) == 0:
sqrq.sq_buildable.add(tid)

into the code which shows the setcene tasks which would have to "cover" before linux-yocto:do_shared_workdir can be covered itself. The fact it prints messages:

WARNING: Bingo, race
WARNING: XXX/make-mod-scripts_1.0.bb:do_populate_sysroot
WARNING: XXX/make-mod-scripts_1.0.bb:do_package

shows that it is not working correctly and it is the task we're seeing failures which which is promising.

The fix should be to check sqdata.sq_revdeps before marking tasks as covered. I'm working on fixes in this area although its not entirely straightforward.

Ironically, the module-base inherit and usage of KERNEL_VERSION in the build-appliance image recipe should be removed anyway, it doesn't even work properly, isn't needed and has a race of its own, the dependency on the right task is missing.

Cheers,

Richard