Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932123AbbD0Gui (ORCPT ); Mon, 27 Apr 2015 02:50:38 -0400 Received: from m15-111.126.com ([220.181.15.111]:35137 "EHLO m15-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932070AbbD0Gue (ORCPT ); Mon, 27 Apr 2015 02:50:34 -0400 From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Ingo Molnar , Xunlei Pang Subject: [RFC PATCH RESEND 2/4] lib/plist: Provide plist_add_head() for nodes with the same prio Date: Mon, 27 Apr 2015 14:48:36 +0800 Message-Id: <1430117318-2080-3-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430117318-2080-1-git-send-email-xlpang@126.com> References: <1430117318-2080-1-git-send-email-xlpang@126.com> X-CM-TRANSID: C8mowEC5g0PH2z1VRqg4AA--.10035S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF18tw1fGrW3uryfGr47XFb_yoWrWFW3pr y3G345J397AryIgw4SyF4UursagF18JF4jyFyxC343Ar1qgr4IqFyfXF1UAFn3JrWkur1f JF4rKw1UGr4UJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jil1kUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiXBfov1R0V4-96gAAsz Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4297 Lines: 124 From: Xunlei Pang 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, change plist_add() to an inline wrapper using plist_add_tail() which has the same behaviour as before. Reviewed-by: Dan Streetman Reviewed-by: Steven Rostedt Signed-off-by: Xunlei Pang --- include/linux/plist.h | 34 +++++++++++++++++++++++++++++++++- lib/plist.c | 28 +++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/include/linux/plist.h b/include/linux/plist.h index 9788360..d060f28 100644 --- a/include/linux/plist.h +++ b/include/linux/plist.h @@ -138,7 +138,39 @@ 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); +} + +static inline +void plist_add(struct plist_node *node, struct plist_head *head) +{ + plist_add_tail(node, head); +} + 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/