Skip to content

Commit 0ccd559

Browse files
committed
sched:use tcb_s inside of task_tcb_s , remove all cast
Signed-off-by: anjiahao <[email protected]>
1 parent 69a2f4b commit 0ccd559

File tree

22 files changed

+259
-279
lines changed

22 files changed

+259
-279
lines changed

Diff for: Documentation/guides/kernel_threads_with_custom_stacks.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Here is the body of some function. It expects to have the following inputs:
3131
* used to that all fields of the new TCB will be zeroed.
3232
*/
3333
34-
tcb = (FAR struct task_tcb_s *)kmm_zalloc(sizeof(struct task_tcb_s));
34+
tcb = kmm_zalloc(sizeof(struct tcb_s) + sizeof(struct task_group_s));
3535
if (tcb == NULL)
3636
{
3737
return -ENOMEM;
@@ -131,4 +131,4 @@ option is to include it in all cases where you do not expect the custom stack
131131
to be de-allocated.
132132

133133
You must not free the custom stack after ``nxtask_activate()`` returns
134-
successfully and until the kernel thread is terminated.
134+
successfully and until the kernel thread is terminated.

Diff for: arch/arm/src/common/arm_fork.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
pid_t arm_fork(const struct fork_s *context)
9393
{
9494
struct tcb_s *parent = this_task();
95-
struct task_tcb_s *child;
95+
struct tcb_s *child;
9696
uint32_t newsp;
9797
uint32_t newfp;
9898
uint32_t newtop;
@@ -144,17 +144,17 @@ pid_t arm_fork(const struct fork_s *context)
144144
* effort is overkill.
145145
*/
146146

147-
newtop = (uint32_t)child->cmn.stack_base_ptr +
148-
child->cmn.adj_stack_size;
147+
newtop = (uint32_t)child->stack_base_ptr +
148+
child->adj_stack_size;
149149

150150
newsp = newtop - stackutil;
151151

152152
/* Move the register context to newtop. */
153153

154154
memcpy((void *)(newsp - XCPTCONTEXT_SIZE),
155-
child->cmn.xcp.regs, XCPTCONTEXT_SIZE);
155+
child->xcp.regs, XCPTCONTEXT_SIZE);
156156

157-
child->cmn.xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
157+
child->xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
158158

159159
memcpy((void *)newsp, (const void *)oldsp, stackutil);
160160

@@ -182,16 +182,16 @@ pid_t arm_fork(const struct fork_s *context)
182182
* child thread.
183183
*/
184184

185-
child->cmn.xcp.regs[REG_R4] = context->r4; /* Volatile register r4 */
186-
child->cmn.xcp.regs[REG_R5] = context->r5; /* Volatile register r5 */
187-
child->cmn.xcp.regs[REG_R6] = context->r6; /* Volatile register r6 */
188-
child->cmn.xcp.regs[REG_R7] = context->r7; /* Volatile register r7 */
189-
child->cmn.xcp.regs[REG_R8] = context->r8; /* Volatile register r8 */
190-
child->cmn.xcp.regs[REG_R9] = context->r9; /* Volatile register r9 */
191-
child->cmn.xcp.regs[REG_R10] = context->r10; /* Volatile register r10 */
192-
child->cmn.xcp.regs[REG_R11] = context->r11; /* Volatile register r11 */
193-
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
194-
child->cmn.xcp.regs[REG_SP] = newsp; /* Stack pointer */
185+
child->xcp.regs[REG_R4] = context->r4; /* Volatile register r4 */
186+
child->xcp.regs[REG_R5] = context->r5; /* Volatile register r5 */
187+
child->xcp.regs[REG_R6] = context->r6; /* Volatile register r6 */
188+
child->xcp.regs[REG_R7] = context->r7; /* Volatile register r7 */
189+
child->xcp.regs[REG_R8] = context->r8; /* Volatile register r8 */
190+
child->xcp.regs[REG_R9] = context->r9; /* Volatile register r9 */
191+
child->xcp.regs[REG_R10] = context->r10; /* Volatile register r10 */
192+
child->xcp.regs[REG_R11] = context->r11; /* Volatile register r11 */
193+
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
194+
child->xcp.regs[REG_SP] = newsp; /* Stack pointer */
195195

196196
#ifdef CONFIG_LIB_SYSCALL
197197
/* If we got here via a syscall, then we are going to have to setup some
@@ -203,37 +203,37 @@ pid_t arm_fork(const struct fork_s *context)
203203
int index;
204204
for (index = 0; index < parent->xcp.nsyscalls; index++)
205205
{
206-
child->cmn.xcp.syscall[index].sysreturn =
206+
child->xcp.syscall[index].sysreturn =
207207
parent->xcp.syscall[index].sysreturn;
208208

209209
/* REVISIT: This logic is *not* common. */
210210

211211
#if defined(CONFIG_ARCH_ARMV7A)
212212
# ifdef CONFIG_BUILD_KERNEL
213213

214-
child->cmn.xcp.syscall[index].cpsr =
214+
child->xcp.syscall[index].cpsr =
215215
parent->xcp.syscall[index].cpsr;
216216

217217
# endif
218218

219219
#elif defined(CONFIG_ARCH_ARMV7R)
220220
# ifdef CONFIG_BUILD_PROTECTED
221221

222-
child->cmn.xcp.syscall[index].cpsr =
222+
child->xcp.syscall[index].cpsr =
223223
parent->xcp.syscall[index].cpsr;
224224

225225
# endif
226226
#elif defined(CONFIG_ARCH_ARMV6M) || defined(CONFIG_ARCH_ARMV7M) || \
227227
defined(CONFIG_ARCH_ARMV8M)
228228

229-
child->cmn.xcp.syscall[index].excreturn =
229+
child->xcp.syscall[index].excreturn =
230230
parent->xcp.syscall[index].excreturn;
231231
#else
232232
# error Missing logic
233233
#endif
234234
}
235235

236-
child->cmn.xcp.nsyscalls = parent->xcp.nsyscalls;
236+
child->xcp.nsyscalls = parent->xcp.nsyscalls;
237237
}
238238
#endif
239239

Diff for: arch/arm64/src/common/arm64_fork.c

+41-41
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void arm64_fork_fpureg_save(struct fork_s *context)
122122
pid_t arm64_fork(const struct fork_s *context)
123123
{
124124
struct tcb_s *parent = this_task();
125-
struct task_tcb_s *child;
125+
struct tcb_s *child;
126126
uint64_t newsp;
127127
uint64_t newfp;
128128
uint64_t newtop;
@@ -156,8 +156,8 @@ pid_t arm64_fork(const struct fork_s *context)
156156
* effort is overkill.
157157
*/
158158

159-
newtop = (uint64_t)child->cmn.stack_base_ptr +
160-
child->cmn.adj_stack_size;
159+
newtop = (uint64_t)child->stack_base_ptr +
160+
child->adj_stack_size;
161161
newsp = newtop - stackutil;
162162
memcpy((void *)newsp, (const void *)context->sp, stackutil);
163163

@@ -183,59 +183,59 @@ pid_t arm64_fork(const struct fork_s *context)
183183
/* make the fork stack frame */
184184

185185
#ifdef CONFIG_ARCH_FPU
186-
child->cmn.xcp.fpu_regs = (void *)(newsp - FPU_CONTEXT_SIZE);
187-
memcpy(child->cmn.xcp.fpu_regs, context->fpu, FPU_CONTEXT_SIZE);
186+
child->xcp.fpu_regs = (void *)(newsp - FPU_CONTEXT_SIZE);
187+
memcpy(child->xcp.fpu_regs, context->fpu, FPU_CONTEXT_SIZE);
188188
#endif
189189

190-
child->cmn.xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
191-
192-
child->cmn.xcp.regs[REG_X0] = 0;
193-
child->cmn.xcp.regs[REG_X8] = context->regs[FORK_REG_X8];
194-
child->cmn.xcp.regs[REG_X9] = context->regs[FORK_REG_X9];
195-
child->cmn.xcp.regs[REG_X10] = context->regs[FORK_REG_X10];
196-
child->cmn.xcp.regs[REG_X11] = context->regs[FORK_REG_X11];
197-
child->cmn.xcp.regs[REG_X12] = context->regs[FORK_REG_X12];
198-
child->cmn.xcp.regs[REG_X13] = context->regs[FORK_REG_X13];
199-
child->cmn.xcp.regs[REG_X14] = context->regs[FORK_REG_X14];
200-
child->cmn.xcp.regs[REG_X15] = context->regs[FORK_REG_X15];
201-
child->cmn.xcp.regs[REG_X16] = context->regs[FORK_REG_X16];
202-
child->cmn.xcp.regs[REG_X17] = context->regs[FORK_REG_X17];
203-
child->cmn.xcp.regs[REG_X18] = context->regs[FORK_REG_X18];
204-
child->cmn.xcp.regs[REG_X19] = context->regs[FORK_REG_X19];
205-
child->cmn.xcp.regs[REG_X20] = context->regs[FORK_REG_X20];
206-
child->cmn.xcp.regs[REG_X21] = context->regs[FORK_REG_X21];
207-
child->cmn.xcp.regs[REG_X22] = context->regs[FORK_REG_X22];
208-
child->cmn.xcp.regs[REG_X23] = context->regs[FORK_REG_X23];
209-
child->cmn.xcp.regs[REG_X24] = context->regs[FORK_REG_X24];
210-
child->cmn.xcp.regs[REG_X25] = context->regs[FORK_REG_X25];
211-
child->cmn.xcp.regs[REG_X26] = context->regs[FORK_REG_X26];
212-
child->cmn.xcp.regs[REG_X27] = context->regs[FORK_REG_X27];
213-
child->cmn.xcp.regs[REG_X28] = context->regs[FORK_REG_X28];
214-
child->cmn.xcp.regs[REG_FP] = newfp;
190+
child->xcp.regs = (void *)(newsp - XCPTCONTEXT_SIZE);
191+
192+
child->xcp.regs[REG_X0] = 0;
193+
child->xcp.regs[REG_X8] = context->regs[FORK_REG_X8];
194+
child->xcp.regs[REG_X9] = context->regs[FORK_REG_X9];
195+
child->xcp.regs[REG_X10] = context->regs[FORK_REG_X10];
196+
child->xcp.regs[REG_X11] = context->regs[FORK_REG_X11];
197+
child->xcp.regs[REG_X12] = context->regs[FORK_REG_X12];
198+
child->xcp.regs[REG_X13] = context->regs[FORK_REG_X13];
199+
child->xcp.regs[REG_X14] = context->regs[FORK_REG_X14];
200+
child->xcp.regs[REG_X15] = context->regs[FORK_REG_X15];
201+
child->xcp.regs[REG_X16] = context->regs[FORK_REG_X16];
202+
child->xcp.regs[REG_X17] = context->regs[FORK_REG_X17];
203+
child->xcp.regs[REG_X18] = context->regs[FORK_REG_X18];
204+
child->xcp.regs[REG_X19] = context->regs[FORK_REG_X19];
205+
child->xcp.regs[REG_X20] = context->regs[FORK_REG_X20];
206+
child->xcp.regs[REG_X21] = context->regs[FORK_REG_X21];
207+
child->xcp.regs[REG_X22] = context->regs[FORK_REG_X22];
208+
child->xcp.regs[REG_X23] = context->regs[FORK_REG_X23];
209+
child->xcp.regs[REG_X24] = context->regs[FORK_REG_X24];
210+
child->xcp.regs[REG_X25] = context->regs[FORK_REG_X25];
211+
child->xcp.regs[REG_X26] = context->regs[FORK_REG_X26];
212+
child->xcp.regs[REG_X27] = context->regs[FORK_REG_X27];
213+
child->xcp.regs[REG_X28] = context->regs[FORK_REG_X28];
214+
child->xcp.regs[REG_FP] = newfp;
215215

216216
#if CONFIG_ARCH_ARM64_EXCEPTION_LEVEL == 3
217-
child->cmn.xcp.regs[REG_SPSR] = SPSR_MODE_EL3H;
217+
child->xcp.regs[REG_SPSR] = SPSR_MODE_EL3H;
218218
#else
219-
child->cmn.xcp.regs[REG_SPSR] = SPSR_MODE_EL1H;
219+
child->xcp.regs[REG_SPSR] = SPSR_MODE_EL1H;
220220
#endif
221221

222222
#ifdef CONFIG_SUPPRESS_INTERRUPTS
223-
child->cmn.xcp.regs[REG_SPSR] |= (DAIF_IRQ_BIT | DAIF_FIQ_BIT);
223+
child->xcp.regs[REG_SPSR] |= (DAIF_IRQ_BIT | DAIF_FIQ_BIT);
224224
#endif /* CONFIG_SUPPRESS_INTERRUPTS */
225225

226-
child->cmn.xcp.regs[REG_ELR] = (uint64_t)context->lr;
227-
228-
child->cmn.xcp.regs[REG_SCTLR_EL1] = read_sysreg(sctlr_el1);
226+
child->xcp.regs[REG_SCTLR_EL1] = read_sysreg(sctlr_el1);
229227
#ifdef CONFIG_ARM64_MTE
230-
child->cmn.xcp.regs[REG_SCTLR_EL1] |= SCTLR_TCF1_BIT;
228+
child->xcp.regs[REG_SCTLR_EL1] |= SCTLR_TCF1_BIT;
231229
#endif
232230

233-
child->cmn.xcp.regs[REG_EXE_DEPTH] = 0;
234-
child->cmn.xcp.regs[REG_SP_ELX] = newsp - XCPTCONTEXT_SIZE;
231+
child->xcp.regs[REG_ELR] = (uint64_t)context->lr;
232+
233+
child->xcp.regs[REG_EXE_DEPTH] = 0;
234+
child->xcp.regs[REG_SP_ELX] = newsp - XCPTCONTEXT_SIZE;
235235
#ifdef CONFIG_ARCH_KERNEL_STACK
236-
child->cmn.xcp.regs[REG_SP_EL0] = (uint64_t)child->cmn.xcp.ustkptr;
236+
child->xcp.regs[REG_SP_EL0] = (uint64_t)child->xcp.ustkptr;
237237
#else
238-
child->cmn.xcp.regs[REG_SP_EL0] = newsp - XCPTCONTEXT_SIZE;
238+
child->xcp.regs[REG_SP_EL0] = newsp - XCPTCONTEXT_SIZE;
239239
#endif
240240

241241
/* And, finally, start the child task. On a failure, nxtask_start_fork()

Diff for: arch/ceva/src/common/ceva_fork.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pid_t ceva_fork(const uint32_t *regs)
8787
{
8888
#ifdef CONFIG_SCHED_WAITPID
8989
struct tcb_s *parent = this_task();
90-
struct task_tcb_s *child;
90+
struct tcb_s *child;
9191
size_t stacksize;
9292
const void *sp = regs + XCPTCONTEXT_REGS;
9393
void *newsp;
@@ -146,22 +146,22 @@ pid_t ceva_fork(const uint32_t *regs)
146146
* effort is overkill.
147147
*/
148148

149-
newsp = child->cmn.stack_base_ptr - stackutil;
149+
newsp = child->stack_base_ptr - stackutil;
150150
memcpy(newsp, sp, stackutil);
151151

152152
/* Allocate the context and copy the parent snapshot */
153153

154154
newsp -= XCPTCONTEXT_SIZE;
155155
memcpy(newsp, regs, XCPTCONTEXT_SIZE);
156-
child->cmn.xcp.regs = newsp;
156+
child->xcp.regs = newsp;
157157

158158
/* Was there a frame pointer in place before? */
159159

160160
if (regs[REG_FP] <= (uint32_t)parent->stack_base_ptr &&
161161
regs[REG_FP] >= (uint32_t)parent->stack_base_ptr - stacksize)
162162
{
163163
uint32_t frameutil = (uint32_t)parent->stack_base_ptr - regs[REG_FP];
164-
newfp = (uint32_t)child->cmn.stack_base_ptr - frameutil;
164+
newfp = (uint32_t)child->stack_base_ptr - frameutil;
165165
}
166166
else
167167
{
@@ -171,17 +171,17 @@ pid_t ceva_fork(const uint32_t *regs)
171171
sinfo("Parent: stack base:%08x SP:%08x FP:%08x\n",
172172
parent->stack_base_ptr, sp, regs[REG_FP]);
173173
sinfo("Child: stack base:%08x SP:%08x FP:%08x\n",
174-
child->cmn.stack_base_ptr, newsp, newfp);
174+
child->stack_base_ptr, newsp, newfp);
175175

176176
/* Update the stack pointer, frame pointer, and the return value in A0
177177
* should be cleared to zero, providing the indication to the newly started
178178
* child thread.
179179
*/
180180

181-
child->cmn.xcp.regs[REG_A0] = 0; /* Return value */
182-
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
183-
child->cmn.xcp.regs[REG_PC] = regs[REG_LR]; /* Program counter */
184-
child->cmn.xcp.regs[REG_SP] = (uint32_t)newsp; /* Stack pointer */
181+
child->xcp.regs[REG_A0] = 0; /* Return value */
182+
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
183+
child->xcp.regs[REG_PC] = regs[REG_LR]; /* Program counter */
184+
child->xcp.regs[REG_SP] = (uint32_t)newsp; /* Stack pointer */
185185

186186
#ifdef CONFIG_LIB_SYSCALL
187187
/* If we got here via a syscall, then we are going to have to setup some
@@ -193,10 +193,10 @@ pid_t ceva_fork(const uint32_t *regs)
193193
int index;
194194
for (index = 0; index < parent->xcp.nsyscalls; index++)
195195
{
196-
child->cmn.xcp.syscall[index] = parent->xcp.syscall[index];
196+
child->xcp.syscall[index] = parent->xcp.syscall[index];
197197
}
198198

199-
child->cmn.xcp.nsyscalls = parent->xcp.nsyscalls;
199+
child->xcp.nsyscalls = parent->xcp.nsyscalls;
200200
}
201201
#endif
202202

Diff for: arch/mips/src/mips32/mips_fork.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
pid_t mips_fork(const struct fork_s *context)
9393
{
9494
struct tcb_s *parent = this_task();
95-
struct task_tcb_s *child;
95+
struct tcb_s *child;
9696
uint32_t newsp;
9797
#ifdef CONFIG_MIPS32_FRAMEPOINTER
9898
uint32_t newfp;
@@ -159,8 +159,8 @@ pid_t mips_fork(const struct fork_s *context)
159159
* effort is overkill.
160160
*/
161161

162-
newtop = (uintptr_t)child->cmn.stack_base_ptr +
163-
child->cmn.adj_stack_size;
162+
newtop = (uintptr_t)child->stack_base_ptr +
163+
child->adj_stack_size;
164164
newsp = newtop - stackutil;
165165
memcpy((void *)newsp, (const void *)context->sp, stackutil);
166166

@@ -195,22 +195,22 @@ pid_t mips_fork(const struct fork_s *context)
195195
* indication to the newly started child thread.
196196
*/
197197

198-
child->cmn.xcp.regs[REG_S0] = context->s0; /* Saved register s0 */
199-
child->cmn.xcp.regs[REG_S1] = context->s1; /* Saved register s1 */
200-
child->cmn.xcp.regs[REG_S2] = context->s2; /* Saved register s2 */
201-
child->cmn.xcp.regs[REG_S3] = context->s3; /* Volatile register s3 */
202-
child->cmn.xcp.regs[REG_S4] = context->s4; /* Volatile register s4 */
203-
child->cmn.xcp.regs[REG_S5] = context->s5; /* Volatile register s5 */
204-
child->cmn.xcp.regs[REG_S6] = context->s6; /* Volatile register s6 */
205-
child->cmn.xcp.regs[REG_S7] = context->s7; /* Volatile register s7 */
198+
child->xcp.regs[REG_S0] = context->s0; /* Saved register s0 */
199+
child->xcp.regs[REG_S1] = context->s1; /* Saved register s1 */
200+
child->xcp.regs[REG_S2] = context->s2; /* Saved register s2 */
201+
child->xcp.regs[REG_S3] = context->s3; /* Volatile register s3 */
202+
child->xcp.regs[REG_S4] = context->s4; /* Volatile register s4 */
203+
child->xcp.regs[REG_S5] = context->s5; /* Volatile register s5 */
204+
child->xcp.regs[REG_S6] = context->s6; /* Volatile register s6 */
205+
child->xcp.regs[REG_S7] = context->s7; /* Volatile register s7 */
206206
#ifdef CONFIG_MIPS32_FRAMEPOINTER
207-
child->cmn.xcp.regs[REG_FP] = newfp; /* Frame pointer */
207+
child->xcp.regs[REG_FP] = newfp; /* Frame pointer */
208208
#else
209-
child->cmn.xcp.regs[REG_S8] = context->s8; /* Volatile register s8 */
209+
child->xcp.regs[REG_S8] = context->s8; /* Volatile register s8 */
210210
#endif
211-
child->cmn.xcp.regs[REG_SP] = newsp; /* Stack pointer */
211+
child->xcp.regs[REG_SP] = newsp; /* Stack pointer */
212212
#ifdef MIPS32_SAVE_GP
213-
child->cmn.xcp.regs[REG_GP] = context->gp; /* Global pointer */
213+
child->xcp.regs[REG_GP] = context->gp; /* Global pointer */
214214
#endif
215215

216216
/* And, finally, start the child task. On a failure, nxtask_start_fork()

0 commit comments

Comments
 (0)