Skip to contentSkip to conversation

printk: modify console_unlock with printk-safe macros

PATCH In review Pierre Kuo 3 participants 4 messages Jul 15, 2017 – Jul 17, 2017 Printk

lore
Share & tools
lore

Pierre Kuo

author
#0 lore raw

PATCH 1/1 printk: modify console_unlock with printk-safe macros

From: pierre Kuo <[email protected]>

In commit de6fcbdb68b2 ("printk: convert the rest to printk-safe"), we create 4 helper macros to make printk-safe usage easier. Here we modify some part of console_unlock with above marcros.

---
 kernel/printk/printk.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/printk/printk.c +2 -4
index fc47863..21557cc 100644
@@ -2194,8 +2194,7 @@ void console_unlock(void)
 		size_t ext_len = 0;
 		size_t len;
 
-		printk_safe_enter_irqsave(flags);
-		raw_spin_lock(&logbuf_lock);
+		logbuf_lock_irqsave(flags);
 		if (seen_seq != log_next_seq) {
 			wake_klogd = true;
 			seen_seq = log_next_seq;
@@ -2267,8 +2266,7 @@ void console_unlock(void)
 	 */
 	raw_spin_lock(&logbuf_lock);
 	retry = console_seq != log_next_seq;
-	raw_spin_unlock(&logbuf_lock);
-	printk_safe_exit_irqrestore(flags);
+	logbuf_unlock_irqrestore(flags);
 
 	if (retry && console_trylock())
 		goto again;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 5 lines · Pierre Kuo

In commit de6fcbdb68b2 ("printk: convert the rest to printk-safe"), we create 4 helper macros to make printk-safe usage easier. Here we modify some part of console_unlock with above marcros.

        raw_spin_lock(&logbuf_lock);

...and now we have "orphaned" call to lock.

kernel/printk/printk.c void console_unlock(void)

Quoted 3 lines
kernel/printk/printk.c +1 -1
-       raw_spin_unlock(&logbuf_lock);
 
+       logbuf_unlock_irqrestore(flags);

Personally I can't say this makes things clearer.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Pierre Kuo

On (07/15/17 18:36), Pierre Kuo wrote:
[..]

Quoted 15 lines
kernel/printk/printk.c +1 -2
index fc47863..21557cc 100644
@@ -2194,8 +2194,7 @@ void console_unlock(void)
 		size_t ext_len = 0;
 		size_t len;
 
-		printk_safe_enter_irqsave(flags);
-		raw_spin_lock(&logbuf_lock);
+		logbuf_lock_irqsave(flags);
 		if (seen_seq != log_next_seq) {
 			wake_klogd = true;
 			seen_seq = log_next_seq;

kernel/printk/printk.c void console_unlock(void) · line 2272

Quoted 9 lines
kernel/printk/printk.c +1 -2
@@ -2267,8 +2266,7 @@ void console_unlock(void)
 	 */
 	raw_spin_lock(&logbuf_lock);
 	retry = console_seq != log_next_seq;
-	raw_spin_unlock(&logbuf_lock);
-	printk_safe_exit_irqrestore(flags);
+	logbuf_unlock_irqrestore(flags);
 
 	if (retry && console_trylock())
 		goto again;

I did it that particular way for a reason - console_unlock() does a bunch of tricks: unlocking logbuf in the middle of printing loop, breaking out of loop with local IRQs disabled, re-taking the logbuf after the loop still will local IRQs disabled, etc. etc. I didn't want to (and still don't) mix-in logbuf macros; we do things that macros don't cover anyway. sorry, I don't agree that the patch improves readability.

	-ss
author
#3 lore raw

hi Sergey and Andy:

Quoted 24 lines · Pierre Kuo

[..]

Quoted 22 lines
kernel/printk/printk.c +2 -4
index fc47863..21557cc 100644
@@ -2194,8 +2194,7 @@ void console_unlock(void)
              size_t ext_len = 0;
              size_t len;
 
-             printk_safe_enter_irqsave(flags);
-             raw_spin_lock(&logbuf_lock);
+             logbuf_lock_irqsave(flags);
              if (seen_seq != log_next_seq) {
                      wake_klogd = true;
                      seen_seq = log_next_seq;
@@ -2267,8 +2266,7 @@ void console_unlock(void)
       */
      raw_spin_lock(&logbuf_lock);
      retry = console_seq != log_next_seq;
-     raw_spin_unlock(&logbuf_lock);
-     printk_safe_exit_irqrestore(flags);
+     logbuf_unlock_irqrestore(flags);
 
Quoted 10 lines

kernel/printk/printk.c void console_unlock(void) · line 2272

Quoted 2 lines
kernel/printk/printk.c +0 -0
      if (retry && console_trylock())
              goto again;

I did it that particular way for a reason - console_unlock() does a bunch of tricks: unlocking logbuf in the middle of printing loop, breaking out of loop with local IRQs disabled, re-taking the logbuf after the loop still will local IRQs disabled, etc. etc. I didn't want to (and still don't) mix-in logbuf macros; we do things that macros don't cover anyway. sorry, I don't agree that the patch improves readability.

Got ur points and appreciate for your illustration. ^^ Thanks a lot,