[RFC][PATCH] ps command race fix take2 [2/4] change task_list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch changes task->tasks from list_head to list_token.

Signed-Off-By: KAMEZAWA Hiroyuki <[email protected]>
Signed-Off-By: Tadashi Saito <[email protected]>

 include/linux/init_task.h |    3 ++-
 include/linux/sched.h     |   11 ++++++++---
 kernel/exit.c             |    2 +-
 kernel/fork.c             |    2 +-
 4 files changed, 12 insertions(+), 6 deletions(-)

Index: linux-2.6.18-rc4/include/linux/sched.h
===================================================================
--- linux-2.6.18-rc4.orig/include/linux/sched.h
+++ linux-2.6.18-rc4/include/linux/sched.h
@@ -74,6 +74,7 @@ struct sched_param {
 #include <linux/rcupdate.h>
 #include <linux/futex.h>
 #include <linux/rtmutex.h>
+#include <linux/listtoken.h>
 
 #include <linux/time.h>
 #include <linux/param.h>
@@ -799,7 +800,7 @@ struct task_struct {
 	struct sched_info sched_info;
 #endif
 
-	struct list_head tasks;
+	struct list_token tasks;
 	/*
 	 * ptrace_list/ptrace_children forms the list of my children
 	 * that were stolen by a ptracer.
@@ -1315,8 +1316,12 @@ extern void wait_task_inactive(struct ta
 #define remove_parent(p)	list_del_init(&(p)->sibling)
 #define add_parent(p)		list_add_tail(&(p)->sibling,&(p)->parent->children)
 
-#define next_task(p)	list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
-
+static inline struct task_struct *next_task(struct task_struct *task)
+{
+	struct list_token *ent;
+	ent = list_next_rcu_skiptoken(&task->tasks);
+	return container_of(ent, struct task_struct, tasks);
+}
 #define for_each_process(p) \
 	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
 
Index: linux-2.6.18-rc4/kernel/exit.c
===================================================================
--- linux-2.6.18-rc4.orig/kernel/exit.c
+++ linux-2.6.18-rc4/kernel/exit.c
@@ -57,7 +57,7 @@ static void __unhash_process(struct task
 		detach_pid(p, PIDTYPE_PGID);
 		detach_pid(p, PIDTYPE_SID);
 
-		list_del_rcu(&p->tasks);
+		list_del_rcu_token(&p->tasks);
 		__get_cpu_var(process_counts)--;
 	}
 	list_del_rcu(&p->thread_group);
Index: linux-2.6.18-rc4/kernel/fork.c
===================================================================
--- linux-2.6.18-rc4.orig/kernel/fork.c
+++ linux-2.6.18-rc4/kernel/fork.c
@@ -1237,7 +1237,7 @@ static struct task_struct *copy_process(
 			attach_pid(p, PIDTYPE_PGID, process_group(p));
 			attach_pid(p, PIDTYPE_SID, p->signal->session);
 
-			list_add_tail_rcu(&p->tasks, &init_task.tasks);
+			list_add_tail_rcu_token(&p->tasks, &init_task.tasks);
 			__get_cpu_var(process_counts)++;
 		}
 		attach_pid(p, PIDTYPE_PID, p->pid);
Index: linux-2.6.18-rc4/include/linux/init_task.h
===================================================================
--- linux-2.6.18-rc4.orig/include/linux/init_task.h
+++ linux-2.6.18-rc4/include/linux/init_task.h
@@ -5,6 +5,7 @@
 #include <linux/rcupdate.h>
 #include <linux/irqflags.h>
 #include <linux/lockdep.h>
+#include <linux/listtoken.h>
 
 #define INIT_FDTABLE \
 {							\
@@ -97,7 +98,7 @@ extern struct group_info init_groups;
 	.run_list	= LIST_HEAD_INIT(tsk.run_list),			\
 	.ioprio		= 0,						\
 	.time_slice	= HZ,						\
-	.tasks		= LIST_HEAD_INIT(tsk.tasks),			\
+	.tasks		= LIST_TOKEN_INIT(tsk.tasks),			\
 	.ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children),		\
 	.ptrace_list	= LIST_HEAD_INIT(tsk.ptrace_list),		\
 	.real_parent	= &tsk,						\

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux