[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 24/25] thread-pool: avoid per-thread-pool EventNoti
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 24/25] thread-pool: avoid per-thread-pool EventNotifier |
Date: |
Wed, 27 Aug 2014 12:36:21 -0500 |
From: Stefan Hajnoczi <address@hidden>
EventNotifier is implemented using an eventfd or pipe. It therefore
consumes file descriptors, which can be limited by rlimits and should
therefore be used sparingly.
Switch from EventNotifier to QEMUBH in thread-pool.c. Originally
EventNotifier was used because qemu_bh_schedule() was not thread-safe
yet.
Reported-by: Christian Borntraeger <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
(cherry picked from commit c2e50e3d11a0bf4c973cc30478c1af0f2d5f8e81)
Signed-off-by: Michael Roth <address@hidden>
---
thread-pool.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/thread-pool.c b/thread-pool.c
index dfb699d..4cfd078 100644
--- a/thread-pool.c
+++ b/thread-pool.c
@@ -21,7 +21,6 @@
#include "block/coroutine.h"
#include "trace.h"
#include "block/block_int.h"
-#include "qemu/event_notifier.h"
#include "block/thread-pool.h"
#include "qemu/main-loop.h"
@@ -57,8 +56,8 @@ struct ThreadPoolElement {
};
struct ThreadPool {
- EventNotifier notifier;
AioContext *ctx;
+ QEMUBH *completion_bh;
QemuMutex lock;
QemuCond check_cancel;
QemuCond worker_stopped;
@@ -119,7 +118,7 @@ static void *worker_thread(void *opaque)
qemu_cond_broadcast(&pool->check_cancel);
}
- event_notifier_set(&pool->notifier);
+ qemu_bh_schedule(pool->completion_bh);
}
pool->cur_threads--;
@@ -168,12 +167,11 @@ static void spawn_thread(ThreadPool *pool)
}
}
-static void event_notifier_ready(EventNotifier *notifier)
+static void thread_pool_completion_bh(void *opaque)
{
- ThreadPool *pool = container_of(notifier, ThreadPool, notifier);
+ ThreadPool *pool = opaque;
ThreadPoolElement *elem, *next;
- event_notifier_test_and_clear(notifier);
restart:
QLIST_FOREACH_SAFE(elem, &pool->head, all, next) {
if (elem->state != THREAD_CANCELED && elem->state != THREAD_DONE) {
@@ -215,7 +213,7 @@ static void thread_pool_cancel(BlockDriverAIOCB *acb)
qemu_sem_timedwait(&pool->sem, 0) == 0) {
QTAILQ_REMOVE(&pool->request_list, elem, reqs);
elem->state = THREAD_CANCELED;
- event_notifier_set(&pool->notifier);
+ qemu_bh_schedule(pool->completion_bh);
} else {
pool->pending_cancellations++;
while (elem->state != THREAD_CANCELED && elem->state != THREAD_DONE) {
@@ -224,7 +222,7 @@ static void thread_pool_cancel(BlockDriverAIOCB *acb)
pool->pending_cancellations--;
}
qemu_mutex_unlock(&pool->lock);
- event_notifier_ready(&pool->notifier);
+ thread_pool_completion_bh(pool);
}
static const AIOCBInfo thread_pool_aiocb_info = {
@@ -293,8 +291,8 @@ static void thread_pool_init_one(ThreadPool *pool,
AioContext *ctx)
}
memset(pool, 0, sizeof(*pool));
- event_notifier_init(&pool->notifier, false);
pool->ctx = ctx;
+ pool->completion_bh = aio_bh_new(ctx, thread_pool_completion_bh, pool);
qemu_mutex_init(&pool->lock);
qemu_cond_init(&pool->check_cancel);
qemu_cond_init(&pool->worker_stopped);
@@ -304,8 +302,6 @@ static void thread_pool_init_one(ThreadPool *pool,
AioContext *ctx)
QLIST_INIT(&pool->head);
QTAILQ_INIT(&pool->request_list);
-
- aio_set_event_notifier(ctx, &pool->notifier, event_notifier_ready);
}
ThreadPool *thread_pool_new(AioContext *ctx)
@@ -339,11 +335,10 @@ void thread_pool_free(ThreadPool *pool)
qemu_mutex_unlock(&pool->lock);
- aio_set_event_notifier(pool->ctx, &pool->notifier, NULL);
+ qemu_bh_delete(pool->completion_bh);
qemu_sem_destroy(&pool->sem);
qemu_cond_destroy(&pool->check_cancel);
qemu_cond_destroy(&pool->worker_stopped);
qemu_mutex_destroy(&pool->lock);
- event_notifier_cleanup(&pool->notifier);
g_free(pool);
}
--
1.9.1
- [Qemu-stable] [PATCH 01/25] qmp: hide "hotplugged" device property from device-list-properties, (continued)
- [Qemu-stable] [PATCH 01/25] qmp: hide "hotplugged" device property from device-list-properties, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 15/25] arm/virt: Use PSCI v0.2 function IDs in the DT when KVM uses PSCI v0.2, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 17/25] raw-posix: fix O_DIRECT short reads, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 16/25] block/iscsi: fix memory corruption on iscsi resize, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 19/25] blkdebug: Delete BH in bdrv_aio_cancel, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 18/25] qemu-iotests: add test case 101 for short file I/O, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 21/25] hostmem: set MPOL_MF_MOVE, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 20/25] vmxnet3: Pad short frames to minimum size (60 bytes), Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 23/25] pc: reserve more memory for ACPI for new machine types, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 25/25] thread-pool: avoid deadlock in nested aio_poll() calls, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 24/25] thread-pool: avoid per-thread-pool EventNotifier,
Michael Roth <=
- [Qemu-stable] [PATCH 14/25] target-arm: Rename QEMU PSCI v0.1 definitions, Michael Roth, 2014/08/27
- [Qemu-stable] [PATCH 22/25] pcihp: fix possible array out of bounds, Michael Roth, 2014/08/27
- Re: [Qemu-stable] [Qemu-devel] Patch Round-up for stable 2.1.1, freeze on 2014-09-03, zhanghailiang, 2014/08/28
- Re: [Qemu-stable] Patch Round-up for stable 2.1.1, freeze on 2014-09-03, Paolo Bonzini, 2014/08/29