All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Jiri Slaby <jirislaby@gmail.com>,
	kenchen@google.com,
	Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org
Subject: [RFC, PATCH] introduce pid_for_each_task() to replace do_each_pid_task()
Date: Tue, 24 Feb 2009 22:49:38 +0100	[thread overview]
Message-ID: <20090224214938.GA3670@redhat.com> (raw)
In-Reply-To: <49A41E90.8090304@gmail.com>

pid_for_each_task() does the same as
do_each_pid_task() + while_each_pid_task(), so instead of

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

we can just do

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

This looks better, and we can use break/continue safely.

This patch changes do_each_pid_task() to use pid_for_each_task(), once
we convert all users of do_each_pid_task() we can kill this helper.

However. The implementation of pid_for_each_task() itself is anything
but clean/simple, so this patch asks for the explicit acks/nacks.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>

--- 6.29-rc3/include/linux/pid.h~FOR_EACH_PID	2009-01-12 23:07:48.000000000 +0100
+++ 6.29-rc3/include/linux/pid.h	2009-02-24 22:07:48.000000000 +0100
@@ -162,21 +162,25 @@ static inline pid_t pid_nr(struct pid *p
 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
 pid_t pid_vnr(struct pid *pid);
 
+/*
+ * Both old and new leaders may be attached to the same pid in the
+ * middle of de_thread(), that is why we do the special check for
+ * PIDTYPE_PID below.
+ */
+#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)
+
 #define do_each_pid_task(pid, type, task)				\
 	do {								\
-		struct hlist_node *pos___;				\
-		if ((pid) != NULL)					\
-			hlist_for_each_entry_rcu((task), pos___,	\
-				&(pid)->tasks[type], pids[type].node) {
+		pid_for_each_task(pid, type, task)
 
-			/*
-			 * Both old and new leaders may be attached to
-			 * the same pid in the middle of de_thread().
-			 */
 #define while_each_pid_task(pid, type, task)				\
-				if (type == PIDTYPE_PID)		\
-					break;				\
-			}						\
 	} while (0)
 
 #define do_each_pid_thread(pid, type, task)				\


  reply	other threads:[~2009-02-24 21:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-14 21:59 broken do_each_pid_{thread,task} Jiri Slaby
2008-12-15  1:02 ` Eric W. Biederman
2008-12-15 10:47   ` Oleg Nesterov
2008-12-15 17:09     ` Oleg Nesterov
2009-02-24 13:22       ` Jiri Slaby
2009-02-24 15:49         ` Oleg Nesterov
2009-02-24 16:21           ` Jiri Slaby
2009-02-24 21:49             ` Oleg Nesterov [this message]
2008-12-15 10:24 ` Oleg Nesterov
2008-12-15 10:50   ` Jiri Slaby
2008-12-15 11:02     ` Oleg Nesterov
2008-12-15 11:33       ` Jiri Slaby
2008-12-15 11:51         ` Oleg Nesterov
2009-10-12 10:55           ` Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090224214938.GA3670@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=jirislaby@gmail.com \
    --cc=kenchen@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sukadev@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.