From patchwork Fri Aug 21 06:20:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 7048781 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 685879F358 for ; Fri, 21 Aug 2015 06:29:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F2AC205BC for ; Fri, 21 Aug 2015 06:29:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9445820591 for ; Fri, 21 Aug 2015 06:29:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753748AbbHUG25 (ORCPT ); Fri, 21 Aug 2015 02:28:57 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:48366 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753776AbbHUG24 (ORCPT ); Fri, 21 Aug 2015 02:28:56 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7L6LQEU013562 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Aug 2015 06:21:26 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t7L6LQEu005124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 21 Aug 2015 06:21:26 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t7L6LPAw032052; Fri, 21 Aug 2015 06:21:25 GMT Received: from linux-siqj.site (/10.154.151.145) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 20 Aug 2015 23:21:25 -0700 From: Yinghai Lu To: Bjorn Helgaas , David Miller , Benjamin Herrenschmidt , Wei Yang , TJ , Yijing Wang Cc: Andrew Morton , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v4 07/52] PCI: Reorder resources list for required/optional resources Date: Thu, 20 Aug 2015 23:20:22 -0700 Message-Id: <1440138067-4314-8-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1440138067-4314-1-git-send-email-yinghai@kernel.org> References: <1440138067-4314-1-git-send-email-yinghai@kernel.org> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After we update size and alignment for required+optional resource, we reorder them with new alignment, but this is only for STARTALIGN. For SIZEALIGN type resource, after add back add_size, the alignment get changed, so need to do sorting like STARTALIGN type resources. Also we need to reorder the sorting back after we restore resource to required only when required+optional fail to allocate for all. So move out the reordering code from the loop to separated function, and call it two times accordingly. Signed-off-by: Yinghai Lu --- drivers/pci/setup-bus.c | 62 +++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index e4aa93e..555a7a3 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -286,6 +286,31 @@ static inline void reset_resource(struct resource *res) res->flags = 0; } +static void sort_resources(struct list_head *head) +{ + struct pci_dev_resource *res1, *tmp_res, *res2; + + list_for_each_entry_safe(res1, tmp_res, head, list) { + resource_size_t align1, size1, align2, size2; + + align1 = pci_resource_alignment(res1->dev, res1->res); + size1 = resource_size(res1->res); + + /* reorder it */ + list_for_each_entry(res2, head, list) { + if (res2 == res1) + break; + + align2 = pci_resource_alignment(res2->dev, res2->res); + size2 = resource_size(res2->res); + if (is_before(align1, size1, align2, size2)) { + list_move_tail(&res1->list, &res2->list); + break; + } + } + } +} + /** * reassign_resources_sorted() - satisfy any additional resource requests * @@ -448,9 +473,9 @@ static void __assign_resources_sorted(struct list_head *head, LIST_HEAD(save_head); LIST_HEAD(local_fail_head); struct pci_dev_resource *save_res; - struct pci_dev_resource *dev_res, *tmp_res, *dev_res2; + struct pci_dev_resource *dev_res, *tmp_res; unsigned long fail_type; - resource_size_t add_align, align; + resource_size_t add_align; /* Check if optional add_size is there */ if (!realloc_head || list_empty(realloc_head)) @@ -465,47 +490,32 @@ static void __assign_resources_sorted(struct list_head *head, } /* Update res in head list with add_size in realloc_head list */ - list_for_each_entry_safe(dev_res, tmp_res, head, list) { + list_for_each_entry(dev_res, head, list) { dev_res->res->end += get_res_add_size(realloc_head, dev_res->res); /* * There are two kinds of additional resources in the list: - * 1. bridge resource -- IORESOURCE_STARTALIGN - * 2. SR-IOV resource -- IORESOURCE_SIZEALIGN - * Here just fix the additional alignment for bridge + * 1. bridge resource with IORESOURCE_STARTALIGN + * need to update start to change alignment + * 2. resource with IORESOURCE_SIZEALIGN + * update size above already change alignment. */ if (!(dev_res->res->flags & IORESOURCE_STARTALIGN)) continue; add_align = get_res_add_align(realloc_head, dev_res->res); - /* - * The "head" list is sorted by the alignment to make sure - * resources with bigger alignment will be assigned first. - * After we change the alignment of a dev_res in "head" list, - * we need to reorder the list by alignment to make it - * consistent. - */ - if (add_align > dev_res->res->start) { + if (add_align) { resource_size_t r_size = resource_size(dev_res->res); dev_res->res->start = add_align; dev_res->res->end = add_align + r_size - 1; - - list_for_each_entry(dev_res2, head, list) { - align = pci_resource_alignment(dev_res2->dev, - dev_res2->res); - if (add_align > align) { - list_move_tail(&dev_res->list, - &dev_res2->list); - break; - } - } } - } + sort_resources(head); + /* Try updated head list with add_size added */ assign_requested_resources_sorted(head, &local_fail_head); @@ -547,6 +557,8 @@ static void __assign_resources_sorted(struct list_head *head, } free_list(&save_head); + sort_resources(head); + requested_and_reassign: /* Satisfy the must-have resource requests */ assign_requested_resources_sorted(head, fail_head);