From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Huang Ying <ying.huang@intel.com>,
Andi Kleen <andi@firstfloor.org>,
lenb@kernel.org, Andrew Morton <akpm@linux-foundation.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: [RFC patch 2/2] llstack: make llstack_push return "prior empty state" information
Date: Sat, 03 Sep 2011 13:47:23 -0400 [thread overview]
Message-ID: <20110903175543.544717224@efficios.com> (raw)
In-Reply-To: 20110903174721.390074195@efficios.com
[-- Attachment #1: llstack-push-return-empty-state.patch --]
[-- Type: text/plain, Size: 3630 bytes --]
A feature request from Peter Zijlstra outlines very well the need for an
llstack API that allows the push operation to return whether the stack
was empty or not before the operation. Peter wants to use this
information to know if a irq_work should be raised when pushing into the
stack.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Huang Ying <ying.huang@intel.com>
CC: Andi Kleen <andi@firstfloor.org>
CC: "lenb@kernel.org" <lenb@kernel.org>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/llstack.h | 6 +++---
lib/llstack.c | 15 +++++++++++++--
2 files changed, 16 insertions(+), 5 deletions(-)
Index: linux-2.6-lttng/lib/llstack.c
===================================================================
--- linux-2.6-lttng.orig/lib/llstack.c
+++ linux-2.6-lttng/lib/llstack.c
@@ -8,6 +8,7 @@
*
* Copyright 2010,2011 Intel Corp.
* Author: Huang Ying <ying.huang@intel.com>
+ * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
@@ -33,8 +34,11 @@
* llstack_push - push a node into a lock-less stack.
* @new: new entry to be added
* @head: the head for your lock-less stack
+ *
+ * Returns 0 if the stack was empty prior to push operation (check performed
+ * atomically with push), returns 1 otherwise.
*/
-void llstack_push(struct llstack_node *new, struct llstack_head *head)
+int llstack_push(struct llstack_node *new, struct llstack_head *head)
{
struct llstack_node *entry, *old_entry;
@@ -48,6 +52,8 @@ void llstack_push(struct llstack_node *n
new->next = entry;
cpu_relax();
} while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry);
+
+ return !!(unsigned long) entry;
}
EXPORT_SYMBOL_GPL(llstack_push);
@@ -56,8 +62,11 @@ EXPORT_SYMBOL_GPL(llstack_push);
* @new_first: first entry in batch to be added
* @new_last: last entry in batch to be added
* @head: the head for your lock-less list
+ *
+ * Returns 0 if the stack was empty prior to push operation (check performed
+ * atomically with push), returns 1 otherwise.
*/
-void llstack_push_batch(struct llstack_node *new_first, struct llstack_node *new_last,
+int llstack_push_batch(struct llstack_node *new_first, struct llstack_node *new_last,
struct llstack_head *head)
{
struct llstack_node *entry, *old_entry;
@@ -72,6 +81,8 @@ void llstack_push_batch(struct llstack_n
new_last->next = entry;
cpu_relax();
} while ((entry = cmpxchg(&head->first, old_entry, new_first)) != old_entry);
+
+ return !!(unsigned long) entry;
}
EXPORT_SYMBOL_GPL(llstack_push_batch);
Index: linux-2.6-lttng/include/linux/llstack.h
===================================================================
--- linux-2.6-lttng.orig/include/linux/llstack.h
+++ linux-2.6-lttng/include/linux/llstack.h
@@ -118,9 +118,9 @@ static inline int llstack_empty(const st
return ACCESS_ONCE(head->first) == NULL;
}
-void llstack_push(struct llstack_node *new, struct llstack_head *head);
-void llstack_push_batch(struct llstack_node *new_first, struct llstack_node *new_last,
- struct llstack_head *head);
+int llstack_push(struct llstack_node *new, struct llstack_head *head);
+int llstack_push_batch(struct llstack_node *new_first, struct llstack_node *new_last,
+ struct llstack_head *head);
struct llstack_node *llstack_pop(struct llstack_head *head);
struct llstack_node *llstack_pop_all(struct llstack_head *head);
#endif /* LLSTACK_H */
prev parent reply other threads:[~2011-09-03 18:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-03 17:47 [RFC patch 0/2] API renaming: "llist" (lockless list) to "llstack" (lockless stack) Mathieu Desnoyers
2011-09-03 17:47 ` [RFC patch 1/2] Rename the " Mathieu Desnoyers
2011-09-03 22:41 ` Andi Kleen
2011-09-04 20:50 ` Mathieu Desnoyers
2011-09-05 2:00 ` Huang Ying
2011-09-03 17:47 ` Mathieu Desnoyers [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=20110903175543.544717224@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--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