From patchwork Mon Jul 1 15:10:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 2808231 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 96125BF4A1 for ; Mon, 1 Jul 2013 15:11:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 69A2F20142 for ; Mon, 1 Jul 2013 15:11:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F94520136 for ; Mon, 1 Jul 2013 15:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751386Ab3GAPL3 (ORCPT ); Mon, 1 Jul 2013 11:11:29 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:46102 "EHLO e28smtp01.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751171Ab3GAPL3 (ORCPT ); Mon, 1 Jul 2013 11:11:29 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 1 Jul 2013 20:34:16 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 1 Jul 2013 20:34:13 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 52209125804E for ; Mon, 1 Jul 2013 20:40:30 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r61FBjYb26542180 for ; Mon, 1 Jul 2013 20:41:45 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r61FBJ94003519 for ; Tue, 2 Jul 2013 01:11:21 +1000 Received: from localhost ([9.77.179.6]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r61FBCr4003204; Tue, 2 Jul 2013 01:11:13 +1000 From: Wei Yang To: linux-pci@vger.kernel.org Cc: weiyang@linux.vnet.ibm.com, linuxram@us.ibm.com, shangw@linux.vnet.ibm.com Subject: [PATCH 1/4] PCI: optimize pci_bus_get_depth() by enumerating on pci bus hierachy Date: Mon, 1 Jul 2013 23:10:29 +0800 Message-Id: <1372691432-6440-2-git-send-email-weiyang@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1372691432-6440-1-git-send-email-weiyang@linux.vnet.ibm.com> References: <1372691432-6440-1-git-send-email-weiyang@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13070115-4790-0000-0000-000009101A06 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 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 Normally, on one pci bus there would be more devices than pci buses. When calculating the depth of pci bus, it would be more time efficient by enumerating through the child buses instead of the child devices. Also by doing so, the code seems more self explaining. Previously, it go through the pci devices and check whether a bridge introduce a child bus or not, which needs more background knowledge to understand it. This patch caculating the depth by enumerating on pci bus hierachy in an iterative way. Signed-off-by: Wei Yang Reviewed-by: Gavin Shan Reviewed-by: Ram Pai Reviewed-by: Xiao Guangrong Reviewed-by: Mike Qiu --- drivers/pci/setup-bus.c | 43 ++++++++++++++++++++++++++++++++----------- 1 files changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 16abaaa..b333f73 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1299,22 +1299,43 @@ static void pci_bus_dump_resources(struct pci_bus *bus) static int __init pci_bus_get_depth(struct pci_bus *bus) { - int depth = 0; - struct pci_dev *dev; + int max_depth, depth; + struct pci_bus *parent, *curr; + struct list_head *node; - list_for_each_entry(dev, &bus->devices, bus_list) { - int ret; - struct pci_bus *b = dev->subordinate; - if (!b) - continue; + /* no child? */ + if (list_empty(&bus->children)) + return 0; - ret = pci_bus_get_depth(b); - if (ret + 1 > depth) - depth = ret + 1; + node = bus->children.next; + parent = bus; + max_depth = depth = 1; + + while (parent) { + /* hit the head, go back to parent level */ + if (node == &parent->children) { + node = parent->node.next; + parent = parent->parent; + depth--; + continue; + } + curr = list_entry(node, struct pci_bus, node); + /* depth first */ + if (!list_empty(&curr->children)) { + node = curr->children.next; + parent = curr; + depth++; + if (max_depth < depth) + max_depth = depth; + } + /* no child, go to the sibling */ + else + node = curr->node.next; } - return depth; + return max_depth; } + static int __init pci_get_max_depth(void) { int depth = 0;