From patchwork Mon Feb 16 09:32:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 44692 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 127C621544 for ; Mon, 16 Feb 2015 09:35:44 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id k14sf16493611wgh.0 for ; Mon, 16 Feb 2015 01:35:43 -0800 (PST) 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=O839K0woLfO8R+YbM98rkn5tAggSxlwVjnIv7ZTdsw8=; b=DTpMM/c6YL4LZrMajMvkCzxodTHtolGXKBQj609lY2NEr6dGQ13rCWOM4e77TYz2sE 9F4YZGPBsgdfsWOXfI5b7FW+yCaO+uxvEEhWGil5WADBMzm01/uPxB/xBtbUdVUGDJai BAQUkka4je8Wcitiw56lzHGcN25E4TpLYMebbA8qooW4Wc7X8qgsY82CmNytOQWl/Zfo jcSPb3yYPM2HMlIbM++n1Bw0plw/mY3NtHEFpJmKMg+6JHLPLPpP27Y+2DPqv/K6Skgw lNyNvFQfJxAZQ5AkQbtyyY2ko5WpIiuNWzOhJYjQQumJsO3cOg9cjvhbJgUsGmhCVdCg 6Vvg== X-Gm-Message-State: ALoCoQk1iOAOvNOpRw7MskyWADp514PORzhGEJRLylbhGw0CxnggY65ytjlzTWZfTG50lmXQ9gmL X-Received: by 10.112.144.130 with SMTP id sm2mr2560969lbb.9.1424079343335; Mon, 16 Feb 2015 01:35:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.98 with SMTP id v2ls36420lal.104.gmail; Mon, 16 Feb 2015 01:35:43 -0800 (PST) X-Received: by 10.152.27.136 with SMTP id t8mr20873886lag.60.1424079343125; Mon, 16 Feb 2015 01:35:43 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id s10si7163598lae.47.2015.02.16.01.35.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Feb 2015 01:35:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lams18 with SMTP id s18so27255309lam.13 for ; Mon, 16 Feb 2015 01:35:43 -0800 (PST) X-Received: by 10.112.40.201 with SMTP id z9mr20506026lbk.117.1424079342984; Mon, 16 Feb 2015 01:35:42 -0800 (PST) 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 h5csp1472225lbj; Mon, 16 Feb 2015 01:35:42 -0800 (PST) X-Received: by 10.67.6.225 with SMTP id cx1mr38098190pad.1.1424079341179; Mon, 16 Feb 2015 01:35:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id de9si3691640pdb.145.2015.02.16.01.35.39; Mon, 16 Feb 2015 01:35:41 -0800 (PST) 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 S1755389AbbBPJfe (ORCPT + 28 others); Mon, 16 Feb 2015 04:35:34 -0500 Received: from m15-113.126.com ([220.181.15.113]:36981 "EHLO m15-113.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754774AbbBPJfd (ORCPT ); Mon, 16 Feb 2015 04:35:33 -0500 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp3 (Coremail) with SMTP id DcmowAA3sXVVueFU6xL6AQ--.1340S2; Mon, 16 Feb 2015 17:33:20 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Andrew Morton , Dan Streetman , Xunlei Pang Subject: [PATCH v4 1/3] lib/plist: Provide plist_add_head() for nodes with the same prio Date: Mon, 16 Feb 2015 17:32:22 +0800 Message-Id: <1424079144-5194-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DcmowAA3sXVVueFU6xL6AQ--.1340S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF18tw1fGrW3uryfCr1Utrb_yoW5ur17pr y5G34fA397ArWxWw4SyF429wsIgF18JF4jkryxC343Ar12gr4IqFy7XF4UAF1fJr4kurWr Jr48Kw17Gr4UJr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jmVbgUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbipBWiv1GofbTSHAABsT 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 209.85.215.49 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 behind 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() with plist_add_tail() which has the same behaviour as before. Signed-off-by: Xunlei Pang --- include/linux/plist.h | 30 +++++++++++++++++++++++++++++- lib/plist.c | 15 ++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/include/linux/plist.h b/include/linux/plist.h index 9788360..e17bb96 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, 1); +} + +/** + * 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, 0); +} + +#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 d408e77..0e1f1b3 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -67,12 +67,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; @@ -97,8 +101,13 @@ 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) { + 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);