Skip to contentSkip to conversation

x86 cleanup: convert round_up() to roundup()

PATCH Applied Joerg Roedel 3 participants 10 messages Jul 25, 2008 – Jul 29, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86 cleanup: convert round_up() to roundup()

The x86 architecture declares its own round_up macro. But there is a generic one in <linux/kernel.h> which can also be used. This patchset replaces the x86 round_up() macro with the generic roundup() one where possible. The patches have been compile-tested for 32 and 64 bit and boot-tested for 64 bit.
If we can fix the other places too we can get rid of the x86 specific round_up() in the future.

diffstat:

 arch/x86/kernel/pci-dma.c  |    2 +-
 arch/x86/mm/discontig_32.c |    2 +-
 arch/x86/mm/init_64.c      |    8 ++++----
 arch/x86/mm/numa_64.c      |   10 +++++-----
 arch/x86/mm/pageattr.c     |    2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)
#1 lore raw

PATCH 1/5 x86: convert pci-dma.c from round_up to roundup

---
 arch/x86/kernel/pci-dma.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/pci-dma.c +1 -1
index d5b9e11..8f4dbd7 100644
@@ -82,7 +82,7 @@ void __init dma32_reserve_bootmem(void)
 	 * using 512M as goal
 	 */
 	align = 64ULL<<20;
-	size = round_up(dma32_bootmem_size, align);
+	size = roundup(dma32_bootmem_size, align);
 	dma32_bootmem_ptr = __alloc_bootmem_nopanic(size, align,
 				 512ULL<<20);
 	if (dma32_bootmem_ptr)
Signature · 1 line
1.5.3.7
#2 lore raw

PATCH 2/5 x86: convert pageattr.c from round_up to roundup

In reply to Joerg Roedel
---
 arch/x86/mm/pageattr.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/mm/pageattr.c +1 -1
index ba24537..6b10a6b 100644
@@ -78,7 +78,7 @@ static inline unsigned long highmap_start_pfn(void)
 
 static inline unsigned long highmap_end_pfn(void)
 {
-	return __pa(round_up((unsigned long)_end, PMD_SIZE)) >> PAGE_SHIFT;
+	return __pa(roundup((unsigned long)_end, PMD_SIZE)) >> PAGE_SHIFT;
 }
 
 #endif
Signature · 1 line
1.5.3.7
#3 lore raw

PATCH 3/5 x86: convert init_64.c from round_up to roundup

In reply to Joerg Roedel
---
 arch/x86/mm/init_64.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/mm/init_64.c +4 -4
