All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Michael Opdenacker <michael.opdenacker@bootlin.com>,
	docs@lists.yoctoproject.org
Subject: Re: [docs] [PATCH] overview-manual: add details about hash equivalence
Date: Fri, 07 Jan 2022 11:11:17 +0000	[thread overview]
Message-ID: <0d8e444ff5127484ecde2e04a7ef3b67d4b449c9.camel@linuxfoundation.org> (raw)
In-Reply-To: <20211217171859.54664-1-michael.opdenacker@bootlin.com>

On Fri, 2021-12-17 at 18:18 +0100, Michael Opdenacker wrote:
> In particular, mention the different hashes which are
> managed in Hash Equivalence mode: task hash, output hash and unihash.
> 
> Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
> ---
>  documentation/overview-manual/concepts.rst | 97 +++++++++++++++++-----
>  1 file changed, 76 insertions(+), 21 deletions(-)
> 
> diff --git a/documentation/overview-manual/concepts.rst b/documentation/overview-manual/concepts.rst
> index 2d3d6f8040..2df5011ef6 100644
> --- a/documentation/overview-manual/concepts.rst
> +++ b/documentation/overview-manual/concepts.rst
> @@ -1942,19 +1942,60 @@ Hash Equivalence
>  ----------------
>  
>  The above section explained how BitBake skips the execution of tasks
> -which output can already be found in the Shared State Cache.
> +which output can already be found in the Shared State cache.
>  
>  During a build, it may often be the case that the output / result of a task might
>  be unchanged despite changes in the task's input values. An example might be
>  whitespace changes in some input C code. In project terms, this is what we define
> -as "equivalence". We can create a hash / checksum which represents a task and two
> -input task hashes are said to be equivalent if the hash of the generated output
> -(as stored / restored by sstate) is the same.
> -
> -Once bitbake knows that two input hashes for a task have equivalent output,
> -this has important and useful implications for all tasks depending on this task.
> -
> -Thanks to this equivalence, a change in one of the tasks in BitBake's run queue
> +as "equivalence".
> +
> +To keep track of such equivalence, BitBake has to manage three hashes
> +for each task:
> +
> +- The *task hash* explained earlier: computed from the recipe metadata,
> +  the task code and the task hash veported to be different, BitBake will update
+the task's unihash, causing the task hash of depending tasks to be
> +modified too, and making such tasks ralues from its dependencies.
> +  When changes are made, these task hashes are therefore modified,
> +  causing the task to re-execute. The task hashes of tasks depending on this
> +  task are therefore modified too, causing the whole dependency
> +  chain to re-execute.
> +
> +- The *output hash*, a new hash computed from the output of Shared State tasks,
> +  tasks that save their resulting output to a Shared State tarball.
> +  The mapping between the task hash and its output hash is reported
> +  to a new *Hash Equivalence* server. This mapping is stored in a database
> +  by the server for future reference.
> +
> +- The *unihash*, a new hash, initially set to the task hash for the task.
> +  This is used to track the *unicity* of task output, and we will explain
> +  how its value is maintained.
> +
> +When Hash Equivalence is enabled, BitBake computes the task hash
> +for each task by using the unihash of its dependencies, instead
> +of their task hash.
> +
> +Now, imagine that a Shared State task is modified because of a change in
> +its code or metadata, or because of a change in its dependencies.
> +Since this modifies its task hash, this task will need re-executing.
> +Its output hash will therefore be computed again.
> +
> +Then, the new mapping between the new task hash and its output hash
> +will be reported to the Hash Equivalence server. The server will
> +let BitBake know whether this output hash is the same as a previously
> +reported output hash, for a different task hash.
> +
> +If the output hash is reported to be different, BitBake will update
> +the task's unihash, causing the task hash of depending tasks to be
> +modified too, and making such tasks re-execute. This change is
> +propagating to the depending tasks.
>
> +On the contrary, if the output hash is reported to be identical
> +to the previously recorded output hash, BitBake will keep the
> +task's unihash unmodified. Thanks to this, the depending tasks
> +will keep the same task hash, and won't need re-executing. The
> +change is not propagating to the depending tasks.
> 

These paragraphs are reversed and this is an important detail to get right. The
output hash is always computed for a task that runs and the output hash is
queried on the hash equivalence server.

If the output hash is known, the unihash is updated to match the original input
hash that generated that output. If the output hash is unknown, a new entry is
created on the hash equivalence server matching that task hash to that output.

The unihash would therefore be unchanged for a new output hash and would update
if the output hash matched some other value already there.

Cheers,

Richard



  reply	other threads:[~2022-01-07 11:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-17 17:18 [PATCH] overview-manual: add details about hash equivalence Michael Opdenacker
2022-01-07 11:11 ` Richard Purdie [this message]
2022-01-07 18:55   ` [docs] " Michael Opdenacker
     [not found] <16C19A718ADC2220.17299@lists.yoctoproject.org>
2021-12-17 17:21 ` Michael Opdenacker
     [not found] ` <16C19A96C9FA3638.23092@lists.yoctoproject.org>
2022-01-03 15:17   ` Michael Opdenacker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d8e444ff5127484ecde2e04a7ef3b67d4b449c9.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=docs@lists.yoctoproject.org \
    --cc=michael.opdenacker@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.