From f3ff911f3cfeb6af3e32513c4301be389a936d76 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 13 Jul 2013 10:32:46 +0000 Subject: ioq: set contended flag if we are the last one acquiring the lock We could be completely out of threads upon acquiring an ioq, so the last thread to acquire a lock slot must trigger a yield soon to avoid starvation and fairness issues. Otherwise, all threads for a given device could remained pinned indefinitely. --- ioq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ioq.c b/ioq.c index 0a32c71..772da38 100644 --- a/ioq.c +++ b/ioq.c @@ -46,8 +46,14 @@ bool mog_ioq_ready(struct mog_ioq *ioq, struct mog_fd *client_mfd) CHECK(int, 0, pthread_mutex_lock(&ioq->mtx)); good = ioq->cur > 0; - if (good) { /* uncontended case is simple */ - ioq->cur--; + if (good) { + /* + * assume the worst when we are the last one to + * acquire a free slot + */ + if (--ioq->cur == 0) + ioq_set_contended(ioq); + mog_ioq_current = ioq; } else { client_mfd->ioq_blocked = 1; -- cgit v1.2.3-24-ge0c7