mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
wqueue: change single queue to double queue to improve speed
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 */
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user