From patchwork Mon Apr 27 06:48:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 47597 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 73F9220553 for ; Mon, 27 Apr 2015 06:51:01 +0000 (UTC) Received: by wgin8 with SMTP id n8sf23119786wgi.0 for ; Sun, 26 Apr 2015 23:51:00 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=wCtjU8aKa9M9FcYLhhpLPPM/kmy6itNm1UdWOqwWZR8=; b=UZovGTuzyp0QP6LrlyHwDizSZsEeOYaY0DFyn4myNzWaaaXMbyjDfUejMwYfbxSkuB 0GcKrvakbE+YA1OkDH+YSAigeJs3b/NLg6SZVsKJ5NWJsZepDTvSbvx2VrfCCLSZrlLw 6mtJfISWpwLZjSaQvkoG/NDPmQDQNAeTXbw4X68+YQT82Rq9PBfco+g2XCzUlFXZtgo1 PA1qnfpNGg9Xr980v80zTNl3KJr3xJzsF23cZMCvoOji94OTKoGIOSs88y5frL0UKsmV 3I851kBofRR7iXVlRaCHVywSOBSvzsChWsOnfTzJD+C6ZoZ+5hetFQY92fW8cSx2NEpe YIMw== X-Gm-Message-State: ALoCoQkzPhpYVXmwjmcEkDM/9bVfKaDDj0kUntqybaESHuPXOEHDMXxEygL98Nc3xlBufk83Qnn9 X-Received: by 10.112.122.39 with SMTP id lp7mr6430979lbb.5.1430117460535; Sun, 26 Apr 2015 23:51:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.2 with SMTP id ls2ls83773lac.31.gmail; Sun, 26 Apr 2015 23:51:00 -0700 (PDT) X-Received: by 10.152.44.169 with SMTP id f9mr9025270lam.7.1430117460214; Sun, 26 Apr 2015 23:51:00 -0700 (PDT) Received: from mail-lb0-x22a.google.com (mail-lb0-x22a.google.com. [2a00:1450:4010:c04::22a]) by mx.google.com with ESMTPS id g1si14118672lbs.32.2015.04.26.23.51.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Apr 2015 23:51:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22a as permitted sender) client-ip=2a00:1450:4010:c04::22a; Received: by lbbzk7 with SMTP id zk7so74844317lbb.0 for ; Sun, 26 Apr 2015 23:51:00 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr8874773laj.88.1430117460117; Sun, 26 Apr 2015 23:51:00 -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 l1csp1101711lbt; Sun, 26 Apr 2015 23:50:59 -0700 (PDT) X-Received: by 10.66.192.1 with SMTP id hc1mr19457311pac.38.1430117458056; Sun, 26 Apr 2015 23:50:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si28560616pds.131.2015.04.26.23.50.56; Sun, 26 Apr 2015 23:50:58 -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 S932126AbbD0Gui (ORCPT + 27 others); 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 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp1 (Coremail) with SMTP id C8mowEC5g0PH2z1VRqg4AA--.10035S4; Mon, 27 Apr 2015 14:48:53 +0800 (CST) 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 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::22a 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, 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);