public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "'Felix Moessbauer' via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Cc: adriaan.schmidt@siemens.com, cedric.hombourger@siemens.com,
	Felix Moessbauer <felix.moessbauer@siemens.com>
Subject: [PATCH v2 2/2] report approximate progress during initrd generation
Date: Wed, 23 Apr 2025 14:43:59 +0200	[thread overview]
Message-ID: <20250423124359.1081781-3-felix.moessbauer@siemens.com> (raw)
In-Reply-To: <20250423124359.1081781-1-felix.moessbauer@siemens.com>

On non native architectures, the initrd generation has to be emulated.
In combination with kernels that provide many modules (like the distro
kernels), this leads to long initrd build times. To give a rough
estimation of the duration, we add progress reporting to that step.

As we always build the initrd with MODULES=most, we know from
experiments, that ~50% of the kernel modules of the rootfs are included
in the initrd. We use that number as a guesstimate, as we don't have
precise numbers when starting the task.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes/rootfs.bbclass |  6 ++++++
 meta/lib/rootfs_progress.py | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index fd6bb24a..ab30ab91 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -454,6 +454,10 @@ do_generate_initramfs[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
 python do_generate_initramfs() {
     bb.build.exec_func('rootfs_do_mounts', d)
     bb.build.exec_func('rootfs_do_qemu', d)
+
+    progress_reporter = bb.progress.ProgressHandler(d)
+    d.rootfs_progress = progress_reporter
+
     try:
         bb.build.exec_func('rootfs_generate_initramfs', d)
     finally:
@@ -468,7 +472,9 @@ rootfs_generate_initramfs[progress] = "custom:rootfs_progress.InitrdProgressHand
 rootfs_generate_initramfs() {
     if [ -n "$(sudo find '${ROOTFSDIR}/boot' -type f -name 'vmlinu[xz]*')" ]; then
         sudo -E chroot "${ROOTFSDIR}" sh -c '\
+            mods_total="$(find /usr/lib/modules -type f -name '*.ko*' | wc -l)"; \
             export kernel_version=$(basename /boot/vmlinu[xz]-* | cut -d'-' -f2-); \
+            echo "Total number of modules: $mods_total"; \
             echo "Generating initrd for kernel version: $kernel_version"; \
             update-initramfs -u -v -k "$kernel_version";'
         if [ -n "${INITRD_DEPLOY_FILE}" ]; then
diff --git a/meta/lib/rootfs_progress.py b/meta/lib/rootfs_progress.py
index f808852f..1cc70c87 100644
--- a/meta/lib/rootfs_progress.py
+++ b/meta/lib/rootfs_progress.py
@@ -28,14 +28,16 @@ class PkgsProgressHandler(bb.progress.ProgressHandler):
             self._linebuffer = self._linebuffer[breakpos:]
 
             if self._stage == 'prepare':
-                match = re.search(
-                    r'^([0-9]+) upgraded, ([0-9]+) newly installed', line)
-                if match:
-                    self._num_pkgs = int(match.group(1)) + int(match.group(2))
-                    self._stage = 'post-prepare'
+                self.process_total(line)
             else:
                 self.process_line(line)
 
+    def process_total(self, line):
+        m = re.search(r'^([0-9]+) upgraded, ([0-9]+) newly installed', line)
+        if m:
+            self._num_pkgs = int(m.group(1)) + int(m.group(2))
+            self._stage = 'post-prepare'
+
     def process_line(self, line):
         return
 
@@ -65,3 +67,24 @@ class PkgsInstallProgressHandler(PkgsProgressHandler):
 
         progress = 99 * (self._pkg + self._pkg_set_up) / (self._num_pkgs * 2)
         self._progress.update(progress)
+
+
+class InitrdProgressHandler(PkgsProgressHandler):
+    def __init__(self, d, outfile, otherargs=None):
+        super().__init__(d, outfile)
+
+    def process_total(self, line):
+        m = re.search(r'^Total number of modules: ([0-9]+)', line)
+        if m:
+            # in MODULES=most mode, we install ~half of all modules
+            self._num_pkgs = int(m.group(1)) // 2
+            self._stage = 'post-prepare'
+
+    def process_line(self, line):
+        if line.startswith('Adding module'):
+            self._pkg += 1
+        elif line.startswith('(excluding'):
+            self._pkg += len(line.split(' ')) - 1
+        else:
+            return
+        self._progress.update(99 * self._pkg / self._num_pkgs)
-- 
2.39.5

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250423124359.1081781-3-felix.moessbauer%40siemens.com.

      parent reply	other threads:[~2025-04-23 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 12:43 [PATCH v2 0/2] Significantly speedup image generation 'Felix Moessbauer' via isar-users
2025-04-23 12:43 ` [PATCH v2 1/2] delay creation of initrd until end of rootfs install 'Felix Moessbauer' via isar-users
2025-04-23 12:43 ` 'Felix Moessbauer' via isar-users [this message]

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=20250423124359.1081781-3-felix.moessbauer@siemens.com \
    --to=isar-users@googlegroups.com \
    --cc=adriaan.schmidt@siemens.com \
    --cc=cedric.hombourger@siemens.com \
    --cc=felix.moessbauer@siemens.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox