linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Jason Baron <jbaron@akamai.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH v2 13/23] dynamic_debug: refactor dynamic_pr_debug and friends
Date: Tue,  9 Oct 2018 13:20:03 +0200	[thread overview]
Message-ID: <20181009112013.14238-14-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <20181009112013.14238-1-linux@rasmusvillemoes.dk>

For the upcoming 'define the _ddebug descriptor in assembly', we need
all the descriptors in a translation unit to have distinct
names (because asm does not understand C scope). The easiest way to
achieve that is as usual with an extra level of macros, passing the
identifier to use to the innermost macro, generating it via __UNIQUE_ID
or something.

However, instead of repeating that exercise for dynamic_pr_debug,
dynamic_dev_dbg, dynamic_netdev_dbg and dynamic_hex_dump separately, we
can use the similarity between their bodies to implement them via a
common macro, _dynamic_func_call - though the hex_dump case requires
a slight variant, since print_hex_dump does not take the _ddebug
descriptor. We'll also get to use that variant elsewhere (btrfs).

Acked-by: Jason Baron <jbaron@akamai.com>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/dynamic_debug.h | 72 +++++++++++++++++++++--------------
 1 file changed, 43 insertions(+), 29 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 6a002b789d51..b9424097df37 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -112,40 +112,54 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,
 
 #endif
 
-#define dynamic_pr_debug(fmt, ...)				\
-do {								\
-	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);		\
-	if (DYNAMIC_DEBUG_BRANCH(descriptor))			\
-		__dynamic_pr_debug(&descriptor, pr_fmt(fmt),	\
-				   ##__VA_ARGS__);		\
+#define __dynamic_func_call(id, fmt, func, ...) do {	\
+	DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt);		\
+	if (DYNAMIC_DEBUG_BRANCH(id))			\
+		func(&id, ##__VA_ARGS__);		\
 } while (0)
 
-#define dynamic_dev_dbg(dev, fmt, ...)				\
-do {								\
-	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);		\
-	if (DYNAMIC_DEBUG_BRANCH(descriptor))			\
-		__dynamic_dev_dbg(&descriptor, dev, fmt,	\
-				  ##__VA_ARGS__);		\
+#define __dynamic_func_call_no_desc(id, fmt, func, ...) do {	\
+	DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt);			\
+	if (DYNAMIC_DEBUG_BRANCH(id))				\
+		func(__VA_ARGS__);				\
 } while (0)
 
