Re: [PATCH 3/4 v2] rculist: add list_for_each_entry_from_rcu()

2018-05-01 Thread NeilBrown
On Tue, May 01 2018, Paul E. McKenney wrote:

> On Tue, May 01, 2018 at 01:11:29PM +1000, NeilBrown wrote:
>> 
>> list_for_each_entry_from_rcu() is an RCU version of
>> list_for_each_entry_from().  It walks a linked list under rcu
>> protection, from a given start point.
>> 
>> It is similar to list_for_each_entry_continue_rcu() but starts *at*
>> the given position rather than *after* it.
>> 
>> Naturally, the start point must be known to be in the list.
>> 
>> Also update the documentation for list_for_each_entry_continue_rcu()
>> to match the documentation for the new list_for_each_entry_from_rcu(),
>> and add list_for_each_entry_from_rcu() and the already existing
>> hlist_for_each_entry_from_rcu() to section 7 of whatisRCU.txt.
>> 
>> Signed-off-by: NeilBrown 
>
> I am guessing that it would be more convenient for you to carry this
> with the patches using it, so:
>
> Reviewed-by: Paul E. McKenney 

Thanks Paul,
 yes I do hope this patch will go in with the other NFS patches.
 I'll wait to see what Trond and Anna think before proceeding with
 anything myself.

Thanks a lot,
NeilBrown


>
> If not, please let me know.
>
>   Thanx, Paul
>
>> ---
>>  Documentation/RCU/whatisRCU.txt |  2 ++
>>  include/linux/rculist.h | 32 +++-
>>  2 files changed, 33 insertions(+), 1 deletion(-)
>> 
>> diff --git a/Documentation/RCU/whatisRCU.txt 
>> b/Documentation/RCU/whatisRCU.txt
>> index a27fbfb0efb8..b7d38bd212d2 100644
>> --- a/Documentation/RCU/whatisRCU.txt
>> +++ b/Documentation/RCU/whatisRCU.txt
>> @@ -814,11 +814,13 @@ RCU list traversal:
>>  list_next_rcu
>>  list_for_each_entry_rcu
>>  list_for_each_entry_continue_rcu
>> +list_for_each_entry_from_rcu
>>  hlist_first_rcu
>>  hlist_next_rcu
>>  hlist_pprev_rcu
>>  hlist_for_each_entry_rcu
>>  hlist_for_each_entry_rcu_bh
>> +hlist_for_each_entry_from_rcu
>>  hlist_for_each_entry_continue_rcu
>>  hlist_for_each_entry_continue_rcu_bh
>>  hlist_nulls_first_rcu
>> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
>> index 127f534fec94..4786c2235b98 100644
>> --- a/include/linux/rculist.h
>> +++ b/include/linux/rculist.h
>> @@ -396,13 +396,43 @@ static inline void list_splice_tail_init_rcu(struct 
>> list_head *list,
>>   * @member: the name of the list_head within the struct.
>>   *
>>   * Continue to iterate over list of given type, continuing after
>> - * the current position.
>> + * the current position which must have been in the list when the RCU read
>> + * lock was taken.
>> + * This would typically require either that you obtained the node from a
>> + * previous walk of the list in the same RCU read-side critical section, or
>> + * that you held some sort of non-RCU reference (such as a reference count)
>> + * to keep the node alive *and* in the list.
>> + *
>> + * This iterator is similar to list_for_each_entry_from_rcu() except
>> + * this starts after the given position and that one starts at the given
>> + * position.
>>   */
>>  #define list_for_each_entry_continue_rcu(pos, head, member) 
>> \
>>  for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
>>   &pos->member != (head);\
>>   pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
>>  
>> +/**
>> + * list_for_each_entry_from_rcu - iterate over a list from current point
>> + * @pos:the type * to use as a loop cursor.
>> + * @head:   the head for your list.
>> + * @member: the name of the list_node within the struct.
>> + *
>> + * Iterate over the tail of a list starting from a given position,
>> + * which must have been in the list when the RCU read lock was taken.
>> + * This would typically require either that you obtained the node from a
>> + * previous walk of the list in the same RCU read-side critical section, or
>> + * that you held some sort of non-RCU reference (such as a reference count)
>> + * to keep the node alive *and* in the list.
>> + *
>> + * This iterator is similar to list_for_each_entry_continue_rcu() except
>> + * this starts from the given position and that one starts from the position
>> + * after the given position.
>> + */
>> +#define list_for_each_entry_from_rcu(pos, head, member) 
>> \
>> +for (; &(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.
>> -- 
>> 2.14.0.rc0.dirty
>> 


signature.asc
Description: PGP signature


Re: [PATCH 3/4 v2] rculist: add list_for_each_entry_from_rcu()

2018-05-01 Thread Paul E. McKenney
On Tue, May 01, 2018 at 01:11:29PM +1000, NeilBrown wrote:
> 
> list_for_each_entry_from_rcu() is an RCU version of
> list_for_each_entry_from().  It walks a linked list under rcu
> protection, from a given start point.
> 
> It is similar to list_for_each_entry_continue_rcu() but starts *at*
> the given position rather than *after* it.
> 
> Naturally, the start point must be known to be in the list.
> 
> Also update the documentation for list_for_each_entry_continue_rcu()
> to match the documentation for the new list_for_each_entry_from_rcu(),
> and add list_for_each_entry_from_rcu() and the already existing
> hlist_for_each_entry_from_rcu() to section 7 of whatisRCU.txt.
> 
> Signed-off-by: NeilBrown 

I am guessing that it would be more convenient for you to carry this
with the patches using it, so:

Reviewed-by: Paul E. McKenney 

If not, please let me know.

Thanx, Paul

> ---
>  Documentation/RCU/whatisRCU.txt |  2 ++
>  include/linux/rculist.h | 32 +++-
>  2 files changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
> index a27fbfb0efb8..b7d38bd212d2 100644
> --- a/Documentation/RCU/whatisRCU.txt
> +++ b/Documentation/RCU/whatisRCU.txt
> @@ -814,11 +814,13 @@ RCU list traversal:
>   list_next_rcu
>   list_for_each_entry_rcu
>   list_for_each_entry_continue_rcu
> + list_for_each_entry_from_rcu
>   hlist_first_rcu
>   hlist_next_rcu
>   hlist_pprev_rcu
>   hlist_for_each_entry_rcu
>   hlist_for_each_entry_rcu_bh
> + hlist_for_each_entry_from_rcu
>   hlist_for_each_entry_continue_rcu
>   hlist_for_each_entry_continue_rcu_bh
>   hlist_nulls_first_rcu
> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> index 127f534fec94..4786c2235b98 100644
> --- a/include/linux/rculist.h
> +++ b/include/linux/rculist.h
> @@ -396,13 +396,43 @@ static inline void list_splice_tail_init_rcu(struct 
> list_head *list,
>   * @member:  the name of the list_head within the struct.
>   *
>   * Continue to iterate over list of given type, continuing after
> - * the current position.
> + * the current position which must have been in the list when the RCU read
> + * lock was taken.
> + * This would typically require either that you obtained the node from a
> + * previous walk of the list in the same RCU read-side critical section, or
> + * that you held some sort of non-RCU reference (such as a reference count)
> + * to keep the node alive *and* in the list.
> + *
> + * This iterator is similar to list_for_each_entry_from_rcu() except
> + * this starts after the given position and that one starts at the given
> + * position.
>   */
>  #define list_for_each_entry_continue_rcu(pos, head, member)  \
>   for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
>&pos->member != (head);\
>pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
>  
> +/**
> + * list_for_each_entry_from_rcu - iterate over a list from current point
> + * @pos: the type * to use as a loop cursor.
> + * @head:the head for your list.
> + * @member:  the name of the list_node within the struct.
> + *
> + * Iterate over the tail of a list starting from a given position,
> + * which must have been in the list when the RCU read lock was taken.
> + * This would typically require either that you obtained the node from a
> + * previous walk of the list in the same RCU read-side critical section, or
> + * that you held some sort of non-RCU reference (such as a reference count)
> + * to keep the node alive *and* in the list.
> + *
> + * This iterator is similar to list_for_each_entry_continue_rcu() except
> + * this starts from the given position and that one starts from the position
> + * after the given position.
> + */
> +#define list_for_each_entry_from_rcu(pos, head, member)  
> \
> + for (; &(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.
> -- 
> 2.14.0.rc0.dirty
> 




[PATCH 3/4 v2] rculist: add list_for_each_entry_from_rcu()

2018-04-30 Thread NeilBrown

list_for_each_entry_from_rcu() is an RCU version of
list_for_each_entry_from().  It walks a linked list under rcu
protection, from a given start point.

It is similar to list_for_each_entry_continue_rcu() but starts *at*
the given position rather than *after* it.

Naturally, the start point must be known to be in the list.

Also update the documentation for list_for_each_entry_continue_rcu()
to match the documentation for the new list_for_each_entry_from_rcu(),
and add list_for_each_entry_from_rcu() and the already existing
hlist_for_each_entry_from_rcu() to section 7 of whatisRCU.txt.

Signed-off-by: NeilBrown 
---
 Documentation/RCU/whatisRCU.txt |  2 ++
 include/linux/rculist.h | 32 +++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
index a27fbfb0efb8..b7d38bd212d2 100644
--- a/Documentation/RCU/whatisRCU.txt
+++ b/Documentation/RCU/whatisRCU.txt
@@ -814,11 +814,13 @@ RCU list traversal:
list_next_rcu
list_for_each_entry_rcu
list_for_each_entry_continue_rcu
+   list_for_each_entry_from_rcu
hlist_first_rcu
hlist_next_rcu
hlist_pprev_rcu
hlist_for_each_entry_rcu
hlist_for_each_entry_rcu_bh
+   hlist_for_each_entry_from_rcu
hlist_for_each_entry_continue_rcu
hlist_for_each_entry_continue_rcu_bh
hlist_nulls_first_rcu
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index 127f534fec94..4786c2235b98 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -396,13 +396,43 @@ static inline void list_splice_tail_init_rcu(struct 
list_head *list,
  * @member:the name of the list_head within the struct.
  *
  * Continue to iterate over list of given type, continuing after
- * the current position.
+ * the current position which must have been in the list when the RCU read
+ * lock was taken.
+ * This would typically require either that you obtained the node from a
+ * previous walk of the list in the same RCU read-side critical section, or
+ * that you held some sort of non-RCU reference (such as a reference count)
+ * to keep the node alive *and* in the list.
+ *
+ * This iterator is similar to list_for_each_entry_from_rcu() except
+ * this starts after the given position and that one starts at the given
+ * position.
  */
 #define list_for_each_entry_continue_rcu(pos, head, member)\
for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
 &pos->member != (head);\
 pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
 
+/**
+ * list_for_each_entry_from_rcu - iterate over a list from current point
+ * @pos:   the type * to use as a loop cursor.
+ * @head:  the head for your list.
+ * @member:the name of the list_node within the struct.
+ *
+ * Iterate over the tail of a list starting from a given position,
+ * which must have been in the list when the RCU read lock was taken.
+ * This would typically require either that you obtained the node from a
+ * previous walk of the list in the same RCU read-side critical section, or
+ * that you held some sort of non-RCU reference (such as a reference count)
+ * to keep the node alive *and* in the list.
+ *
+ * This iterator is similar to list_for_each_entry_continue_rcu() except
+ * this starts from the given position and that one starts from the position
+ * after the given position.
+ */
+#define list_for_each_entry_from_rcu(pos, head, member)
\
+   for (; &(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.
-- 
2.14.0.rc0.dirty



signature.asc
Description: PGP signature