summaryrefslogtreecommitdiffstats
path: root/debian/patches-rt/HACK-printk-drop-the-logbuf_lock-more-often.patch
blob: cc0ec0e7bc1b23b70927b5da8b9d2be1dd247333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Thu, 21 Mar 2013 19:01:05 +0100
Subject: printk: Drop the logbuf_lock more often
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patches-4.19.13-rt10.tar.xz

The lock is hold with irgs off. The latency drops 500us+ on my arm bugs
with a "full" buffer after executing "dmesg" on the shell.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/printk/printk.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1420,12 +1420,23 @@ static int syslog_print_all(char __user
 	u64 next_seq;
 	u64 seq;
 	u32 idx;
+	int attempts = 0;
+	int num_msg;
 
 	text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
 	if (!text)
 		return -ENOMEM;
 
 	logbuf_lock_irq();
+
+try_again:
+	attempts++;
+	if (attempts > 10) {
+		len = -EBUSY;
+		goto out;
+	}
+	num_msg = 0;
+
 	/*
 	 * Find first record that fits, including all following records,
 	 * into the user-provided buffer for this dump.
@@ -1438,6 +1449,14 @@ static int syslog_print_all(char __user
 		len += msg_print_text(msg, true, NULL, 0);
 		idx = log_next(idx);
 		seq++;
+		num_msg++;
+		if (num_msg > 5) {
+			num_msg = 0;
+			logbuf_unlock_irq();
+			logbuf_lock_irq();
+			if (clear_seq < log_first_seq)
+				goto try_again;
+		}
 	}
 
 	/* move first record forward until length fits into the buffer */
@@ -1449,6 +1468,14 @@ static int syslog_print_all(char __user
 		len -= msg_print_text(msg, true, NULL, 0);
 		idx = log_next(idx);
 		seq++;
+		num_msg++;
+		if (num_msg > 5) {
+			num_msg = 0;
+			logbuf_unlock_irq();
+			logbuf_lock_irq();
+			if (clear_seq < log_first_seq)
+				goto try_again;
+		}
 	}
 
 	/* last message fitting into this dump */
@@ -1486,6 +1513,7 @@ static int syslog_print_all(char __user
 		clear_seq = log_next_seq;
 		clear_idx = log_next_idx;
 	}
+out:
 	logbuf_unlock_irq();
 
 	kfree(text);