Re: broken do_each_pid_{thread,task}

From: Jiri Slaby
Date: Tue Feb 24 2009 - 11:21:54 EST


On 24.2.2009 16:49, Oleg Nesterov wrote:
But why do you dislike it? Yes, the implementation of pid_for_each_task()
is not simple. Partly because hlist_for_each_entry_rcu() is ugly and
imho should be fixed (see btw http://marc.info/?t=120879441200004).

But with this patch the callers become simpler, we can just do

pid_for_each_task(pid, type, task)
do_something(task);

instead of

do_each_pid_task(pid, type, task) {
do_something(task);
} while_each_pid_task(pid, type, task);

and we can use break/continue safely.

I like what it does, not much how. Anyway I was thinking about hlist_for_each_entry_rcu_param or alike (which would take additional parameters for 3 `for' expressions to add to standard hlist for each ones), but I think it would be less readable than this:

+#define pid_for_each_task(pid, type, p) \
+ for (p = (pid) ? (void*)(pid)->tasks[type].first : NULL; \
+ rcu_dereference(p)&& ({ \
+ prefetch(((struct hlist_node*)p)->next); \
+ p = hlist_entry((void*)p, typeof(*p), pids[type].node); \
+ 1; }); \
+ p = ((type) != PIDTYPE_PID) ? \
+ (void*)(p)->pids[type].node.next : NULL)
+

Really, is this too bad?

Well, it still can be worse :).

Ok, could you repost with commit log and proper CCs or merge anywhere to pull from?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/