Jan Beulich
2012-Mar-07 09:56 UTC
[PATCH] provide a single, common implementation for get_order_from_{bytes, pages}()
All three per-architecture implementations were identical, and I cannot see how future architectures would need any sort of customization here (the only per-architecture aspect here is the actual PAGE_SHIFT value). Signed-off-by: Jan Beulich <jbeulich@suse.com> --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -202,25 +202,6 @@ static inline paddr_t gvirt_to_maddr(uin #define mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)) -static inline int get_order_from_bytes(paddr_t size) -{ - int order; - size = (size-1) >> PAGE_SHIFT; - for ( order = 0; size; order++ ) - size >>= 1; - return order; -} - -static inline int get_order_from_pages(unsigned long nr_pages) -{ - int order; - nr_pages--; - for ( order = 0; nr_pages; order++ ) - nr_pages >>= 1; - return order; -} - - /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v) { --- a/xen/include/asm-ia64/xenpage.h +++ b/xen/include/asm-ia64/xenpage.h @@ -60,24 +60,6 @@ typedef union xen_va { void *p; } xen_va; -static inline int get_order_from_bytes(paddr_t size) -{ - int order; - size = (size-1) >> PAGE_SHIFT; - for ( order = 0; size; order++ ) - size >>= 1; - return order; -} - -static inline int get_order_from_pages(unsigned long nr_pages) -{ - int order; - nr_pages--; - for ( order = 0; nr_pages; order++ ) - nr_pages >>= 1; - return order; -} - static inline int get_order_from_shift(unsigned long shift) { if (shift <= PAGE_SHIFT) --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -354,24 +354,6 @@ void setup_idle_pagetable(void); #ifndef __ASSEMBLY__ -static inline int get_order_from_bytes(paddr_t size) -{ - int order; - size = (size-1) >> PAGE_SHIFT; - for ( order = 0; size; order++ ) - size >>= 1; - return order; -} - -static inline int get_order_from_pages(unsigned long nr_pages) -{ - int order; - nr_pages--; - for ( order = 0; nr_pages; order++ ) - nr_pages >>= 1; - return order; -} - /* Allocator functions for Xen pagetables. */ void *alloc_xen_pagetable(void); void free_xen_pagetable(void *v); --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -318,6 +318,28 @@ page_list_splice(struct page_list_head * # define page_list_splice(list, hd) list_splice(list, hd) #endif +static inline unsigned int get_order_from_bytes(paddr_t size) +{ + unsigned int order; + + size = (size - 1) >> PAGE_SHIFT; + for ( order = 0; size; order++ ) + size >>= 1; + + return order; +} + +static inline unsigned int get_order_from_pages(unsigned long nr_pages) +{ + unsigned int order; + + nr_pages--; + for ( order = 0; nr_pages; order++ ) + nr_pages >>= 1; + + return order; +} + void scrub_one_page(struct page_info *); /* Returns 1 on success, 0 on error, negative if the ring _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Keir Fraser
2012-Mar-07 10:20 UTC
Re: [PATCH] provide a single, common implementation for get_order_from_{bytes, pages}()
On 07/03/2012 09:56, "Jan Beulich" <JBeulich@suse.com> wrote:> All three per-architecture implementations were identical, and I cannot > see how future architectures would need any sort of customization here > (the only per-architecture aspect here is the actual PAGE_SHIFT value). > > Signed-off-by: Jan Beulich <jbeulich@suse.com>Acked-by: Keir Fraser <keir@xen.org>> --- a/xen/include/asm-arm/mm.h > +++ b/xen/include/asm-arm/mm.h > @@ -202,25 +202,6 @@ static inline paddr_t gvirt_to_maddr(uin > #define mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)) > > > -static inline int get_order_from_bytes(paddr_t size) > -{ > - int order; > - size = (size-1) >> PAGE_SHIFT; > - for ( order = 0; size; order++ ) > - size >>= 1; > - return order; > -} > - > -static inline int get_order_from_pages(unsigned long nr_pages) > -{ > - int order; > - nr_pages--; > - for ( order = 0; nr_pages; order++ ) > - nr_pages >>= 1; > - return order; > -} > - > - > /* Convert between Xen-heap virtual addresses and page-info structures. */ > static inline struct page_info *virt_to_page(const void *v) > { > --- a/xen/include/asm-ia64/xenpage.h > +++ b/xen/include/asm-ia64/xenpage.h > @@ -60,24 +60,6 @@ typedef union xen_va { > void *p; > } xen_va; > > -static inline int get_order_from_bytes(paddr_t size) > -{ > - int order; > - size = (size-1) >> PAGE_SHIFT; > - for ( order = 0; size; order++ ) > - size >>= 1; > - return order; > -} > - > -static inline int get_order_from_pages(unsigned long nr_pages) > -{ > - int order; > - nr_pages--; > - for ( order = 0; nr_pages; order++ ) > - nr_pages >>= 1; > - return order; > -} > - > static inline int get_order_from_shift(unsigned long shift) > { > if (shift <= PAGE_SHIFT) > --- a/xen/include/asm-x86/page.h > +++ b/xen/include/asm-x86/page.h > @@ -354,24 +354,6 @@ void setup_idle_pagetable(void); > > #ifndef __ASSEMBLY__ > > -static inline int get_order_from_bytes(paddr_t size) > -{ > - int order; > - size = (size-1) >> PAGE_SHIFT; > - for ( order = 0; size; order++ ) > - size >>= 1; > - return order; > -} > - > -static inline int get_order_from_pages(unsigned long nr_pages) > -{ > - int order; > - nr_pages--; > - for ( order = 0; nr_pages; order++ ) > - nr_pages >>= 1; > - return order; > -} > - > /* Allocator functions for Xen pagetables. */ > void *alloc_xen_pagetable(void); > void free_xen_pagetable(void *v); > --- a/xen/include/xen/mm.h > +++ b/xen/include/xen/mm.h > @@ -318,6 +318,28 @@ page_list_splice(struct page_list_head * > # define page_list_splice(list, hd) list_splice(list, hd) > #endif > > +static inline unsigned int get_order_from_bytes(paddr_t size) > +{ > + unsigned int order; > + > + size = (size - 1) >> PAGE_SHIFT; > + for ( order = 0; size; order++ ) > + size >>= 1; > + > + return order; > +} > + > +static inline unsigned int get_order_from_pages(unsigned long nr_pages) > +{ > + unsigned int order; > + > + nr_pages--; > + for ( order = 0; nr_pages; order++ ) > + nr_pages >>= 1; > + > + return order; > +} > + > void scrub_one_page(struct page_info *); > > /* Returns 1 on success, 0 on error, negative if the ring > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel