From patchwork Mon Mar 9 07:32:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 45530 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 54B6C20285 for ; Mon, 9 Mar 2015 07:42:00 +0000 (UTC) Received: by lbiz11 with SMTP id z11sf31802350lbi.2 for ; Mon, 09 Mar 2015 00:41:59 -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=QZVlPW7VoYS37yAR31bZ+1HiPwXEz7s7o8gYeBT0JC0=; b=Fl59HliVO1pdCzVUQmcIA01GiZzhWl/aqq2Q0ThgMMDH5KaviGZRaFxvlfy7sXQOM+ /HVktllVVOEeqlCKg23N5SZgqES3a4A6mVBtJuC0lQEIvEMt7wwiGUbLN9vitsXwmL8h hgZPzaqyDiQH9EnGchAs4Yl/wek/afuqmd4WNOQVLQ1JQyYF+k3t7wk6j9GlkUG6KXWZ G9HmiryaeQGwAVBeHG4QmCqzt5NAOQGCkoils0MuAq1L2dKeD6cWfkiv6kt5ME9SJx84 C+tgGhZPHIHFNTYM9Faxu8IBhltgRM+Rx7Ie2G01qFKK+f0GGrNMKpZjs089znIoQx5A FzPQ== X-Gm-Message-State: ALoCoQk4cQKgcUZ18Ly8K674ZLG7bhJViIpH7QQ+iwN3C6+jF16i4onCPORc7O/u/KWyztmcfgtV X-Received: by 10.152.29.97 with SMTP id j1mr3677086lah.3.1425886919332; Mon, 09 Mar 2015 00:41:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.102 with SMTP id q6ls283254laa.24.gmail; Mon, 09 Mar 2015 00:41:59 -0700 (PDT) X-Received: by 10.152.27.39 with SMTP id q7mr23626910lag.49.1425886919150; Mon, 09 Mar 2015 00:41:59 -0700 (PDT) Received: from mail-lb0-x234.google.com (mail-lb0-x234.google.com. [2a00:1450:4010:c04::234]) by mx.google.com with ESMTPS id g1si13533830laa.128.2015.03.09.00.41.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2015 00:41:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::234 as permitted sender) client-ip=2a00:1450:4010:c04::234; Received: by lbdu10 with SMTP id u10so22169012lbd.4 for ; Mon, 09 Mar 2015 00:41:59 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr18416199lba.19.1425886919061; Mon, 09 Mar 2015 00:41:59 -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.35.133 with SMTP id h5csp1310800lbj; Mon, 9 Mar 2015 00:41:58 -0700 (PDT) X-Received: by 10.66.66.230 with SMTP id i6mr50226073pat.108.1425886917283; Mon, 09 Mar 2015 00:41:57 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oz10si24829553pdb.15.2015.03.09.00.41.55; Mon, 09 Mar 2015 00:41:57 -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 S1752961AbbCIHlv (ORCPT + 28 others); Mon, 9 Mar 2015 03:41:51 -0400 Received: from m15-111.126.com ([220.181.15.111]:44642 "EHLO m15-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752655AbbCIHls (ORCPT ); Mon, 9 Mar 2015 03:41:48 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp1 (Coremail) with SMTP id C8mowEDJjkaiTP1UiXhUAw--.132S2; Mon, 09 Mar 2015 15:33:14 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Xunlei Pang , Andrew Morton , Dan Streetman Subject: [PATCH RESEND v4 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Date: Mon, 9 Mar 2015 15:32:26 +0800 Message-Id: <1425886348-3191-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: C8mowEDJjkaiTP1UiXhUAw--.132S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF18tw1fGrW3uryfCFWfZrb_yoWrJw4Dpr y5G343J397ArWxWw4SyF4UuwsIgF18JF4jkryxC343Ar1jgr4IqFyxXF4UAFn3Jr48urWr Jr48K348Gr4UJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jmq2NUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbimhu3v1GfVXTjUAAAsV 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::234 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. cc: Andrew Morton cc: Dan Streetman Signed-off-by: Xunlei Pang --- include/linux/plist.h | 30 +++++++++++++++++++++++++++++- lib/plist.c | 24 +++++++++++++++++++++--- 2 files changed, 50 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..d3ebac6 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,22 @@ 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, 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. + */ + list_add(&node->prio_list, &prev->prio_list); + list_del_init(&prev->prio_list); + node_next = &prev->node_list; + } ins_node: list_add_tail(&node->node_list, node_next);