Blame SOURCES/0213-Implement-boot-time-analysis-framework.patch

f96e0b
From 2fa8f0208a907ec3e59e75a5ad970739d308d286 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Tue, 19 Mar 2013 20:25:09 +0100
f96e0b
Subject: [PATCH 213/482] 	Implement boot time analysis framework.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                     |  6 +++-
f96e0b
 config.h.in                   |  1 +
f96e0b
 configure.ac                  | 19 +++++++++++++
f96e0b
 grub-core/Makefile.core.def   |  6 ++++
f96e0b
 grub-core/bus/usb/ehci.c      |  7 +++++
f96e0b
 grub-core/bus/usb/usb.c       |  9 ++++--
f96e0b
 grub-core/bus/usb/usbhub.c    | 35 +++++++++++++++++++----
f96e0b
 grub-core/commands/boottime.c | 66 +++++++++++++++++++++++++++++++++++++++++++
f96e0b
 grub-core/disk/usbms.c        |  4 +++
f96e0b
 grub-core/kern/dl.c           |  3 ++
f96e0b
 grub-core/kern/main.c         | 12 ++++++++
f96e0b
 grub-core/kern/misc.c         | 39 +++++++++++++++++++++++++
f96e0b
 grub-core/normal/main.c       | 13 +++++++++
f96e0b
 include/grub/misc.h           | 20 +++++++++++++
f96e0b
 14 files changed, 232 insertions(+), 8 deletions(-)
f96e0b
 create mode 100644 grub-core/commands/boottime.c
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index a544fbf..94dd5bb 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,6 +1,10 @@
f96e0b
 2013-03-19  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
-	remove get_endpoint_descriptor and change all functions needing
f96e0b
+	Implement boot time analysis framework.
f96e0b
+
f96e0b
+2013-03-19  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
+	Remove get_endpoint_descriptor and change all functions needing
f96e0b
 	descriptor to just receive it as argument rather than endpoint
f96e0b
 	address.
f96e0b
 
f96e0b
diff --git a/config.h.in b/config.h.in
f96e0b
index 621742c..2e1f459 100644
f96e0b
--- a/config.h.in
f96e0b
+++ b/config.h.in
f96e0b
@@ -8,6 +8,7 @@
f96e0b
 
f96e0b
 /* Define to 1 to enable disk cache statistics.  */
f96e0b
 #define DISK_CACHE_STATS @DISK_CACHE_STATS@
f96e0b
+#define BOOT_TIME_STATS @BOOT_TIME_STATS@
f96e0b
 
f96e0b
 #if defined (GRUB_UTIL) || !defined (GRUB_MACHINE)
f96e0b
 #include <config-util.h>
f96e0b
diff --git a/configure.ac b/configure.ac
f96e0b
index 038f429..a39a025 100644
f96e0b
--- a/configure.ac
f96e0b
+++ b/configure.ac
f96e0b
@@ -798,6 +798,17 @@ else
f96e0b
 fi
f96e0b
 AC_SUBST([DISK_CACHE_STATS])
f96e0b
 
