Skip to content

Commit

Permalink
once: replace uses of __section(".data.once") with DO_ONCE_LITE(_IF)?
Browse files Browse the repository at this point in the history
DO_ONCE_LITE(_IF)? abstracts this "do once" functionality, presenting
an opportunity for code reuse.

This commit changes the behavior of xfs_printk_once, printk_once and
printk_deferred_once. Before, these macros resulted in code ultimately
evaluating to __print_once. Now, they ultimately evaluate to true.
This is acceptable because none of the clients of these macros relies
on the value.

Signed-off-by: Tanner Love <tannerlove@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Acked-by: Mahesh Bandewar <maheshb@google.com>
  • Loading branch information
tannerlove authored and intel-lab-lkp committed Apr 22, 2021
1 parent 996f656 commit eaeb33f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 70 deletions.
13 changes: 3 additions & 10 deletions fs/xfs/xfs_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef __XFS_MESSAGE_H
#define __XFS_MESSAGE_H 1

#include <linux/once.h>

struct xfs_mount;

extern __printf(2, 3)
Expand Down Expand Up @@ -41,16 +43,7 @@ do { \
} while (0)

#define xfs_printk_once(func, dev, fmt, ...) \
({ \
static bool __section(".data.once") __print_once; \
bool __ret_print_once = !__print_once; \
\
if (!__print_once) { \
__print_once = true; \
func(dev, fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_print_once); \
})
DO_ONCE_LITE(func, dev, fmt, ##__VA_ARGS__)

#define xfs_emerg_ratelimited(dev, fmt, ...) \
xfs_printk_ratelimited(xfs_emerg, dev, fmt, ##__VA_ARGS__)
Expand Down
37 changes: 7 additions & 30 deletions include/asm-generic/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <linux/compiler.h>
#include <linux/instrumentation.h>
#include <linux/once.h>

#define CUT_HERE "------------[ cut here ]------------\n"

Expand Down Expand Up @@ -140,39 +141,15 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
})

#ifndef WARN_ON_ONCE
#define WARN_ON_ONCE(condition) ({ \
static bool __section(".data.once") __warned; \
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
WARN_ON(1); \
} \
unlikely(__ret_warn_once); \
})
#define WARN_ON_ONCE(condition) \
DO_ONCE_LITE_IF(condition, WARN_ON, 1)
#endif

#define WARN_ONCE(condition, format...) ({ \
static bool __section(".data.once") __warned; \
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
WARN(1, format); \
} \
unlikely(__ret_warn_once); \
})
#define WARN_ONCE(condition, format...) \
DO_ONCE_LITE_IF(condition, WARN, 1, format)

#define WARN_TAINT_ONCE(condition, taint, format...) ({ \
static bool __section(".data.once") __warned; \
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
WARN_TAINT(1, taint, format); \
} \
unlikely(__ret_warn_once); \
})
#define WARN_TAINT_ONCE(condition, taint, format...) \
DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format)

#else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG
Expand Down
23 changes: 3 additions & 20 deletions include/linux/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/linkage.h>
#include <linux/cache.h>
#include <linux/ratelimit_types.h>
#include <linux/once.h>

extern const char linux_banner[];
extern const char linux_proc_banner[];
Expand Down Expand Up @@ -436,27 +437,9 @@ extern int kptr_restrict;

#ifdef CONFIG_PRINTK
#define printk_once(fmt, ...) \
({ \
static bool __section(".data.once") __print_once; \
bool __ret_print_once = !__print_once; \
\
if (!__print_once) { \
__print_once = true; \
printk(fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_print_once); \
})
DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
#define printk_deferred_once(fmt, ...) \
({ \
static bool __section(".data.once") __print_once; \
bool __ret_print_once = !__print_once; \
\
if (!__print_once) { \
__print_once = true; \
printk_deferred(fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_print_once); \
})
DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
#else
#define printk_once(fmt, ...) \
no_printk(fmt, ##__VA_ARGS__)
Expand Down
13 changes: 3 additions & 10 deletions kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/irq_work.h>
#include <linux/workqueue.h>
#include <linux/ctype.h>
#include <linux/once.h>

#ifdef CONFIG_FTRACE_SYSCALLS
#include <asm/unistd.h> /* For NR_SYSCALLS */
Expand Down Expand Up @@ -98,16 +99,8 @@ enum trace_type {
#include "trace_entries.h"

/* Use this for memory failure errors */
#define MEM_FAIL(condition, fmt, ...) ({ \
static bool __section(".data.once") __warned; \
int __ret_warn_once = !!(condition); \
\
if (unlikely(__ret_warn_once && !__warned)) { \
__warned = true; \
pr_err("ERROR: " fmt, ##__VA_ARGS__); \
} \
unlikely(__ret_warn_once); \
})
#define MEM_FAIL(condition, fmt, ...) \
DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__)

/*
* syscalls are special, and need special handling, this is why
Expand Down

0 comments on commit eaeb33f

Please sign in to comment.