public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/3] efi_loader: indent entry/exit prints to show nesting level
Date: Wed, 26 Jul 2017 09:55:59 -0400	[thread overview]
Message-ID: <20170726135559.16653-3-robdclark@gmail.com> (raw)
In-Reply-To: <20170726135559.16653-1-robdclark@gmail.com>

This should make it easier to see when a callback back to UEFI world
calls back in to the u-boot world, and generally match up EFI_ENTRY()
and EFI_EXIT() calls.

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 include/efi_loader.h          | 12 ++++++++----
 lib/efi_loader/efi_boottime.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 4b49fac84b..88091d4914 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -16,20 +16,24 @@
 #include <linux/list.h>
 
 int __efi_check_nesting(int delta);
+const char *__efi_nesting_level(int delta);
+
 /*
  * Enter the u-boot world from UEFI:
  */
 #define EFI_ENTRY(format, ...) do { \
 	efi_restore_gd(); \
+	debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_level(1), \
+		__func__, ##__VA_ARGS__); \
 	assert(__efi_check_nesting(+1)); \
-	debug("EFI: Entry %s(" format ")\n", __func__, ##__VA_ARGS__); \
 	} while(0)
 
 /*
  * Exit the u-boot world back to UEFI:
  */
 #define EFI_EXIT(ret) ({ \
-	debug("EFI: Exit: %s: %u\n", __func__, (u32)((ret) & ~EFI_ERROR_MASK)); \
+	debug("%sEFI: Exit: %s: %u\n", __efi_nesting_level(-1), \
+		__func__, (u32)((ret) & ~EFI_ERROR_MASK)); \
 	assert(__efi_check_nesting(-1)); \
 	efi_exit_func(ret); \
 	})
@@ -38,12 +42,12 @@ int __efi_check_nesting(int delta);
  * Callback into UEFI world from u-boot:
  */
 #define EFI_CALL(exp) do { \
-	debug("EFI: Call: %s\n", #exp); \
+	debug("%sEFI: Call: %s\n", __efi_nesting_level(1), #exp); \
 	assert(__efi_check_nesting(-1)); \
 	efi_exit_func(EFI_SUCCESS); \
 	exp; \
 	efi_restore_gd(); \
-	debug("EFI: Return From: %s\n", #exp); \
+	debug("%sEFI: Return From: %s\n", __efi_nesting_level(-1), #exp); \
 	assert(__efi_check_nesting(+1)); \
 	} while(0)
 
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index b21df7bd5d..f6c4c162cf 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -92,6 +92,34 @@ efi_status_t efi_exit_func(efi_status_t ret)
 	return ret;
 }
 
+/*
+ * Two spaces per indent level, maxing out at 10.. which ought to be
+ * enough for anyone ;-)
+ */
+static const char *indent_string(int level)
+{
+	static const char *indent = "                    ";
+	const int max = strlen(indent);
+	level = min(max, level * 2);
+	return &indent[max - level];
+}
+
+const char *__efi_nesting_level(int delta)
+{
+	static int nesting_level;
+	const char *s;
+	/* post-increment, pre-decrement */
+	if (delta > 0) {
+		s = indent_string(nesting_level);
+		nesting_level += delta;
+	} else {
+		nesting_level += delta;
+		s = indent_string(nesting_level);
+		assert(nesting_level >= 0);
+	}
+	return s;
+}
+
 /* Low 32 bit */
 #define EFI_LOW32(a) (a & 0xFFFFFFFFULL)
 /* High 32 bit */
-- 
2.13.0

  parent reply	other threads:[~2017-07-26 13:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 13:55 [U-Boot] [PATCH 1/3] efi_loader: Add an EFI_CALL() macro Rob Clark
2017-07-26 13:55 ` [U-Boot] [PATCH 2/3] efi_loader: add checking for incorrect use of EFI_ENTRY/EXIT Rob Clark
2017-07-26 15:25   ` Alexander Graf
2017-07-26 16:41     ` Rob Clark
2017-07-26 20:12       ` Alexander Graf
2017-07-26 20:55         ` Rob Clark
2017-07-26 20:16   ` Heinrich Schuchardt
2017-07-26 13:55 ` Rob Clark [this message]
2017-07-26 15:36   ` [U-Boot] [PATCH 3/3] efi_loader: indent entry/exit prints to show nesting level Alexander Graf
2017-07-26 20:16   ` Heinrich Schuchardt
2017-07-26 20:15 ` [U-Boot] [PATCH 1/3] efi_loader: Add an EFI_CALL() macro Heinrich Schuchardt

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=20170726135559.16653-3-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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