lkml.org 
[lkml]   [2017]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] printk: Move printk_delay to separate file
Date
printk.c is a huge file with too many local functions for a
human to read and easily parse.

Start to separate out bits into smaller files.

Miscellanea:

o Rename suppress_message_printing to printk_suppress_message
o Add function definitions to printk.h

Signed-off-by: Joe Perches <joe@perches.com>
---
include/linux/printk.h | 4 +++
kernel/printk/Makefile | 2 +-
kernel/printk/delay.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++
kernel/printk/printk.c | 78 +++-----------------------------------------------
4 files changed, 82 insertions(+), 75 deletions(-)
create mode 100644 kernel/printk/delay.c

diff --git a/include/linux/printk.h b/include/linux/printk.h
index e10f27468322..c86cb07baf83 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -186,7 +186,11 @@ extern int __printk_ratelimit(const char *func);
extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
unsigned int interval_msec);

+bool printk_suppress_message(int level);
+
extern int printk_delay_msec;
+void printk_delay(int level);
+
extern int dmesg_restrict;
extern int kptr_restrict;

diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
index 4a2ffc39eb95..9b38d597575e 100644
--- a/kernel/printk/Makefile
+++ b/kernel/printk/Makefile
@@ -1,3 +1,3 @@
-obj-y = printk.o
+obj-y = printk.o delay.o
obj-$(CONFIG_PRINTK) += printk_safe.o
obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o
diff --git a/kernel/printk/delay.c b/kernel/printk/delay.c
new file mode 100644
index 000000000000..b8edd6d20818
--- /dev/null
+++ b/kernel/printk/delay.c
@@ -0,0 +1,73 @@
+#include <linux/kernel.h>
+#include <linux/jiffies.h>
+#include <linux/nmi.h>
+#include <linux/delay.h>
+
+#ifdef CONFIG_BOOT_PRINTK_DELAY
+
+static int boot_delay; /* msecs delay after each printk during bootup */
+static unsigned long long loops_per_msec; /* based on boot_delay */
+
+static int __init boot_delay_setup(char *str)
+{
+ unsigned long lpj;
+
+ lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
+ loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
+
+ get_option(&str, &boot_delay);
+ if (boot_delay > 10 * 1000)
+ boot_delay = 0;
+
+ pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, HZ: %d, loops_per_msec: %llu\n",
+ boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
+ return 0;
+}
+early_param("boot_delay", boot_delay_setup);
+
+static void boot_delay_msec(int level)
+{
+ unsigned long long k;
+ unsigned long timeout;
+
+ if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING) ||
+ printk_suppress_message(level))
+ return;
+
+ k = (unsigned long long)loops_per_msec * boot_delay;
+
+ timeout = jiffies + msecs_to_jiffies(boot_delay);
+ while (k) {
+ k--;
+ cpu_relax();
+ /*
+ * use (volatile) jiffies to prevent compiler reduction;
+ * loop termination via jiffies is secondary
+ * and may or may not happen.
+ */
+ if (time_after(jiffies, timeout))
+ break;
+ touch_nmi_watchdog();
+ }
+}
+#else
+static inline void boot_delay_msec(int level)
+{
+}
+#endif
+
+int printk_delay_msec __read_mostly;
+
+void printk_delay(int level)
+{
+ boot_delay_msec(level);
+
+ if (unlikely(printk_delay_msec)) {
+ int m = printk_delay_msec;
+
+ while (m--) {
+ mdelay(1);
+ touch_nmi_watchdog();
+ }
+ }
+}
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fc47863f629c..b8e63a5f1558 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1142,66 +1142,11 @@ module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ignore_loglevel,
"ignore loglevel setting (prints all kernel messages to the console)");

-static bool suppress_message_printing(int level)
+bool printk_suppress_message(int level)
{
return (level >= console_loglevel && !ignore_loglevel);
}

-#ifdef CONFIG_BOOT_PRINTK_DELAY
-
-static int boot_delay; /* msecs delay after each printk during bootup */
-static unsigned long long loops_per_msec; /* based on boot_delay */
-
-static int __init boot_delay_setup(char *str)
-{
- unsigned long lpj;
-
- lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
- loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
-
- get_option(&str, &boot_delay);
- if (boot_delay > 10 * 1000)
- boot_delay = 0;
-
- pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
- "HZ: %d, loops_per_msec: %llu\n",
- boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
- return 0;
-}
-early_param("boot_delay", boot_delay_setup);
-
-static void boot_delay_msec(int level)
-{
- unsigned long long k;
- unsigned long timeout;
-
- if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING)
- || suppress_message_printing(level)) {
- return;
- }
-
- k = (unsigned long long)loops_per_msec * boot_delay;
-
- timeout = jiffies + msecs_to_jiffies(boot_delay);
- while (k) {
- k--;
- cpu_relax();
- /*
- * use (volatile) jiffies to prevent
- * compiler reduction; loop termination via jiffies
- * is secondary and may or may not happen.
- */
- if (time_after(jiffies, timeout))
- break;
- touch_nmi_watchdog();
- }
-}
-#else
-static inline void boot_delay_msec(int level)
-{
-}
-#endif
-
static bool printk_time = IS_ENABLED(CONFIG_PRINTK_TIME);
module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);

@@ -1587,20 +1532,6 @@ static void call_console_drivers(const char *ext_text, size_t ext_len,
}
}

-int printk_delay_msec __read_mostly;
-
-static inline void printk_delay(void)
-{
- if (unlikely(printk_delay_msec)) {
- int m = printk_delay_msec;
-
- while (m--) {
- mdelay(1);
- touch_nmi_watchdog();
- }
- }
-}
-
/*
* Continuation lines are buffered, and not committed to the record buffer
* until the line is complete, or a race forces it. The line fragments
@@ -1709,8 +1640,7 @@ asmlinkage int vprintk_emit(int facility, int level,
in_sched = true;
}

- boot_delay_msec(level);
- printk_delay();
+ printk_delay(level);

/* This stops the holder of console_sem just where we want him */
logbuf_lock_irqsave(flags);
@@ -1871,7 +1801,7 @@ static void call_console_drivers(const char *ext_text, size_t ext_len,
const char *text, size_t len) {}
static size_t msg_print_text(const struct printk_log *msg,
bool syslog, char *buf, size_t size) { return 0; }
-static bool suppress_message_printing(int level) { return false; }
+bool printk_suppress_message(int level) { return false; }

#endif /* CONFIG_PRINTK */

@@ -2216,7 +2146,7 @@ void console_unlock(void)
break;

msg = log_from_idx(console_idx);
- if (suppress_message_printing(msg->level)) {
+ if (printk_suppress_message(msg->level)) {
/*
* Skip record we have buffered and already printed
* directly to the console when we received it, and
--
2.10.0.rc2.1.g053435c
\
 
 \ /
  Last update: 2017-07-07 20:09    [W:0.080 / U:2.368 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site