clean up duplicated alloc/free_thread_info

We duplicate alloc/free_thread_info defines on many platforms (the
majority uses __get_free_pages/free_pages).  This patch defines common
defines and removes these duplicated defines.
__HAVE_ARCH_THREAD_INFO_ALLOCATOR is introduced for platforms that do
something different.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
FUJITA Tomonori 2008-07-25 01:45:40 -07:00 committed by Linus Torvalds
parent 62ec30d45e
commit b69c49b784
23 changed files with 50 additions and 80 deletions

View File

@ -50,10 +50,8 @@ register struct thread_info *__current_thread_info __asm__("$8");
#define current_thread_info() __current_thread_info #define current_thread_info() __current_thread_info
/* Thread information allocation. */ /* Thread information allocation. */
#define THREAD_SIZE_ORDER 1
#define THREAD_SIZE (2*PAGE_SIZE) #define THREAD_SIZE (2*PAGE_SIZE)
#define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */

View File

@ -97,19 +97,6 @@ static inline struct thread_info *current_thread_info(void)
return (struct thread_info *)(sp & ~(THREAD_SIZE - 1)); return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
} }
/* thread information allocation */
#ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) \
((struct thread_info *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, \
THREAD_SIZE_ORDER))
#else
#define alloc_thread_info(tsk) \
((struct thread_info *)__get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER))
#endif
#define free_thread_info(info) \
free_pages((unsigned long)info, THREAD_SIZE_ORDER);
#define thread_saved_pc(tsk) \ #define thread_saved_pc(tsk) \
((unsigned long)(pc_pointer(task_thread_info(tsk)->cpu_context.pc))) ((unsigned long)(pc_pointer(task_thread_info(tsk)->cpu_context.pc)))
#define thread_saved_fp(tsk) \ #define thread_saved_fp(tsk) \

View File

@ -61,10 +61,6 @@ static inline struct thread_info *current_thread_info(void)
return (struct thread_info *)addr; return (struct thread_info *)addr;
} }
/* thread information allocation */
#define alloc_thread_info(ti) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER))
#define free_thread_info(ti) free_pages((unsigned long)(ti), 1)
#define get_thread_info(ti) get_task_struct((ti)->task) #define get_thread_info(ti) get_task_struct((ti)->task)
#define put_thread_info(ti) put_task_struct((ti)->task) #define put_thread_info(ti) put_task_struct((ti)->task)

View File

@ -42,6 +42,7 @@
/* /*
* Size of kernel stack for each process. This must be a power of 2... * Size of kernel stack for each process. This must be a power of 2...
*/ */
#define THREAD_SIZE_ORDER 1
#define THREAD_SIZE 8192 /* 2 pages */ #define THREAD_SIZE 8192 /* 2 pages */
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
@ -94,10 +95,6 @@ static inline struct thread_info *current_thread_info(void)
return (struct thread_info *)((long)ti & ~((long)THREAD_SIZE-1)); return (struct thread_info *)((long)ti & ~((long)THREAD_SIZE-1));
} }
/* thread information allocation */
#define alloc_thread_info(tsk) ((struct thread_info *) \
__get_free_pages(GFP_KERNEL, 1))
#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
/* /*

View File

@ -11,6 +11,8 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <asm/types.h> #include <asm/types.h>
#include <asm/processor.h> #include <asm/processor.h>

View File

@ -82,6 +82,8 @@ register struct thread_info *__current_thread_info asm("gr15");
#define current_thread_info() ({ __current_thread_info; }) #define current_thread_info() ({ __current_thread_info; })
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
/* thread information allocation */ /* thread information allocation */
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) \ #define alloc_thread_info(tsk) \

View File

@ -49,6 +49,7 @@ struct thread_info {
/* /*
* Size of kernel stack for each process. This must be a power of 2... * Size of kernel stack for each process. This must be a power of 2...
*/ */
#define THREAD_SIZE_ORDER 1
#define THREAD_SIZE 8192 /* 2 pages */ #define THREAD_SIZE 8192 /* 2 pages */
@ -65,10 +66,6 @@ static inline struct thread_info *current_thread_info(void)
return ti; return ti;
} }
/* thread information allocation */
#define alloc_thread_info(tsk) ((struct thread_info *) \
__get_free_pages(GFP_KERNEL, 1))
#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
/* /*

View File

@ -54,6 +54,8 @@ struct thread_info {
}, \ }, \
} }
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
#ifndef ASM_OFFSETS_C #ifndef ASM_OFFSETS_C
/* how to get the thread information struct from C */ /* how to get the thread information struct from C */
#define current_thread_info() ((struct thread_info *) ((char *) current + IA64_TASK_SIZE)) #define current_thread_info() ((struct thread_info *) ((char *) current + IA64_TASK_SIZE))

