Rev 860 | Rev 935 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 860 | Rev 906 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | 61 | ||
62 | SPINLOCK_INITIALIZE(tidlock); |
62 | SPINLOCK_INITIALIZE(tidlock); |
63 | __u32 last_tid = 0; |
63 | __u32 last_tid = 0; |
64 | 64 | ||
65 | static slab_cache_t *thread_slab; |
65 | static slab_cache_t *thread_slab; |
- | 66 | #ifdef ARCH_HAS_FPU |
|
- | 67 | slab_cache_t *fpu_context_slab; |
|
- | 68 | #endif |
|
66 | 69 | ||
67 | 70 | ||
68 | /** Thread wrapper |
71 | /** Thread wrapper |
69 | * |
72 | * |
70 | * This wrapper is provided to ensure that every thread |
73 | * This wrapper is provided to ensure that every thread |
Line 101... | Line 104... | ||
101 | link_initialize(&t->rq_link); |
104 | link_initialize(&t->rq_link); |
102 | link_initialize(&t->wq_link); |
105 | link_initialize(&t->wq_link); |
103 | link_initialize(&t->th_link); |
106 | link_initialize(&t->th_link); |
104 | link_initialize(&t->threads_link); |
107 | link_initialize(&t->threads_link); |
105 | 108 | ||
- | 109 | #ifdef ARCH_HAS_FPU |
|
- | 110 | # ifdef CONFIG_FPU_LAZY |
|
- | 111 | t->saved_fpu_context = NULL; |
|
- | 112 | # else |
|
- | 113 | t->saved_fpu_context = slab_alloc(fpu_context_slab,kmflags); |
|
- | 114 | if (!t->saved_fpu_context) |
|
- | 115 | return -1; |
|
- | 116 | # endif |
|
- | 117 | #endif |
|
- | 118 | ||
106 | pfn = frame_alloc_rc(ONE_FRAME, FRAME_KA | kmflags,&status); |
119 | pfn = frame_alloc_rc(ONE_FRAME, FRAME_KA | kmflags,&status); |
107 | if (status) |
120 | if (status) { |
- | 121 | #ifdef ARCH_HAS_FPU |
|
- | 122 | if (t->saved_fpu_context) |
|
- | 123 | slab_free(fpu_context_slab,t->saved_fpu_context); |
|
- | 124 | #endif |
|
108 | return -1; |
125 | return -1; |
- | 126 | } |
|
109 | t->kstack = (__u8 *)PA2KA(PFN2ADDR(pfn)); |
127 | t->kstack = (__u8 *)PA2KA(PFN2ADDR(pfn)); |
110 | 128 | ||
111 | return 0; |
129 | return 0; |
112 | } |
130 | } |
113 | 131 | ||
Line 115... | Line 133... | ||
115 | static int thr_destructor(void *obj) |
133 | static int thr_destructor(void *obj) |
116 | { |
134 | { |
117 | thread_t *t = (thread_t *)obj; |
135 | thread_t *t = (thread_t *)obj; |
118 | 136 | ||
119 | frame_free(ADDR2PFN(KA2PA(t->kstack))); |
137 | frame_free(ADDR2PFN(KA2PA(t->kstack))); |
- | 138 | #ifdef ARCH_HAS_FPU |
|
- | 139 | if (t->saved_fpu_context) |
|
- | 140 | slab_free(fpu_context_slab,t->saved_fpu_context); |
|
- | 141 | #endif |
|
120 | return 1; /* One page freed */ |
142 | return 1; /* One page freed */ |
121 | } |
143 | } |
122 | 144 | ||
123 | /** Initialize threads |
145 | /** Initialize threads |
124 | * |
146 | * |
Line 130... | Line 152... | ||
130 | THREAD = NULL; |
152 | THREAD = NULL; |
131 | atomic_set(&nrdy,0); |
153 | atomic_set(&nrdy,0); |
132 | thread_slab = slab_cache_create("thread_slab", |
154 | thread_slab = slab_cache_create("thread_slab", |
133 | sizeof(thread_t),0, |
155 | sizeof(thread_t),0, |
134 | thr_constructor, thr_destructor, 0); |
156 | thr_constructor, thr_destructor, 0); |
- | 157 | #ifdef ARCH_HAS_FPU |
|
- | 158 | fpu_context_slab = slab_cache_create("fpu_slab", |
|
- | 159 | sizeof(fpu_context_t), |
|
- | 160 | FPU_CONTEXT_ALIGN, |
|
- | 161 | NULL, NULL, 0); |
|
- | 162 | #endif |
|
135 | } |
163 | } |
136 | 164 | ||
137 | 165 | ||
138 | /** Make thread ready |
166 | /** Make thread ready |
139 | * |
167 | * |