Skip to contentSkip to conversation

Optimize the resource overlap check

PATCH Applied Richard Yang 2 participants 3 messages May 5, 2012 – May 8, 2012 1 message not in the archive PCI

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Bjorn,

How do you think of my this version?

Quoted 61 lines · Wei Yang

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_overlaps() a common function for others.

---
arch/x86/pci/acpi.c | 12 +-----------
include/linux/ioport.h | 7 +++++++

2 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/pci/acpi.c +1 -11
index 68c3c13..fd3f541 100644
@@ -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_overlaps(res1, res2)) {
 				res1->start = min(res1->start, res2->start);
 				res1->end = max(res1->end, res2->end);
 				dev_info(&info->bridge->dev,
include/linux/ioport.h +7 -0
index e9bb22c..05d2c70 100644
@@ -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 bool resource_overlaps(struct resource *r1,
+                                         struct resource *r2)
+{
+       return (r1->start <= r2->end && r1->end >= r2->start);
+}
+
+
 #endif /* __ASSEMBLY__ */
 #endif	/* _LINUX_IOPORT_H */
Signature · 1 line
1.7.4.1
Signature · 2 lines
Richard Yang
Help you, Help me
maintainer Applied
#2 lore raw
Quoted 3 lines · Richard Yang

Bjorn,

How do you think of my this version?

Applied to my 'next' branch, thanks.

Quoted 71 lines · Wei Yang
Quoted 60 lines

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_overlaps() a common function for others.

---
arch/x86/pci/acpi.c    |   12 +-----------
include/linux/ioport.h |    7 +++++++

2 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/pci/acpi.c +1 -11
index 68c3c13..fd3f541 100644
@@ -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_overlaps(res1, res2)) {
                               res1->start = min(res1->start, res2->start);
                               res1->end = max(res1->end, res2->end);
                               dev_info(&info->bridge->dev,
include/linux/ioport.h +7 -1
index e9bb22c..05d2c70 100644
@@ -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 bool resource_overlaps(struct resource *r1,
+                                         struct resource *r2)
+{
+       return (r1->start <= r2->end && r1->end >= r2->start);
+}
+
+
 #endif /* __ASSEMBLY__ */
 #endif        /* _LINUX_IOPORT_H */
--
Quoted 1 line

1.7.4.1

--
Richard Yang
Help you, Help me

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 6 lines · Bjorn Helgaas
Quoted 3 lines · Richard Yang

Bjorn,

How do you think of my this version?

Applied to my 'next' branch, thanks.

Thanks :)

Quoted 72 lines
Quoted 72 lines · Wei Yang
Quoted 60 lines

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_overlaps() a common function for others.

---
arch/x86/pci/acpi.c    |   12 +-----------
include/linux/ioport.h |    7 +++++++

2 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/pci/acpi.c +1 -11
index 68c3c13..fd3f541 100644
@@ -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_overlaps(res1, res2)) {
                               res1->start = min(res1->start, res2->start);
                               res1->end = max(res1->end, res2->end);
                               dev_info(&info->bridge->dev,
include/linux/ioport.h +7 -1
index e9bb22c..05d2c70 100644
@@ -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 bool resource_overlaps(struct resource *r1,
+                                         struct resource *r2)
+{
+       return (r1->start <= r2->end && r1->end >= r2->start);
+}
+
+
 #endif /* __ASSEMBLY__ */
 #endif        /* _LINUX_IOPORT_H */
--
Quoted 1 line

1.7.4.1

--
Richard Yang
Help you, Help me

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Richard Yang
Help you, Help me