Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1430466 > unrolled thread

[PATCH 2/3] printk: Make the printk*once() variants return a value

Started byBorislav Petkov <bp@alien8.de>
First post2016-06-24 10:40 +0200
Last post2016-06-27 11:20 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/3] printk: Make the printk*once() variants return a value Borislav Petkov <bp@alien8.de> - 2016-06-24 10:40 +0200
    Re: [PATCH 2/3] printk: Make the printk*once() variants return a  value Joe Perches <joe@perches.com> - 2016-06-24 15:50 +0200
      Re: [PATCH 2/3] printk: Make the printk*once() variants return a  value Borislav Petkov <bp@alien8.de> - 2016-06-25 13:10 +0200
        [PATCH -v2 2/3] printk: Make the printk*once() variants return a  value Borislav Petkov <bp@alien8.de> - 2016-06-27 11:20 +0200

#1430466 — [PATCH 2/3] printk: Make the printk*once() variants return a value

FromBorislav Petkov <bp@alien8.de>
Date2016-06-24 10:40 +0200
Subject[PATCH 2/3] printk: Make the printk*once() variants return a value
Message-ID<rNuOB-5IF-17@gated-at.bofh.it>
From: Borislav Petkov <bp@suse.de>

Have printk*once() return a bool which denotes whether the string was
printed or not so that calling code can react accordingly.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 include/linux/printk.h | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index f4da695fd615..464fcdddb359 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -108,11 +108,14 @@ struct va_format {
  * Dummy printk for disabled debugging statements to use whilst maintaining
  * gcc's format checking.
  */
-#define no_printk(fmt, ...)			\
-do {						\
-	if (0)					\
-		printk(fmt, ##__VA_ARGS__);	\
-} while (0)
+#define no_printk(fmt, ...)				\
+({							\
+	do {						\
+		if (0)					\
+			printk(fmt, ##__VA_ARGS__);	\
+	} while (0);					\
+	0;						\
+})
 
 #ifdef CONFIG_EARLY_PRINTK
 extern asmlinkage __printf(1, 2)
@@ -309,20 +312,24 @@ extern asmlinkage void dump_stack(void) __cold;
 #define printk_once(fmt, ...)					\
 ({								\
 	static bool __print_once __read_mostly;			\
+	bool __ret_print_once = !__print_once;			\
 								\
 	if (!__print_once) {					\
 		__print_once = true;				\
 		printk(fmt, ##__VA_ARGS__);			\
 	}							\
+	__ret_print_once;					\
 })
 #define printk_deferred_once(fmt, ...)				\
 ({								\
 	static bool __print_once __read_mostly;			\
+	bool __ret_print_once = !__print_once;			\
 								\
 	if (!__print_once) {					\
 		__print_once = true;				\
 		printk_deferred(fmt, ##__VA_ARGS__);		\
 	}							\
+	__ret_print_once;					\
 })
 #else
 #define printk_once(fmt, ...)					\
-- 
2.8.4

[toc] | [next] | [standalone]


#1430682 — Re: [PATCH 2/3] printk: Make the printk*once() variants return a value

FromJoe Perches <joe@perches.com>
Date2016-06-24 15:50 +0200
SubjectRe: [PATCH 2/3] printk: Make the printk*once() variants return a value
Message-ID<rNzEC-h8-33@gated-at.bofh.it>
In reply to#1430466
On Fri, 2016-06-24 at 10:30 +0200, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> Have printk*once() return a bool which denotes whether the string was
> printed or not so that calling code can react accordingly.

I expected object size to either increase or stay the
same with just this change.

Oddly, at least with gcc 5.3, some defconfig x86-64
objects _decrease_ in size.

for example: drivers/gpu/drm/i915/intel_opregion.o

I presume there's some curiosity in the gcc optimizer
with the evaluation of statement expression macros that
don't return a value.

Perhaps the printk_once macros should end with
	unlikely(__ret_print_once);
like the WARN_ONCE variants.

> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  include/linux/printk.h | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index f4da695fd615..464fcdddb359 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -108,11 +108,14 @@ struct va_format {
>   * Dummy printk for disabled debugging statements to use whilst maintaining
>   * gcc's format checking.
>   */
> -#define no_printk(fmt, ...)			\
> -do {						\
> -	if (0)					\
> -		printk(fmt, ##__VA_ARGS__);	\
> -} while (0)
> +#define no_printk(fmt, ...)				\
> +({							\
> +	do {						\
> +		if (0)					\
> +			printk(fmt, ##__VA_ARGS__);	\
> +	} while (0);					\
> +	0;						\
> +})
>  
>  #ifdef CONFIG_EARLY_PRINTK
>  extern asmlinkage __printf(1, 2)
> @@ -309,20 +312,24 @@ extern asmlinkage void dump_stack(void) __cold;
>  #define printk_once(fmt, ...)					\
>  ({								\
>  	static bool __print_once __read_mostly;			\
> +	bool __ret_print_once = !__print_once;			\
>  								\
>  	if (!__print_once) {					\
>  		__print_once = true;				\
>  		printk(fmt, ##__VA_ARGS__);			\
>  	}							\
> +	__ret_print_once;					\
>  })
>  #define printk_deferred_once(fmt, ...)				\
>  ({								\
>  	static bool __print_once __read_mostly;			\
> +	bool __ret_print_once = !__print_once;			\
>  								\
>  	if (!__print_once) {					\
>  		__print_once = true;				\
>  		printk_deferred(fmt, ##__VA_ARGS__);		\
>  	}							\
> +	__ret_print_once;					\
>  })
>  #else
>  #define printk_once(fmt, ...)					\

[toc] | [prev] | [next] | [standalone]


#1431116 — Re: [PATCH 2/3] printk: Make the printk*once() variants return a value

FromBorislav Petkov <bp@alien8.de>
Date2016-06-25 13:10 +0200
SubjectRe: [PATCH 2/3] printk: Make the printk*once() variants return a value
Message-ID<rNTDj-4JZ-1@gated-at.bofh.it>
In reply to#1430682
On Fri, Jun 24, 2016 at 06:43:04AM -0700, Joe Perches wrote:
> Perhaps the printk_once macros should end with
> 	unlikely(__ret_print_once);
> like the WARN_ONCE variants.

Done, thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

[toc] | [prev] | [next] | [standalone]


#1431846 — [PATCH -v2 2/3] printk: Make the printk*once() variants return a value

FromBorislav Petkov <bp@alien8.de>
Date2016-06-27 11:20 +0200
Subject[PATCH -v2 2/3] printk: Make the printk*once() variants return a value
Message-ID<rOARY-6GU-21@gated-at.bofh.it>
In reply to#1431116
From: Borislav Petkov <bp@suse.de>
Date: Thu, 23 Jun 2016 10:41:30 +0200
Subject: [PATCH] printk: Make the printk*once() variants return a value

Have printk*once() return a bool which denotes whether the string was
printed or not so that calling code can react accordingly.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
---

v2: Wrap __ret_print_once in unlikely.

 include/linux/printk.h | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index f4da695fd615..f136b22c7772 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -108,11 +108,14 @@ struct va_format {
  * Dummy printk for disabled debugging statements to use whilst maintaining
  * gcc's format checking.
  */
-#define no_printk(fmt, ...)			\
-do {						\
-	if (0)					\
-		printk(fmt, ##__VA_ARGS__);	\
-} while (0)
+#define no_printk(fmt, ...)				\
+({							\
+	do {						\
+		if (0)					\
+			printk(fmt, ##__VA_ARGS__);	\
+	} while (0);					\
+	0;						\
+})
 
 #ifdef CONFIG_EARLY_PRINTK
 extern asmlinkage __printf(1, 2)
@@ -309,20 +312,24 @@ extern asmlinkage void dump_stack(void) __cold;
 #define printk_once(fmt, ...)					\
 ({								\
 	static bool __print_once __read_mostly;			\
+	bool __ret_print_once = !__print_once;			\
 								\
 	if (!__print_once) {					\
 		__print_once = true;				\
 		printk(fmt, ##__VA_ARGS__);			\
 	}							\
+	unlikely(__ret_print_once);				\
 })
 #define printk_deferred_once(fmt, ...)				\
 ({								\
 	static bool __print_once __read_mostly;			\
+	bool __ret_print_once = !__print_once;			\
 								\
 	if (!__print_once) {					\
 		__print_once = true;				\
 		printk_deferred(fmt, ##__VA_ARGS__);		\
 	}							\
+	unlikely(__ret_print_once);				\
 })
 #else
 #define printk_once(fmt, ...)					\
-- 
2.8.4

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web