mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: task: turn the WQ lock to an RW_LOCK
For now it's exclusively used as a write lock though, thus it remains 100% equivalent to the spinlock it replaces.
This commit is contained in:
parent
186e96ece0
commit
ef28dc11e3
@ -102,7 +102,7 @@ extern int global_rqueue_size; /* Number of element sin the global runqueue */
|
|||||||
extern struct task_per_thread task_per_thread[MAX_THREADS];
|
extern struct task_per_thread task_per_thread[MAX_THREADS];
|
||||||
|
|
||||||
__decl_hathreads(extern HA_SPINLOCK_T rq_lock); /* spin lock related to run queue */
|
__decl_hathreads(extern HA_SPINLOCK_T rq_lock); /* spin lock related to run queue */
|
||||||
__decl_hathreads(extern HA_SPINLOCK_T wq_lock); /* spin lock related to wait queue */
|
__decl_hathreads(extern HA_RWLOCK_T wq_lock); /* RW lock related to the wait queue */
|
||||||
|
|
||||||
|
|
||||||
static inline void task_insert_into_tasklet_list(struct task *t);
|
static inline void task_insert_into_tasklet_list(struct task *t);
|
||||||
@ -180,10 +180,10 @@ static inline struct task *task_unlink_wq(struct task *t)
|
|||||||
if (likely(task_in_wq(t))) {
|
if (likely(task_in_wq(t))) {
|
||||||
locked = atleast2(t->thread_mask);
|
locked = atleast2(t->thread_mask);
|
||||||
if (locked)
|
if (locked)
|
||||||
HA_SPIN_LOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
__task_unlink_wq(t);
|
__task_unlink_wq(t);
|
||||||
if (locked)
|
if (locked)
|
||||||
HA_SPIN_UNLOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRUNLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@ -400,10 +400,10 @@ static inline void task_queue(struct task *task)
|
|||||||
|
|
||||||
#ifdef USE_THREAD
|
#ifdef USE_THREAD
|
||||||
if (atleast2(task->thread_mask)) {
|
if (atleast2(task->thread_mask)) {
|
||||||
HA_SPIN_LOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
if (!task_in_wq(task) || tick_is_lt(task->expire, task->wq.key))
|
if (!task_in_wq(task) || tick_is_lt(task->expire, task->wq.key))
|
||||||
__task_queue(task, &timers);
|
__task_queue(task, &timers);
|
||||||
HA_SPIN_UNLOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRUNLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -424,14 +424,15 @@ static inline void task_schedule(struct task *task, int when)
|
|||||||
|
|
||||||
#ifdef USE_THREAD
|
#ifdef USE_THREAD
|
||||||
if (atleast2(task->thread_mask)) {
|
if (atleast2(task->thread_mask)) {
|
||||||
HA_SPIN_LOCK(TASK_WQ_LOCK, &wq_lock);
|
/* FIXME: is it really needed to lock the WQ during the check ? */
|
||||||
|
HA_RWLOCK_WRLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
if (task_in_wq(task))
|
if (task_in_wq(task))
|
||||||
when = tick_first(when, task->expire);
|
when = tick_first(when, task->expire);
|
||||||
|
|
||||||
task->expire = when;
|
task->expire = when;
|
||||||
if (!task_in_wq(task) || tick_is_lt(task->expire, task->wq.key))
|
if (!task_in_wq(task) || tick_is_lt(task->expire, task->wq.key))
|
||||||
__task_queue(task, &timers);
|
__task_queue(task, &timers);
|
||||||
HA_SPIN_UNLOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRUNLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ unsigned int niced_tasks = 0; /* number of niced tasks in the run queue */
|
|||||||
THREAD_LOCAL struct task *curr_task = NULL; /* task currently running or NULL */
|
THREAD_LOCAL struct task *curr_task = NULL; /* task currently running or NULL */
|
||||||
|
|
||||||
__decl_aligned_spinlock(rq_lock); /* spin lock related to run queue */
|
__decl_aligned_spinlock(rq_lock); /* spin lock related to run queue */
|
||||||
__decl_aligned_spinlock(wq_lock); /* spin lock related to wait queue */
|
__decl_aligned_rwlock(wq_lock); /* RW lock related to the wait queue */
|
||||||
|
|
||||||
#ifdef USE_THREAD
|
#ifdef USE_THREAD
|
||||||
struct eb_root timers; /* sorted timers tree, global */
|
struct eb_root timers; /* sorted timers tree, global */
|
||||||
@ -211,7 +211,7 @@ int wake_expired_tasks()
|
|||||||
|
|
||||||
#ifdef USE_THREAD
|
#ifdef USE_THREAD
|
||||||
while (1) {
|
while (1) {
|
||||||
HA_SPIN_LOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
lookup_next:
|
lookup_next:
|
||||||
eb = eb32_lookup_ge(&timers, now_ms - TIMER_LOOK_BACK);
|
eb = eb32_lookup_ge(&timers, now_ms - TIMER_LOOK_BACK);
|
||||||
if (!eb) {
|
if (!eb) {
|
||||||
@ -253,10 +253,10 @@ int wake_expired_tasks()
|
|||||||
goto lookup_next;
|
goto lookup_next;
|
||||||
}
|
}
|
||||||
task_wakeup(task, TASK_WOKEN_TIMER);
|
task_wakeup(task, TASK_WOKEN_TIMER);
|
||||||
HA_SPIN_UNLOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRUNLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
HA_SPIN_UNLOCK(TASK_WQ_LOCK, &wq_lock);
|
HA_RWLOCK_WRUNLOCK(TASK_WQ_LOCK, &wq_lock);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user