From 4cfeb4a04082de41856875224190cd57ad3d2b36 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Tue, 4 Dec 2018 15:57:16 +0100
Subject: [PATCH] tracing: add cond_resched to ftrace_replace_code()

ftrace_replace_code(), which is expensive because it changes the page
tables and flush caches. Microseconds add up because this is called in a
loop for each dyn_ftrace record, and this triggers the softlockup
watchdog unless we let it sleep occationally.
Rework so that we call cond_resched() if preemptible().

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index c375e33239f7..126b27354b5d 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2435,6 +2435,8 @@ void __weak ftrace_replace_code(int enable)
 			/* Stop processing */
 			return;
 		}
+		if (preemptible())
+			cond_resched();
 	} while_for_each_ftrace_rec();
 }
 
-- 
2.19.2

