Skip to contentSkip to conversation

printk: Add config option for disabling printk offloading

PATCH Sergey Senozhatsky 1 participant 1 message Dec 10, 2015 Printk

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines

Necessity for offloading of printing was observed only for large systems. So add a config option (disabled by default) which removes most of the overhead added by this functionality.

to be folded:

- add spin_lock_init_print_lock() to be called from zap_lock()
- move PRINTK_OFFLOAD defines up, so zap_lock() sees them

---
 kernel/printk/printk.c | 119 ++++++++++++++++++++++++++-----------------------
 1 file changed, 63 insertions(+), 56 deletions(-)
kernel/printk/printk.c +63 -56
index 2a500a5..86f5abf 100644
@@ -333,7 +333,66 @@ module_param_cb(offload_chars, &offload_chars_ops, &printk_offload_chars,
 		   S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(offload_chars, "offload printing to console to a different"
 	" cpu after this number of characters");
-#endif
+
+/*
+ * Returns true iff there is other cpu waiting to take over printing. This
+ * function also takes are of setting PRINTK_HANDOVER_B if we want to hand over
+ * printing to some other cpu.
+ */
+static bool cpu_stop_printing(int printed_chars)
+{
+	/* Oops? Print everything now to maximize chances user will see it */
+	if (oops_in_progress)
+		return false;
+	if (!printk_offload_chars || printed_chars < printk_offload_chars)
+		return false;
+	/*
+	 * Make sure we load fresh value of printing_tasks_spinning. Matches
+	 * the barrier in printing_task()
+	 */
+	smp_rmb();
+	if (atomic_read(&printing_tasks_spinning))
+		return true;
+	wake_up(&print_queue);
+
+	return false;
+}
+
+static bool cpu_should_cond_resched(bool do_cond_resched)
+{
+	/* Oops? Print everything now to maximize chances user will see it */
+	if (oops_in_progress)
+		return false;
+	if (!printk_offload_chars && do_cond_resched)
+		return true;
+	return false;
+}
+
+#define spin_lock_print_lock(flags) raw_spin_lock_irqsave(&print_lock, flags)
+
+#define spin_unlock_print_lock(flags) raw_spin_unlock_irqrestore(&print_lock, flags)
+
+#define spin_lock_init_print_lock() raw_spin_lock_init(&print_lock)
+
+#else /* !CONFIG_PRINTK_OFFLOAD */
+
+static bool cpu_stop_printing(int printed_chars)
+{
+	return false;
+}
+
+static bool cpu_should_cond_resched(bool do_cond_resched)
+{
+	return do_cond_resched && !oops_in_progress;
+}
+
+#define spin_lock_print_lock(flags) local_irq_save(flags)
+
+#define spin_unlock_print_lock(flags) local_irq_restore(flags)
+
+#define spin_lock_init_print_lock()
+
+#endif /* CONFIG_PRINTK_OFFLOAD */
 
 /* Return log buffer address */
 char *log_buf_addr_get(void)
@@ -1531,7 +1590,7 @@ static void zap_locks(void)
 	/* If a crash is occurring, make sure we can't deadlock */
 	raw_spin_lock_init(&logbuf_lock);
 	/* And make sure that we print immediately */
-	raw_spin_lock_init(&print_lock);
+	spin_lock_init_print_lock();
 	sema_init(&console_sem, 1);
 }
 
@@ -2265,58 +2324,6 @@ out:
 	raw_spin_unlock_irqrestore(&logbuf_lock, flags);
 }
 
-#ifdef CONFIG_PRINTK_OFFLOAD
-/*
- * Returns true iff there is other cpu waiting to take over printing. This
- * function also takes are of setting PRINTK_HANDOVER_B if we want to hand over
- * printing to some other cpu.
- */
-static bool cpu_stop_printing(int printed_chars)
-{
-	/* Oops? Print everything now to maximize chances user will see it */
-	if (oops_in_progress)
-		return false;
-	if (!printk_offload_chars || printed_chars < printk_offload_chars)
-		return false;
-	/*
-	 * Make sure we load fresh value of printing_tasks_spinning. Matches
-	 * the barrier in printing_task()
-	 */
-	smp_rmb();
-	if (atomic_read(&printing_tasks_spinning))
-		return true;
-	wake_up(&print_queue);
-
-	return false;
-}
-
-static bool cpu_should_cond_resched(bool do_cond_resched)
-{
-	/* Oops? Print everything now to maximize chances user will see it */
-	if (oops_in_progress)
-		return false;
-	if (!printk_offload_chars && do_cond_resched)
-		return true;
-	return false;
-}
-
-#define spin_lock_print_lock(flags) raw_spin_lock_irqsave(&print_lock, flags)
-
-#define spin_unlock_print_lock(flags) raw_spin_unlock_irqrestore(&print_lock, flags)
-
-#else
-
-static bool cpu_stop_printing(int printed_chars)
-{
-	return false;
-}
-
-#define spin_lock_print_lock(flags) local_irq_save(flags)
-
-#define spin_unlock_print_lock(flags) local_irq_restore(flags)
-
-#endif
-
 /**
  * console_unlock - unlock the console system
  *
@@ -2440,9 +2447,9 @@ skip:
 		printed_chars += len;
 
 		if (unlikely(cpu_should_cond_resched(do_cond_resched))) {
-			raw_spin_unlock_irqrestore(&print_lock, flags);
+			spin_unlock_print_lock(flags);
 			cond_resched();
-			raw_spin_lock_irqsave(&print_lock, flags);
+			spin_lock_print_lock(flags);
 		}
 	}
 
Signature · 1 line
2.6.3