Skip to content

Commit

Permalink
ftrace: convert ftrace_lock from a spinlock to mutex
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Steven Rostedt committed Feb 16, 2009
1 parent f618077 commit 52baf11
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int function_trace_stop;
*/
static int ftrace_disabled __read_mostly;

static DEFINE_SPINLOCK(ftrace_lock);
static DEFINE_MUTEX(ftrace_lock);
static DEFINE_MUTEX(ftrace_sysctl_lock);
static DEFINE_MUTEX(ftrace_start_lock);

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

static int __register_ftrace_function(struct ftrace_ops *ops)
{
/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);

ops->next = ftrace_list;
/*
Expand Down Expand Up @@ -172,7 +171,7 @@ static int __register_ftrace_function(struct ftrace_ops *ops)
#endif
}

spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);

return 0;
}
Expand All @@ -182,8 +181,7 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops)
struct ftrace_ops **p;
int ret = 0;

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);

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

out:
spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);

return ret;
}
Expand All @@ -233,8 +231,7 @@ static void ftrace_update_pid_func(void)
{
ftrace_func_t func;

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);

if (ftrace_trace_function == ftrace_stub)
goto out;
Expand All @@ -256,7 +253,7 @@ static void ftrace_update_pid_func(void)
#endif

out:
spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);
}

#ifdef CONFIG_DYNAMIC_FTRACE
Expand Down Expand Up @@ -358,15 +355,12 @@ void ftrace_release(void *start, unsigned long size)
if (ftrace_disabled || !start)
return;

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);

mutex_lock(&ftrace_lock);
do_for_each_ftrace_rec(pg, rec) {
if ((rec->ip >= s) && (rec->ip < e))
ftrace_free_rec(rec);
} while_for_each_ftrace_rec();

spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);
}

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

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);
retry:
if (iter->idx >= iter->pg->index) {
if (iter->pg->next) {
Expand Down Expand Up @@ -833,7 +826,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
goto retry;
}
}
spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);

return rec;
}
Expand Down Expand Up @@ -962,17 +955,15 @@ static void ftrace_filter_reset(int enable)
struct dyn_ftrace *rec;
unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);
if (enable)
ftrace_filtered = 0;
do_for_each_ftrace_rec(pg, rec) {
if (rec->flags & FTRACE_FL_FAILED)
continue;
rec->flags &= ~type;
} while_for_each_ftrace_rec();

spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);
}

static int
Expand Down Expand Up @@ -1151,8 +1142,7 @@ static void ftrace_match_records(char *buff, int len, int enable)

search_len = strlen(search);

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);
do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_FAILED)
Expand All @@ -1171,7 +1161,7 @@ static void ftrace_match_records(char *buff, int len, int enable)
if (enable && (rec->flags & FTRACE_FL_FILTER))
ftrace_filtered = 1;
} while_for_each_ftrace_rec();
spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);
}

static int
Expand Down Expand Up @@ -1218,8 +1208,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable)
search_len = strlen(search);
}

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);
mutex_lock(&ftrace_lock);
do_for_each_ftrace_rec(pg, rec) {

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

} while_for_each_ftrace_rec();
spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);
}

/*
Expand Down Expand Up @@ -1676,9 +1665,7 @@ ftrace_set_func(unsigned long *array, int idx, char *buffer)
if (ftrace_disabled)
return -ENODEV;

/* should not be called from interrupt context */
spin_lock(&ftrace_lock);

mutex_lock(&ftrace_lock);
do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE))
Expand All @@ -1699,7 +1686,7 @@ ftrace_set_func(unsigned long *array, int idx, char *buffer)
}
} while_for_each_ftrace_rec();
out:
spin_unlock(&ftrace_lock);
mutex_unlock(&ftrace_lock);

return found ? 0 : -EINVAL;
}
Expand Down

0 comments on commit 52baf11

Please sign in to comment.