Skip to content

Commit 5cc8976

Browse files
committed
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>
1 parent d8275c4 commit 5cc8976

3 files changed

Lines changed: 77 additions & 31 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,77 @@ void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
397397
clear_bit(task->pid, pid_list->pids);
398398
}
399399

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+
*/
412+
void *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+
*/
439+
void *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+
*/
463+
int 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+
400471
static cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu)
401472
{
402473
u64 ts;

‎kernel/trace/trace.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
636636
void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
637637
struct task_struct *self,
638638
struct task_struct *task);
639+
void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
640+
void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
641+
int trace_pid_show(struct seq_file *m, void *v);
639642

640643
#ifdef CONFIG_TRACER_MAX_TRACE
641644
void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);

‎kernel/trace/trace_events.c‎

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -983,27 +983,15 @@ p_next(struct seq_file *m, void *v, loff_t *pos)
983983
{
984984
struct trace_array *tr = m->private;
985985
struct trace_pid_list *pid_list = rcu_dereference_sched(tr->filtered_pids);
986-
unsigned long pid = (unsigned long)v;
987986

988-
(*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;
987+
return trace_pid_next(pid_list, v, pos);
998988
}
999989

1000990
static void *p_start(struct seq_file *m, loff_t *pos)
1001991
__acquires(RCU)
1002992
{
1003993
struct trace_pid_list *pid_list;
1004994
struct trace_array *tr = m->private;
1005-
unsigned long pid;
1006-
loff_t l = 0;
1007995

1008996
/*
1009997
* 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)
10191007
if (!pid_list)
10201008
return NULL;
10211009

1022-
pid = find_first_bit(pid_list->pids, pid_list->pid_max);
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;
1010+
return trace_pid_start(pid_list, pos);
10311011
}
10321012

10331013
static void p_stop(struct seq_file *m, void *p)
@@ -1037,14 +1017,6 @@ static void p_stop(struct seq_file *m, void *p)
10371017
mutex_unlock(&event_mutex);
10381018
}
10391019

1040-
static 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-
10481020
static ssize_t
10491021
event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
10501022
loff_t *ppos)
@@ -1795,7 +1767,7 @@ static const struct seq_operations show_set_event_seq_ops = {
17951767
static const struct seq_operations show_set_pid_seq_ops = {
17961768
.start = p_start,
17971769
.next = p_next,
1798-
.show = p_show,
1770+
.show = trace_pid_show,
17991771
.stop = p_stop,
18001772
};
18011773

0 commit comments

Comments
 (0)