f96e0b
+AC_ARG_ENABLE([boot-time],
f96e0b
+	      AS_HELP_STRING([--enable-boot-time],
f96e0b
+                             [enable boot time statistics collection]))
f96e0b
+
f96e0b
+if test x$enable_boot_time = xyes; then
f96e0b
+  BOOT_TIME_STATS=1
f96e0b
+else
f96e0b
+  BOOT_TIME_STATS=0
f96e0b
+fi
f96e0b
+AC_SUBST([BOOT_TIME_STATS])
f96e0b
+
f96e0b
 AC_ARG_ENABLE([grub-emu-usb],
f96e0b
 	      [AS_HELP_STRING([--enable-grub-emu-usb],
f96e0b
                              [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
f96e0b
@@ -1159,6 +1170,7 @@ AM_CONDITIONAL([COND_GRUB_PE2ELF], [test x$TARGET_OBJ2ELF != x])
f96e0b
 AM_CONDITIONAL([COND_APPLE_CC], [test x$TARGET_APPLE_CC = x1])
f96e0b
 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
f96e0b
 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
f96e0b
+AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
f96e0b
 
f96e0b
 AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
f96e0b
 AM_CONDITIONAL([COND_CYGWIN], [test x$host_os = xcygwin])
f96e0b
@@ -1231,6 +1243,13 @@ echo With disk cache statistics: Yes
f96e0b
 else
f96e0b
 echo With disk cache statistics: No
f96e0b
 fi
f96e0b
+
f96e0b
+if [ x"$enable_boot_time" = xyes ]; then
f96e0b
+echo With boot time statistics: Yes
f96e0b
+else
f96e0b
+echo With boot time statistics: No
f96e0b
+fi
f96e0b
+
f96e0b
 if [ x"$efiemu_excuse" = x ]; then
f96e0b
 echo efiemu runtime: Yes
f96e0b
 else
f96e0b
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f96e0b
index 3bcf662..5c15f32 100644
f96e0b
--- a/grub-core/Makefile.core.def
f96e0b
+++ b/grub-core/Makefile.core.def
f96e0b
@@ -1869,6 +1869,12 @@ module = {
f96e0b
 };
f96e0b
 
f96e0b
 module = {
f96e0b
+  name = boottime;
f96e0b
+  common = commands/boottime.c;
f96e0b
+  condition = COND_ENABLE_BOOT_TIME_STATS;
f96e0b
+};
f96e0b
+
f96e0b
+module = {
f96e0b
   name = adler32;
f96e0b
   common = lib/adler32.c;
f96e0b
 };
f96e0b
diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c
f96e0b
index c60873d..a5a24af 100644
f96e0b
--- a/grub-core/bus/usb/ehci.c
f96e0b
+++ b/grub-core/bus/usb/ehci.c
f96e0b
@@ -715,6 +715,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
f96e0b
       usblegsup = grub_pci_read (pciaddr_eecp);
f96e0b
       if (usblegsup & GRUB_EHCI_BIOS_OWNED)
f96e0b
 	{
f96e0b
+	  grub_boot_time ("Taking ownership of EHCI port");
f96e0b
 	  grub_dprintf ("ehci",
f96e0b
 			"EHCI grub_ehci_pci_iter: EHCI owned by: BIOS\n");
f96e0b
 	  /* Ownership change - set OS_OWNED bit */
f96e0b
@@ -741,6 +742,7 @@ grub_ehci_pci_iter (grub_pci_device_t dev, grub_pci_id_t pciid,
f96e0b
 	      /* Ensure PCI register is written */
f96e0b
 	      grub_pci_read (pciaddr_eecp);
f96e0b
 	    }
f96e0b
+	  grub_boot_time ("Ownership of EHCI port taken");
f96e0b
 	}
f96e0b
       else if (usblegsup & GRUB_EHCI_OS_OWNED)
f96e0b
 	/* XXX: What to do in this case - nothing ? Can it happen ? */
f96e0b
@@ -1706,10 +1708,12 @@ grub_ehci_portstatus (grub_usb_controller_t dev,
f96e0b
   /* Reset RESET bit and wait for the end of reset */
f96e0b
   grub_ehci_port_resbits (e, port, GRUB_EHCI_PORT_RESET);
f96e0b
   endtime = grub_get_time_ms () + 1000;
f96e0b
+  grub_boot_time ("Resetting port %d", port);
f96e0b
   while (grub_ehci_port_read (e, port) & GRUB_EHCI_PORT_RESET)
f96e0b
     if (grub_get_time_ms () > endtime)
f96e0b
       return grub_error (GRUB_ERR_IO,
f96e0b
 			 "portstatus: EHCI Timed out - reset port");
f96e0b
+  grub_boot_time ("Port %d reset", port);
f96e0b
   /* Remember "we did the reset" - needed by detect_dev */
f96e0b
   e->reset |= (1 << port);
f96e0b
   /* Test if port enabled, i.e. HIGH speed device connected */
f96e0b
@@ -1911,8 +1915,11 @@ GRUB_MOD_INIT (ehci)
f96e0b
 {
f96e0b
   COMPILE_TIME_ASSERT (sizeof (struct grub_ehci_td) == 64);
f96e0b
   COMPILE_TIME_ASSERT (sizeof (struct grub_ehci_qh) == 96);
f96e0b
+  grub_boot_time ("Initing EHCI hardware");
f96e0b
   grub_ehci_inithw ();
f96e0b
+  grub_boot_time ("Registering EHCI driver");
f96e0b
   grub_usb_controller_dev_register (&usb_controller);
f96e0b
+  grub_boot_time ("EHCI driver registered");
f96e0b
   grub_loader_register_preboot_hook (grub_ehci_fini_hw, grub_ehci_restore_hw,
f96e0b
 				     GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK);
f96e0b
 }
f96e0b
diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c
f96e0b
index 7a517f8..108c69b 100644
f96e0b
--- a/grub-core/bus/usb/usb.c
f96e0b
+++ b/grub-core/bus/usb/usb.c
f96e0b
@@ -262,8 +262,13 @@ void grub_usb_device_attach (grub_usb_device_t dev)
f96e0b
 	continue;
f96e0b
 
f96e0b
       for (desc = attach_hooks; desc; desc = desc->next)
f96e0b
-	if (interf->class == desc->class && desc->hook (dev, 0, i))
f96e0b
-	  dev->config[0].interf[i].attached = 1;
f96e0b
+	if (interf->class == desc->class)
f96e0b
+	  {
f96e0b
+	    grub_boot_time ("Probing USB device driver class %x", desc->class);
f96e0b
+	    if (desc->hook (dev, 0, i))
f96e0b
+	      dev->config[0].interf[i].attached = 1;
f96e0b
+	    grub_boot_time ("Probed USB device driver class %x", desc->class);
f96e0b
+	  }
f96e0b
 
f96e0b
       if (dev->config[0].interf[i].attached)
f96e0b
 	continue;
f96e0b
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
f96e0b
index 7e7dc8c..f95a567 100644
f96e0b
--- a/grub-core/bus/usb/usbhub.c
f96e0b
+++ b/grub-core/bus/usb/usbhub.c
f96e0b
@@ -52,6 +52,8 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
f96e0b
   int i;
f96e0b
   grub_usb_err_t err;
f96e0b
 
f96e0b
+  grub_boot_time ("Attaching USB device");
f96e0b
+
f96e0b
   dev = grub_zalloc (sizeof (struct grub_usb_device));
f96e0b
   if (! dev)
f96e0b
     return NULL;
f96e0b
@@ -108,8 +110,12 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller,
f96e0b
 
f96e0b
   /* Wait "recovery interval", spec. says 2ms */
f96e0b
   grub_millisleep (2);
f96e0b
+
f96e0b
+  grub_boot_time ("Probing USB device driver");
f96e0b
   
f96e0b
   grub_usb_device_attach (dev);
f96e0b
+
f96e0b
+  grub_boot_time ("Attached USB device");
f96e0b
   
f96e0b
   return dev;
f96e0b
 }
f96e0b
@@ -194,6 +200,8 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
f96e0b
   grub_usb_speed_t current_speed = GRUB_USB_SPEED_NONE;
f96e0b
   int changed=0;
f96e0b
 
f96e0b
+  grub_boot_time ("detect_dev USB root portno=%d\n", portno);
f96e0b
+
f96e0b
 #if 0
f96e0b
 /* Specification does not say about disabling of port when device
f96e0b
  * connected. If disabling is really necessary for some devices,
f96e0b
@@ -203,6 +211,9 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
f96e0b
   if (err)
f96e0b
     return;
f96e0b
 #endif
f96e0b
+
f96e0b
+  grub_boot_time ("Before the stable power wait portno=%d", portno);
f96e0b
+
f96e0b
   /* Wait for completion of insertion and stable power (USB spec.)
f96e0b
    * Should be at least 100ms, some devices requires more...
f96e0b
    * There is also another thing - some devices have worse contacts
f96e0b
@@ -239,6 +250,8 @@ attach_root_port (struct grub_usb_hub *hub, int portno,
f96e0b
   /* If the device is a Hub, scan it for more devices.  */
f96e0b
   if (dev->descdev.class == 0x09)
f96e0b
     grub_usb_add_hub (dev);
f96e0b
+
f96e0b
+  grub_boot_time ("Attached root port");
f96e0b
 }
f96e0b
 
f96e0b
 grub_usb_err_t
f96e0b
@@ -248,6 +261,8 @@ grub_usb_root_hub (grub_usb_controller_t controller)
f96e0b
   struct grub_usb_hub *hub;
f96e0b
   int changed=0;
f96e0b
 
f96e0b
+  grub_boot_time ("Registering USB root hub");
f96e0b
+
f96e0b
   hub = grub_malloc (sizeof (*hub));
f96e0b
   if (!hub)
f96e0b
     return GRUB_USB_ERR_INTERNAL;
f96e0b
@@ -287,6 +302,8 @@ grub_usb_root_hub (grub_usb_controller_t controller)
f96e0b
         }
f96e0b
     }
f96e0b
 
f96e0b
+  grub_boot_time ("USB root hub registered");
f96e0b
+
f96e0b
   return GRUB_USB_ERR_NONE;
f96e0b
 }
