zyfeier commented on code in PR #21804:
URL: https://github.com/apache/nuttx/pull/21804#discussion_r4675713665
##########
sched/sched/sched_setscheduler.c:
##########
@@ -73,8 +73,7 @@ int process_sporadic(FAR struct tcb_s *tcb,
if (ret >= 0)
{
- tcb->flags &= ~TCB_FLAG_POLICY_MASK;
- tcb->flags |= TCB_FLAG_SCHED_SPORADIC;
+ tcb->sched_policy = SCHED_SPORADIC;
Review Comment:
Done.
##########
include/nuttx/sched.h:
##########
@@ -689,7 +689,7 @@ struct tcb_s
uint8_t cpu; /* CPU index if running/assigned */
cpu_set_t affinity; /* Bit set of permitted CPUs */
#endif
- uint32_t flags; /* Misc. general status flags */
+ atomic_t flags; /* Misc. general status flags */
Review Comment:
Done, merged into the previous patch.
##########
arch/arm/src/armv7-a/arm_userfault.c:
##########
@@ -64,7 +64,8 @@ bool arm_fault_kill(uint32_t *regs)
struct tcb_s *tcb = this_task();
struct tcb_s *ptcb;
- if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL ||
+ if ((atomic_read(&tcb->flags) & TCB_FLAG_TTYPE_MASK) ==
Review Comment:
You are right: the thread type is set by the creator before the task runs
and never changes. It now lives in tcb->exec_flags (new commit "sched: move the
thread type into tcb->exec_flags") and is read with a plain load. It went
through atomic_read() only because it shared tcb->flags with bits that other
CPUs change, and on chips without atomic instructions, such as armv6-m,
atomic_read() is an out-of-line call that disables interrupts.
##########
arch/arm/src/common/arm_createstack.c:
##########
@@ -193,7 +193,7 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size,
uint8_t ttype)
arm_stack_color(tcb->stack_base_ptr, tcb->adj_stack_size);
#endif /* CONFIG_STACK_COLORATION */
- tcb->flags |= TCB_FLAG_FREE_STACK;
+ atomic_or(&tcb->flags, TCB_FLAG_FREE_STACK);
Review Comment:
TCB_FLAG_FREE_STACK is different: it is also cleared at exit, in
group_leave(), which nxtask_terminate() runs in the context of the task that
deletes the target. So it stays in tcb->flags with atomic access. Here the TCB
is not visible to other CPUs yet, so atomic_or() is not needed for correctness,
but flags is atomic_t, and with GCC a plain |= on it would itself be an atomic
read-modify-write (an __atomic_fetch_or_4 call on chips without atomic
instructions). This is the task creation path, not a hot path.
##########
sched/task/task_terminate.c:
##########
@@ -122,26 +122,24 @@ int nxtask_terminate(pid_t pid)
/* Find for the TCB associated with matching PID */
dtcb = nxsched_get_tcb(pid);
- if (!dtcb || dtcb->flags & TCB_FLAG_EXIT_PROCESSING)
+ if (!dtcb || (atomic_or(&dtcb->flags, TCB_FLAG_EXIT_PROCESSING) &
+ TCB_FLAG_EXIT_PROCESSING) != 0)
{
leave_critical_section(flags);
return -ESRCH;
}
- dtcb->flags |= TCB_FLAG_EXIT_PROCESSING;
-
/* Remove dtcb from tasklist, let remove_readtorun() do the job */
task_state = dtcb->task_state;
#ifdef CONFIG_SMP
if (task_state == TSTATE_TASK_RUNNING &&
dtcb->cpu != this_cpu())
{
- uint16_t tcb_flags;
+ atomic_t tcb_flags;
Review Comment:
Fixed, it is int32_t now: the variable only holds the value returned by
atomic_or().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]