-#define dynamic_netdev_dbg(dev, fmt, ...)			\
-do {								\
-	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);		\
-	if (DYNAMIC_DEBUG_BRANCH(descriptor))			\
-		__dynamic_netdev_dbg(&descriptor, dev, fmt,	\
-				     ##__VA_ARGS__);		\
-} while (0)
+/*
+ * "Factory macro" for generating a call to func, guarded by a
+ * DYNAMIC_DEBUG_BRANCH. The dynamic debug decriptor will be
+ * initialized using the fmt argument. The function will be called with
+ * the address of the descriptor as first argument, followed by all
+ * the varargs. Note that fmt is repeated in invocations of this
+ * macro.
+ */
+#define _dynamic_func_call(fmt, func, ...)				\
+	__dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
+/*
+ * A variant that does the same, except that the descriptor is not
+ * passed as the first argument to the function; it is only called
+ * with precisely the macro's varargs.
+ */
+#define _dynamic_func_call_no_desc(fmt, func, ...)	\
+	__dynamic_func_call_no_desc(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
 
-#define dynamic_hex_dump(prefix_str, prefix_type, rowsize,	\
-			 groupsize, buf, len, ascii)		\
-do {								\
-	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor,		\
-		__builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\
-	if (DYNAMIC_DEBUG_BRANCH(descriptor))			\
-		print_hex_dump(KERN_DEBUG, prefix_str,		\
-			       prefix_type, rowsize, groupsize,	\
-			       buf, len, ascii);		\
-} while (0)
+#define dynamic_pr_debug(fmt, ...)				\
+	_dynamic_func_call(fmt,	__dynamic_pr_debug,		\
+			   pr_fmt(fmt), ##__VA_ARGS__)
+
+#define dynamic_dev_dbg(dev, fmt, ...)				\
+	_dynamic_func_call(fmt,__dynamic_dev_dbg, 		\
+			   dev, fmt, ##__VA_ARGS__)
+
+#define dynamic_netdev_dbg(dev, fmt, ...)			\
+	_dynamic_func_call(fmt, __dynamic_netdev_dbg,		\
+			   dev, fmt, ##__VA_ARGS__)
+
+#define dynamic_hex_dump(prefix_str, prefix_type, rowsize,		\
+			 groupsize, buf, len, ascii)			\
+	_dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \
+				   print_hex_dump,			\
+				   KERN_DEBUG, prefix_str, prefix_type,	\
+				   rowsize, groupsize, buf, len, ascii)
 
 #else
 
-- 
2.19.1.3.g1d92a00e68


  parent reply	other threads:[~2018-10-09 11:22 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19 22:04 [PATCH 00/22] various dynamic_debug patches Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 01/22] linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited Rasmus Villemoes
2018-09-20  8:47   ` Greg Kroah-Hartman
2018-09-19 22:04 ` [PATCH 02/22] linux/device.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-09-20  8:47   ` Greg Kroah-Hartman
2018-09-19 22:04 ` [PATCH 03/22] linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 04/22] linux/net.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 05/22] linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited Rasmus Villemoes
2018-09-27  7:52   ` Petr Mladek
2018-09-19 22:04 ` [PATCH 06/22] linux/printk.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-09-27  8:22   ` Petr Mladek
2018-09-27  8:41     ` Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 07/22] dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 08/22] dynamic_debug: don't duplicate modname in ddebug_add_module Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 09/22] dynamic_debug: use pointer comparison in ddebug_remove_module Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 10/22] dynamic_debug: remove unused EXPORT_SYMBOLs Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 11/22] dynamic_debug: move pr_err from module.c to ddebug_add_module Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 12/22] dynamic_debug: add static inline stub for ddebug_add_module Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 13/22] dynamic_debug: refactor dynamic_pr_debug and friends Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 14/22] btrfs: implement btrfs_debug* in terms of helper macro Rasmus Villemoes
2018-09-20 13:10   ` David Sterba
2018-09-20 14:11     ` Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 15/22] ACPI: use proper DYNAMIC_DEBUG_BRANCH macro Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 16/22] ACPI: remove unused __acpi_handle_debug macro Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 17/22] ACPI: implement acpi_handle_debug in terms of _dynamic_func_call Rasmus Villemoes
2018-09-20  8:05   ` Rafael J. Wysocki
2018-09-19 22:04 ` [PATCH 18/22] dynamic_debug: introduce accessors for string members of struct _ddebug Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 19/22] dynamic_debug: drop use of bitfields in " Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 20/22] dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
2018-09-19 22:04 ` [PATCH 21/22] x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE} Rasmus Villemoes
2018-10-02  8:21   ` Rasmus Villemoes
2018-10-02  9:48   ` Ingo Molnar
2018-09-19 22:04 ` [PATCH 22/22] x86_64: use relative pointers with dynamic debug Rasmus Villemoes
2018-09-20 10:56   ` [PATCH 23/22] x86: dynamic_debug: protect against dynamic debug identifier reuse Rasmus Villemoes
2018-10-02  9:50   ` [PATCH 22/22] x86_64: use relative pointers with dynamic debug Ingo Molnar
2018-10-03 21:40     ` Rasmus Villemoes
2018-09-20  8:05 ` [PATCH 00/22] various dynamic_debug patches Rafael J. Wysocki
2018-10-03  9:25   ` Rafael J. Wysocki
2018-09-22  0:27 ` Jason Baron
2018-10-09 11:19 ` [PATCH v2 00/23] " Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 01/23] linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 02/23] linux/device.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 03/23] linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 04/23] linux/net.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 05/23] linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 06/23] linux/printk.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 07/23] dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 08/23] dynamic_debug: don't duplicate modname in ddebug_add_module Rasmus Villemoes
2018-10-09 11:19   ` [PATCH v2 09/23] dynamic_debug: use pointer comparison in ddebug_remove_module Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 10/23] dynamic_debug: remove unused EXPORT_SYMBOLs Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 11/23] dynamic_debug: move pr_err from module.c to ddebug_add_module Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 12/23] dynamic_debug: add static inline stub for ddebug_add_module Rasmus Villemoes
2018-10-09 11:20   ` Rasmus Villemoes [this message]
2018-10-09 11:20   ` [PATCH v2 14/23] btrfs: implement btrfs_debug* in terms of helper macro Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 15/23] ACPI: use proper DYNAMIC_DEBUG_BRANCH macro Rasmus Villemoes
2018-10-10  9:38     ` Rafael J. Wysocki
2018-10-09 11:20   ` [PATCH v2 16/23] ACPI: remove unused __acpi_handle_debug macro Rasmus Villemoes
2018-10-10  9:38     ` Rafael J. Wysocki
2018-10-09 11:20   ` [PATCH v2 17/23] ACPI: implement acpi_handle_debug in terms of _dynamic_func_call Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 18/23] dynamic_debug: introduce accessors for string members of struct _ddebug Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 19/23] dynamic_debug: drop use of bitfields in " Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 20/23] dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 21/23] x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE} Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 22/23] x86_64: use relative pointers with dynamic debug Rasmus Villemoes
2018-10-09 11:20   ` [PATCH v2 23/23] x86: dynamic_debug: protect against dynamic debug identifier reuse Rasmus Villemoes
2018-10-10  9:37   ` [PATCH v2 00/23] various dynamic_debug patches Rafael J. Wysocki
2018-11-09 23:09   ` [PATCH v3 " Rasmus Villemoes
2018-11-09 23:09     ` [PATCH v3 01/23] linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 02/23] linux/device.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 03/23] linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 04/23] linux/net.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-11-09 23:22       ` Joe Perches
2018-11-09 23:31         ` Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 05/23] linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 06/23] linux/printk.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 07/23] dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 08/23] dynamic_debug: don't duplicate modname in ddebug_add_module Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 09/23] dynamic_debug: use pointer comparison in ddebug_remove_module Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 10/23] dynamic_debug: remove unused EXPORT_SYMBOLs Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 11/23] dynamic_debug: move pr_err from module.c to ddebug_add_module Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 12/23] dynamic_debug: add static inline stub for ddebug_add_module Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 13/23] dynamic_debug: refactor dynamic_pr_debug and friends Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 14/23] btrfs: implement btrfs_debug* in terms of helper macro Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 15/23] ACPI: use proper DYNAMIC_DEBUG_BRANCH macro Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 16/23] ACPI: remove unused __acpi_handle_debug macro Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 17/23] ACPI: implement acpi_handle_debug in terms of _dynamic_func_call Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 18/23] dynamic_debug: introduce accessors for string members of struct _ddebug Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 19/23] dynamic_debug: drop use of bitfields in " Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 20/23] dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 21/23] jump_label: move JUMP_TYPE_* constants to new asm-generic file Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 22/23] x86: jump_label: introduce asm macros STATIC_KEY_INIT{,_TRUE,_FALSE} Rasmus Villemoes
2018-11-09 23:10     ` [PATCH v3 23/23] x86_64: use relative pointers with dynamic debug Rasmus Villemoes
2019-02-12 21:41     ` [PATCH v4 00/14] various dynamic_debug patches Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 01/14] linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 02/14] linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 03/14] linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 04/14] dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 05/14] dynamic_debug: don't duplicate modname in ddebug_add_module Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 06/14] dynamic_debug: use pointer comparison in ddebug_remove_module Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 07/14] dynamic_debug: remove unused EXPORT_SYMBOLs Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 08/14] dynamic_debug: move pr_err from module.c to ddebug_add_module Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 09/14] dynamic_debug: add static inline stub for ddebug_add_module Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 10/14] dynamic_debug: refactor dynamic_pr_debug and friends Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 11/14] btrfs: implement btrfs_debug* in terms of helper macro Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 12/14] ACPI: use proper DYNAMIC_DEBUG_BRANCH macro Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 13/14] ACPI: remove unused __acpi_handle_debug macro Rasmus Villemoes
2019-02-12 21:41       ` [PATCH v4 14/14] ACPI: implement acpi_handle_debug in terms of _dynamic_func_call Rasmus Villemoes

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=20181009112013.14238-14-linux@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=akpm@linux-foundation.org \
    --cc=jbaron@akamai.com \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).