diff mbox

[01/10] netdev: add netdev_continue_rcu

Message ID 20091110175647.200655064@vyatta.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

stephen hemminger Nov. 10, 2009, 5:54 p.m. UTC
This adds an RCU macro for continuing search, useful for some
network devices like vlan.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

Comments

Eric Dumazet Nov. 10, 2009, 6:19 p.m. UTC | #1
Stephen Hemminger a écrit :
> This adds an RCU macro for continuing search, useful for some
> network devices like vlan.
> 
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> 

Acked-by: Eric Dumazet <eric.dumazet@gmail.com>

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paul E. McKenney Nov. 10, 2009, 7:39 p.m. UTC | #2
On Tue, Nov 10, 2009 at 09:54:47AM -0800, Stephen Hemminger wrote:
> This adds an RCU macro for continuing search, useful for some
> network devices like vlan.

Looks good!!!

Of course, you need to either have a single RCU read-side critical section
cover all the chained list_for_each_entry_continue_rcu() invocations, or
you need to do something (e.g., reference count) to make sure that the
element in question doesn't disappear in the meantime, right?

							Thanx, Paul

> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> 
> --- a/include/linux/netdevice.h	2009-11-09 22:19:08.511480873 -0800
> +++ b/include/linux/netdevice.h	2009-11-10 09:27:17.973376267 -0800
> @@ -1079,6 +1079,8 @@ extern rwlock_t				dev_base_lock;		/* De
>  		list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
>  #define for_each_netdev_continue(net, d)		\
>  		list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
> +#define for_each_netdev_continue_rcu(net, d)		\
> +	list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
>  #define net_device_entry(lh)	list_entry(lh, struct net_device, dev_list)
> 
>  static inline struct net_device *next_net_device(struct net_device *dev)
> --- a/include/linux/rculist.h	2009-11-09 22:19:08.529480859 -0800
> +++ b/include/linux/rculist.h	2009-11-10 09:27:17.974376609 -0800
> @@ -262,6 +262,20 @@ static inline void list_splice_init_rcu(
>  		(pos) = rcu_dereference((pos)->next))
> 
>  /**
> + * list_for_each_entry_continue_rcu - continue iteration over list of given type
> + * @pos:	the type * to use as a loop cursor.
> + * @head:	the head for your list.
> + * @member:	the name of the list_struct within the struct.
> + *
> + * Continue to iterate over list of given type, continuing after
> + * the current position.
> + */
> +#define list_for_each_entry_continue_rcu(pos, head, member) 		\
> +	for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
> +	     prefetch(pos->member.next), &pos->member != (head);	\
> +	     pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
> +
> +/**
>   * hlist_del_rcu - deletes entry from hash list without re-initialization
>   * @n: the element to delete from the hash list.
>   *
> 
> -- 
> 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Nov. 11, 2009, 6:47 a.m. UTC | #3
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 10 Nov 2009 19:19:22 +0100

> Stephen Hemminger a écrit :
>> This adds an RCU macro for continuing search, useful for some
>> network devices like vlan.
>> 
>> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>> 
> 
> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- a/include/linux/netdevice.h	2009-11-09 22:19:08.511480873 -0800
+++ b/include/linux/netdevice.h	2009-11-10 09:27:17.973376267 -0800
@@ -1079,6 +1079,8 @@  extern rwlock_t				dev_base_lock;		/* De
 		list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
 #define for_each_netdev_continue(net, d)		\
 		list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
+#define for_each_netdev_continue_rcu(net, d)		\
+	list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
 #define net_device_entry(lh)	list_entry(lh, struct net_device, dev_list)
 
 static inline struct net_device *next_net_device(struct net_device *dev)
--- a/include/linux/rculist.h	2009-11-09 22:19:08.529480859 -0800
+++ b/include/linux/rculist.h	2009-11-10 09:27:17.974376609 -0800
@@ -262,6 +262,20 @@  static inline void list_splice_init_rcu(
 		(pos) = rcu_dereference((pos)->next))
 
 /**
+ * list_for_each_entry_continue_rcu - continue iteration over list of given type
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Continue to iterate over list of given type, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_rcu(pos, head, member) 		\
+	for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
+	     prefetch(pos->member.next), &pos->member != (head);	\
+	     pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
+
+/**
  * hlist_del_rcu - deletes entry from hash list without re-initialization
  * @n: the element to delete from the hash list.
  *