Re: [PATCH 1/3] introduce for_each_process_thread_{break,continue}() helpers

From: Peter Zijlstra
Date: Tue Aug 02 2016 - 12:05:40 EST


On Mon, Jul 25, 2016 at 06:23:48PM +0200, Oleg Nesterov wrote:
> +void for_each_process_thread_continue(struct task_struct **p_leader,
> + struct task_struct **p_thread)
> +{
> + struct task_struct *leader = *p_leader, *thread = *p_thread;
> + struct task_struct *prev, *next;
> + u64 start_time;
> +
> + if (pid_alive(thread)) {
> + /* mt exec could change the leader */
> + *p_leader = thread->group_leader;
> + } else if (pid_alive(leader)) {
> + start_time = thread->start_time;
> + prev = leader;
> +
> + for_each_thread(leader, next) {
> + if (next->start_time > start_time)
> + break;
> + prev = next;
> + }

This,

> + *p_thread = prev;
> + } else {
> + start_time = leader->start_time;
> + prev = &init_task;
> +
> + for_each_process(next) {
> + if (next->start_time > start_time)
> + break;
> + prev = next;
> + }

and this, could be 'SPEND_TOO_MUCH_TIME' all by themselves.

Unlikely though, nor do I really have a better suggestion :/

> +
> + *p_leader = prev;
> + /* a new thread can come after that, but this is fine */
> + *p_thread = list_last_entry(&prev->signal->thread_head,
> + struct task_struct,
> + thread_node);
> + }
> +
> + put_task_struct(leader);
> + put_task_struct(thread);
> +}