[PATCH] __get_order() cleanup

Jakub Jelinek jakub en redhat.com
Vie Ene 28 11:18:16 CST 2000


Hi!

At the moment, there are 11 identical implementations of __get_order
function. This patch moves __get_order implementation to asm/page.h (so that
architectures can optimize it - i386 __get_order is done using bsrl
instruction) and kills all the private copies of that function.
Patch against 2.3.41-4.

--- linux/arch/i386/kernel/pci-dma.c.jj	Wed Jan 26 17:45:04 2000
+++ linux/arch/i386/kernel/pci-dma.c	Wed Jan 26 17:57:47 2000
@@ -13,20 +13,6 @@
 #include <linux/pci.h>
 #include <asm/io.h>
 
-/* Pure 2^n version of get_order */
-extern __inline__ int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size-1) >> (PAGE_SHIFT-1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
-
 void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
 			   dma_addr_t *dma_handle)
 {
--- linux/arch/mips/jazz/floppy-jazz.c.jj	Wed Oct 13 07:44:28 1999
+++ linux/arch/mips/jazz/floppy-jazz.c	Wed Jan 26 17:49:17 2000
@@ -94,26 +94,11 @@ static unsigned long jazz_fd_getfdaddr1(
 	return JAZZ_FDC_BASE;
 }
 
-/* Pure 2^n version of get_order */
-extern inline int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size-1) >> (PAGE_SHIFT-1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
-
 static unsigned long jazz_fd_dma_mem_alloc(unsigned long size)
 {
-	int order = __get_order(size);
 	unsigned long mem;
 
-	mem = __get_dma_pages(GFP_KERNEL, order);
+	mem = __get_dma_pages(GFP_KERNEL, __get_order(size));
 	if(!mem)
 		return 0;
 	vdma_alloc(PHYSADDR(mem), size);	/* XXX error checking */
--- linux/arch/mips/lib/floppy-std.c.jj	Wed Oct 13 07:44:43 1999
+++ linux/arch/mips/lib/floppy-std.c	Wed Jan 26 17:49:50 2000
@@ -102,26 +102,11 @@ static unsigned long std_fd_getfdaddr1(v
 	return 0x3f0;
 }
 
-/* Pure 2^n version of get_order */
-static int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size-1) >> (PAGE_SHIFT-1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
-
 static unsigned long std_fd_dma_mem_alloc(unsigned long size)
 {
-	int order = __get_order(size);
 	unsigned long mem;
 
-	mem = __get_dma_pages(GFP_KERNEL,order);
+	mem = __get_dma_pages(GFP_KERNEL,__get_order(size));
 
 	return mem;
 }
--- linux/drivers/block/floppy.c.jj	Fri Jan 21 10:52:51 2000
+++ linux/drivers/block/floppy.c	Wed Jan 26 17:51:59 2000
@@ -196,7 +196,6 @@ static int use_virtual_dma=0;
 static unsigned short virtual_dma_port=0x3f0;
 void floppy_interrupt(int irq, void *dev_id, struct pt_regs * regs);
 static int set_dor(int fdc, char mask, char data);
-static inline int __get_order(unsigned long size);
 #define K_64	0x10000		/* 64KB */
 #include <asm/floppy.h>
 
@@ -212,20 +211,6 @@ static inline int __get_order(unsigned l
 #endif
 
 /* Dma Memory related stuff */
-
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size-1) >> (PAGE_SHIFT-1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
 
 #ifndef fd_dma_mem_free
 #define fd_dma_mem_free(addr, size) free_pages(addr, __get_order(size))
--- linux/drivers/block/xd.c.jj	Fri Jan 21 10:52:51 2000
+++ linux/drivers/block/xd.c	Wed Jan 26 17:52:33 2000
@@ -87,19 +87,6 @@ XD_INFO xd_info[XD_MAXDRIVES];
    should be able to detect your drive's geometry from this info. (eg: xd=0,5,0x320,3 is the "standard"). */
 
 #include <asm/page.h>
-/* coppied from floppy.c */
-static inline int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size-1) >> (PAGE_SHIFT-1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
 #define xd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,__get_order(size))
 #define xd_dma_mem_free(addr, size) free_pages(addr, __get_order(size))
 static char *xd_dma_buffer = 0;
--- linux/drivers/char/ftape/lowlevel/ftape-buffer.c.jj	Wed Oct 13 07:51:29 1999
+++ linux/drivers/char/ftape/lowlevel/ftape-buffer.c	Wed Jan 26 17:53:48 2000
@@ -39,20 +39,6 @@
 /*  DMA'able memory allocation stuff.
  */
 
-/* Pure 2^n version of get_order */
-static inline int __get_order(size_t size)
-{
-	unsigned long order;
-
-	size = (size-1) >> (PAGE_SHIFT-1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
-
 static inline void *dmaalloc(size_t size)
 {
 	unsigned long addr;
--- linux/drivers/char/esp.c.jj	Wed Oct 13 07:49:45 1999
+++ linux/drivers/char/esp.c	Wed Jan 26 17:52:58 2000
@@ -203,20 +203,6 @@ static inline void serial_out(struct esp
 	outb(value, info->port+offset);
 }
 
-static inline int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size + PAGE_SIZE -1) >> PAGE_SHIFT;
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-
-	return order;
-}
-
 /*
  * ------------------------------------------------------------
  * rs_stop() and rs_start()
--- linux/drivers/char/tpqic02.c.jj	Sat Jan  8 13:25:35 2000
+++ linux/drivers/char/tpqic02.c	Wed Jan 26 17:53:22 2000
@@ -2780,23 +2780,6 @@ static struct file_operations qic02_tape
 };
 
 
-/* Why is this not is one place? */
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
-    int order;
-
-    size = (size-1) >> (PAGE_SHIFT-1);
-    order = -1;
-    do
-    {
-	size >>= 1;
-	order++;
-    } while (size);
-    return order;
-}
-
-
 static void qic02_release_resources(void)
 {
     free_irq(QIC02_TAPE_IRQ, NULL);
--- linux/drivers/char/zr36120_mem.c.jj	Mon Jan  3 08:14:03 2000
+++ linux/drivers/char/zr36120_mem.c	Wed Jan 26 17:54:15 2000
@@ -35,17 +35,6 @@
 /* Memory management functions */
 /*******************************/
 
-inline int __get_order(unsigned long size)
-{
-        int order = 0;
-	size = (size+PAGE_SIZE-1)/PAGE_SIZE;
-	while (size) {
-		size /= 2;
-		order++;
-	}
-	return order;
-}
-			
 void* bmalloc(unsigned long size)
 {
 	void* mem;
--- linux/drivers/net/ltpc.c.jj	Wed Oct 13 07:57:20 1999
+++ linux/drivers/net/ltpc.c	Wed Jan 26 17:55:20 2000
@@ -246,20 +246,6 @@ static int sendup_buffer (struct net_dev
 
 /* Dma Memory related stuff, cribbed directly from 3c505.c */
 
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
-        int order;
-
-        size = (size - 1) >> (PAGE_SHIFT - 1);
-        order = -1;
-        do {
-                size >>= 1;
-                order++;
-        } while (size);
-        return order;
-}
-
 static unsigned long dma_mem_alloc(int size)
 {
         int order = __get_order(size);
--- linux/drivers/net/3c505.c.jj	Wed Oct 13 07:54:51 1999
+++ linux/drivers/net/3c505.c	Wed Jan 26 17:54:40 2000
@@ -183,20 +183,6 @@ static const int addr_list[] __initdata 
 
 /* Dma Memory related stuff */
 
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
-	int order;
-
-	size = (size - 1) >> (PAGE_SHIFT - 1);
-	order = -1;
-	do {
-		size >>= 1;
-		order++;
-	} while (size);
-	return order;
-}
-
 static unsigned long dma_mem_alloc(int size)
 {
 	int order = __get_order(size);
--- linux/include/asm-alpha/page.h.jj	Mon Dec 20 09:28:25 1999
+++ linux/include/asm-alpha/page.h	Wed Jan 26 17:27:21 2000
@@ -109,6 +109,20 @@ typedef unsigned long pgprot_t;
 #define BUG()		__asm__ __volatile__("call_pal 129 # bugchk")
 #define PAGE_BUG(page)	BUG()
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif /* !ASSEMBLY */
 
 /* to align the pointer to the (next) page boundary */
--- linux/include/asm-arm/page.h.jj	Fri Jan 14 09:44:35 2000
+++ linux/include/asm-arm/page.h	Wed Jan 26 17:27:01 2000
@@ -65,6 +65,20 @@ extern void __bug(const char *file, int 
 #define BUG()		__bug(__FILE__, __LINE__, NULL)
 #define PAGE_BUG(page)	__bug(__FILE__, __LINE__, page)
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #include <asm/arch/memory.h>
--- linux/include/asm-i386/page.h.jj	Tue Dec 21 11:17:56 1999
+++ linux/include/asm-i386/page.h	Wed Jan 26 17:26:35 2000
@@ -92,6 +92,17 @@ extern int console_loglevel;
 	BUG(); \
 } while (0)
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	__asm__ ("bsrl %1,%0" : "=r" (order) : "r" (size - 1));
+	order -= PAGE_SHIFT - 1;
+	if (order < 0) order = 0;
+	return order;
+}
+
 #endif /* __ASSEMBLY__ */
 
 #define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
--- linux/include/asm-m68k/page.h.jj	Wed Oct 13 08:07:02 1999
+++ linux/include/asm-m68k/page.h	Wed Jan 26 17:24:37 2000
@@ -174,6 +174,20 @@ static inline void *__va(unsigned long x
 
 #define MAP_NR(addr)		(__pa(addr) >> PAGE_SHIFT)
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #ifndef CONFIG_SUN3
--- linux/include/asm-mips/page.h.jj	Wed Oct 13 08:07:26 1999
+++ linux/include/asm-mips/page.h	Wed Jan 26 17:24:03 2000
@@ -65,6 +65,20 @@ typedef unsigned long pgprot_t;
 
 #endif /* !defined (STRICT_MM_TYPECHECKS) */
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif /* _LANGUAGE_ASSEMBLY */
 
 /* to align the pointer to the (next) page boundary */
--- linux/include/asm-ppc/page.h.jj	Thu Dec  2 09:34:51 1999
+++ linux/include/asm-ppc/page.h	Wed Jan 26 17:21:30 2000
@@ -113,6 +113,21 @@ static inline void* ___va(unsigned long 
 #define MAP_PAGE_RESERVED	(1<<15)
 
 extern unsigned long get_zero_page_fast(void);
+
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif /* __KERNEL__ */
 #endif /* __ASSEMBLY__ */
 #endif /* _PPC_PAGE_H */
--- linux/include/asm-sh/page.h.jj	Thu Dec  9 12:02:17 1999
+++ linux/include/asm-sh/page.h	Wed Jan 26 17:20:58 2000
@@ -76,6 +76,21 @@ extern int console_loglevel;
 #define PAGE_BUG(page) do { \
 	BUG(); \
 } while (0)
+
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif
 
 #endif /* __KERNEL__ */
--- linux/include/asm-sparc/page.h.jj	Sun Jan  9 20:45:10 2000
+++ linux/include/asm-sparc/page.h	Wed Jan 26 17:19:55 2000
@@ -255,6 +255,20 @@ BTFIXUPDEF_SETHI(sparc_unmapped_base)
 
 #define TASK_UNMAPPED_BASE	BTFIXUP_SETHI(sparc_unmapped_base)
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #else /* !(__ASSEMBLY__) */
 
 #define __pgprot(x)	(x)
--- linux/include/asm-sparc64/page.h.jj	Thu Dec  9 12:03:21 1999
+++ linux/include/asm-sparc64/page.h	Wed Jan 26 17:19:02 2000
@@ -126,6 +126,20 @@ struct sparc_phys_banks {
 
 extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS];
 
+/* Pure 2^n version of get_order */
+extern __inline__ int __get_order(unsigned long size)
+{
+	int order;
+
+	size = (size-1) >> (PAGE_SHIFT-1);
+	order = -1;
+	do {
+		size >>= 1;
+		order++;
+	} while (size);
+	return order;
+}
+
 #endif /* !(__ASSEMBLY__) */
 
 #endif /* !(__KERNEL__) */


Cheers,
    Jakub
___________________________________________________________________
Jakub Jelinek | jakub en redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.41 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo en vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



Más información sobre la lista de distribución Ayuda