.buckets = notrace_buckets,
};
-static int ftrace_filtered;
+static struct hlist_head filter_buckets[1 << FTRACE_HASH_MAX_BITS];
+static struct ftrace_hash filter_hash = {
+ .size_bits = FTRACE_HASH_MAX_BITS,
+ .buckets = filter_buckets,
+};
static struct dyn_ftrace *ftrace_new_addrs;
* it's filtered
*/
if (enable && !ftrace_lookup_ip(¬race_hash, rec->ip)) {
- if (!ftrace_filtered || (rec->flags & FTRACE_FL_FILTER))
+ if (!filter_hash.count || ftrace_lookup_ip(&filter_hash, rec->ip))
flag = FTRACE_FL_ENABLED;
}
struct dyn_ftrace *func;
struct ftrace_func_probe *probe;
struct trace_parser parser;
+ struct ftrace_hash *hash;
int hidx;
int idx;
unsigned flags;
if ((rec->flags & FTRACE_FL_FREE) ||
((iter->flags & FTRACE_ITER_FILTER) &&
- !(rec->flags & FTRACE_FL_FILTER)) ||
+ !(ftrace_lookup_ip(&filter_hash, rec->ip))) ||
((iter->flags & FTRACE_ITER_NOTRACE) &&
!ftrace_lookup_ip(¬race_hash, rec->ip))) {
* off, we can short cut and just print out that all
* functions are enabled.
*/
- if (iter->flags & FTRACE_ITER_FILTER && !ftrace_filtered) {
+ if (iter->flags & FTRACE_ITER_FILTER && !filter_hash.count) {
if (*pos > 0)
return t_hash_start(m, pos);
iter->flags |= FTRACE_ITER_PRINTALL;
return ret;
}
-static void ftrace_filter_reset(int enable)
+static void ftrace_filter_reset(struct ftrace_hash *hash)
{
- struct ftrace_page *pg;
- struct dyn_ftrace *rec;
-
mutex_lock(&ftrace_lock);
- if (enable) {
- ftrace_filtered = 0;
- do_for_each_ftrace_rec(pg, rec) {
- rec->flags &= ~FTRACE_FL_FILTER;
- } while_for_each_ftrace_rec();
- } else
- ftrace_hash_clear(¬race_hash);
+ ftrace_hash_clear(hash);
mutex_unlock(&ftrace_lock);
}
static int
-ftrace_regex_open(struct inode *inode, struct file *file, int enable)
+ftrace_regex_open(struct ftrace_hash *hash, int flag,
+ struct inode *inode, struct file *file)
{
struct ftrace_iterator *iter;
int ret = 0;
return -ENOMEM;
}
+ iter->hash = hash;
+
mutex_lock(&ftrace_regex_lock);
if ((file->f_mode & FMODE_WRITE) &&
(file->f_flags & O_TRUNC))
- ftrace_filter_reset(enable);
+ ftrace_filter_reset(hash);
if (file->f_mode & FMODE_READ) {
iter->pg = ftrace_pages_start;
- iter->flags = enable ? FTRACE_ITER_FILTER :
- FTRACE_ITER_NOTRACE;
+ iter->flags = flag;
ret = seq_open(file, &show_ftrace_seq_ops);
if (!ret) {
static int
ftrace_filter_open(struct inode *inode, struct file *file)
{
- return ftrace_regex_open(inode, file, 1);
+ return ftrace_regex_open(&filter_hash, FTRACE_ITER_FILTER,
+ inode, file);
}
static int
ftrace_notrace_open(struct inode *inode, struct file *file)
{
- return ftrace_regex_open(inode, file, 0);
+ return ftrace_regex_open(¬race_hash, FTRACE_ITER_NOTRACE,
+ inode, file);
}
static loff_t
}
static int
-update_record(struct dyn_ftrace *rec, int enable, int not)
+enter_record(struct ftrace_hash *hash, struct dyn_ftrace *rec, int not)
{
struct ftrace_func_entry *entry;
- struct ftrace_hash *hash = ¬race_hash;
int ret = 0;
- if (enable) {
- if (not)
- rec->flags &= ~FTRACE_FL_FILTER;
- else
- rec->flags |= FTRACE_FL_FILTER;
- } else {
- if (not) {
- /* Do nothing if it doesn't exist */
- entry = ftrace_lookup_ip(hash, rec->ip);
- if (!entry)
- return 0;
+ entry = ftrace_lookup_ip(hash, rec->ip);
+ if (not) {
+ /* Do nothing if it doesn't exist */
+ if (!entry)
+ return 0;
- remove_hash_entry(hash, entry);
- } else {
- /* Do nothing if it exists */
- entry = ftrace_lookup_ip(hash, rec->ip);
- if (entry)
- return 0;
+ remove_hash_entry(hash, entry);
+ } else {
+ /* Do nothing if it exists */
+ if (entry)
+ return 0;
- ret = add_hash_entry(hash, rec->ip);
- }
+ ret = add_hash_entry(hash, rec->ip);
}
return ret;
}
return ftrace_match(str, regex, len, type);
}
-static int match_records(char *buff, int len, char *mod, int enable, int not)
+static int
+match_records(struct ftrace_hash *hash, char *buff,
+ int len, char *mod, int not)
{
unsigned search_len = 0;
struct ftrace_page *pg;
do_for_each_ftrace_rec(pg, rec) {
if (ftrace_match_record(rec, mod, search, search_len, type)) {
- ret = update_record(rec, enable, not);
+ ret = enter_record(hash, rec, not);
if (ret < 0) {
found = ret;
goto out_unlock;
}
found = 1;
}
- /*
- * Only enable filtering if we have a function that
- * is filtered on.
- */
- if (enable && (rec->flags & FTRACE_FL_FILTER))
- ftrace_filtered = 1;
-
} while_for_each_ftrace_rec();
out_unlock:
mutex_unlock(&ftrace_lock);
}
static int
-ftrace_match_records(char *buff, int len, int enable)
+ftrace_match_records(struct ftrace_hash *hash, char *buff, int len)
{
- return match_records(buff, len, NULL, enable, 0);
+ return match_records(hash, buff, len, NULL, 0);
}
-static int ftrace_match_module_records(char *buff, char *mod, int enable)
+static int
+ftrace_match_module_records(struct ftrace_hash *hash, char *buff, char *mod)
{
int not = 0;
not = 1;
}
- return match_records(buff, strlen(buff), mod, enable, not);
+ return match_records(hash, buff, strlen(buff), mod, not);
}
/*
static int
ftrace_mod_callback(char *func, char *cmd, char *param, int enable)
{
+ struct ftrace_hash *hash;
char *mod;
int ret = -EINVAL;
if (!strlen(mod))
return ret;
- ret = ftrace_match_module_records(func, mod, enable);
+ if (enable)
+ hash = &filter_hash;
+ else
+ hash = ¬race_hash;
+
+ ret = ftrace_match_module_records(hash, func, mod);
if (!ret)
ret = -EINVAL;
if (ret < 0)
{
char *func, *command, *next = buff;
struct ftrace_func_command *p;
+ struct ftrace_hash *hash;
int ret;
+ if (enable)
+ hash = &filter_hash;
+ else
+ hash = ¬race_hash;
+
func = strsep(&next, ":");
if (!next) {
- ret = ftrace_match_records(func, len, enable);
+ ret = ftrace_match_records(hash, func, len);
if (!ret)
ret = -EINVAL;
if (ret < 0)
}
static void
-ftrace_set_regex(unsigned char *buf, int len, int reset, int enable)
+ftrace_set_regex(struct ftrace_hash *hash, unsigned char *buf, int len, int reset)
{
if (unlikely(ftrace_disabled))
return;
mutex_lock(&ftrace_regex_lock);
if (reset)
- ftrace_filter_reset(enable);
+ ftrace_filter_reset(hash);
if (buf)
- ftrace_match_records(buf, len, enable);
+ ftrace_match_records(hash, buf, len);
mutex_unlock(&ftrace_regex_lock);
}
*/
void ftrace_set_filter(unsigned char *buf, int len, int reset)
{
- ftrace_set_regex(buf, len, reset, 1);
+ ftrace_set_regex(&filter_hash, buf, len, reset);
}
/**
*/
void ftrace_set_notrace(unsigned char *buf, int len, int reset)
{
- ftrace_set_regex(buf, len, reset, 0);
+ ftrace_set_regex(¬race_hash, buf, len, reset);
}
/*
}
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
-static void __init set_ftrace_early_filter(char *buf, int enable)
+static void __init set_ftrace_early_filter(struct ftrace_hash *hash, char *buf)
{
char *func;
while (buf) {
func = strsep(&buf, ",");
- ftrace_set_regex(func, strlen(func), 0, enable);
+ ftrace_set_regex(hash, func, strlen(func), 0);
}
}
static void __init set_ftrace_early_filters(void)
{
if (ftrace_filter_buf[0])
- set_ftrace_early_filter(ftrace_filter_buf, 1);
+ set_ftrace_early_filter(&filter_hash, ftrace_filter_buf);
if (ftrace_notrace_buf[0])
- set_ftrace_early_filter(ftrace_notrace_buf, 0);
+ set_ftrace_early_filter(¬race_hash, ftrace_notrace_buf);
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
if (ftrace_graph_buf[0])
set_ftrace_early_graph(ftrace_graph_buf);
}
static int
-ftrace_regex_release(struct inode *inode, struct file *file, int enable)
+ftrace_regex_release(struct inode *inode, struct file *file)
{
struct seq_file *m = (struct seq_file *)file->private_data;
struct ftrace_iterator *iter;
parser = &iter->parser;
if (trace_parser_loaded(parser)) {
parser->buffer[parser->idx] = 0;
- ftrace_match_records(parser->buffer, parser->idx, enable);
+ ftrace_match_records(iter->hash, parser->buffer, parser->idx);
}
trace_parser_put(parser);
return 0;
}
-static int
-ftrace_filter_release(struct inode *inode, struct file *file)
-{
- return ftrace_regex_release(inode, file, 1);
-}
-
-static int
-ftrace_notrace_release(struct inode *inode, struct file *file)
-{
- return ftrace_regex_release(inode, file, 0);
-}
-
static const struct file_operations ftrace_avail_fops = {
.open = ftrace_avail_open,
.read = seq_read,
.read = seq_read,
.write = ftrace_filter_write,
.llseek = ftrace_regex_lseek,
- .release = ftrace_filter_release,
+ .release = ftrace_regex_release,
};
static const struct file_operations ftrace_notrace_fops = {
.read = seq_read,
.write = ftrace_notrace_write,
.llseek = ftrace_regex_lseek,
- .release = ftrace_notrace_release,
+ .release = ftrace_regex_release,
};
#ifdef CONFIG_FUNCTION_GRAPH_TRACER