View File

@ -94,6 +94,8 @@ static inline struct thread_info *current_thread_info(void)
return ti; return ti;
} }
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
/* thread information allocation */ /* thread information allocation */
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) \ #define alloc_thread_info(tsk) \

View File

@ -25,13 +25,7 @@ struct thread_info {
} }
/* THREAD_SIZE should be 8k, so handle differently for 4k and 8k machines */ /* THREAD_SIZE should be 8k, so handle differently for 4k and 8k machines */
#if PAGE_SHIFT == 13 /* 8k machines */ #define THREAD_SIZE_ORDER (13 - PAGE_SHIFT)
#define alloc_thread_info(tsk) ((struct thread_info *)__get_free_pages(GFP_KERNEL,0))
#define free_thread_info(ti) free_pages((unsigned long)(ti),0)
#else /* otherwise assume 4k pages */
#define alloc_thread_info(tsk) ((struct thread_info *)__get_free_pages(GFP_KERNEL,1))
#define free_thread_info(ti) free_pages((unsigned long)(ti),1)
#endif /* PAGE_SHIFT == 13 */
#define init_thread_info (init_task.thread.info) #define init_thread_info (init_task.thread.info)
#define init_stack (init_thread_union.stack) #define init_stack (init_thread_union.stack)

View File

@ -71,10 +71,6 @@ static inline struct thread_info *current_thread_info(void)
return ti; return ti;
} }
/* thread information allocation */
#define alloc_thread_info(tsk) ((struct thread_info *) \
__get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER))
#define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_SIZE_ORDER)
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#define PREEMPT_ACTIVE 0x4000000 #define PREEMPT_ACTIVE 0x4000000

View File

@ -82,6 +82,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
#define THREAD_MASK (THREAD_SIZE - 1UL) #define THREAD_MASK (THREAD_SIZE - 1UL)
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) \ #define alloc_thread_info(tsk) \
({ \ ({ \

View File

@ -112,6 +112,8 @@ static inline unsigned long current_stack_pointer(void)
return sp; return sp;
} }
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
/* thread information allocation */ /* thread information allocation */
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL) #define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL)

View File

@ -34,15 +34,11 @@ struct thread_info {
/* thread information allocation */ /* thread information allocation */
#define THREAD_ORDER 2 #define THREAD_SIZE_ORDER 2
/* Be sure to hunt all references to this down when you change the size of /* Be sure to hunt all references to this down when you change the size of
* the kernel stack */ * the kernel stack */
#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER) #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
#define THREAD_SHIFT (PAGE_SHIFT + THREAD_ORDER) #define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER)
#define alloc_thread_info(tsk) ((struct thread_info *) \
__get_free_pages(GFP_KERNEL, THREAD_ORDER))
#define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
/* how to get the thread information struct from C */ /* how to get the thread information struct from C */
#define current_thread_info() ((struct thread_info *)mfctl(30)) #define current_thread_info() ((struct thread_info *)mfctl(30))

View File

@ -66,20 +66,12 @@ struct thread_info {
#if THREAD_SHIFT >= PAGE_SHIFT #if THREAD_SHIFT >= PAGE_SHIFT
#define THREAD_ORDER (THREAD_SHIFT - PAGE_SHIFT) #define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
#ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) \
((struct thread_info *)__get_free_pages(GFP_KERNEL | \
__GFP_ZERO, THREAD_ORDER))
#else
#define alloc_thread_info(tsk) \
((struct thread_info *)__get_free_pages(GFP_KERNEL, THREAD_ORDER))
#endif
#define free_thread_info(ti) free_pages((unsigned long)ti, THREAD_ORDER)
#else /* THREAD_SHIFT < PAGE_SHIFT */ #else /* THREAD_SHIFT < PAGE_SHIFT */
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
extern struct thread_info *alloc_thread_info(struct task_struct *tsk); extern struct thread_info *alloc_thread_info(struct task_struct *tsk);
extern void free_thread_info(struct thread_info *ti); extern void free_thread_info(struct thread_info *ti);

View File

@ -78,10 +78,7 @@ static inline struct thread_info *current_thread_info(void)
return (struct thread_info *)((*(unsigned long *) __LC_KERNEL_STACK)-THREAD_SIZE); return (struct thread_info *)((*(unsigned long *) __LC_KERNEL_STACK)-THREAD_SIZE);
} }
/* thread information allocation */ #define THREAD_SIZE_ORDER THREAD_ORDER
#define alloc_thread_info(tsk) ((struct thread_info *) \
__get_free_pages(GFP_KERNEL,THREAD_ORDER))
#define free_thread_info(ti) free_pages((unsigned long) (ti),THREAD_ORDER)
#endif #endif

