From patchwork Thu Apr 9 03:27:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 46902 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CD0B421416 for ; Thu, 9 Apr 2015 03:30:21 +0000 (UTC) Received: by lbbrr5 with SMTP id rr5sf21280598lbb.3 for ; Wed, 08 Apr 2015 20:30:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=XGqtVJIYvLKFrLGroK4y1H3FJ5yCyWxpsgHrAUJn98Q=; b=bxWj1gB8zGDZkBZhAIl5PFPz+X6cowq5a9VfbMSK4LRh0nn9pIW2Y0iwNdNOvqiHL9 ZCWNmd1yfyL/etXo/5NZxzvCUymUHCmODtQ3MZFBnlB+lkcqekgTSB06mpekY62HXjzP YQ0iWoaYMIh06eC3tUNiyU/37XTWdx58nKkYj3FAokE4EpTOPUmfQKFx2tCYc7FVZJVI qjhTZhUDuOxhoCX8PMxYee8KGXaffWe8IyqT9V2mpXLn54WJnFOjCbQFrfmmxeZeWiPR 8p5aktRj2cXeBKOwsusvhgt6aHq7ipe0+EDFBrNG2z5IZ3YgPqKq57BPoT3Zm+iSQXho uamw== X-Gm-Message-State: ALoCoQlbdaAEtwvXmgR2PLjuqxKwBq1cyinYVvJurYCeXsEB93euyQETAkcR12dZM1co4enYPeHt X-Received: by 10.180.23.40 with SMTP id j8mr202596wif.2.1428550220779; Wed, 08 Apr 2015 20:30:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.225 with SMTP id db1ls238740lac.78.gmail; Wed, 08 Apr 2015 20:30:20 -0700 (PDT) X-Received: by 10.112.65.37 with SMTP id u5mr14380048lbs.44.1428550220513; Wed, 08 Apr 2015 20:30:20 -0700 (PDT) Received: from mail-lb0-x235.google.com (mail-lb0-x235.google.com. [2a00:1450:4010:c04::235]) by mx.google.com with ESMTPS id az14si10339800lab.154.2015.04.08.20.30.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2015 20:30:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::235 as permitted sender) client-ip=2a00:1450:4010:c04::235; Received: by lbcga7 with SMTP id ga7so31885759lbc.1 for ; Wed, 08 Apr 2015 20:30:20 -0700 (PDT) X-Received: by 10.152.5.72 with SMTP id q8mr2648543laq.73.1428550220413; Wed, 08 Apr 2015 20:30:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp221405lbt; Wed, 8 Apr 2015 20:30:19 -0700 (PDT) X-Received: by 10.66.66.7 with SMTP id b7mr52791749pat.9.1428550217797; Wed, 08 Apr 2015 20:30:17 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ck5si19062466pbb.147.2015.04.08.20.30.16; Wed, 08 Apr 2015 20:30:17 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932266AbbDIDaL (ORCPT + 27 others); Wed, 8 Apr 2015 23:30:11 -0400 Received: from m15-112.126.com ([220.181.15.112]:40882 "EHLO m15-112.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754530AbbDIDaE (ORCPT ); Wed, 8 Apr 2015 23:30:04 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp2 (Coremail) with SMTP id DMmowEDJvlOa8SVVTV0aAQ--.926S2; Thu, 09 Apr 2015 11:27:27 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Dan Streetman , Xunlei Pang Subject: [PATCH v5 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Date: Thu, 9 Apr 2015 11:27:16 +0800 Message-Id: <1428550038-13619-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DMmowEDJvlOa8SVVTV0aAQ--.926S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF18tw1fGrW3uryfGr47XFb_yoWrJr1rpr y5G343J397ArWxWw4SyF429wnIgF18JF4jkryxC343Ar1Ygr4IqFyxXF4UAFn3Jr4kurWf Jr4rK34UGr4UJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jZqXdUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbijB7Wv1GfUtz90wACsX Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::235 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=126.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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, define plist_add() as plist_add_tail() which has the same behaviour as before. Reviewed-by: Dan Streetman Signed-off-by: Xunlei Pang --- include/linux/plist.h | 30 +++++++++++++++++++++++++++++- lib/plist.c | 22 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/include/linux/plist.h b/include/linux/plist.h index 9788360..10c834c 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, true); +} + +/** + * 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, 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..9f396f1 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -66,12 +66,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; @@ -96,8 +100,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);