linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Joel Fernandes <joelaf@google.com>
Cc: linux-kernel@vger.kernel.org, Huang Ying <ying.huang@intel.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Ingo Molnar <mingo@kernel.org>, Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH v3] llist: Clarify comments about when locking is needed
Date: Tue, 3 Jan 2017 16:08:49 -0800	[thread overview]
Message-ID: <20170104000849.GC3742@linux.vnet.ibm.com> (raw)
In-Reply-To: <1481594505-2779-1-git-send-email-joelaf@google.com>

On Mon, Dec 12, 2016 at 06:01:45PM -0800, Joel Fernandes wrote:
> llist.h comments are confusing about when locking is needed versus when it
> isn't. Clarify these comments by being more descriptive about why locking is
> needed for llist_del_first.
> 
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
> Acked-by: Huang Ying <ying.huang@intel.com>
> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Signed-off-by: Joel Fernandes <joelaf@google.com>

Queued for 4.12, thank you all!

							Thanx, Paul

> ---
> Changes since before:
> 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
> 

      reply	other threads:[~2017-01-04  0:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13  2:01 [PATCH v3] llist: Clarify comments about when locking is needed Joel Fernandes
2017-01-04  0:08 ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170104000849.GC3742@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=joelaf@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=will.deacon@arm.com \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).