f96e0b
 
f96e0b
@@ -407,12 +424,13 @@ poll_nonroot_hub (grub_usb_device_t dev)
f96e0b
 	  /* Connected and status of connection changed ? */
f96e0b
 	  if (status & GRUB_USB_HUB_STATUS_PORT_CONNECTED)
f96e0b
 	    {
f96e0b
+	      grub_boot_time ("Before the stable power wait portno=%d", i);
f96e0b
 	      /* A device is actually connected to this port. */
f96e0b
-  /* Wait for completion of insertion and stable power (USB spec.)
f96e0b
-   * Should be at least 100ms, some devices requires more...
f96e0b
-   * There is also another thing - some devices have worse contacts
f96e0b
-   * and connected signal is unstable for some time - we should handle
f96e0b
-   * it - but prevent deadlock in case when device is too faulty... */
f96e0b
+	      /* Wait for completion of insertion and stable power (USB spec.)
f96e0b
+	       * Should be at least 100ms, some devices requires more...
f96e0b
+	       * There is also another thing - some devices have worse contacts
f96e0b
+	       * and connected signal is unstable for some time - we should handle
f96e0b
+	       * it - but prevent deadlock in case when device is too faulty... */
f96e0b
               for (total = j = 0; (j < 250) && (total < 2000); j++, total++)
f96e0b
                 {
f96e0b
                   grub_millisleep (1);
f96e0b
@@ -432,6 +450,9 @@ poll_nonroot_hub (grub_usb_device_t dev)
f96e0b
                   if (!(current_status & GRUB_USB_HUB_STATUS_PORT_CONNECTED))
f96e0b
                     j = 0;
f96e0b
                 }
f96e0b
+
f96e0b
+	      grub_boot_time ("After the stable power wait portno=%d", i);
f96e0b
+
f96e0b
               grub_dprintf ("usb", "(non-root) total=%d\n", total);
f96e0b
               if (total >= 2000)
f96e0b
                 continue;
f96e0b
@@ -443,6 +464,8 @@ poll_nonroot_hub (grub_usb_device_t dev)
f96e0b
 				    GRUB_USB_REQ_SET_FEATURE,
f96e0b
 				    GRUB_USB_HUB_FEATURE_PORT_RESET,
f96e0b
 				    i, 0, 0);
