Skip to content

Commit

Permalink
sched: rm nxsched_remove_readytorun
Browse files Browse the repository at this point in the history
resson:
1In the scenario of active waiting, context switching is inevitable, and we can eliminate redundant judgments.

code size
before
hujun5@hujun5-OptiPlex-7070:~/downloads1/vela_sim/nuttx$ size nuttx
   text    data     bss     dec     hex filename
 262848   49985   63893  376726   5bf96 nuttx

after
hujun5@hujun5-OptiPlex-7070:~/downloads1/vela_sim/nuttx$ size nuttx
   text    data     bss     dec     hex filename
 263324   49985   63893  377202   5c172 nuttx

reduce code size by  -476

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
  • Loading branch information
hujun260 committed Sep 13, 2024
1 parent 512a496 commit 8ed6183
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 269 deletions.
12 changes: 4 additions & 8 deletions sched/mqueue/mq_rcvinternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
{
FAR struct mqueue_msg_s *newmsg;
FAR struct tcb_s *rtcb;
bool switch_needed;

DEBUGASSERT(rcvmsg != NULL);

Expand Down Expand Up @@ -186,21 +185,18 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,

DEBUGASSERT(!is_idle_task(rtcb));

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_running(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTEMPTY;
nxsched_add_prioritized(rtcb, MQ_WNELIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/mqueue/mq_sndinternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ FAR struct mqueue_msg_s *nxmq_alloc_msg(void)
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
{
FAR struct tcb_s *rtcb;
bool switch_needed;

#ifdef CONFIG_CANCELLATION_POINTS
/* nxmq_wait_send() is not a cancellation point, but may be called via
Expand Down Expand Up @@ -271,21 +270,18 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)

DEBUGASSERT(!is_idle_task(rtcb));

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_running(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTFULL;
nxsched_add_prioritized(rtcb, MQ_WNFLIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/mqueue/msgrcv.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct msgbuf_s **rcvmsg,
FAR struct msgbuf_s *newmsg = NULL;
FAR struct msgbuf_s *tmp;
FAR struct tcb_s *rtcb;
bool switch_needed;

#ifdef CONFIG_CANCELLATION_POINTS
/* msgrcv_wait() is not a cancellation point, but it may be called
Expand Down Expand Up @@ -129,21 +128,18 @@ static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct msgbuf_s **rcvmsg,

DEBUGASSERT(NULL != rtcb->flink);

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_running(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTEMPTY;
nxsched_add_prioritized(rtcb, MQ_WNELIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/mqueue/msgsnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)
{
FAR struct tcb_s *rtcb;
bool switch_needed;

#ifdef CONFIG_CANCELLATION_POINTS
/* msgsnd_wait() is not a cancellation point, but may be called via
Expand Down Expand Up @@ -95,21 +94,18 @@ static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)

DEBUGASSERT(NULL != rtcb->flink);

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(rtcb, true);
nxsched_remove_running(rtcb);

/* Add the task to the specified blocked task list */

rtcb->task_state = TSTATE_WAIT_MQNOTFULL;
nxsched_add_prioritized(rtcb, MQ_WNFLIST(msgq->cmn));

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), rtcb);
}
up_switch_context(this_task(), rtcb);

/* When we resume at this point, either (1) the message queue
* is no longer empty, or (2) the wait has been interrupted by
Expand Down
12 changes: 4 additions & 8 deletions sched/paging/pg_miss.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void pg_miss(void)
{
FAR struct tcb_s *ftcb = this_task();
FAR struct tcb_s *wtcb;
bool switch_needed;

/* Sanity checking
*
Expand All @@ -138,21 +137,18 @@ void pg_miss(void)

DEBUGASSERT(!is_idle_task(ftcb));

/* Remove the tcb task from the ready-to-run list. */
/* Remove the tcb task from the running list. */

switch_needed = nxsched_remove_readytorun(ftcb, true);
nxsched_remove_running(ftcb);

/* Add the task to the specified blocked task list */

ftcb->task_state = TSTATE_WAIT_PAGEFILL;
nxsched_add_prioritized(ftcb, list_waitingforfill());

/* Now, perform the context switch if one is needed */
/* Now, perform the context switch */

if (switch_needed)
{
up_switch_context(this_task(), ftcb);
}
up_switch_context(this_task(), ftcb);

/* Boost the page fill worker thread priority.
* - Check the priority of the task at the head of the g_waitingforfill
Expand Down
4 changes: 3 additions & 1 deletion sched/sched/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
/* Task list manipulation functions */

bool nxsched_add_readytorun(FAR struct tcb_s *rtrtcb);
bool nxsched_remove_readytorun(FAR struct tcb_s *rtrtcb, bool merge);
bool nxsched_remove(FAR struct tcb_s *rtrtcb);
void nxsched_remove_running(FAR struct tcb_s *rtrtcb);
void nxsched_remove_not_running(FAR struct tcb_s *rtrtcb);
bool nxsched_add_prioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list);
void nxsched_merge_prioritized(FAR dq_queue_t *list1, FAR dq_queue_t *list2,
uint8_t task_state);
Expand Down
Loading

0 comments on commit 8ed6183

Please sign in to comment.