From: NeilBrown <neilb@suse.de>
To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 04/10] llist: add llist_del_first_this()
Date: Wed, 30 Aug 2023 12:54:47 +1000 [thread overview]
Message-ID: <20230830025755.21292-5-neilb@suse.de> (raw)
In-Reply-To: <20230830025755.21292-1-neilb@suse.de>
llist_del_first_this() deletes a specific entry from an llist, providing
it is at the head of the list. Multiple threads can call this
concurrently providing they each offer a different entry.
This can be uses for a set of worker threads which are on the llist when
they are idle. The head can always be woken, and when it is woken it
can remove itself, and possibly wake the next if there is an excess of
work to do.
Signed-off-by: NeilBrown <neilb@suse.de>
---
include/linux/llist.h | 4 ++++
lib/llist.c | 28 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/include/linux/llist.h b/include/linux/llist.h
index dcb91e3bac1c..2c982ff7475a 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -291,6 +291,10 @@ static inline struct llist_node *llist_del_first_init(struct llist_head *head)
init_llist_node(n);
return n;
}
+
+extern bool llist_del_first_this(struct llist_head *head,
+ struct llist_node *this);
+
struct llist_node *llist_reverse_order(struct llist_node *head);
#endif /* LLIST_H */
diff --git a/lib/llist.c b/lib/llist.c
index 6e668fa5a2c6..f21d0cfbbaaa 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -65,6 +65,34 @@ struct llist_node *llist_del_first(struct llist_head *head)
}
EXPORT_SYMBOL_GPL(llist_del_first);
+/**
+ * llist_del_first_this - delete given entry of lock-less list if it is first
+ * @head: the head for your lock-less list
+ * @this: a list entry.
+ *
+ * If head of the list is given entry, delete and return %true else
+ * return %false.
+ *
+ * Multiple callers can safely call this concurrently with multiple
+ * llist_add() callers, providing all the callers offer a different @this.
+ */
+bool llist_del_first_this(struct llist_head *head,
+ struct llist_node *this)
+{
+ struct llist_node *entry, *next;
+
+ /* acquire ensures orderig wrt try_cmpxchg() is llist_del_first() */
+ entry = smp_load_acquire(&head->first);
+ do {
+ if (entry != this)
+ return false;
+ next = READ_ONCE(entry->next);
+ } while (!try_cmpxchg(&head->first, &entry, next));
+
+ return true;
+}
+EXPORT_SYMBOL_GPL(llist_del_first_this);
+
/**
* llist_reverse_order - reverse order of a llist chain
* @head: first item of the list to be reversed
--
2.41.0
next prev parent reply other threads:[~2023-08-30 2:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 2:54 [PATCH 00/10] SUNRPC thread management changes NeilBrown
2023-08-30 2:54 ` [PATCH 01/10] SQUASH: revise comments in SUNRPC: change service idle list to be an llist NeilBrown
2023-08-30 2:54 ` [PATCH 02/10] llist: add interface to check if a node is on a list NeilBrown
2023-08-30 2:54 ` [PATCH 03/10] SQUASH use new llist interfaces in SUNRPC: change service idle list to be an llist NeilBrown
2023-08-30 2:54 ` NeilBrown [this message]
2023-08-30 2:54 ` [PATCH 05/10] lib: add light-weight queuing mechanism NeilBrown
2023-08-30 15:21 ` Chuck Lever
2023-09-03 23:57 ` NeilBrown
2023-08-30 15:35 ` Chuck Lever
2023-09-03 23:59 ` NeilBrown
2023-08-30 16:03 ` Chuck Lever
2023-09-04 0:02 ` NeilBrown
2023-08-30 2:54 ` [PATCH 06/10] SUNRPC: only have one thread waking up at a time NeilBrown
2023-08-30 15:28 ` Chuck Lever
2023-09-04 0:35 ` NeilBrown
2023-08-30 2:54 ` [PATCH 07/10] SUNRPC: use lwq for sp_sockets - renamed to sp_xprts NeilBrown
2023-08-30 2:54 ` [PATCH 08/10] SUNRPC: change sp_nrthreads to atomic_t NeilBrown
2023-08-30 2:54 ` [PATCH 09/10] SUNRPC: discard sp_lock NeilBrown
2023-08-30 2:54 ` [PATCH 10/10] SUNRPC: change the back-channel queue to lwq NeilBrown
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=20230830025755.21292-5-neilb@suse.de \
--to=neilb@suse.de \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
/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