2 #include <linux/kernel.h>
3 #include <linux/slab.h>
4 #include <linux/sched.h>
6 struct kmem_cache *task_xstate_cachep = NULL;
7 unsigned int xstate_size;
10 * this gets called so that we can store lazy state into memory and copy the
11 * current task into the new thread.
13 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
15 #ifdef CONFIG_SUPERH32
16 unlazy_fpu(src, task_pt_regs(src));
20 if (src->thread.xstate) {
21 dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
23 if (!dst->thread.xstate)
25 memcpy(dst->thread.xstate, src->thread.xstate, xstate_size);
31 void free_thread_xstate(struct task_struct *tsk)
33 if (tsk->thread.xstate) {
34 kmem_cache_free(task_xstate_cachep, tsk->thread.xstate);
35 tsk->thread.xstate = NULL;
39 #if THREAD_SHIFT < PAGE_SHIFT
40 static struct kmem_cache *thread_info_cache;
42 struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
44 struct thread_info *ti;
45 #ifdef CONFIG_DEBUG_STACK_USAGE
46 gfp_t mask = GFP_KERNEL | __GFP_ZERO;
48 gfp_t mask = GFP_KERNEL;
51 ti = kmem_cache_alloc_node(thread_info_cache, mask, node);
55 void free_thread_info(struct thread_info *ti)
57 free_thread_xstate(ti->task);
58 kmem_cache_free(thread_info_cache, ti);
61 void thread_info_cache_init(void)
63 thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
64 THREAD_SIZE, SLAB_PANIC, NULL);
67 struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
69 #ifdef CONFIG_DEBUG_STACK_USAGE
70 gfp_t mask = GFP_KERNEL | __GFP_ZERO;
72 gfp_t mask = GFP_KERNEL;
74 struct page *page = alloc_pages_node(node, mask, THREAD_SIZE_ORDER);
76 return page ? page_address(page) : NULL;
79 void free_thread_info(struct thread_info *ti)
81 free_thread_xstate(ti->task);
82 free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
84 #endif /* THREAD_SHIFT < PAGE_SHIFT */
86 void arch_task_cache_init(void)
91 task_xstate_cachep = kmem_cache_create("task_xstate", xstate_size,
92 __alignof__(union thread_xstate),
93 SLAB_PANIC | SLAB_NOTRACK, NULL);
96 #ifdef CONFIG_SH_FPU_EMU
97 # define HAVE_SOFTFP 1
99 # define HAVE_SOFTFP 0
102 void __cpuinit init_thread_xstate(void)
104 if (boot_cpu_data.flags & CPU_HAS_FPU)
105 xstate_size = sizeof(struct sh_fpu_hard_struct);
106 else if (HAVE_SOFTFP)
107 xstate_size = sizeof(struct sh_fpu_soft_struct);