mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros
@ 2023-02-02 13:34 Ahmad Fatoum
  2023-02-02 13:34 ` [PATCH v2 2/3] fs: tftp: print message when stack can't keep us with TFTP windowsize Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-02-02 13:34 UTC (permalink / raw)
  To: barebox; +Cc: Christian Melki, Ahmad Fatoum

These are useful as a less verbose alternative to WARN_ONCE, which also
prints a stack trace if possible.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  unchanged
---
 include/linux/printk.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 2fd6551e0ccb..a9d1b05f6f0f 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -94,6 +94,15 @@ static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
 		(level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
 	 })
 
+#define __pr_printk_once(level, format, args...) do {	\
+	static bool __print_once;			\
+							\
+	if (!__print_once && (level) <= LOGLEVEL) {	\
+		__print_once = true;			\
+		pr_print((level), (format), ##args);	\
+	}						\
+} while (0)
+
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
 #endif
@@ -110,7 +119,18 @@ static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
 #define pr_vdebug(fmt, arg...)	__pr_printk(8, pr_fmt(fmt), ##arg)
 #define pr_cont(fmt, arg...)	__pr_printk(-1, fmt, ##arg)
 
+#define pr_emerg_once(fmt, arg...)	__pr_printk_once(0, pr_fmt(fmt), ##arg)
+#define pr_alert_once(fmt, arg...)	__pr_printk_once(1, pr_fmt(fmt), ##arg)
+#define pr_crit_once(fmt, arg...)	__pr_printk_once(2, pr_fmt(fmt), ##arg)
+#define pr_err_once(fmt, arg...)	__pr_printk_once(3, pr_fmt(fmt), ##arg)
+#define pr_warning_once(fmt, arg...)	__pr_printk_once(4, pr_fmt(fmt), ##arg)
+#define pr_notice_once(fmt, arg...)	__pr_printk_once(5, pr_fmt(fmt), ##arg)
+#define pr_info_once(fmt, arg...)	__pr_printk_once(6, pr_fmt(fmt), ##arg)
+#define pr_debug_once(fmt, arg...)	__pr_printk_once(7, pr_fmt(fmt), ##arg)
+#define pr_vdebug_once(fmt, arg...)	__pr_printk_once(8, pr_fmt(fmt), ##arg)
+
 #define pr_warn			pr_warning
+#define pr_warn_once		pr_warning_once
 
 int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
 		   int swab);
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] fs: tftp: print message when stack can't keep us with TFTP windowsize
  2023-02-02 13:34 [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Ahmad Fatoum
@ 2023-02-02 13:34 ` Ahmad Fatoum
  2023-02-02 13:34 ` [PATCH v2 3/3] include: printk: retire printk_once for pr_debug_once Ahmad Fatoum
  2023-02-03  7:58 ` [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-02-02 13:34 UTC (permalink / raw)
  To: barebox; +Cc: Christian Melki, Ahmad Fatoum

When the NIC driver doesn't configure enough buffers to keep up
with a big TFTP windowsize, error reporting is less than optimal,
e.g. on AX88x72A

  T BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBT T BBBBBBBBBBBBT
  BBBBBBBBBBBBBBBBBBBBBBBBBT

or on older DWMAC1000 (non-EQOS):

  WARNING: eth0: Rx error status (8800)
  T BBBBBBWARNING: eth0: Rx error status (8800)

While we probably want to:

  - decrease rate limit in __net_poll()
  - increase ring buffer depth for affected drivers

For now, at least print a helpful warning.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - reword commit and warning message to point finger at
    network stack (Michael)
---
 fs/tftp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/tftp.c b/fs/tftp.c
index 0b0b86a1a07e..a63b133caa25 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -477,6 +477,8 @@ static void tftp_handle_data(struct file_priv *priv, uint16_t block,
 		/* completely unexpected and unrelated to actual window;
 		   ignore the packet. */
 		printf("B");
+		if (g_tftp_window_size > 1)
+			pr_warn_once("Unexpected packet. global.tftp.windowsize set too high?\n");
 	} else {
 		/* The 'rc < 0' below happens e.g. when datagrams in the first
 		   part of the transfer window are dropped.
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] include: printk: retire printk_once for pr_debug_once
  2023-02-02 13:34 [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Ahmad Fatoum
  2023-02-02 13:34 ` [PATCH v2 2/3] fs: tftp: print message when stack can't keep us with TFTP windowsize Ahmad Fatoum
@ 2023-02-02 13:34 ` Ahmad Fatoum
  2023-02-03  7:58 ` [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-02-02 13:34 UTC (permalink / raw)
  To: barebox; +Cc: Christian Melki, Ahmad Fatoum

printk is just printf and KERN_DEBUG is just "", so printk_once(KERN_DEBUG
doesn't do what's promised. Replace instead with pr_debug_once, which
does what one would expect.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  no change
--
 include/printk.h     | 10 ----------
 lib/list_sort.c      |  5 ++---
 scripts/bareboxenv.c |  2 +-
 3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/include/printk.h b/include/printk.h
index 90c45afd9fc7..6f8635fae2c0 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -31,16 +31,6 @@ void __attribute__((noreturn)) panic(const char *fmt, ...);
 
 #define printk			printf
 
-#define printk_once(fmt, ...)					\
-({								\
-	static bool __print_once	;			\
-								\
-	if (!__print_once) {					\
-		__print_once = true;				\
-		printk(fmt, ##__VA_ARGS__);			\
-	}							\
-})
-
 enum {
 	DUMP_PREFIX_NONE,
 	DUMP_PREFIX_ADDRESS,
diff --git a/lib/list_sort.c b/lib/list_sort.c
index 77ddadb3d6ac..eea87f834ca4 100644
--- a/lib/list_sort.c
+++ b/lib/list_sort.c
@@ -4,6 +4,7 @@
 #include <linux/kernel.h>
 #define EXPORT_SYMBOL(x)
 #else
+#define pr_fmt(fmt) "list_sort: " fmt
 #include <common.h>
 #include <malloc.h>
 #endif
@@ -129,9 +130,7 @@ void list_sort(void *priv, struct list_head *head,
 		}
 		if (lev > max_lev) {
 			if (unlikely(lev >= ARRAY_SIZE(part)-1)) {
-				printk_once(KERN_DEBUG "list passed to"
-					" list_sort() too long for"
-					" efficiency\n");
+				pr_debug_once("list passed to too long for efficient sorting\n");
 				lev--;
 			}
 			max_lev = lev;
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index f1706a5e175b..e954447015c5 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -20,7 +20,7 @@
 #include "compiler.h"
 
 #define debug(...)
-#define printk_once(...)
+#define pr_debug_once(...)
 
 /* Find out if the last character of a string matches the one given.
  * Don't underrun the buffer if the string length is 0.
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros
  2023-02-02 13:34 [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Ahmad Fatoum
  2023-02-02 13:34 ` [PATCH v2 2/3] fs: tftp: print message when stack can't keep us with TFTP windowsize Ahmad Fatoum
  2023-02-02 13:34 ` [PATCH v2 3/3] include: printk: retire printk_once for pr_debug_once Ahmad Fatoum
@ 2023-02-03  7:58 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-02-03  7:58 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, Christian Melki

On Thu, Feb 02, 2023 at 02:34:13PM +0100, Ahmad Fatoum wrote:
> These are useful as a less verbose alternative to WARN_ONCE, which also
> prints a stack trace if possible.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   unchanged
> ---
>  include/linux/printk.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index 2fd6551e0ccb..a9d1b05f6f0f 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -94,6 +94,15 @@ static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
>  		(level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
>  	 })
>  
> +#define __pr_printk_once(level, format, args...) do {	\
> +	static bool __print_once;			\
> +							\
> +	if (!__print_once && (level) <= LOGLEVEL) {	\
> +		__print_once = true;			\
> +		pr_print((level), (format), ##args);	\
> +	}						\
> +} while (0)
> +
>  #ifndef pr_fmt
>  #define pr_fmt(fmt) fmt
>  #endif
> @@ -110,7 +119,18 @@ static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
>  #define pr_vdebug(fmt, arg...)	__pr_printk(8, pr_fmt(fmt), ##arg)
>  #define pr_cont(fmt, arg...)	__pr_printk(-1, fmt, ##arg)
>  
> +#define pr_emerg_once(fmt, arg...)	__pr_printk_once(0, pr_fmt(fmt), ##arg)
> +#define pr_alert_once(fmt, arg...)	__pr_printk_once(1, pr_fmt(fmt), ##arg)
> +#define pr_crit_once(fmt, arg...)	__pr_printk_once(2, pr_fmt(fmt), ##arg)
> +#define pr_err_once(fmt, arg...)	__pr_printk_once(3, pr_fmt(fmt), ##arg)
> +#define pr_warning_once(fmt, arg...)	__pr_printk_once(4, pr_fmt(fmt), ##arg)
> +#define pr_notice_once(fmt, arg...)	__pr_printk_once(5, pr_fmt(fmt), ##arg)
> +#define pr_info_once(fmt, arg...)	__pr_printk_once(6, pr_fmt(fmt), ##arg)
> +#define pr_debug_once(fmt, arg...)	__pr_printk_once(7, pr_fmt(fmt), ##arg)
> +#define pr_vdebug_once(fmt, arg...)	__pr_printk_once(8, pr_fmt(fmt), ##arg)
> +
>  #define pr_warn			pr_warning
> +#define pr_warn_once		pr_warning_once
>  
>  int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
>  		   int swab);
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-03  8:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 13:34 [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Ahmad Fatoum
2023-02-02 13:34 ` [PATCH v2 2/3] fs: tftp: print message when stack can't keep us with TFTP windowsize Ahmad Fatoum
2023-02-02 13:34 ` [PATCH v2 3/3] include: printk: retire printk_once for pr_debug_once Ahmad Fatoum
2023-02-03  7:58 ` [PATCH master v2 1/3] include: linux/printk: implement pr_*_once macros Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox