* [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu
@ 2009-04-14 15:33 Jiri Pirko
2009-04-14 15:53 ` Paul E. McKenney
2009-04-14 16:42 ` [tip:core/rcu] rculist.h: introduce list_entry_rcu() and list_first_entry_rcu() tip-bot for Jiri Pirko
0 siblings, 2 replies; 6+ messages in thread
From: Jiri Pirko @ 2009-04-14 15:33 UTC (permalink / raw)
To: linux-kernel; +Cc: dipankar, paulmck, mingo
I've run into the situation where I need to use list_first_entry with
rcu-guarded list. This patch introduces this. Also changed
list_for_each_entry_rcu to use new list_entry_rcu instead of list_entry.
Jirka
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
---
include/linux/rculist.h | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index e649bd3..5710f43 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -198,6 +198,32 @@ static inline void list_splice_init_rcu(struct list_head *list,
at->prev = last;
}
+/**
+ * list_entry_rcu - get the struct for this entry
+ * @ptr: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * This primitive may safely run concurrently with the _rcu list-mutation
+ * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
+ */
+#define list_entry_rcu(ptr, type, member) \
+ container_of(rcu_dereference(ptr), type, member)
+
+/**
+ * list_first_entry_rcu - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ *
+ * This primitive may safely run concurrently with the _rcu list-mutation
+ * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
+ */
+#define list_first_entry_rcu(ptr, type, member) \
+ list_entry_rcu((ptr)->next, type, member)
+
#define __list_for_each_rcu(pos, head) \
for (pos = rcu_dereference((head)->next); \
pos != (head); \
@@ -214,9 +240,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_entry_rcu(pos, head, member) \
- for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), member); \
+ for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
- pos = list_entry(rcu_dereference(pos->member.next), typeof(*pos), member))
+ pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
/**
--
1.6.0.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu
2009-04-14 15:33 [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu Jiri Pirko
@ 2009-04-14 15:53 ` Paul E. McKenney
2009-04-14 16:39 ` Jiri Pirko
2009-04-14 16:42 ` [tip:core/rcu] rculist.h: introduce list_entry_rcu() and list_first_entry_rcu() tip-bot for Jiri Pirko
1 sibling, 1 reply; 6+ messages in thread
From: Paul E. McKenney @ 2009-04-14 15:53 UTC (permalink / raw)
To: Jiri Pirko; +Cc: linux-kernel, dipankar, mingo
On Tue, Apr 14, 2009 at 05:33:57PM +0200, Jiri Pirko wrote:
> I've run into the situation where I need to use list_first_entry with
> rcu-guarded list. This patch introduces this. Also changed
> list_for_each_entry_rcu to use new list_entry_rcu instead of list_entry.
>
> Jirka
Looks good -- and very nice list_entry_rcu() primitive!
There are a couple more places where this primitive could be applied.
I would welcome a patch for these as well.
include/linux/sched.h next_task 1986 #define next_task(p) list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
include/linux/sched.h next_thread 2025 return list_entry(rcu_dereference(p->thread_group.next),
ipc/sem.c exit_sem 1293 un = list_entry(rcu_dereference(ulp->list_proc.next),
Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> Signed-off-by: Jiri Pirko <jpirko@redhat.com>
> ---
> include/linux/rculist.h | 30 ++++++++++++++++++++++++++++--
> 1 files changed, 28 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> index e649bd3..5710f43 100644
> --- a/include/linux/rculist.h
> +++ b/include/linux/rculist.h
> @@ -198,6 +198,32 @@ static inline void list_splice_init_rcu(struct list_head *list,
> at->prev = last;
> }
>
> +/**
> + * list_entry_rcu - get the struct for this entry
> + * @ptr: the &struct list_head pointer.
> + * @type: the type of the struct this is embedded in.
> + * @member: the name of the list_struct within the struct.
> + *
> + * This primitive may safely run concurrently with the _rcu list-mutation
> + * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
> + */
> +#define list_entry_rcu(ptr, type, member) \
> + container_of(rcu_dereference(ptr), type, member)
> +
> +/**
> + * list_first_entry_rcu - get the first element from a list
> + * @ptr: the list head to take the element from.
> + * @type: the type of the struct this is embedded in.
> + * @member: the name of the list_struct within the struct.
> + *
> + * Note, that list is expected to be not empty.
> + *
> + * This primitive may safely run concurrently with the _rcu list-mutation
> + * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
> + */
> +#define list_first_entry_rcu(ptr, type, member) \
> + list_entry_rcu((ptr)->next, type, member)
> +
> #define __list_for_each_rcu(pos, head) \
> for (pos = rcu_dereference((head)->next); \
> pos != (head); \
> @@ -214,9 +240,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
> * as long as the traversal is guarded by rcu_read_lock().
> */
> #define list_for_each_entry_rcu(pos, head, member) \
> - for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), member); \
> + for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \
> prefetch(pos->member.next), &pos->member != (head); \
> - pos = list_entry(rcu_dereference(pos->member.next), typeof(*pos), member))
> + pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
>
>
> /**
> --
> 1.6.0.6
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu
2009-04-14 15:53 ` Paul E. McKenney
@ 2009-04-14 16:39 ` Jiri Pirko
2009-04-14 16:44 ` Ingo Molnar
2009-04-14 16:56 ` Paul E. McKenney
0 siblings, 2 replies; 6+ messages in thread
From: Jiri Pirko @ 2009-04-14 16:39 UTC (permalink / raw)
To: paulmck; +Cc: linux-kernel, dipankar, mingo
----- "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> There are a couple more places where this primitive could be applied.
> I would welcome a patch for these as well.
>
Ok I will do this once this patch hits the tree.
Jirka
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu
2009-04-14 16:39 ` Jiri Pirko
@ 2009-04-14 16:44 ` Ingo Molnar
2009-04-14 16:56 ` Paul E. McKenney
1 sibling, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-04-14 16:44 UTC (permalink / raw)
To: Jiri Pirko; +Cc: paulmck, linux-kernel, dipankar
* Jiri Pirko <jpirko@redhat.com> wrote:
> ----- "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > There are a couple more places where this primitive could be applied.
> > I would welcome a patch for these as well.
> >
> Ok I will do this once this patch hits the tree.
it has just hit the RCU tree so feel free :)
http://people.redhat.com/mingo/tip.git/README
Ingo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu
2009-04-14 16:39 ` Jiri Pirko
2009-04-14 16:44 ` Ingo Molnar
@ 2009-04-14 16:56 ` Paul E. McKenney
1 sibling, 0 replies; 6+ messages in thread
From: Paul E. McKenney @ 2009-04-14 16:56 UTC (permalink / raw)
To: Jiri Pirko; +Cc: linux-kernel, dipankar, mingo
On Tue, Apr 14, 2009 at 12:39:51PM -0400, Jiri Pirko wrote:
> ----- "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > There are a couple more places where this primitive could be applied.
> > I would welcome a patch for these as well.
> >
> Ok I will do this once this patch hits the tree.
Thank you!!!
Thanx, Paul
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip:core/rcu] rculist.h: introduce list_entry_rcu() and list_first_entry_rcu()
2009-04-14 15:33 [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu Jiri Pirko
2009-04-14 15:53 ` Paul E. McKenney
@ 2009-04-14 16:42 ` tip-bot for Jiri Pirko
1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Jiri Pirko @ 2009-04-14 16:42 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, paulmck, hpa, mingo, tglx, mingo, jpirko
Commit-ID: 72c6a9870f901045f2464c3dc6ee8914bfdc07aa
Gitweb: http://git.kernel.org/tip/72c6a9870f901045f2464c3dc6ee8914bfdc07aa
Author: Jiri Pirko <jpirko@redhat.com>
AuthorDate: Tue, 14 Apr 2009 17:33:57 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 14 Apr 2009 18:41:15 +0200
rculist.h: introduce list_entry_rcu() and list_first_entry_rcu()
I've run into the situation where I need to use list_first_entry with
rcu-guarded list. This patch introduces this.
Also simplify list_for_each_entry_rcu() to use new list_entry_rcu()
instead of list_entry().
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: dipankar@in.ibm.com
LKML-Reference: <20090414153356.GC3999@psychotron.englab.brq.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/rculist.h | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index e649bd3..5710f43 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -198,6 +198,32 @@ static inline void list_splice_init_rcu(struct list_head *list,
at->prev = last;
}
+/**
+ * list_entry_rcu - get the struct for this entry
+ * @ptr: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * This primitive may safely run concurrently with the _rcu list-mutation
+ * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
+ */
+#define list_entry_rcu(ptr, type, member) \
+ container_of(rcu_dereference(ptr), type, member)
+
+/**
+ * list_first_entry_rcu - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ *
+ * This primitive may safely run concurrently with the _rcu list-mutation
+ * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
+ */
+#define list_first_entry_rcu(ptr, type, member) \
+ list_entry_rcu((ptr)->next, type, member)
+
#define __list_for_each_rcu(pos, head) \
for (pos = rcu_dereference((head)->next); \
pos != (head); \
@@ -214,9 +240,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_entry_rcu(pos, head, member) \
- for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), member); \
+ for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
- pos = list_entry(rcu_dereference(pos->member.next), typeof(*pos), member))
+ pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
/**
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-04-14 16:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-14 15:33 [PATCH] rculist.h: introduce list_entry_rcu and list_first_entry_rcu Jiri Pirko
2009-04-14 15:53 ` Paul E. McKenney
2009-04-14 16:39 ` Jiri Pirko
2009-04-14 16:44 ` Ingo Molnar
2009-04-14 16:56 ` Paul E. McKenney
2009-04-14 16:42 ` [tip:core/rcu] rculist.h: introduce list_entry_rcu() and list_first_entry_rcu() tip-bot for Jiri Pirko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox