xref: /linux/arch/sh/kernel/process.c (revision a3705799e2cc5fb69d88ad6a7f317a8f5597f18d)
1cbf6b1baSPaul Mundt #include <linux/mm.h>
2cbf6b1baSPaul Mundt #include <linux/kernel.h>
3cbf6b1baSPaul Mundt #include <linux/sched.h>
4cbf6b1baSPaul Mundt 
5cbf6b1baSPaul Mundt #if THREAD_SHIFT < PAGE_SHIFT
6cbf6b1baSPaul Mundt static struct kmem_cache *thread_info_cache;
7cbf6b1baSPaul Mundt 
8cbf6b1baSPaul Mundt struct thread_info *alloc_thread_info(struct task_struct *tsk)
9cbf6b1baSPaul Mundt {
10cbf6b1baSPaul Mundt 	struct thread_info *ti;
11cbf6b1baSPaul Mundt 
12cbf6b1baSPaul Mundt 	ti = kmem_cache_alloc(thread_info_cache, GFP_KERNEL);
13cbf6b1baSPaul Mundt 	if (unlikely(ti == NULL))
14cbf6b1baSPaul Mundt 		return NULL;
15cbf6b1baSPaul Mundt #ifdef CONFIG_DEBUG_STACK_USAGE
16cbf6b1baSPaul Mundt 	memset(ti, 0, THREAD_SIZE);
17cbf6b1baSPaul Mundt #endif
18cbf6b1baSPaul Mundt 	return ti;
19cbf6b1baSPaul Mundt }
20cbf6b1baSPaul Mundt 
21cbf6b1baSPaul Mundt void free_thread_info(struct thread_info *ti)
22cbf6b1baSPaul Mundt {
23cbf6b1baSPaul Mundt 	kmem_cache_free(thread_info_cache, ti);
24cbf6b1baSPaul Mundt }
25cbf6b1baSPaul Mundt 
26cbf6b1baSPaul Mundt void thread_info_cache_init(void)
27cbf6b1baSPaul Mundt {
28cbf6b1baSPaul Mundt 	thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
29*a3705799SPaul Mundt 					      THREAD_SIZE, SLAB_PANIC, NULL);
30cbf6b1baSPaul Mundt }
31cbf6b1baSPaul Mundt #else
32cbf6b1baSPaul Mundt struct thread_info *alloc_thread_info(struct task_struct *tsk)
33cbf6b1baSPaul Mundt {
34cbf6b1baSPaul Mundt #ifdef CONFIG_DEBUG_STACK_USAGE
35cbf6b1baSPaul Mundt 	gfp_t mask = GFP_KERNEL | __GFP_ZERO;
36cbf6b1baSPaul Mundt #else
37cbf6b1baSPaul Mundt 	gfp_t mask = GFP_KERNEL;
38cbf6b1baSPaul Mundt #endif
39cbf6b1baSPaul Mundt 	return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
40cbf6b1baSPaul Mundt }
41cbf6b1baSPaul Mundt 
42cbf6b1baSPaul Mundt void free_thread_info(struct thread_info *ti)
43cbf6b1baSPaul Mundt {
44cbf6b1baSPaul Mundt 	free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
45cbf6b1baSPaul Mundt }
46cbf6b1baSPaul Mundt #endif /* THREAD_SHIFT < PAGE_SHIFT */
47