f96e0b
+	      grub_boot_time ("Resetting port %d", i);
f96e0b
+
f96e0b
 	      rescan = 1;
f96e0b
 	      /* We cannot reset more than one device at the same time !
f96e0b
 	       * Resetting more devices together results in very bad
f96e0b
@@ -464,6 +487,8 @@ poll_nonroot_hub (grub_usb_device_t dev)
f96e0b
 				GRUB_USB_REQ_CLEAR_FEATURE,
f96e0b
 				GRUB_USB_HUB_FEATURE_C_PORT_RESET, i, 0, 0);
f96e0b
 
f96e0b
+	  grub_boot_time ("Port %d reset", i);
f96e0b
+
f96e0b
 	  if (status & GRUB_USB_HUB_STATUS_PORT_CONNECTED)
f96e0b
 	    {
f96e0b
 	      grub_usb_speed_t speed;
f96e0b
diff --git a/grub-core/commands/boottime.c b/grub-core/commands/boottime.c
f96e0b
new file mode 100644
f96e0b
index 0000000..cd7f70a
f96e0b
--- /dev/null
f96e0b
+++ b/grub-core/commands/boottime.c
f96e0b
@@ -0,0 +1,66 @@
f96e0b
+/* cacheinfo.c - disk cache statistics  */
f96e0b
+/*
f96e0b
+ *  GRUB  --  GRand Unified Bootloader
f96e0b
+ *  Copyright (C) 2008,2010  Free Software Foundation, Inc.
f96e0b
+ *
f96e0b
+ *  GRUB is free software: you can redistribute it and/or modify
f96e0b
+ *  it under the terms of the GNU General Public License as published by
f96e0b
+ *  the Free Software Foundation, either version 3 of the License, or
f96e0b
+ *  (at your option) any later version.
f96e0b
+ *
f96e0b
+ *  GRUB is distributed in the hope that it will be useful,
f96e0b
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
f96e0b
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f96e0b
+ *  GNU General Public License for more details.
f96e0b
+ *
f96e0b
+ *  You should have received a copy of the GNU General Public License
f96e0b
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
f96e0b
+ */
f96e0b
+
f96e0b
+#include <grub/dl.h>
f96e0b
+#include <grub/misc.h>
f96e0b
+#include <grub/command.h>
f96e0b
+#include <grub/i18n.h>
f96e0b
+
f96e0b
+GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
+
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_cmd_boottime (struct grub_command *cmd __attribute__ ((unused)),
f96e0b
+		   int argc __attribute__ ((unused)),
f96e0b
+		   char *argv[] __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  struct grub_boot_time *cur;
f96e0b
+  grub_uint64_t last_time = 0, start_time = 0;
f96e0b
+  if (!grub_boot_time_head)
f96e0b
+    {
f96e0b
+      grub_puts_ (N_("No boot time statistics is available\n"));
f96e0b
+      return 0;
f96e0b
+    }
f96e0b
+  start_time = last_time = grub_boot_time_head->tp;
f96e0b
+  for (cur = grub_boot_time_head; cur; cur = cur->next)
f96e0b
+    {
f96e0b
+      grub_uint32_t tmabs = cur->tp - start_time;
f96e0b
+      grub_uint32_t tmrel = cur->tp - last_time;
f96e0b
+      last_time = cur->tp;
f96e0b
+
f96e0b
+      grub_printf ("%3d.%03ds %2d.%03ds %s:%d %s\n", 
f96e0b
+		   tmabs / 1000, tmabs % 1000, tmrel / 1000, tmrel % 1000, cur->file, cur->line,
f96e0b
+		   cur->msg);
f96e0b
+    }
f96e0b
+ return 0;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_command_t cmd_boottime;
f96e0b
+
f96e0b
+GRUB_MOD_INIT(boottime)
f96e0b
+{
f96e0b
+  cmd_boottime =
f96e0b
+    grub_register_command ("boottime", grub_cmd_boottime,
f96e0b
+			   0, N_("Get boot time statistics."));
f96e0b
+}
f96e0b
+
f96e0b
+GRUB_MOD_FINI(boottime)
f96e0b
+{
f96e0b
+  grub_unregister_command (cmd_boottime);
f96e0b
+}
f96e0b
diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c
f96e0b
index dd35bff..2cfc537 100644
f96e0b
--- a/grub-core/disk/usbms.c
f96e0b
+++ b/grub-core/disk/usbms.c
f96e0b
@@ -151,6 +151,8 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
f96e0b
   unsigned curnum;
f96e0b
   grub_usb_err_t err = GRUB_ERR_NONE;
f96e0b
 
f96e0b
+  grub_boot_time ("Attaching USB mass storage");
f96e0b
+
f96e0b
   if (first_available_slot == ARRAY_SIZE (grub_usbms_devices))
f96e0b
     return 0;
f96e0b
 
f96e0b
@@ -246,6 +248,8 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
f96e0b
 
f96e0b
   usbdev->config[configno].interf[interfno].detach_hook = grub_usbms_detach;
f96e0b
 
f96e0b
+  grub_boot_time ("Attached USB mass storage");
f96e0b
+
f96e0b
 #if 0 /* All this part should be probably deleted.
f96e0b
        * This make trouble on some devices if they are not in
f96e0b
        * Phase Error state - and there they should be not in such state...
f96e0b
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
f96e0b
index 5b0aa65..d06b6ae 100644
f96e0b
--- a/grub-core/kern/dl.c
f96e0b
+++ b/grub-core/kern/dl.c
f96e0b
@@ -648,7 +648,10 @@ grub_dl_load_core (void *addr, grub_size_t size)
f96e0b
 
f96e0b
   grub_dprintf ("modules", "module name: %s\n", mod->name);
f96e0b
   grub_dprintf ("modules", "init function: %p\n", mod->init);
f96e0b
+
f96e0b
+  grub_boot_time ("Initing module %s", mod->name);
f96e0b
   grub_dl_call_init (mod);
f96e0b
+  grub_boot_time ("Module %s inited", mod->name);
f96e0b
 
f96e0b
   if (grub_dl_add (mod))
f96e0b
     {
f96e0b
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
f96e0b
index e1a2001..19dc988 100644
f96e0b
--- a/grub-core/kern/main.c
f96e0b
+++ b/grub-core/kern/main.c
f96e0b
@@ -254,6 +254,8 @@ grub_main (void)
f96e0b
   /* First of all, initialize the machine.  */
f96e0b
   grub_machine_init ();
f96e0b
 
f96e0b
+  grub_boot_time ("After machine init.");
f96e0b
+
f96e0b
   /* Hello.  */
f96e0b
   grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
f96e0b
   grub_printf ("Welcome to GRUB!\n\n");
f96e0b
@@ -261,6 +263,8 @@ grub_main (void)
f96e0b
 
f96e0b
   grub_load_config ();
f96e0b
 
f96e0b
+  grub_boot_time ("Before loading embedded modules.");
f96e0b
+
f96e0b
   /* Load pre-loaded modules and free the space.  */
f96e0b
   grub_register_exported_symbols ();
f96e0b
 #ifdef GRUB_LINKER_HAVE_INIT
f96e0b
@@ -268,6 +272,8 @@ grub_main (void)
f96e0b
 #endif  
f96e0b
   grub_load_modules ();
f96e0b
 
f96e0b
+  grub_boot_time ("After loading embedded modules.");
f96e0b
+
f96e0b
   /* It is better to set the root device as soon as possible,
f96e0b
      for convenience.  */
f96e0b
   grub_set_prefix_and_root ();
f96e0b
@@ -277,11 +283,17 @@ grub_main (void)
f96e0b
   /* Reclaim space used for modules.  */
f96e0b
   reclaim_module_space ();
f96e0b
 
f96e0b
+  grub_boot_time ("After reclaiming module space.");
f96e0b
+
f96e0b
   grub_register_core_commands ();
f96e0b
 
f96e0b
+  grub_boot_time ("Before execution of embedded config.");
f96e0b
+
f96e0b
   if (load_config)
f96e0b
     grub_parser_execute (load_config);
f96e0b
 
f96e0b
+  grub_boot_time ("After execution of embedded config. Attempt to go to normal mode");
f96e0b
+
f96e0b
   grub_load_normal_mode ();
f96e0b
   grub_rescue_run ();
f96e0b
 }
f96e0b
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
f96e0b
index 6cb8f0e..94b88a3 100644
f96e0b
--- a/grub-core/kern/misc.c
f96e0b
+++ b/grub-core/kern/misc.c
f96e0b
@@ -1130,3 +1130,42 @@ void __deregister_frame_info (void)
f96e0b
 }
