Skip to content

Commit e13d255

Browse files
hujun260anchao
authored andcommitted
sched: add nxsched_remove_self
reason: 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>
1 parent dc6eeba commit e13d255

File tree

11 files changed

+179
-192
lines changed

11 files changed

+179
-192
lines changed

sched/mqueue/mq_rcvinternal.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
138138
{
139139
FAR struct mqueue_msg_s *newmsg;
140140
FAR struct tcb_s *rtcb;
141-
bool switch_needed;
142141

143142
DEBUGASSERT(rcvmsg != NULL);
144143

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

187186
DEBUGASSERT(!is_idle_task(rtcb));
188187

189-
/* Remove the tcb task from the ready-to-run list. */
188+
/* Remove the tcb task from the running list. */
190189

191-
switch_needed = nxsched_remove_readytorun(rtcb, true);
190+
nxsched_remove_self(rtcb);
192191

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

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

198-
/* Now, perform the context switch if one is needed */
197+
/* Now, perform the context switch */
199198

200-
if (switch_needed)
201-
{
202-
up_switch_context(this_task(), rtcb);
203-
}
199+
up_switch_context(this_task(), rtcb);
204200

205201
/* When we resume at this point, either (1) the message queue
206202
* is no longer empty, or (2) the wait has been interrupted by

sched/mqueue/mq_sndinternal.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ FAR struct mqueue_msg_s *nxmq_alloc_msg(void)
215215
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
216216
{
217217
FAR struct tcb_s *rtcb;
218-
bool switch_needed;
219218

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

272271
DEBUGASSERT(!is_idle_task(rtcb));
273272

274-
/* Remove the tcb task from the ready-to-run list. */
273+
/* Remove the tcb task from the running list. */
275274

276-
switch_needed = nxsched_remove_readytorun(rtcb, true);
275+
nxsched_remove_self(rtcb);
277276

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

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

283-
/* Now, perform the context switch if one is needed */
282+
/* Now, perform the context switch */
284283

285-
if (switch_needed)
286-
{
287-
up_switch_context(this_task(), rtcb);
288-
}
284+
up_switch_context(this_task(), rtcb);
289285

290286
/* When we resume at this point, either (1) the message queue
291287
* is no longer empty, or (2) the wait has been interrupted by

sched/mqueue/msgrcv.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct msgbuf_s **rcvmsg,
4545
FAR struct msgbuf_s *newmsg = NULL;
4646
FAR struct msgbuf_s *tmp;
4747
FAR struct tcb_s *rtcb;
48-
bool switch_needed;
4948

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

130129
DEBUGASSERT(NULL != rtcb->flink);
131130

132-
/* Remove the tcb task from the ready-to-run list. */
131+
/* Remove the tcb task from the running list. */
133132

134-
switch_needed = nxsched_remove_readytorun(rtcb, true);
133+
nxsched_remove_self(rtcb);
135134

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

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

141-
/* Now, perform the context switch if one is needed */
140+
/* Now, perform the context switch */
142141

143-
if (switch_needed)
144-
{
145-
up_switch_context(this_task(), rtcb);
146-
}
142+
up_switch_context(this_task(), rtcb);
147143

148144
/* When we resume at this point, either (1) the message queue
149145
* is no longer empty, or (2) the wait has been interrupted by

sched/mqueue/msgsnd.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)
4343
{
4444
FAR struct tcb_s *rtcb;
45-
bool switch_needed;
4645

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

9695
DEBUGASSERT(NULL != rtcb->flink);
9796

98-
/* Remove the tcb task from the ready-to-run list. */
97+
/* Remove the tcb task from the running list. */
9998

100-
switch_needed = nxsched_remove_readytorun(rtcb, true);
99+
nxsched_remove_self(rtcb);
101100

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

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

107-
/* Now, perform the context switch if one is needed */
106+
/* Now, perform the context switch */
108107

109-
if (switch_needed)
110-
{
111-
up_switch_context(this_task(), rtcb);
112-
}
108+
up_switch_context(this_task(), rtcb);
113109

114110
/* When we resume at this point, either (1) the message queue
115111
* is no longer empty, or (2) the wait has been interrupted by

sched/paging/pg_miss.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void pg_miss(void)
112112
{
113113
FAR struct tcb_s *ftcb = this_task();
114114
FAR struct tcb_s *wtcb;
115-
bool switch_needed;
116115

117116
/* Sanity checking
118117
*
@@ -138,21 +137,18 @@ void pg_miss(void)
138137

139138
DEBUGASSERT(!is_idle_task(ftcb));
140139

141-
/* Remove the tcb task from the ready-to-run list. */
140+
/* Remove the tcb task from the running list. */
142141

143-
switch_needed = nxsched_remove_readytorun(ftcb, true);
142+
nxsched_remove_self(ftcb);
144143

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

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

150-
/* Now, perform the context switch if one is needed */
149+
/* Now, perform the context switch */
151150

152-
if (switch_needed)
153-
{
154-
up_switch_context(this_task(), ftcb);
155-
}
151+
up_switch_context(this_task(), ftcb);
156152

157153
/* Boost the page fill worker thread priority.
158154
* - Check the priority of the task at the head of the g_waitingforfill

sched/sched/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ int nxthread_create(FAR const char *name, uint8_t ttype, int priority,
321321

322322
bool nxsched_add_readytorun(FAR struct tcb_s *rtrtcb);
323323
bool nxsched_remove_readytorun(FAR struct tcb_s *rtrtcb, bool merge);
324+
void nxsched_remove_self(FAR struct tcb_s *rtrtcb);
324325
bool nxsched_add_prioritized(FAR struct tcb_s *tcb, DSEG dq_queue_t *list);
325326
void nxsched_merge_prioritized(FAR dq_queue_t *list1, FAR dq_queue_t *list2,
326327
uint8_t task_state);

0 commit comments

Comments
 (0)