Re: [PATCH 1/2] introduce for_each_process_thread_break() and for_each_process_thread_continue()

From: Oleg Nesterov
Date: Thu Sep 13 2018 - 11:55:52 EST


On 09/12, Andrew Morton wrote:
>
> > Usage:
> >
> > rcu_read_lock();
> > for_each_process_thread(p, t) {
> > do_something_slow(p, t);
> >
> > if (SPENT_TOO_MUCH_TIME) {
> > for_each_process_thread_break(p, t);
> > rcu_read_unlock();
> > schedule();
> > rcu_read_lock();
> > for_each_process_thread_continue(&p, &t);
> > }
> > }
> > rcu_read_unlock();

...

> > +static inline void
> > +for_each_process_thread_break(struct task_struct *p, struct task_struct *t)
> > +{
> > + get_task_struct(p);
> > + get_task_struct(t);
> > +}
> > +
> > +extern void
> > +for_each_process_thread_continue(struct task_struct **, struct task_struct **);
>
> These things will need some documentation, please. What they do, why
> they do it, how people should use them, when and why they should use
> them. Etcetera! This is tricky stuff.

See "Usage" above, this is as simple as list_for_each_entry_continue_rcu(),
just you need to call _break() first.

OK, I'll try to add some comments and send V2.

> Should these be available to modules, like the rest of these things
> appear to be? Or we could do that later if a need is shown.

Yes, I think this can be exported on demand,

Oleg.