[Intel-gfx] [PATCH 1/3] resource: Use a common string for .name = "System RAM"

Chris Wilson chris at chris-wilson.co.uk
Tue Jun 21 18:17:22 CEST 2011


On a PAT system, inserting a pfn is quite expensive due to the query of
the protections for the page based on its physical location. A large
part of this overhead is due to the linear walk of resource regions and
the strcmp to find "System RAM". By restricting memory to use a global
string for its resource name, we can reduce this strcmp to a direct
pointer comparison and so eliminate the largest single overhead for
vma_insert_pfn().

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 arch/arm/kernel/setup.c          |    8 ++++----
 arch/arm/plat-samsung/pm-check.c |    2 +-
 arch/avr32/kernel/setup.c        |    2 +-
 arch/ia64/kernel/efi.c           |    8 ++++----
 arch/mips/kernel/setup.c         |    4 ++--
 arch/parisc/mm/init.c            |    2 +-
 arch/s390/kernel/setup.c         |    6 +++---
 arch/score/kernel/setup.c        |    2 +-
 arch/sh/kernel/setup.c           |    2 +-
 arch/sparc/kernel/pci_common.c   |    2 +-
 arch/tile/kernel/setup.c         |    2 +-
 arch/unicore32/kernel/setup.c    |    2 +-
 arch/x86/kernel/e820.c           |    4 ++--
 arch/x86/kernel/probe_roms.c     |    2 +-
 include/linux/ioport.h           |    5 +++++
 kernel/resource.c                |   15 +++++++++++----
 mm/memory_hotplug.c              |    4 ++--
 17 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index ed11fb0..e525baa 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -166,19 +166,19 @@ static struct resource mem_res[] = {
 
 static struct resource io_res[] = {
 	{
-		.name = "reserved",
+		.name = resource_name__reserved,
 		.start = 0x3bc,
 		.end = 0x3be,
 		.flags = IORESOURCE_IO | IORESOURCE_BUSY
 	},
 	{
-		.name = "reserved",
+		.name = resource_name__reserved,
 		.start = 0x378,
 		.end = 0x37f,
 		.flags = IORESOURCE_IO | IORESOURCE_BUSY
 	},
 	{
-		.name = "reserved",
+		.name = resource_name__reserved,
 		.start = 0x278,
 		.end = 0x27f,
 		.flags = IORESOURCE_IO | IORESOURCE_BUSY
@@ -543,7 +543,7 @@ static void __init request_standard_resources(struct machine_desc *mdesc)
 
 	for_each_memblock(memory, region) {
 		res = alloc_bootmem_low(sizeof(*res));
-		res->name  = "System RAM";
+		res->name  = resource_name__system_ram;
 		res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
 		res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
diff --git a/arch/arm/plat-samsung/pm-check.c b/arch/arm/plat-samsung/pm-check.c
index 6b733fa..d402409 100644
--- a/arch/arm/plat-samsung/pm-check.c
+++ b/arch/arm/plat-samsung/pm-check.c
@@ -54,7 +54,7 @@ static void s3c_pm_run_res(struct resource *ptr, run_fn_t fn, u32 *arg)
 			s3c_pm_run_res(ptr->child, fn, arg);
 
 		if ((ptr->flags & IORESOURCE_MEM) &&
-		    strcmp(ptr->name, "System RAM") == 0) {
+		    ptr->name == resource_name__system_ram) {
 			S3C_PMDBG("Found system RAM at %08lx..%08lx\n",
 				  (unsigned long)ptr->start,
 				  (unsigned long)ptr->end);
diff --git a/arch/avr32/kernel/setup.c b/arch/avr32/kernel/setup.c
index bb0974c..90ded04 100644
--- a/arch/avr32/kernel/setup.c
+++ b/arch/avr32/kernel/setup.c
@@ -133,7 +133,7 @@ add_physical_memory(resource_size_t start, resource_size_t end)
 	new = &res_cache[res_cache_next_free++];
 	new->start = start;
 	new->end = end;
-	new->name = "System RAM";
+	new->name = resource_name__system_ram;
 	new->flags = IORESOURCE_MEM;
 
 	*pprev = new;
diff --git a/arch/ia64/kernel/efi.c b/arch/ia64/kernel/efi.c
index 6fc03af..44d5116 100644
--- a/arch/ia64/kernel/efi.c
+++ b/arch/ia64/kernel/efi.c
@@ -1233,12 +1233,12 @@ efi_initialize_iomem_resources(struct resource *code_resource,
 			case EFI_BOOT_SERVICES_CODE:
 			case EFI_CONVENTIONAL_MEMORY:
 				if (md->attribute & EFI_MEMORY_WP) {
-					name = "System ROM";
+					name = resource_name__system_rom;
 					flags |= IORESOURCE_READONLY;
 				} else if (md->attribute == EFI_MEMORY_UC)
 					name = "Uncached RAM";
 				else
-					name = "System RAM";
+					name = resource_name__system_ram;
 				break;
 
 			case EFI_ACPI_MEMORY_NVS:
@@ -1246,7 +1246,7 @@ efi_initialize_iomem_resources(struct resource *code_resource,
 				break;
 
 			case EFI_UNUSABLE_MEMORY:
-				name = "reserved";
+				name = resource_name__reserved;
 				flags |= IORESOURCE_DISABLED;
 				break;
 
@@ -1255,7 +1255,7 @@ efi_initialize_iomem_resources(struct resource *code_resource,
 			case EFI_RUNTIME_SERVICES_DATA:
 			case EFI_ACPI_RECLAIM_MEMORY:
 			default:
-				name = "reserved";
+				name = resource_name__reserved;
 				break;
 		}
 
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 8ad1d56..713352d 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -524,11 +524,11 @@ static void __init resource_init(void)
 		switch (boot_mem_map.map[i].type) {
 		case BOOT_MEM_RAM:
 		case BOOT_MEM_ROM_DATA:
-			res->name = "System RAM";
+			res->name = resource_name__system_ram;
 			break;
 		case BOOT_MEM_RESERVED:
 		default:
-			res->name = "reserved";
+			res->name = resource_name__reserved;
 		}
 
 		res->start = start;
diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c
index 82f364e..4915ca8 100644
--- a/arch/parisc/mm/init.c
+++ b/arch/parisc/mm/init.c
@@ -183,7 +183,7 @@ static void __init setup_bootmem(void)
 	sysram_resource_count = npmem_ranges;
 	for (i = 0; i < sysram_resource_count; i++) {
 		struct resource *res = &sysram_resources[i];
-		res->name = "System RAM";
+		res->name = resource_name__system_ram;
 		res->start = pmem_ranges[i].start_pfn << PAGE_SHIFT;
 		res->end = res->start + (pmem_ranges[i].pages << PAGE_SHIFT)-1;
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index 0c35dee..f892eb4 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -439,14 +439,14 @@ static void __init setup_resources(void)
 		res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
 		switch (memory_chunk[i].type) {
 		case CHUNK_READ_WRITE:
-			res->name = "System RAM";
+			res->name = resource_name__system_ram;
 			break;
 		case CHUNK_READ_ONLY:
-			res->name = "System ROM";
+			res->name = resource_name__system_rom;
 			res->flags |= IORESOURCE_READONLY;
 			break;
 		default:
-			res->name = "reserved";
+			res->name = resource_name__reserved;
 		}
 		res->start = memory_chunk[i].addr;
 		res->end = res->start + memory_chunk[i].size - 1;
diff --git a/arch/score/kernel/setup.c b/arch/score/kernel/setup.c
index 6f898c0..5feab05 100644
--- a/arch/score/kernel/setup.c
+++ b/arch/score/kernel/setup.c
@@ -96,7 +96,7 @@ static void __init resource_init(void)
 	data_resource.end = __pa(&_edata) - 1;
 
 	res = alloc_bootmem(sizeof(struct resource));
-	res->name = "System RAM";
+	res->name = resource_name__system_ram;
 	res->start = MEMORY_START;
 	res->end = MEMORY_START + MEMORY_SIZE - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index 58bff45..4d8edae 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -199,7 +199,7 @@ void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
 	start = start_pfn << PAGE_SHIFT;
 	end = end_pfn << PAGE_SHIFT;
 
-	res->name = "System RAM";
+	res->name = resource_name__system_ram;
 	res->start = start;
 	res->end = end - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
diff --git a/arch/sparc/kernel/pci_common.c b/arch/sparc/kernel/pci_common.c
index 6e3874b..e7cf5ea 100644
--- a/arch/sparc/kernel/pci_common.c
+++ b/arch/sparc/kernel/pci_common.c
@@ -349,7 +349,7 @@ static void pci_register_legacy_regions(struct resource *io_res,
 	if (!p)
 		return;
 
-	p->name = "System ROM";
+	p->name = resource_name__system_rom;
 	p->start = mem_res->start + 0xf0000UL;
 	p->end = p->start + 0xffffUL;
 	p->flags = IORESOURCE_BUSY;
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index 6cdc9ba..901d908 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -1466,7 +1466,7 @@ insert_ram_resource(u64 start_pfn, u64 end_pfn)
 {
 	struct resource *res =
 		kzalloc(sizeof(struct resource), GFP_ATOMIC);
-	res->name = "System RAM";
+	res->name = resource_name__system_ram;
 	res->start = start_pfn << PAGE_SHIFT;
 	res->end = (end_pfn << PAGE_SHIFT) - 1;
 	res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
diff --git a/arch/unicore32/kernel/setup.c b/arch/unicore32/kernel/setup.c
index 471b6bc..2522832 100644
--- a/arch/unicore32/kernel/setup.c
+++ b/arch/unicore32/kernel/setup.c
@@ -203,7 +203,7 @@ request_standard_resources(struct meminfo *mi)
 			continue;
 
 		res = alloc_bootmem_low(sizeof(*res));
-		res->name  = "System RAM";
+		res->name  = resource_name__system_ram;
 		res->start = mi->bank[i].start;
 		res->end   = mi->bank[i].start + mi->bank[i].size - 1;
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 3e2ef84..8642272 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -925,11 +925,11 @@ static inline const char *e820_type_to_string(int e820_type)
 {
 	switch (e820_type) {
 	case E820_RESERVED_KERN:
-	case E820_RAM:	return "System RAM";
+	case E820_RAM:	return resource_name__system_ram;
 	case E820_ACPI:	return "ACPI Tables";
 	case E820_NVS:	return "ACPI Non-volatile Storage";
 	case E820_UNUSABLE:	return "Unusable memory";
-	default:	return "reserved";
+	default:	return resource_name__reserved;
 	}
 }
 
diff --git a/arch/x86/kernel/probe_roms.c b/arch/x86/kernel/probe_roms.c
index ba0a4cc..ce7f8d4 100644
--- a/arch/x86/kernel/probe_roms.c
+++ b/arch/x86/kernel/probe_roms.c
@@ -21,7 +21,7 @@
 #include <asm/setup_arch.h>
 
 static struct resource system_rom_resource = {
-	.name	= "System ROM",
+	.name	= resource_name__system_rom,
 	.start	= 0xf0000,
 	.end	= 0xfffff,
 	.flags	= IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index e9bb22c..b6222ee 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -109,6 +109,11 @@ struct resource_list {
 /* PCI control bits.  Shares IORESOURCE_BITS with above PCI ROM.  */
 #define IORESOURCE_PCI_FIXED		(1<<4)	/* Do not move resource */
 
+/* Some common resource names, must be used when appropriate. */
+extern const char resource_name__system_ram[];
+extern const char resource_name__system_rom[];
+extern const char resource_name__reserved[];
+
 /* PC/ISA/whatever - the normal PC address spaces: IO and memory */
 extern struct resource ioport_resource;
 extern struct resource iomem_resource;
diff --git a/kernel/resource.c b/kernel/resource.c
index 798e2fa..8c29c2e 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -269,13 +269,20 @@ int release_resource(struct resource *old)
 
 EXPORT_SYMBOL(release_resource);
 
+const char resource_name__system_ram[] = "System RAM";
+EXPORT_SYMBOL(resource_name__system_ram);
+const char resource_name__system_rom[] = "System ROM";
+EXPORT_SYMBOL(resource_name__system_rom);
+const char resource_name__reserved[] = "reserved";
+EXPORT_SYMBOL(resource_name__reserved);
+
 #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
 /*
  * Finds the lowest memory reosurce exists within [res->start.res->end)
  * the caller must specify res->start, res->end, res->flags and "name".
  * If found, returns 0, res is overwritten, if not found, returns -1.
  */
-static int find_next_system_ram(struct resource *res, char *name)
+static int find_next_system_ram(struct resource *res, const char *name)
 {
 	resource_size_t start, end;
 	struct resource *p;
@@ -291,7 +298,7 @@ static int find_next_system_ram(struct resource *res, char *name)
 		/* system ram is just marked as IORESOURCE_MEM */
 		if (p->flags != res->flags)
 			continue;
-		if (name && strcmp(p->name, name))
+		if (name && p->name == name)
 			continue;
 		if (p->start > end) {
 			p = NULL;
@@ -329,7 +336,7 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
 	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	orig_end = res.end;
 	while ((res.start < res.end) &&
-		(find_next_system_ram(&res, "System RAM") >= 0)) {
+		(find_next_system_ram(&res, resource_name__system_ram) >= 0)) {
 		pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
 		end_pfn = (res.end + 1) >> PAGE_SHIFT;
 		if (end_pfn > pfn)
@@ -936,7 +943,7 @@ static int __init reserve_setup(char *str)
 			break;
 		if (x < MAXRESERVE) {
 			struct resource *res = reserve + x;
-			res->name = "reserved";
+			res->name = resource_name__reserved;
 			res->start = io_start;
 			res->end = io_start + io_num - 1;
 			res->flags = IORESOURCE_BUSY;
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 9f64637..97aa891 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -58,7 +58,7 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
 	BUG_ON(!res);
 
-	res->name = "System RAM";
+	res->name = resource_name__system_ram;
 	res->start = start;
 	res->end = start + size - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
@@ -571,7 +571,7 @@ int __ref add_memory(int nid, u64 start, u64 size)
 	}
 
 	/* create new memmap entry */
-	firmware_map_add_hotplug(start, start + size, "System RAM");
+	firmware_map_add_hotplug(start, start + size, resource_name__system_ram);
 
 	goto out;
 
-- 
1.7.5.4




More information about the Intel-gfx mailing list