You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/28 10:08:44 UTC
[incubator-nuttx] 02/02: sched: mqueue wait list optimize
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 85d013f69a3fc26500fcf7e0782c97d3d6adb843
Author: zhangyuan21 <zh...@xiaomi.com>
AuthorDate: Fri Sep 9 14:26:43 2022 +0800
sched: mqueue wait list optimize
---
include/nuttx/mqueue.h | 5 +++++
sched/init/nx_start.c | 24 ++++--------------------
sched/mqueue/mq_msgqalloc.c | 3 +++
sched/mqueue/mq_rcvinternal.c | 8 ++------
sched/mqueue/mq_sndinternal.c | 8 ++------
sched/sched/sched.h | 16 ----------------
6 files changed, 16 insertions(+), 48 deletions(-)
diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h
index b6673a3b73..191b193a7e 100644
--- a/include/nuttx/mqueue.h
+++ b/include/nuttx/mqueue.h
@@ -85,6 +85,9 @@
# define nxmq_pollnotify(msgq, eventset)
#endif
+# define MQ_WNELIST(mq) (&((mq)->waitfornotempty))
+# define MQ_WNFLIST(mq) (&((mq)->waitfornotfull))
+
/****************************************************************************
* Public Type Declarations
****************************************************************************/
@@ -94,6 +97,8 @@
struct mqueue_inode_s
{
FAR struct inode *inode; /* Containing inode */
+ dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+ dq_queue_t waitfornotfull; /* Task list waiting for not full */
struct list_node msglist; /* Prioritized message list */
int16_t maxmsgs; /* Maximum number of messages in the queue */
int16_t nmsgs; /* Number of message in the queue */
diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c
index 4be3b50750..3d329194a6 100644
--- a/sched/init/nx_start.c
+++ b/sched/init/nx_start.c
@@ -138,22 +138,6 @@ dq_queue_t g_pendingtasks;
dq_queue_t g_waitingforsignal;
-#ifndef CONFIG_DISABLE_MQUEUE
-/* This is the list of all tasks that are blocked waiting for a message
- * queue to become non-empty.
- */
-
-dq_queue_t g_waitingformqnotempty;
-#endif
-
-#ifndef CONFIG_DISABLE_MQUEUE
-/* This is the list of all tasks that are blocked waiting for a message
- * queue to become non-full.
- */
-
-dq_queue_t g_waitingformqnotfull;
-#endif
-
#ifdef CONFIG_PAGING
/* This is the list of all tasks that are blocking waiting for a page fill */
@@ -243,12 +227,12 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] =
#ifndef CONFIG_DISABLE_MQUEUE
,
{ /* TSTATE_WAIT_MQNOTEMPTY */
- &g_waitingformqnotempty,
- TLIST_ATTR_PRIORITIZED
+ (FAR void *)offsetof(struct mqueue_inode_s, waitfornotempty),
+ TLIST_ATTR_PRIORITIZED | TLIST_ATTR_OFFSET
},
{ /* TSTATE_WAIT_MQNOTFULL */
- &g_waitingformqnotfull,
- TLIST_ATTR_PRIORITIZED
+ (FAR void *)offsetof(struct mqueue_inode_s, waitfornotfull),
+ TLIST_ATTR_PRIORITIZED | TLIST_ATTR_OFFSET
}
#endif
#ifdef CONFIG_PAGING
diff --git a/sched/mqueue/mq_msgqalloc.c b/sched/mqueue/mq_msgqalloc.c
index a2faf54788..0728278b74 100644
--- a/sched/mqueue/mq_msgqalloc.c
+++ b/sched/mqueue/mq_msgqalloc.c
@@ -101,6 +101,9 @@ int nxmq_alloc_msgq(FAR struct mq_attr *attr,
#ifndef CONFIG_DISABLE_MQUEUE_NOTIFICATION
msgq->ntpid = INVALID_PROCESS_ID;
#endif
+
+ dq_init(&msgq->waitfornotempty);
+ dq_init(&msgq->waitfornotfull);
}
else
{
diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c
index c704576af7..328c21bf87 100644
--- a/sched/mqueue/mq_rcvinternal.c
+++ b/sched/mqueue/mq_rcvinternal.c
@@ -280,16 +280,12 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
if (msgq->nwaitnotfull > 0)
{
/* Find the highest priority task that is waiting for
- * this queue to be not-full in g_waitingformqnotfull list.
+ * this queue to be not-full in waitfornotfull list.
* This must be performed in a critical section because
* messages can be sent from interrupt handlers.
*/
- for (btcb = (FAR struct tcb_s *)g_waitingformqnotfull.head;
- btcb && btcb->waitobj != msgq;
- btcb = btcb->flink)
- {
- }
+ btcb = (FAR struct tcb_s *)dq_peek(MQ_WNFLIST(msgq));
/* If one was found, unblock it. NOTE: There is a race
* condition here: the queue might be full again by the
diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c
index af1e3eb44d..5ec5d2ba80 100644
--- a/sched/mqueue/mq_sndinternal.c
+++ b/sched/mqueue/mq_sndinternal.c
@@ -389,17 +389,13 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
if (msgq->nwaitnotempty > 0)
{
/* Find the highest priority task that is waiting for
- * this queue to be non-empty in g_waitingformqnotempty
+ * this queue to be non-empty in waitfornotempty
* list. leave_critical_section() should give us sufficient
* protection since interrupts should never cause a change
* in this list
*/
- for (btcb = (FAR struct tcb_s *)g_waitingformqnotempty.head;
- btcb && btcb->waitobj != msgq;
- btcb = btcb->flink)
- {
- }
+ btcb = (FAR struct tcb_s *)dq_peek(MQ_WNELIST(msgq));
/* If one was found, unblock it */
diff --git a/sched/sched/sched.h b/sched/sched/sched.h
index 82454fae1c..c876eb205b 100644
--- a/sched/sched/sched.h
+++ b/sched/sched/sched.h
@@ -178,22 +178,6 @@ extern dq_queue_t g_pendingtasks;
extern dq_queue_t g_waitingforsignal;
-/* This is the list of all tasks that are blocked waiting for a message
- * queue to become non-empty.
- */
-
-#ifndef CONFIG_DISABLE_MQUEUE
-extern dq_queue_t g_waitingformqnotempty;
-#endif
-
-/* This is the list of all tasks that are blocked waiting for a message
- * queue to become non-full.
- */
-
-#ifndef CONFIG_DISABLE_MQUEUE
-extern dq_queue_t g_waitingformqnotfull;
-#endif
-
/* This is the list of all tasks that are blocking waiting for a page fill */
#ifdef CONFIG_PAGING