f96e0b
 #endif
f96e0b
 
f96e0b
+#if BOOT_TIME_STATS
f96e0b
+
f96e0b
+#include <grub/time.h>
f96e0b
+
f96e0b
+struct grub_boot_time *grub_boot_time_head;
f96e0b
+static struct grub_boot_time **boot_time_last = &grub_boot_time_head;
f96e0b
+
f96e0b
+void
f96e0b
+grub_real_boot_time (const char *file,
f96e0b
+		     const int line,
f96e0b
+		     const char *fmt, ...)
f96e0b
+{
f96e0b
+  struct grub_boot_time *n;
f96e0b
+  va_list args;
f96e0b
+
f96e0b
+  grub_error_push ();
f96e0b
+  n = grub_malloc (sizeof (*n));
f96e0b
+  if (!n)
f96e0b
+    {
f96e0b
+      grub_errno = 0;
f96e0b
+      grub_error_pop ();
f96e0b
+      return;
f96e0b
+    }
f96e0b
+  n->file = file;
f96e0b
+  n->line = line;
f96e0b
+  n->tp = grub_get_time_ms ();
f96e0b
+  n->next = 0;
f96e0b
+
f96e0b
+  va_start (args, fmt);
f96e0b
+  n->msg = grub_xvasprintf (fmt, args);    
f96e0b
+  va_end (args);
f96e0b
+
f96e0b
+  *boot_time_last = n;
f96e0b
+  boot_time_last = &n->next;
f96e0b
+
f96e0b
+  grub_errno = 0;
f96e0b
+  grub_error_pop ();
f96e0b
+}
f96e0b
+#endif
f96e0b
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
f96e0b
index 07f337d..9aaa3b2 100644
f96e0b
--- a/grub-core/normal/main.c
f96e0b
+++ b/grub-core/normal/main.c
f96e0b
@@ -296,6 +296,8 @@ grub_normal_execute (const char *config, int nested, int batch)
f96e0b
       grub_register_variable_hook ("prefix", NULL, read_lists_hook);
