From patchwork Mon Apr 16 09:26:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 152778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 16317B7010 for ; Mon, 16 Apr 2012 19:26:19 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752009Ab2DPJ0R (ORCPT ); Mon, 16 Apr 2012 05:26:17 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:37869 "EHLO e28smtp01.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751811Ab2DPJ0R (ORCPT ); Mon, 16 Apr 2012 05:26:17 -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, 16 Apr 2012 14:56:11 +0530 Received: from d28relay02.in.ibm.com (9.184.220.59) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Apr 2012 14:56:09 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3G9QCtk2314242 for ; Mon, 16 Apr 2012 14:56:12 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3GEtsoC020408 for ; Mon, 16 Apr 2012 20:25:54 +0530 Received: from localhost ([9.123.247.128]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3GEtrmQ020393; Mon, 16 Apr 2012 20:25:53 +0530 Date: Mon, 16 Apr 2012 17:26:10 +0800 From: Richard Yang To: bhelgaas@google.com, linux-pci@vger.kernel.org Cc: Wei Yang Subject: [PATCH] Optimize the resource overlap check Message-ID: <20120416092610.GA28908@richard> Reply-To: Richard Yang References: <1334223550-9514-1-git-send-email-weiyang@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1334223550-9514-1-git-send-email-weiyang@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) x-cbid: 12041609-4790-0000-0000-000002339B69 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In coalesce_windows() it tries to check whether the res1 and res2 overlap. This function do four comparisons, which could be done with one comparisons. Also make the resource_check_overlap() a common function for others. Signed-Off-By: Wei Yang --- arch/x86/pci/acpi.c | 12 +----------- include/linux/ioport.h | 7 +++++++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 68c3c13..f2bb99e 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -181,13 +181,6 @@ setup_resource(struct acpi_resource *acpi_res, void *data) return AE_OK; } -static bool resource_contains(struct resource *res, resource_size_t point) -{ - if (res->start <= point && point <= res->end) - return true; - return false; -} - static void coalesce_windows(struct pci_root_info *info, unsigned long type) { int i, j; @@ -208,10 +201,7 @@ static void coalesce_windows(struct pci_root_info *info, unsigned long type) * our resources no longer match the ACPI _CRS, but * the kernel resource tree doesn't allow overlaps. */ - if (resource_contains(res1, res2->start) || - resource_contains(res1, res2->end) || - resource_contains(res2, res1->start) || - resource_contains(res2, res1->end)) { + if (resource_check_overlap(res1, res2)) { res1->start = min(res1->start, res2->start); res1->end = max(res1->end, res2->end); dev_info(&info->bridge->dev, diff --git a/include/linux/ioport.h b/include/linux/ioport.h index e9bb22c..374259b 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -198,5 +198,12 @@ extern int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, void *arg, int (*func)(unsigned long, unsigned long, void *)); +static inline int resource_check_overlap(struct resource *r1, + struct resource *r2) +{ + return (r1->start <= r2->end && r1->end >= r2->start); +} + + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_IOPORT_H */