aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2016-04-20 15:19:54 -0400
committerSteven Rostedt <rostedt@goodmis.org>2016-06-20 09:54:17 -0400
commit5cc8976bd52153678ca37cc1e3000833b20276f3 (patch)
treeec30f4a4b19cf5da11a5d798343cb89d1bd26f1a
parentd8275c454dcdba296675221b4c12f19d1b6e0ee8 (diff)
tracing: Move the pid_list seq_file functions to be global
To allow other aspects of ftrace to use the pid_list logic, we need to reuse the seq_file functions. Making the generic part into functions that can be called by other files will help in this regard. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--kernel/trace/trace.c71
-rw-r--r--kernel/trace/trace.h3
-rw-r--r--kernel/trace/trace_events.c34
3 files changed, 77 insertions, 31 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 0b87fe8e6d0b..7943e306cc7f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -397,6 +397,77 @@ void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
397 clear_bit(task->pid, pid_list->pids); 397 clear_bit(task->pid, pid_list->pids);
398} 398}
399 399
400/**
401 * trace_pid_next - Used for seq_file to get to the next pid of a pid_list
402 * @pid_list: The pid list to show
403 * @v: The last pid that was shown (+1 the actual pid to let zero be displayed)
404 * @pos: The position of the file
405 *
406 * This is used by the seq_file "next" operation to iterate the pids
407 * listed in a trace_pid_list structure.
408 *
409 * Returns the pid+1 as we want to display pid of zero, but NULL would
410 * stop the iteration.
411 */
412void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos)
413{
414 unsigned long pid = (unsigned long)v;
415
416 (*pos)++;
417
418 /* pid already is +1 of the actual prevous bit */
419 pid = find_next_bit(pid_list->pids, pid_list->pid_max, pid);
420
421 /* Return pid + 1 to allow zero to be represented */
422 if (pid < pid_list->pid_max)
423 return (void *)(pid + 1);
424
425 return NULL;
426}
427
428/**
429 * trace_pid_start - Used for seq_file to start reading pid lists
430 * @pid_list: The pid list to show
431 * @pos: The position of the file
432 *
433 * This is used by seq_file "start" operation to start the iteration
434 * of listing pids.
435 *
436 * Returns the pid+1 as we want to display pid of zero, but NULL would
437 * stop the iteration.
438 */
439void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos)
440{
441 unsigned long pid;
442 loff_t l = 0;
443
444 pid = find_first_bit(pid_list->pids, pid_list->pid_max);
445 if (pid >= pid_list->pid_max)
446 return NULL;
447
448 /* Return pid + 1 so that zero can be the exit value */
449 for (pid++; pid && l < *pos;
450 pid = (unsigned long)trace_pid_next(pid_list, (void *)pid, &l))
451 ;
452 return (void *)pid;
453}
454
455/**
456 * trace_pid_show - show the current pid in seq_file processing
457 * @m: The seq_file structure to write into
458 * @v: A void pointer of the pid (+1) value to display
459 *
460 * Can be directly used by seq_file operations to display the current
461 * pid value.
462 */
463int trace_pid_show(struct seq_file *m, void *v)
464{
465 unsigned long pid = (unsigned long)v - 1;
466
467 seq_printf(m, "%lu\n", pid);
468 return 0;
469}
470
400static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu) 471static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu)
401{ 472{
402 u64 ts; 473 u64 ts;
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 172330891c6d..45442d5842f2 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -636,6 +636,9 @@ bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
636void trace_filter_add_remove_task(struct trace_pid_list *pid_list, 636void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
637 struct task_struct *self, 637 struct task_struct *self,
638 struct task_struct *task); 638 struct task_struct *task);
639void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
640void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
641int trace_pid_show(struct seq_file *m, void *v);
639 642
640#ifdef CONFIG_TRACER_MAX_TRACE 643#ifdef CONFIG_TRACER_MAX_TRACE
641void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu); 644void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index a11e6d9a3841..fd831a972bae 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -983,18 +983,8 @@ p_next(struct seq_file *m, void *v, loff_t *pos)
983{ 983{
984 struct trace_array *tr = m->private; 984 struct trace_array *tr = m->private;
985 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->filtered_pids); 985 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->filtered_pids);
986 unsigned long pid = (unsigned long)v;
987 986
988 (*pos)++; 987 return trace_pid_next(pid_list, v, pos);
989
990 /* pid already is +1 of the actual prevous bit */
991 pid = find_next_bit(pid_list->pids, pid_list->pid_max, pid);
992
993 /* Return pid + 1 to allow zero to be represented */
994 if (pid < pid_list->pid_max)
995 return (void *)(pid + 1);
996
997 return NULL;
998} 988}
999 989
1000static void *p_start(struct seq_file *m, loff_t *pos) 990static void *p_start(struct seq_file *m, loff_t *pos)
@@ -1002,8 +992,6 @@ static void *p_start(struct seq_file *m, loff_t *pos)
1002{ 992{
1003 struct trace_pid_list *pid_list; 993 struct trace_pid_list *pid_list;
1004 struct trace_array *tr = m->private; 994 struct trace_array *tr = m->private;
1005 unsigned long pid;
1006 loff_t l = 0;
1007 995
1008 /* 996 /*
1009 * Grab the mutex, to keep calls to p_next() having the same 997 * Grab the mutex, to keep calls to p_next() having the same
@@ -1019,15 +1007,7 @@ static void *p_start(struct seq_file *m, loff_t *pos)
1019 if (!pid_list) 1007 if (!pid_list)
1020 return NULL; 1008 return NULL;
1021 1009
1022 pid = find_first_bit(pid_list->pids, pid_list->pid_max); 1010 return trace_pid_start(pid_list, pos);
1023 if (pid >= pid_list->pid_max)
1024 return NULL;
1025
1026 /* Return pid + 1 so that zero can be the exit value */
1027 for (pid++; pid && l < *pos;
1028 pid = (unsigned long)p_next(m, (void *)pid, &l))
1029 ;
1030 return (void *)pid;
1031} 1011}
1032 1012
1033static void p_stop(struct seq_file *m, void *p) 1013static void p_stop(struct seq_file *m, void *p)
@@ -1037,14 +1017,6 @@ static void p_stop(struct seq_file *m, void *p)
1037 mutex_unlock(&event_mutex); 1017 mutex_unlock(&event_mutex);
1038} 1018}
1039 1019
1040static int p_show(struct seq_file *m, void *v)
1041{
1042 unsigned long pid = (unsigned long)v - 1;
1043
1044 seq_printf(m, "%lu\n", pid);
1045 return 0;
1046}
1047
1048static ssize_t 1020static ssize_t
1049event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, 1021event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
1050 loff_t *ppos) 1022 loff_t *ppos)
@@ -1795,7 +1767,7 @@ static const struct seq_operations show_set_event_seq_ops = {
1795static const struct seq_operations show_set_pid_seq_ops = { 1767static const struct seq_operations show_set_pid_seq_ops = {
1796 .start = p_start, 1768 .start = p_start,
1797 .next = p_next, 1769 .next = p_next,
1798 .show = p_show, 1770 .show = trace_pid_show,
1799 .stop = p_stop, 1771 .stop = p_stop,
1800}; 1772};
1801 1773