From patchwork Sun Apr 26 17:10:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 47585 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 95D6021550 for ; Sun, 26 Apr 2015 17:12:42 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf20336279lbb.0 for ; Sun, 26 Apr 2015 10:12:41 -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=Kk1HDwd/CoXmJ0JYwMwTXgGfi1hJNrBL1c81IcAcrUeAmC73H1GkA8ePpKhccWLmPC jTwiHIWOCkx6BrXedHJD4DerDPM8CTbCSZnGH/IL4ksnaG4iN7g0ZfThRKHOFxkP2C1L 4JxRHmLo5qHxMSGhf6ID4/C8dxA8EloOHYUQHd9YvTqYooKX3ndlqkwjGYspD/nJigdY PcC/1qUnAOkdSY8yyF0t+P2v2viLVpzcK8qMM4Hh7GxTYyeLiDaKKXLcDgj9fU/WOhTh fEXyO/GWEA7Iqajb88hfgYkuKBnXvZapUoitLSUVAEDPoTxdved8aVd3TacX8MsA8Qr3 G0pA== X-Gm-Message-State: ALoCoQnud2/hn5XB7pcs9lV6zyi6i9FScMlywzYKgj/4h3I7Q0LNqneefmWRWGOJ/6lqk0tBpNB3 X-Received: by 10.194.249.1 with SMTP id yq1mr5028621wjc.2.1430068361612; Sun, 26 Apr 2015 10:12:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.163.200 with SMTP id yk8ls47469lab.95.gmail; Sun, 26 Apr 2015 10:12:41 -0700 (PDT) X-Received: by 10.112.156.97 with SMTP id wd1mr6700087lbb.30.1430068361418; Sun, 26 Apr 2015 10:12:41 -0700 (PDT) Received: from mail-la0-x230.google.com (mail-la0-x230.google.com. [2a00:1450:4010:c03::230]) by mx.google.com with ESMTPS id th3si12956739lbb.146.2015.04.26.10.12.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Apr 2015 10:12:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::230 as permitted sender) client-ip=2a00:1450:4010:c03::230; Received: by layy10 with SMTP id y10so65106530lay.0 for ; Sun, 26 Apr 2015 10:12:41 -0700 (PDT) X-Received: by 10.112.161.226 with SMTP id xv2mr6867423lbb.106.1430068361312; Sun, 26 Apr 2015 10:12:41 -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 l1csp868152lbt; Sun, 26 Apr 2015 10:12:40 -0700 (PDT) X-Received: by 10.70.44.76 with SMTP id c12mr15067178pdm.49.1430068359034; Sun, 26 Apr 2015 10:12:39 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ub8si7050624pbc.64.2015.04.26.10.12.38; Sun, 26 Apr 2015 10:12:39 -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 S1752028AbbDZRM3 (ORCPT + 27 others); Sun, 26 Apr 2015 13:12:29 -0400 Received: from m15-114.126.com ([220.181.15.114]:53268 "EHLO m15-114.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751004AbbDZRMW (ORCPT ); Sun, 26 Apr 2015 13:12:22 -0400 Received: from localhost.localdomain (unknown [220.166.221.63]) by smtp7 (Coremail) with SMTP id DsmowACX+G4iHD1V8BojAA--.830S5; Mon, 27 Apr 2015 01:11:08 +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 4/6] lib/plist: Provide plist_add_head() for nodes with the same prio Date: Mon, 27 Apr 2015 01:10:56 +0800 Message-Id: <1430068258-1960-4-git-send-email-xlpang@126.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430068258-1960-1-git-send-email-xlpang@126.com> References: <1430068258-1960-1-git-send-email-xlpang@126.com> X-CM-TRANSID: DsmowACX+G4iHD1V8BojAA--.830S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF18tw1fGrW3uryfGr47XFb_yoWrWFW3pr y3G345J397AryIgw4SyF4UursagF18JF4jyFyxC343Ar1qgr4IqFyfXF1UAFn3JrWkur1f JF4rKw1UGr4UJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b1PEhUUUUU= X-Originating-IP: [220.166.221.63] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbijBrnv1GfVBu55gAAsQ 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:c03::230 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);