* [PATCH v2] llist: Clarify comments about when locking is needed
@ 2016-12-10 18:03 Joel Fernandes
2016-12-10 18:15 ` Mathieu Desnoyers
2016-12-12 1:15 ` Huang, Ying
0 siblings, 2 replies; 4+ messages in thread
From: Joel Fernandes @ 2016-12-10 18:03 UTC (permalink / raw)
To: linux-kernel
Cc: Joel Fernandes, Huang Ying, Ingo Molnar, Will Deacon,
Paul McKenney, Mathieu Desnoyers
llist.h comments are a bit confusing about when locking is needed versus when
it isn't. Clarify these comments a bit more by being a bit more descriptive
about why locking is needed for llist_del_first.
Cc: Huang Ying <ying.huang@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Joel Fernandes <joelaf@google.com>
---
v2 changes:
Minor changes to comment and commit message based on Mathieu's suggestions
(https://lkml.org/lkml/2016/12/10/39)
include/linux/llist.h | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/include/linux/llist.h b/include/linux/llist.h
index fd4ca0b..31822bb 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -3,28 +3,33 @@
/*
* Lock-less NULL terminated single linked list
*
- * If there are multiple producers and multiple consumers, llist_add
- * can be used in producers and llist_del_all can be used in
- * consumers. They can work simultaneously without lock. But
- * llist_del_first can not be used here. Because llist_del_first
- * depends on list->first->next does not changed if list->first is not
- * changed during its operation, but llist_del_first, llist_add,
- * llist_add (or llist_del_all, llist_add, llist_add) sequence in
- * another consumer may violate that.
- *
- * If there are multiple producers and one consumer, llist_add can be
- * used in producers and llist_del_all or llist_del_first can be used
- * in the consumer.
- *
- * This can be summarized as follow:
+ * Cases where locking is not needed:
+ * If there are multiple producers and multiple consumers, llist_add can be
+ * used in producers and llist_del_all can be used in consumers simultaneously
+ * without locking. Also a single consumer can use llist_del_first while
+ * multiple producers simultaneously use llist_add, without any locking.
+ *
+ * Cases where locking is needed:
+ * If we have multiple consumers with llist_del_first used in one consumer, and
+ * llist_del_first or llist_del_all used in other consumers, then a lock is
+ * needed. This is because llist_del_first depends on list->first->next not
+ * changing, but without lock protection, there's no way to be sure about that
+ * if a preemption happens in the middle of the delete operation and on being
+ * preempted back, the list->first is the same as before causing the cmpxchg in
+ * llist_del_first to succeed. For example, while a llist_del_first operation
+ * is in progress in one consumer, then a llist_del_first, llist_add,
+ * llist_add (or llist_del_all, llist_add, llist_add) sequence in another
+ * consumer may cause violations.
+ *
+ * This can be summarized as follows:
*
* | add | del_first | del_all
* add | - | - | -
* del_first | | L | L
* del_all | | | -
*
- * Where "-" stands for no lock is needed, while "L" stands for lock
- * is needed.
+ * Where, a particular row's operation can happen concurrently with a column's
+ * operation, with "-" being no lock needed, while "L" being lock is needed.
*
* The list entries deleted via llist_del_all can be traversed with
* traversing function such as llist_for_each etc. But the list
--
2.8.0.rc3.226.g39d4020
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] llist: Clarify comments about when locking is needed
2016-12-10 18:03 [PATCH v2] llist: Clarify comments about when locking is needed Joel Fernandes
@ 2016-12-10 18:15 ` Mathieu Desnoyers
2016-12-10 18:20 ` Joel Fernandes
2016-12-12 1:15 ` Huang, Ying
1 sibling, 1 reply; 4+ messages in thread
From: Mathieu Desnoyers @ 2016-12-10 18:15 UTC (permalink / raw)
To: Joel Fernandes
Cc: linux-kernel, Huang Ying, Ingo Molnar, Will Deacon, Paul E. McKenney
----- On Dec 10, 2016, at 7:03 PM, Joel Fernandes joelaf@google.com wrote:
> llist.h comments are a bit confusing about when locking is needed versus when
> it isn't. Clarify these comments a bit more by being a bit more descriptive
> about why locking is needed for llist_del_first.
As I stated in my earlier review, please remove a couple of "a bit"
from the changelog.
Thanks,
Mathieu
>
> Cc: Huang Ying <ying.huang@intel.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Signed-off-by: Joel Fernandes <joelaf@google.com>
> ---
> v2 changes:
> Minor changes to comment and commit message based on Mathieu's suggestions
> (https://lkml.org/lkml/2016/12/10/39)
>
> include/linux/llist.h | 37 +++++++++++++++++++++----------------
> 1 file changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/llist.h b/include/linux/llist.h
> index fd4ca0b..31822bb 100644
> --- a/include/linux/llist.h
> +++ b/include/linux/llist.h
> @@ -3,28 +3,33 @@
> /*
> * Lock-less NULL terminated single linked list
> *
> - * If there are multiple producers and multiple consumers, llist_add
> - * can be used in producers and llist_del_all can be used in
> - * consumers. They can work simultaneously without lock. But
> - * llist_del_first can not be used here. Because llist_del_first
> - * depends on list->first->next does not changed if list->first is not
> - * changed during its operation, but llist_del_first, llist_add,
> - * llist_add (or llist_del_all, llist_add, llist_add) sequence in
> - * another consumer may violate that.
> - *
> - * If there are multiple producers and one consumer, llist_add can be
> - * used in producers and llist_del_all or llist_del_first can be used
> - * in the consumer.
> - *
> - * This can be summarized as follow:
> + * Cases where locking is not needed:
> + * If there are multiple producers and multiple consumers, llist_add can be
> + * used in producers and llist_del_all can be used in consumers simultaneously
> + * without locking. Also a single consumer can use llist_del_first while
> + * multiple producers simultaneously use llist_add, without any locking.
> + *
> + * Cases where locking is needed:
> + * If we have multiple consumers with llist_del_first used in one consumer, and
> + * llist_del_first or llist_del_all used in other consumers, then a lock is
> + * needed. This is because llist_del_first depends on list->first->next not
> + * changing, but without lock protection, there's no way to be sure about that
> + * if a preemption happens in the middle of the delete operation and on being
> + * preempted back, the list->first is the same as before causing the cmpxchg in
> + * llist_del_first to succeed. For example, while a llist_del_first operation
> + * is in progress in one consumer, then a llist_del_first, llist_add,
> + * llist_add (or llist_del_all, llist_add, llist_add) sequence in another
> + * consumer may cause violations.
> + *
> + * This can be summarized as follows:
> *
> * | add | del_first | del_all
> * add | - | - | -
> * del_first | | L | L
> * del_all | | | -
> *
> - * Where "-" stands for no lock is needed, while "L" stands for lock
> - * is needed.
> + * Where, a particular row's operation can happen concurrently with a column's
> + * operation, with "-" being no lock needed, while "L" being lock is needed.
> *
> * The list entries deleted via llist_del_all can be traversed with
> * traversing function such as llist_for_each etc. But the list
> --
> 2.8.0.rc3.226.g39d4020
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] llist: Clarify comments about when locking is needed
2016-12-10 18:15 ` Mathieu Desnoyers
@ 2016-12-10 18:20 ` Joel Fernandes
0 siblings, 0 replies; 4+ messages in thread
From: Joel Fernandes @ 2016-12-10 18:20 UTC (permalink / raw)
To: Mathieu Desnoyers
Cc: linux-kernel, Huang Ying, Ingo Molnar, Will Deacon, Paul E. McKenney
On Sat, Dec 10, 2016 at 10:15 AM, Mathieu Desnoyers
<mathieu.desnoyers@efficios.com> wrote:
> ----- On Dec 10, 2016, at 7:03 PM, Joel Fernandes joelaf@google.com wrote:
>
>> llist.h comments are a bit confusing about when locking is needed versus when
>> it isn't. Clarify these comments a bit more by being a bit more descriptive
>> about why locking is needed for llist_del_first.
>
> As I stated in my earlier review, please remove a couple of "a bit"
> from the changelog.
>
I'm sorry I missed that. I will update it correctly in the next rev.
Regards,
Joel
> Thanks,
>
> Mathieu
>
>>
>> Cc: Huang Ying <ying.huang@intel.com>
>> Cc: Ingo Molnar <mingo@kernel.org>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
>> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
>> Signed-off-by: Joel Fernandes <joelaf@google.com>
>> ---
>> v2 changes:
>> Minor changes to comment and commit message based on Mathieu's suggestions
>> (https://lkml.org/lkml/2016/12/10/39)
>>
>> include/linux/llist.h | 37 +++++++++++++++++++++----------------
>> 1 file changed, 21 insertions(+), 16 deletions(-)
>>
>> diff --git a/include/linux/llist.h b/include/linux/llist.h
>> index fd4ca0b..31822bb 100644
>> --- a/include/linux/llist.h
>> +++ b/include/linux/llist.h
>> @@ -3,28 +3,33 @@
>> /*
>> * Lock-less NULL terminated single linked list
>> *
>> - * If there are multiple producers and multiple consumers, llist_add
>> - * can be used in producers and llist_del_all can be used in
>> - * consumers. They can work simultaneously without lock. But
>> - * llist_del_first can not be used here. Because llist_del_first
>> - * depends on list->first->next does not changed if list->first is not
>> - * changed during its operation, but llist_del_first, llist_add,
>> - * llist_add (or llist_del_all, llist_add, llist_add) sequence in
>> - * another consumer may violate that.
>> - *
>> - * If there are multiple producers and one consumer, llist_add can be
>> - * used in producers and llist_del_all or llist_del_first can be used
>> - * in the consumer.
>> - *
>> - * This can be summarized as follow:
>> + * Cases where locking is not needed:
>> + * If there are multiple producers and multiple consumers, llist_add can be
>> + * used in producers and llist_del_all can be used in consumers simultaneously
>> + * without locking. Also a single consumer can use llist_del_first while
>> + * multiple producers simultaneously use llist_add, without any locking.
>> + *
>> + * Cases where locking is needed:
>> + * If we have multiple consumers with llist_del_first used in one consumer, and
>> + * llist_del_first or llist_del_all used in other consumers, then a lock is
>> + * needed. This is because llist_del_first depends on list->first->next not
>> + * changing, but without lock protection, there's no way to be sure about that
>> + * if a preemption happens in the middle of the delete operation and on being
>> + * preempted back, the list->first is the same as before causing the cmpxchg in
>> + * llist_del_first to succeed. For example, while a llist_del_first operation
>> + * is in progress in one consumer, then a llist_del_first, llist_add,
>> + * llist_add (or llist_del_all, llist_add, llist_add) sequence in another
>> + * consumer may cause violations.
>> + *
>> + * This can be summarized as follows:
>> *
>> * | add | del_first | del_all
>> * add | - | - | -
>> * del_first | | L | L
>> * del_all | | | -
>> *
>> - * Where "-" stands for no lock is needed, while "L" stands for lock
>> - * is needed.
>> + * Where, a particular row's operation can happen concurrently with a column's
>> + * operation, with "-" being no lock needed, while "L" being lock is needed.
>> *
>> * The list entries deleted via llist_del_all can be traversed with
>> * traversing function such as llist_for_each etc. But the list
>> --
>> 2.8.0.rc3.226.g39d4020
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] llist: Clarify comments about when locking is needed
2016-12-10 18:03 [PATCH v2] llist: Clarify comments about when locking is needed Joel Fernandes
2016-12-10 18:15 ` Mathieu Desnoyers
@ 2016-12-12 1:15 ` Huang, Ying
1 sibling, 0 replies; 4+ messages in thread
From: Huang, Ying @ 2016-12-12 1:15 UTC (permalink / raw)
To: Joel Fernandes
Cc: linux-kernel, Huang Ying, Ingo Molnar, Will Deacon,
Paul McKenney, Mathieu Desnoyers
Joel Fernandes <joelaf@google.com> writes:
> llist.h comments are a bit confusing about when locking is needed versus when
> it isn't. Clarify these comments a bit more by being a bit more descriptive
> about why locking is needed for llist_del_first.
>
> Cc: Huang Ying <ying.huang@intel.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Signed-off-by: Joel Fernandes <joelaf@google.com>
Acked-by: "Huang, Ying" <ying.huang@intel.com>
Best Regards,
Huang, Ying
> ---
> v2 changes:
> Minor changes to comment and commit message based on Mathieu's suggestions
> (https://lkml.org/lkml/2016/12/10/39)
>
> include/linux/llist.h | 37 +++++++++++++++++++++----------------
> 1 file changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/llist.h b/include/linux/llist.h
> index fd4ca0b..31822bb 100644
> --- a/include/linux/llist.h
> +++ b/include/linux/llist.h
> @@ -3,28 +3,33 @@
> /*
> * Lock-less NULL terminated single linked list
> *
> - * If there are multiple producers and multiple consumers, llist_add
> - * can be used in producers and llist_del_all can be used in
> - * consumers. They can work simultaneously without lock. But
> - * llist_del_first can not be used here. Because llist_del_first
> - * depends on list->first->next does not changed if list->first is not
> - * changed during its operation, but llist_del_first, llist_add,
> - * llist_add (or llist_del_all, llist_add, llist_add) sequence in
> - * another consumer may violate that.
> - *
> - * If there are multiple producers and one consumer, llist_add can be
> - * used in producers and llist_del_all or llist_del_first can be used
> - * in the consumer.
> - *
> - * This can be summarized as follow:
> + * Cases where locking is not needed:
> + * If there are multiple producers and multiple consumers, llist_add can be
> + * used in producers and llist_del_all can be used in consumers simultaneously
> + * without locking. Also a single consumer can use llist_del_first while
> + * multiple producers simultaneously use llist_add, without any locking.
> + *
> + * Cases where locking is needed:
> + * If we have multiple consumers with llist_del_first used in one consumer, and
> + * llist_del_first or llist_del_all used in other consumers, then a lock is
> + * needed. This is because llist_del_first depends on list->first->next not
> + * changing, but without lock protection, there's no way to be sure about that
> + * if a preemption happens in the middle of the delete operation and on being
> + * preempted back, the list->first is the same as before causing the cmpxchg in
> + * llist_del_first to succeed. For example, while a llist_del_first operation
> + * is in progress in one consumer, then a llist_del_first, llist_add,
> + * llist_add (or llist_del_all, llist_add, llist_add) sequence in another
> + * consumer may cause violations.
> + *
> + * This can be summarized as follows:
> *
> * | add | del_first | del_all
> * add | - | - | -
> * del_first | | L | L
> * del_all | | | -
> *
> - * Where "-" stands for no lock is needed, while "L" stands for lock
> - * is needed.
> + * Where, a particular row's operation can happen concurrently with a column's
> + * operation, with "-" being no lock needed, while "L" being lock is needed.
> *
> * The list entries deleted via llist_del_all can be traversed with
> * traversing function such as llist_for_each etc. But the list
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-12 1:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-10 18:03 [PATCH v2] llist: Clarify comments about when locking is needed Joel Fernandes
2016-12-10 18:15 ` Mathieu Desnoyers
2016-12-10 18:20 ` Joel Fernandes
2016-12-12 1:15 ` Huang, Ying
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).