index ec37121..e480577 100644
@@ -258,7 +258,7 @@ void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
 void __init cleanup_highmap(void)
 {
 	unsigned long vaddr = __START_KERNEL_map;
-	unsigned long end = round_up((unsigned long)_end, PMD_SIZE) - 1;
+	unsigned long end = roundup((unsigned long)_end, PMD_SIZE) - 1;
 	pmd_t *pmd = level2_kernel_pgt;
 	pmd_t *last_pmd = pmd + PTRS_PER_PMD;
 
@@ -474,14 +474,14 @@ static void __init find_early_table_space(unsigned long end)
 	unsigned long puds, pmds, ptes, tables, start;
 
 	puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
-	tables = round_up(puds * sizeof(pud_t), PAGE_SIZE);
+	tables = roundup(puds * sizeof(pud_t), PAGE_SIZE);
 	if (direct_gbpages) {
 		unsigned long extra;
 		extra = end - ((end>>PUD_SHIFT) << PUD_SHIFT);
 		pmds = (extra + PMD_SIZE - 1) >> PMD_SHIFT;
 	} else
 		pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
-	tables += round_up(pmds * sizeof(pmd_t), PAGE_SIZE);
+	tables += roundup(pmds * sizeof(pmd_t), PAGE_SIZE);
 
 	if (cpu_has_pse) {
 		unsigned long extra;
@@ -489,7 +489,7 @@ static void __init find_early_table_space(unsigned long end)
 		ptes = (extra + PAGE_SIZE - 1) >> PAGE_SHIFT;
 	} else
 		ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
-	tables += round_up(ptes * sizeof(pte_t), PAGE_SIZE);
+	tables += roundup(ptes * sizeof(pte_t), PAGE_SIZE);
 
 	/*
 	 * RED-PEN putting page tables only on node 0 could
Signature · 1 line
1.5.3.7
#4 lore raw

PATCH 4/5 x86: convert numa_64.c from round_up to roundup

In reply to Joerg Roedel
---
 arch/x86/mm/numa_64.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/mm/numa_64.c +5 -5
index 9782f42..e8e2aed 100644
@@ -81,7 +81,7 @@ static int __init allocate_cachealigned_memnodemap(void)
 		return 0;
 
 	addr = 0x8000;
-	nodemap_size = round_up(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
+	nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
 	nodemap_addr = find_e820_area(addr, max_pfn<<PAGE_SHIFT,
 				      nodemap_size, L1_CACHE_BYTES);
 	if (nodemap_addr == -1UL) {
@@ -178,10 +178,10 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
 	unsigned long start_pfn, last_pfn, bootmap_pages, bootmap_size;
 	unsigned long bootmap_start, nodedata_phys;
 	void *bootmap;
-	const int pgdat_size = round_up(sizeof(pg_data_t), PAGE_SIZE);
+	const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
 	int nid;
 
-	start = round_up(start, ZONE_ALIGN);
+	start = roundup(start, ZONE_ALIGN);
 
 	printk(KERN_INFO "Bootmem setup node %d %016lx-%016lx\n", nodeid,
 	       start, end);
@@ -212,9 +212,9 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
 	bootmap_pages = bootmem_bootmap_pages(last_pfn - start_pfn);
 	nid = phys_to_nid(nodedata_phys);
 	if (nid == nodeid)
-		bootmap_start = round_up(nodedata_phys + pgdat_size, PAGE_SIZE);
+		bootmap_start = roundup(nodedata_phys + pgdat_size, PAGE_SIZE);
 	else
-		bootmap_start = round_up(start, PAGE_SIZE);
+		bootmap_start = roundup(start, PAGE_SIZE);
 	/*
 	 * SMP_CACHE_BYTES could be enough, but init_bootmem_node like
 	 * to use that to align to PAGE_SIZE
Signature · 1 line
1.5.3.7
#5 lore raw

PATCH 5/5 x86: convert discontig_32.c from round_up to roundup

In reply to Joerg Roedel
---
 arch/x86/mm/discontig_32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/mm/discontig_32.c +1 -1
index 5dfef9f..d28796e 100644
@@ -329,7 +329,7 @@ void __init initmem_init(unsigned long start_pfn,
 
 	get_memcfg_numa();
 
-	kva_pages = round_up(calculate_numa_remap_pages(), PTRS_PER_PTE);
+	kva_pages = roundup(calculate_numa_remap_pages(), PTRS_PER_PTE);
 
 	kva_target_pfn = round_down(max_low_pfn - kva_pages, PTRS_PER_PTE);
 	do {
Signature · 1 line
1.5.3.7
Applied
#6 lore raw
In reply to Joerg Roedel
Quoted 6 lines · Joerg Roedel

The x86 architecture declares its own round_up macro. But there is a generic one in <linux/kernel.h> which can also be used. This patchset replaces the x86 round_up() macro with the generic roundup() one where possible. The patches have been compile-tested for 32 and 64 bit and boot-tested for 64 bit. If we can fix the other places too we can get rid of the x86 specific round_up() in the future.

applied to tip/x86/cleanups - thanks Joerg!

Ingo

#7 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 6 lines · Joerg Roedel

The x86 architecture declares its own round_up macro. But there is a generic one in <linux/kernel.h> which can also be used. This patchset replaces the x86 round_up() macro with the generic roundup() one where possible. The patches have been compile-tested for 32 and 64 bit and boot-tested for 64 bit. If we can fix the other places too we can get rid of the x86 specific round_up() in the future.

applied to tip/x86/cleanups - thanks Joerg!

these patches looks like some backward, aka wrong direction.

#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

#define round_up(x, y) (((x) + (y) - 1) & ~((y) - 1)) #define round_down(x, y) ((x) & ~((y) - 1))

round_up looks more efficient.

YH

#8 lore raw
Quoted 13 lines · Yinghai Lu
Quoted 12 lines · Ingo Molnar
Quoted 6 lines · Joerg Roedel

The x86 architecture declares its own round_up macro. But there is a generic one in <linux/kernel.h> which can also be used. This patchset replaces the x86 round_up() macro with the generic roundup() one where possible. The patches have been compile-tested for 32 and 64 bit and boot-tested for 64 bit. If we can fix the other places too we can get rid of the x86 specific round_up() in the future.

applied to tip/x86/cleanups - thanks Joerg!

Quoted 8 lines

these patches looks like some backward, aka wrong direction.

#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

#define round_up(x, y) (((x) + (y) - 1) & ~((y) - 1)) #define round_down(x, y) ((x) & ~((y) - 1))

round_up looks more efficient.

hm, does it ever make a difference to the compiled output?

Ingo

#9 lore raw
In reply to Yinghai Lu
Quoted 13 lines · Yinghai Lu
Quoted 12 lines · Ingo Molnar
Quoted 6 lines · Joerg Roedel

The x86 architecture declares its own round_up macro. But there is a generic one in <linux/kernel.h> which can also be used. This patchset replaces the x86 round_up() macro with the generic roundup() one where possible. The patches have been compile-tested for 32 and 64 bit and boot-tested for 64 bit. If we can fix the other places too we can get rid of the x86 specific round_up() in the future.

applied to tip/x86/cleanups - thanks Joerg!

Quoted 8 lines

these patches looks like some backward, aka wrong direction.

#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

#define round_up(x, y) (((x) + (y) - 1) & ~((y) - 1)) #define round_down(x, y) ((x) & ~((y) - 1))

round_up looks more efficient.

It may be more efficient depending on the compiler optimizations. The other problem with the x86 round_up is that it only works when rounding to multiples of power of 2. This behavior is not represented in the macro name and also the generic roundup macro does not have this problem.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy