From 4a87578bdbdbe70a2de98a80ae0c95c6638adc84 Mon Sep 17 00:00:00 2001 From: ligd Date: Wed, 17 Aug 2022 15:55:03 +0800 Subject: [PATCH] wqueue: change single queue to double queue to improve speed Signed-off-by: ligd --- include/nuttx/wqueue.h | 2 +- libs/libc/wqueue/work_cancel.c | 12 ++++++------ libs/libc/wqueue/work_queue.c | 10 +++++----- libs/libc/wqueue/work_usrthread.c | 4 ++-- libs/libc/wqueue/wqueue.h | 2 +- sched/wqueue/kwork_cancel.c | 2 +- sched/wqueue/kwork_queue.c | 8 ++++---- sched/wqueue/kwork_thread.c | 2 +- sched/wqueue/wqueue.h | 6 +++--- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index 5bdc25e22ef..95522f109d2 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -249,7 +249,7 @@ struct work_s { struct { - struct sq_entry_s sq; /* Implements a single linked list */ + struct dq_entry_s dq; /* Implements a double linked list */ clock_t qtime; /* Time work queued */ } s; struct wdog_s timer; /* Delay expiry timer */ diff --git a/libs/libc/wqueue/work_cancel.c b/libs/libc/wqueue/work_cancel.c index 5ba5ac7fe6e..852b7418354 100644 --- a/libs/libc/wqueue/work_cancel.c +++ b/libs/libc/wqueue/work_cancel.c @@ -63,8 +63,8 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work) { - FAR sq_entry_t *prev = NULL; - FAR sq_entry_t *curr; + FAR dq_entry_t *prev = NULL; + FAR dq_entry_t *curr; int ret = -ENOENT; int semcount; @@ -82,12 +82,12 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue, if (work->worker != NULL) { /* Search the work activelist for the target work. We can't - * use sq_rem to do this because there are additional operations that + * use dq_rem to do this because there are additional operations that * need to be done. */ curr = wqueue->q.head; - while (curr && curr != &work->u.s.sq) + while (curr && curr != &work->u.s.dq) { prev = curr; curr = curr->flink; @@ -105,13 +105,13 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue, { /* Remove the work from mid- or end-of-queue */ - sq_remafter(prev, &wqueue->q); + dq_remafter(prev, &wqueue->q); } else { /* Remove the work at the head of the queue */ - sq_remfirst(&wqueue->q); + dq_remfirst(&wqueue->q); _SEM_GETVALUE(&wqueue->wake, &semcount); if (semcount < 1) { diff --git a/libs/libc/wqueue/work_queue.c b/libs/libc/wqueue/work_queue.c index 492df4c8ebe..00c5c1aa8a5 100644 --- a/libs/libc/wqueue/work_queue.c +++ b/libs/libc/wqueue/work_queue.c @@ -75,8 +75,8 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, FAR struct work_s *work, worker_t worker, FAR void *arg, clock_t delay) { - FAR sq_entry_t *prev = NULL; - FAR sq_entry_t *curr; + FAR dq_entry_t *prev = NULL; + FAR dq_entry_t *curr; sclock_t delta; int semcount; @@ -96,7 +96,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, { /* Add the watchdog to the head == tail of the queue. */ - sq_addfirst(&work->u.s.sq, &wqueue->q); + dq_addfirst(&work->u.s.dq, &wqueue->q); _SEM_POST(&wqueue->wake); } @@ -127,7 +127,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, { /* Insert the watchdog at the head of the list */ - sq_addfirst(&work->u.s.sq, &wqueue->q); + dq_addfirst(&work->u.s.dq, &wqueue->q); _SEM_GETVALUE(&wqueue->wake, &semcount); if (semcount < 1) { @@ -138,7 +138,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue, { /* Insert the watchdog in mid- or end-of-queue */ - sq_addafter(prev, &work->u.s.sq, &wqueue->q); + dq_addafter(prev, &work->u.s.dq, &wqueue->q); } } diff --git a/libs/libc/wqueue/work_usrthread.c b/libs/libc/wqueue/work_usrthread.c index 41831f2d07a..f19fdf6f1a6 100644 --- a/libs/libc/wqueue/work_usrthread.c +++ b/libs/libc/wqueue/work_usrthread.c @@ -127,7 +127,7 @@ static void work_process(FAR struct usr_wqueue_s *wqueue) { /* Remove the ready-to-execute work from the list */ - sq_remfirst(&wqueue->q); + dq_remfirst(&wqueue->q); /* Extract the work description from the entry (in case the work * instance by the re-used after it has been de-queued). @@ -288,7 +288,7 @@ int work_usrstart(void) /* Initialize the work queue */ - sq_init(&g_usrwork.q); + dq_init(&g_usrwork.q); #ifdef CONFIG_BUILD_PROTECTED diff --git a/libs/libc/wqueue/wqueue.h b/libs/libc/wqueue/wqueue.h index e8b5d36a124..1d6280288c4 100644 --- a/libs/libc/wqueue/wqueue.h +++ b/libs/libc/wqueue/wqueue.h @@ -46,7 +46,7 @@ struct usr_wqueue_s { - struct sq_queue_s q; /* The queue of pending work */ + struct dq_queue_s q; /* The queue of pending work */ sem_t lock; /* exclusive access to user-mode work queue */ sem_t wake; /* The wake-up semaphore of the usrthread */ }; diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index b5936b54e3a..6bab1e76f29 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -87,7 +87,7 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, } else { - sq_rem((FAR sq_entry_t *)work, &wqueue->q); + dq_rem((FAR dq_entry_t *)work, &wqueue->q); } work->worker = NULL; diff --git a/sched/wqueue/kwork_queue.c b/sched/wqueue/kwork_queue.c index 159fc6c285e..2a62b68b83b 100644 --- a/sched/wqueue/kwork_queue.c +++ b/sched/wqueue/kwork_queue.c @@ -50,7 +50,7 @@ static void hp_work_timer_expiry(wdparm_t arg) { irqstate_t flags = enter_critical_section(); - sq_addlast((FAR sq_entry_t *)arg, &g_hpwork.q); + dq_addlast((FAR dq_entry_t *)arg, &g_hpwork.q); nxsem_post(&g_hpwork.sem); leave_critical_section(flags); } @@ -64,7 +64,7 @@ static void hp_work_timer_expiry(wdparm_t arg) static void lp_work_timer_expiry(wdparm_t arg) { irqstate_t flags = enter_critical_section(); - sq_addlast((FAR sq_entry_t *)arg, &g_lpwork.q); + dq_addlast((FAR dq_entry_t *)arg, &g_lpwork.q); nxsem_post(&g_lpwork.sem); leave_critical_section(flags); } @@ -134,7 +134,7 @@ int work_queue(int qid, FAR struct work_s *work, worker_t worker, if (!delay) { - sq_addlast((FAR sq_entry_t *)work, &g_hpwork.q); + dq_addlast((FAR dq_entry_t *)work, &g_hpwork.q); nxsem_post(&g_hpwork.sem); } else @@ -152,7 +152,7 @@ int work_queue(int qid, FAR struct work_s *work, worker_t worker, if (!delay) { - sq_addlast((FAR sq_entry_t *)work, &g_lpwork.q); + dq_addlast((FAR dq_entry_t *)work, &g_lpwork.q); nxsem_post(&g_lpwork.sem); } else diff --git a/sched/wqueue/kwork_thread.c b/sched/wqueue/kwork_thread.c index 081278ffcf6..04c3d3985ce 100644 --- a/sched/wqueue/kwork_thread.c +++ b/sched/wqueue/kwork_thread.c @@ -153,7 +153,7 @@ static int work_thread(int argc, FAR char *argv[]) /* Remove the ready-to-execute work from the list */ - work = (FAR struct work_s *)sq_remfirst(&wqueue->q); + work = (FAR struct work_s *)dq_remfirst(&wqueue->q); if (work && work->worker) { /* Extract the work description from the entry (in case the work diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h index 399a3fbddc7..48b49da2cc5 100644 --- a/sched/wqueue/wqueue.h +++ b/sched/wqueue/wqueue.h @@ -58,7 +58,7 @@ struct kworker_s struct kwork_wqueue_s { - struct sq_queue_s q; /* The queue of pending work */ + struct dq_queue_s q; /* The queue of pending work */ sem_t sem; /* The counting semaphore of the wqueue */ struct kworker_s worker[1]; /* Describes a worker thread */ }; @@ -70,7 +70,7 @@ struct kwork_wqueue_s #ifdef CONFIG_SCHED_HPWORK struct hp_wqueue_s { - struct sq_queue_s q; /* The queue of pending work */ + struct dq_queue_s q; /* The queue of pending work */ sem_t sem; /* The counting semaphore of the wqueue */ /* Describes each thread in the high priority queue's thread pool */ @@ -86,7 +86,7 @@ struct hp_wqueue_s #ifdef CONFIG_SCHED_LPWORK struct lp_wqueue_s { - struct sq_queue_s q; /* The queue of pending work */ + struct dq_queue_s q; /* The queue of pending work */ sem_t sem; /* The counting semaphore of the wqueue */ /* Describes each thread in the low priority queue's thread pool */