revert waiting-queue optimization (#19301)
Costa Tsaousis committed
Dec 30, 2024 at 22:03 UTC
799f45cdd6b5e159a8ac09fe8a4e31689b18e160
1 file changed
+6
-4
src/libnetdata/waiting-queue/waiting-queue.c
+6
-4
@@ -70,6 +70,7 @@ struct waiting_queue {
70
Word_t last_seqno; // incrementing sequence counter
71
SPINLOCK spinlock; // ensures there is only 1 runner at a time
72
REFCOUNT running; // number of threads, including the one holding the lock
73
+ pid_t writer;
74
WAITING_THREAD *list; // the list of threads waiting, not including the 1 holding the lock
75
};
76
@@ -185,6 +186,7 @@ usec_t waiting_queue_acquire(WAITING_QUEUE *wq, WAITING_QUEUE_PRIORITY priority)
186
WQ_COND_wait(&wt.cond, &wq->mutex);
187
} while(true);
188
189
+ wq->writer = gettid_cached();
190
WAITERS_DEL(wq, &wt);
191
WQ_MUTEX_unlock(&wq->mutex);
192
WAITING_THREAD_cleanup(wq, &wt);
@@ -193,11 +195,12 @@ usec_t waiting_queue_acquire(WAITING_QUEUE *wq, WAITING_QUEUE_PRIORITY priority)
195
}
196
197
void waiting_queue_release(WAITING_QUEUE *wq) {
198
+ wq->writer = 0;
199
+ spinlock_unlock(&wq->spinlock);
200
+
201
// Fast path if we're alone
197
- if(__atomic_sub_fetch(&wq->running, 1, __ATOMIC_RELAXED) == 0) {
198
- spinlock_unlock(&wq->spinlock);
202
+ if(__atomic_sub_fetch(&wq->running, 1, __ATOMIC_RELAXED) == 0)
203
return;
200
- }
204
205
// Slow path - need to signal next in line
206
WQ_MUTEX_lock(&wq->mutex);
@@ -206,7 +209,6 @@ void waiting_queue_release(WAITING_QUEUE *wq) {
209
if(wq->list)
210
WQ_COND_signal(&wq->list->cond);
211
209
- spinlock_unlock(&wq->spinlock);
212
WQ_MUTEX_unlock(&wq->mutex);
213
}
214