View File

@ -92,6 +92,8 @@ static inline struct thread_info *current_thread_info(void)
return ti; return ti;
} }
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
/* thread information allocation */ /* thread information allocation */
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(ti) kzalloc(THREAD_SIZE, GFP_KERNEL) #define alloc_thread_info(ti) kzalloc(THREAD_SIZE, GFP_KERNEL)

View File

@ -86,6 +86,8 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define THREAD_INFO_ORDER 1 #define THREAD_INFO_ORDER 1
#endif #endif
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info, void) BTFIXUPDEF_CALL(struct thread_info *, alloc_thread_info, void)
#define alloc_thread_info(tsk) BTFIXUP_CALL(alloc_thread_info)() #define alloc_thread_info(tsk) BTFIXUP_CALL(alloc_thread_info)()

View File

@ -155,6 +155,8 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define __THREAD_INFO_ORDER 0 #define __THREAD_INFO_ORDER 0
#endif /* PAGE_SHIFT == 13 */ #endif /* PAGE_SHIFT == 13 */
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
#ifdef CONFIG_DEBUG_STACK_USAGE #ifdef CONFIG_DEBUG_STACK_USAGE
#define alloc_thread_info(tsk) \ #define alloc_thread_info(tsk) \
({ \ ({ \

View File

@ -53,21 +53,7 @@ static inline struct thread_info *current_thread_info(void)
return ti; return ti;
} }
#ifdef CONFIG_DEBUG_STACK_USAGE #define THREAD_SIZE_ORDER CONFIG_KERNEL_STACK_ORDER
#define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, \
CONFIG_KERNEL_STACK_ORDER))
#else
/* thread information allocation */
#define alloc_thread_info(tsk) \
((struct thread_info *) __get_free_pages(GFP_KERNEL, \
CONFIG_KERNEL_STACK_ORDER))
#endif
#define free_thread_info(ti) \
free_pages((unsigned long)(ti),CONFIG_KERNEL_STACK_ORDER)
#endif #endif

View File

@ -152,6 +152,8 @@ struct thread_info {
#define THREAD_FLAGS GFP_KERNEL #define THREAD_FLAGS GFP_KERNEL
#endif #endif
#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
#define alloc_thread_info(tsk) \ #define alloc_thread_info(tsk) \
((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER)) ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))

View File

@ -111,10 +111,6 @@ static inline struct thread_info *current_thread_info(void)
return ti; return ti;
} }
/* thread information allocation */
#define alloc_thread_info(tsk) ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
#else /* !__ASSEMBLY__ */ #else /* !__ASSEMBLY__ */
/* how to get the thread information struct from ASM */ /* how to get the thread information struct from ASM */
@ -160,6 +156,7 @@ static inline struct thread_info *current_thread_info(void)
#define TS_USEDFPU 0x0001 /* FPU was used by this task this quantum (SMP) */ #define TS_USEDFPU 0x0001 /* FPU was used by this task this quantum (SMP) */
#define THREAD_SIZE 8192 //(2*PAGE_SIZE) #define THREAD_SIZE 8192 //(2*PAGE_SIZE)
#define THREAD_SIZE_ORDER 1
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _XTENSA_THREAD_INFO */ #endif /* _XTENSA_THREAD_INFO */

View File

@ -93,6 +93,23 @@ int nr_processes(void)
static struct kmem_cache *task_struct_cachep; static struct kmem_cache *task_struct_cachep;
#endif #endif
#ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR
static inline struct thread_info *alloc_thread_info(struct task_struct *tsk)
{
#ifdef CONFIG_DEBUG_STACK_USAGE
gfp_t mask = GFP_KERNEL | __GFP_ZERO;
#else
gfp_t mask = GFP_KERNEL;
#endif
return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
}
static inline void free_thread_info(struct thread_info *ti)
{
free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
}
#endif
/* SLAB cache for signal_struct structures (tsk->signal) */ /* SLAB cache for signal_struct structures (tsk->signal) */
static struct kmem_cache *signal_cachep; static struct kmem_cache *signal_cachep;