Commit 780aa8df authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Alexei Starovoitov

bpf: task_group_seq_get_next: simplify the "next tid" logic

Kill saved_tid. It looks ugly to update *tid and then restore the
previous value if __task_pid_nr_ns() returns 0. Change this code
to update *tid and common->pid_visiting once before return.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20230905154656.GA24950@redhat.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 0ee9808b
...@@ -37,7 +37,7 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm ...@@ -37,7 +37,7 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm
{ {
struct task_struct *task; struct task_struct *task;
struct pid *pid; struct pid *pid;
u32 saved_tid; u32 next_tid;
if (!*tid) { if (!*tid) {
/* The first time, the iterator calls this function. */ /* The first time, the iterator calls this function. */
...@@ -70,21 +70,18 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm ...@@ -70,21 +70,18 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm
retry: retry:
task = next_thread(task); task = next_thread(task);
saved_tid = *tid; next_tid = __task_pid_nr_ns(task, PIDTYPE_PID, common->ns);
*tid = __task_pid_nr_ns(task, PIDTYPE_PID, common->ns); if (!next_tid || next_tid == common->pid) {
if (!*tid || *tid == common->pid) {
/* Run out of tasks of a process. The tasks of a /* Run out of tasks of a process. The tasks of a
* thread_group are linked as circular linked list. * thread_group are linked as circular linked list.
*/ */
*tid = saved_tid;
return NULL; return NULL;
} }
common->pid_visiting = *tid;
if (skip_if_dup_files && task->files == task->group_leader->files) if (skip_if_dup_files && task->files == task->group_leader->files)
goto retry; goto retry;
*tid = common->pid_visiting = next_tid;
get_task_struct(task); get_task_struct(task);
return task; return task;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment