Skip to content

Commit 52baf11

Browse files
author
Steven Rostedt
committed
ftrace: convert ftrace_lock from a spinlock to mutex
Impact: clean up The older versions of ftrace required doing the ftrace list search under atomic context. Now all the calls are in non-atomic context. There is no reason to keep the ftrace_lock as a spinlock. This patch converts it to a mutex. Signed-off-by: Steven Rostedt <srostedt@redhat.com>
1 parent f618077 commit 52baf11

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

kernel/trace/ftrace.c

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int function_trace_stop;
6161
*/
6262
static int ftrace_disabled __read_mostly;
6363

64-
static DEFINE_SPINLOCK(ftrace_lock);
64+
static DEFINE_MUTEX(ftrace_lock);
6565
static DEFINE_MUTEX(ftrace_sysctl_lock);
6666
static DEFINE_MUTEX(ftrace_start_lock);
6767

@@ -134,8 +134,7 @@ static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip)
134134

135135
static int __register_ftrace_function(struct ftrace_ops *ops)
136136
{
137-
/* should not be called from interrupt context */
138-
spin_lock(&ftrace_lock);
137+
mutex_lock(&ftrace_lock);
139138

140139
ops->next = ftrace_list;
141140
/*
@@ -172,7 +171,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops)
172171
#endif
173172
}
174173

175-
spin_unlock(&ftrace_lock);
174+
mutex_unlock(&ftrace_lock);
176175

177176
return 0;
178177
}
@@ -182,8 +181,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops)
182181
struct ftrace_ops **p;
183182
int ret = 0;
184183

185-
/* should not be called from interrupt context */
186-
spin_lock(&ftrace_lock);
184+
mutex_lock(&ftrace_lock);
187185

188186
/*
189187
* If we are removing the last function, then simply point
@@ -224,7 +222,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops)
224222
}
225223

226224
out:
227-
spin_unlock(&ftrace_lock);
225+
mutex_unlock(&ftrace_lock);
228226

229227
return ret;
230228
}
@@ -233,8 +231,7 @@ static void ftrace_update_pid_func(void)
233231
{
234232
ftrace_func_t func;
235233

236-
/* should not be called from interrupt context */
237-
spin_lock(&ftrace_lock);
234+
mutex_lock(&ftrace_lock);
238235

239236
if (ftrace_trace_function == ftrace_stub)
240237
goto out;
@@ -256,7 +253,7 @@ static void ftrace_update_pid_func(void)
256253
#endif
257254

258255
out:
259-
spin_unlock(&ftrace_lock);
256+
mutex_unlock(&ftrace_lock);
260257
}
261258

262259
#ifdef CONFIG_DYNAMIC_FTRACE
@@ -358,15 +355,12 @@ void ftrace_release(void *start, unsigned long size)
358355
if (ftrace_disabled || !start)
359356
return;
360357

361-
/* should not be called from interrupt context */
362-
spin_lock(&ftrace_lock);
363-
358+
mutex_lock(&ftrace_lock);
364359
do_for_each_ftrace_rec(pg, rec) {
365360
if ((rec->ip >= s) && (rec->ip < e))
366361
ftrace_free_rec(rec);
367362
} while_for_each_ftrace_rec();
368-
369-
spin_unlock(&ftrace_lock);
363+
mutex_unlock(&ftrace_lock);
370364
}
371365

372366
static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip)
@@ -803,8 +797,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
803797
if (iter->flags & FTRACE_ITER_PRINTALL)
804798
return NULL;
805799

806-
/* should not be called from interrupt context */
807-
spin_lock(&ftrace_lock);
800+
mutex_lock(&ftrace_lock);
808801
retry:
809802
if (iter->idx >= iter->pg->index) {
810803
if (iter->pg->next) {
@@ -833,7 +826,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
833826
goto retry;
834827
}
835828
}
836-
spin_unlock(&ftrace_lock);
829+
mutex_unlock(&ftrace_lock);
837830

838831
return rec;
839832
}
@@ -962,17 +955,15 @@ static void ftrace_filter_reset(int enable)
962955
struct dyn_ftrace *rec;
963956
unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
964957

965-
/* should not be called from interrupt context */
966-
spin_lock(&ftrace_lock);
958+
mutex_lock(&ftrace_lock);
967959
if (enable)
968960
ftrace_filtered = 0;
969961
do_for_each_ftrace_rec(pg, rec) {
970962
if (rec->flags & FTRACE_FL_FAILED)
971963
continue;
972964
rec->flags &= ~type;
973965
} while_for_each_ftrace_rec();
974-
975-
spin_unlock(&ftrace_lock);
966+
mutex_unlock(&ftrace_lock);
976967
}
977968

978969
static int
@@ -1151,8 +1142,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
11511142

11521143
search_len = strlen(search);
11531144

1154-
/* should not be called from interrupt context */
1155-
spin_lock(&ftrace_lock);
1145+
mutex_lock(&ftrace_lock);
11561146
do_for_each_ftrace_rec(pg, rec) {
11571147

11581148
if (rec->flags & FTRACE_FL_FAILED)
@@ -1171,7 +1161,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
11711161
if (enable && (rec->flags & FTRACE_FL_FILTER))
11721162
ftrace_filtered = 1;
11731163
} while_for_each_ftrace_rec();
1174-
spin_unlock(&ftrace_lock);
1164+
mutex_unlock(&ftrace_lock);
11751165
}
11761166

11771167
static int
@@ -1218,8 +1208,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
12181208
search_len = strlen(search);
12191209
}
12201210

1221-
/* should not be called from interrupt context */
1222-
spin_lock(&ftrace_lock);
1211+
mutex_lock(&ftrace_lock);
12231212
do_for_each_ftrace_rec(pg, rec) {
12241213

12251214
if (rec->flags & FTRACE_FL_FAILED)
@@ -1236,7 +1225,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
12361225
ftrace_filtered = 1;
12371226

12381227
} while_for_each_ftrace_rec();
1239-
spin_unlock(&ftrace_lock);
1228+
mutex_unlock(&ftrace_lock);
12401229
}
12411230

12421231
/*
@@ -1676,9 +1665,7 @@ ftrace_set_func(unsigned long *array, int idx, char *buffer)
16761665
if (ftrace_disabled)
16771666
return -ENODEV;
16781667

1679-
/* should not be called from interrupt context */
1680-
spin_lock(&ftrace_lock);
1681-
1668+
mutex_lock(&ftrace_lock);
16821669
do_for_each_ftrace_rec(pg, rec) {
16831670

16841671
if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE))
@@ -1699,7 +1686,7 @@ ftrace_set_func(unsigned long *array, int idx, char *buffer)
16991686
}
17001687
} while_for_each_ftrace_rec();
17011688
out:
1702-
spin_unlock(&ftrace_lock);
1689+
mutex_unlock(&ftrace_lock);
17031690

17041691
return found ? 0 : -EINVAL;
17051692
}

0 commit comments

Comments
 (0)