f96e0b
     }
f96e0b
 
f96e0b
+  grub_boot_time ("Executing config file");
f96e0b
+
f96e0b
   if (config)
f96e0b
     {
f96e0b
       menu = read_config_file (config);
f96e0b
@@ -304,10 +306,14 @@ grub_normal_execute (const char *config, int nested, int batch)
f96e0b
       grub_errno = GRUB_ERR_NONE;
f96e0b
     }
f96e0b
 
f96e0b
+  grub_boot_time ("Executed config file");
f96e0b
+
f96e0b
   if (! batch)
f96e0b
     {
f96e0b
       if (menu && menu->size)
f96e0b
 	{
f96e0b
+
f96e0b
+	  grub_boot_time ("Entering menu");
f96e0b
 	  grub_show_menu (menu, nested, 0);
f96e0b
 	  if (nested)
f96e0b
 	    grub_normal_free_menu (menu);
f96e0b
@@ -319,12 +325,15 @@ grub_normal_execute (const char *config, int nested, int batch)
f96e0b
 void
f96e0b
 grub_enter_normal_mode (const char *config)
f96e0b
 {
f96e0b
+  grub_boot_time ("Entering normal mode");
f96e0b
   nested_level++;
f96e0b
   grub_normal_execute (config, 0, 0);
f96e0b
+  grub_boot_time ("Entering shell");
f96e0b
   grub_cmdline_run (0);
f96e0b
   nested_level--;
f96e0b
   if (grub_normal_exit_level)
f96e0b
     grub_normal_exit_level--;
f96e0b
+  grub_boot_time ("Exiting normal mode");
f96e0b
 }
f96e0b
 
f96e0b
 /* Enter normal mode from rescue mode.  */
f96e0b
@@ -504,6 +513,8 @@ GRUB_MOD_INIT(normal)
f96e0b
 {
f96e0b
   unsigned i;
f96e0b
 
f96e0b
+  grub_boot_time ("Preparing normal module");
f96e0b
+
f96e0b
   /* Previously many modules depended on gzio. Be nice to user and load it.  */
f96e0b
   grub_dl_load ("gzio");
f96e0b
   grub_errno = 0;
f96e0b
@@ -556,6 +567,8 @@ GRUB_MOD_INIT(normal)
f96e0b
   grub_env_export ("grub_cpu");
f96e0b
   grub_env_set ("grub_platform", GRUB_PLATFORM);
f96e0b
   grub_env_export ("grub_platform");
f96e0b
+
f96e0b
+  grub_boot_time ("Normal module prepared");
f96e0b
 }
f96e0b
 
f96e0b
 GRUB_MOD_FINI(normal)
f96e0b
diff --git a/include/grub/misc.h b/include/grub/misc.h
f96e0b
index 11eeb22..f0ecaec 100644
f96e0b
--- a/include/grub/misc.h
f96e0b
+++ b/include/grub/misc.h
f96e0b
@@ -458,4 +458,24 @@ grub_error_load (const struct grub_error_saved *save)
f96e0b
   grub_errno = save->grub_errno;
f96e0b
 }
f96e0b
 
f96e0b
+#if BOOT_TIME_STATS
f96e0b
+struct grub_boot_time
f96e0b
+{
f96e0b
+  struct grub_boot_time *next;
f96e0b
+  grub_uint64_t tp;
f96e0b
+  const char *file;
f96e0b
+  int line;
f96e0b
+  char *msg;
f96e0b
+};
f96e0b
+
f96e0b
+extern struct grub_boot_time *EXPORT_VAR(grub_boot_time_head);
f96e0b
+
f96e0b
+void EXPORT_FUNC(grub_real_boot_time) (const char *file,
f96e0b
+				       const int line,
f96e0b
+				       const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
f96e0b
+#define grub_boot_time(fmt, args...) grub_real_boot_time(GRUB_FILE, __LINE__, fmt, ## args)
f96e0b
+#else
f96e0b
+#define grub_boot_time(fmt, args...) 
f96e0b
+#endif
f96e0b
+
f96e0b
 #endif /* ! GRUB_MISC_HEADER */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b