All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio
@ 2015-04-20  8:22 Xunlei Pang
  2015-04-20  8:22 ` [PATCH v6 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Xunlei Pang
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Xunlei Pang @ 2015-04-20  8:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Steven Rostedt, Juri Lelli, Xunlei Pang

From: Xunlei Pang <pang.xunlei@linaro.org>

If there're multiple nodes with the same prio as @node, currently
plist_add() will add @node behind all of them. Now we need to add
@node before all of these nodes for SMP RT scheduler.

This patch adds a common __plist_add() for adding @node before or
after existing nodes with the same prio, then adds plist_add_head()
and plist_add_tail() inline wrapper functions for convenient uses.

Finally, define plist_add() as plist_add_tail() which has the same
behaviour as before.

Reviewed-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
v5->v6:
Add more detailed annotations.

 include/linux/plist.h | 30 +++++++++++++++++++++++++++++-
 lib/plist.c           | 28 +++++++++++++++++++++++-----
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/include/linux/plist.h b/include/linux/plist.h
index 9788360..39806a2 100644
--- a/include/linux/plist.h
+++ b/include/linux/plist.h
@@ -138,7 +138,35 @@ static inline void plist_node_init(struct plist_node *node, int prio)
 	INIT_LIST_HEAD(&node->node_list);
 }
 
-extern void plist_add(struct plist_node *node, struct plist_head *head);
+extern void __plist_add(struct plist_node *node,
+				struct plist_head *head, bool is_head);
+
+/**
+ * plist_add_head - add @node to @head, before all existing same-prio nodes
+ *
+ * @node:	The plist_node to be added to @head
+ * @head:	The plist_head that @node is being added to
+ */
+static inline
+void plist_add_head(struct plist_node *node, struct plist_head *head)
+{
+	__plist_add(node, head, true);
+}
+
+/**
+ * plist_add_tail - add @node to @head, after all existing same-prio nodes
+ *
+ * @node:	The plist_node to be added to @head
+ * @head:	The plist_head that @node is being added to
+ */
+static inline
+void plist_add_tail(struct plist_node *node, struct plist_head *head)
+{
+	__plist_add(node, head, false);
+}
+
+#define plist_add plist_add_tail
+
 extern void plist_del(struct plist_node *node, struct plist_head *head);
 
 extern void plist_requeue(struct plist_node *node, struct plist_head *head);
diff --git a/lib/plist.c b/lib/plist.c
index 3a30c53..c1ee2b0 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -66,12 +66,18 @@ static void plist_check_head(struct plist_head *head)
 #endif
 
 /**
- * plist_add - add @node to @head
+ * __plist_add - add @node to @head
  *
- * @node:	&struct plist_node pointer
- * @head:	&struct plist_head pointer
+ * @node:    The plist_node to be added to @head
+ * @head:    The plist_head that @node is being added to
+ * @is_head: True if adding to head of prio list, false otherwise
+ *
+ * For nodes of the same prio, @node will be added at the
+ * head of previously added nodes if @is_head is true, or
+ * it will be added at the tail of previously added nodes
+ * if @is_head is false.
  */
-void plist_add(struct plist_node *node, struct plist_head *head)
+void __plist_add(struct plist_node *node, struct plist_head *head, bool is_head)
 {
 	struct plist_node *first, *iter, *prev = NULL;
 	struct list_head *node_next = &head->node_list;
@@ -96,8 +102,20 @@ void plist_add(struct plist_node *node, struct plist_head *head)
 				struct plist_node, prio_list);
 	} while (iter != first);
 
-	if (!prev || prev->prio != node->prio)
+	if (!prev || prev->prio != node->prio) {
 		list_add_tail(&node->prio_list, &iter->prio_list);
+	} else if (is_head) {
+		/*
+		 * prev has the same priority as the node that is being
+		 * added. It is also the first node for this priority,
+		 * but the new node needs to be added ahead of it.
+		 * To accomplish this, replace prev in the prio_list
+		 * with node. Then set node_next to prev->node_list so
+		 * that the new node gets added before prev and not iter.
+		 */
+		list_replace_init(&prev->prio_list, &node->prio_list);
+		node_next = &prev->node_list;
+	}
 ins_node:
 	list_add_tail(&node->node_list, node_next);
 
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-04-28 12:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-20  8:22 [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Xunlei Pang
2015-04-20  8:22 ` [PATCH v6 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Xunlei Pang
2015-04-20 14:52   ` Steven Rostedt
2015-04-20 17:20     ` Peter Zijlstra
2015-04-20 17:48       ` Steven Rostedt
2015-04-20 23:45         ` Peter Zijlstra
2015-04-21 13:10           ` Steven Rostedt
     [not found]         ` <OFB1503F16.1E65406F-ON48257E2E.002B562D-48257E30.0008BFEB@zte.com.cn>
2015-04-23  3:01           ` Steven Rostedt
     [not found]             ` <OFE3B71874.C9D81693-ON48257E30.0024F69F-48257E30.0025E2D3@zte.com.cn>
2015-04-23 13:10               ` Steven Rostedt
2015-04-24 18:32               ` Peter Zijlstra
     [not found]                 ` <OF0B05B4FE.F40C0BE3-ON48257E32.004EF485-48257E32.00513DB3@zte.com.cn>
2015-04-25 18:23                   ` Peter Zijlstra
     [not found]                     ` <OFD410EB1E.5A02675A-ON48257E33.00309252-48257E33.003641FF@zte.com.cn>
2015-04-26 15:58                       ` Steven Rostedt
2015-04-28 10:19                         ` Peter Zijlstra
2015-04-28 12:48                           ` Mike Galbraith
2015-04-20  8:22 ` [PATCH v6 3/3] sched/rt: Check to push the task when changing its affinity Xunlei Pang
2015-04-20 16:06   ` Steven Rostedt
2015-04-20 14:42 ` [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Steven Rostedt
2015-04-20 14:48 ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.