From patchwork Mon Apr 20 08:22:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 47334 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D21CE20553 for ; Mon, 20 Apr 2015 08:25:33 +0000 (UTC) Received: by wicmx19 with SMTP id mx19sf8904192wic.3 for ; Mon, 20 Apr 2015 01:25:33 -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=RQdfB21kAJNX1FQNjLVwH8hohQ0UjMaXr8QMaEiuUT8=; b=CkM6fwngJ2LywOSDxd82wXDIJILtxTaYnbL539q75icoiUdueOY9Hp+HBjRWtJ6tCe 0p0mUG0sT6tLtfxzJHf3jcNU20wacBca7Qf+6/hCB3qM4xz3ZOLI0v+3WAo+2XLahaDF GqQ2SbI8faxi5T7IU8oJ61C7o0KOJ/Flp3ukANTmmUrEAYeh+jcK7hcXI9hzOazjpxMn zoO4AitZFwpNbnaFWWpOxOn6Dcaond4KQJ6Ikj/RYkGHByk1OJpeZ87nK3cur1sjYByJ NVgLsFVDUYQaE4jryhCY7z6b0iLtBYeiogv61VkhoDE+HQrhVT0MAldxB/YhAm5B52mg ensw== X-Gm-Message-State: ALoCoQkcadIl2kkstZKBlxZxRAx3HuroFBy+b5ic8yGKKE9k7ZqwzlkxvSCbjkj8q3+1+/AQUimS X-Received: by 10.112.29.39 with SMTP id g7mr6669964lbh.1.1429518333097; Mon, 20 Apr 2015 01:25:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.2 with SMTP id x2ls792297lag.99.gmail; Mon, 20 Apr 2015 01:25:32 -0700 (PDT) X-Received: by 10.112.42.233 with SMTP id r9mr14939424lbl.58.1429518332797; Mon, 20 Apr 2015 01:25:32 -0700 (PDT) Received: from mail-lb0-x232.google.com (mail-lb0-x232.google.com. [2a00:1450:4010:c04::232]) by mx.google.com with ESMTPS id wu8si14444710lac.157.2015.04.20.01.25.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Apr 2015 01:25:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::232 as permitted sender) client-ip=2a00:1450:4010:c04::232; Received: by lbbzk7 with SMTP id zk7so124718822lbb.0 for ; Mon, 20 Apr 2015 01:25:32 -0700 (PDT) X-Received: by 10.152.19.199 with SMTP id h7mr15017942lae.32.1429518332695; Mon, 20 Apr 2015 01:25:32 -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 l1csp1297179lbt; Mon, 20 Apr 2015 01:25:31 -0700 (PDT) X-Received: by 10.66.160.71 with SMTP id xi7mr25991513pab.19.1429518330700; Mon, 20 Apr 2015 01:25:30 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gl1si27224387pbd.2.2015.04.20.01.25.29; Mon, 20 Apr 2015 01:25:30 -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 S1754724AbbDTIZU (ORCPT + 26 others); Mon, 20 Apr 2015 04:25:20 -0400 Received: from m50-110.126.com ([123.125.50.110]:40667 "EHLO m50-110.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754659AbbDTIZK (ORCPT ); Mon, 20 Apr 2015 04:25:10 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp4 (Coremail) with SMTP id jdKowAD3__uLtzRVzV2uAQ--.4394S2; Mon, 20 Apr 2015 16:23:49 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Xunlei Pang Subject: [PATCH v6 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Date: Mon, 20 Apr 2015 16:22:46 +0800 Message-Id: <1429518168-7965-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: jdKowAD3__uLtzRVzV2uAQ--.4394S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF18tw1fGrW3uryfGr47XFb_yoWrXFyDpr y5G345J397AryIgw4SyF4j9rsagF18JF4jyryxCr9xAr1jgr4IqFy3XF4UAFn3JrWkur1r JF4rKw1UGr4UJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jk8n5UUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiXBXhv1R0VxnWQwAAss 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::232 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 --- v5->v6: Add more detailed annotations. include/linux/plist.h | 30 +++++++++++++++++++++++++++++- lib/plist.c | 28 +++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/include/linux/plist.h b/include/linux/plist.h index 9788360..39806a2 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: 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); +} + +#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..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);