From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755676AbbBPPct (ORCPT ); Mon, 16 Feb 2015 10:32:49 -0500 Received: from smtprelay0199.hostedemail.com ([216.40.44.199]:37519 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752955AbbBPPcr (ORCPT ); Mon, 16 Feb 2015 10:32:47 -0500 X-Session-Marker: 6E657665747340676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2840:3138:3139:3140:3141:3142:3151:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:4605:5007:6119:6261:7576:7875:9010:10004:10848:10967:11026:11232:11473:11658:11914:12043:12291:12296:12517:12519:12555:12683:12740:13161:13229:13255:14096:14097:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: event76_6f22764839f20 X-Filterd-Recvd-Size: 5526 Date: Mon, 16 Feb 2015 10:32:42 -0500 From: Steven Rostedt To: Xunlei Pang Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Juri Lelli , Andrew Morton , Dan Streetman , Xunlei Pang Subject: Re: [PATCH v4 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Message-ID: <20150216103242.335ab984@gandalf.local.home> In-Reply-To: <1424079144-5194-1-git-send-email-xlpang@126.com> References: <1424079144-5194-1-git-send-email-xlpang@126.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 16 Feb 2015 17:32:22 +0800 Xunlei Pang wrote: > 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 > behind 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() with plist_add_tail() which has the same > behaviour as before. > > Signed-off-by: Xunlei Pang > --- > include/linux/plist.h | 30 +++++++++++++++++++++++++++++- > lib/plist.c | 15 ++++++++++++--- > 2 files changed, 41 insertions(+), 4 deletions(-) > > diff --git a/include/linux/plist.h b/include/linux/plist.h > index 9788360..e17bb96 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: &struct plist_node pointer > + * @head: &struct plist_head pointer > + */ > +static inline > +void plist_add_head(struct plist_node *node, struct plist_head *head) > +{ > + __plist_add(node, head, 1); is_head is boolean, shouldn't that be "true" instead of "1". > +} > + > +/** > + * plist_add_tail - add @node to @head, after all existing same-prio nodes > + * > + * @node: &struct plist_node pointer > + * @head: &struct plist_head pointer > + */ > +static inline > +void plist_add_tail(struct plist_node *node, struct plist_head *head) > +{ > + __plist_add(node, head, 0); And "false" here. > +} > + > +#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 d408e77..0e1f1b3 100644 > --- a/lib/plist.c > +++ b/lib/plist.c > @@ -67,12 +67,16 @@ 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 > + * @is_head: bool > + * > + * If there're any nodes with the same prio, add @node > + * behind or before all of them according to @is_head. > */ > -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; > @@ -97,8 +101,13 @@ 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) { > + list_add(&node->prio_list, &prev->prio_list); > + list_del_init(&prev->prio_list); > + node_next = &prev->node_list; The above could use some comments. I would say the entire plist code could use more comments, but that's out of scope with this series. But at least lets add comments when adding new code. Something like: } 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, insert node right after prev * in the prio_list and then remove prev from that list. * Then set node_next to prev->node_list so that the * new node gets added before prev and not iter. */ Something like that, because it took me some time to figure out how plist works. It's one of those algorithms that seem to page fault out quickly, and takes some time to page fault back into one's mind. -- Steve > + } > ins_node: > list_add_tail(&node->node_list, node_next); >