aboutsummaryrefslogtreecommitdiff
path: root/qemu-coroutine.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2013-09-11 16:42:35 +0200
committerKevin Wolf <kwolf@redhat.com>2013-09-12 10:12:48 +0200
commit70c60c089fdc6bf8a79324e492c13e8c08d55942 (patch)
tree03f26370db88432b5808f3a6a5c3c4bce229eaf5 /qemu-coroutine.c
parent2c78857bf6a9b5d06e17533b8f40fee14e087987 (diff)
coroutine: add ./configure --disable-coroutine-pool
The 'gthread' coroutine backend was written before the freelist (aka pool) existed in qemu-coroutine.c. This means that every thread is expected to exit when its coroutine terminates. It is not possible to reuse threads from a pool. This patch automatically disables the pool when 'gthread' is used. This allows the 'gthread' backend to work again (for example, tests/test-coroutine completes successfully instead of hanging). I considered implementing thread reuse but I don't want quirks like CPU affinity differences due to coroutine threads being recycled. The 'gthread' backend is a reference backend and it's therefore okay to skip the pool optimization. Note this patch also makes it easy to toggle the pool for benchmarking purposes: ./configure --with-coroutine-backend=ucontext \ --disable-coroutine-pool Reported-by: Gabriel Kerneis <gabriel@kerneis.info> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Gabriel Kerneis <gabriel@kerneis.info> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-coroutine.c')
-rw-r--r--qemu-coroutine.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/qemu-coroutine.c b/qemu-coroutine.c
index 423430d3a0..470852100a 100644
--- a/qemu-coroutine.c
+++ b/qemu-coroutine.c
@@ -30,15 +30,17 @@ static unsigned int pool_size;
Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
{
- Coroutine *co;
-
- qemu_mutex_lock(&pool_lock);
- co = QSLIST_FIRST(&pool);
- if (co) {
- QSLIST_REMOVE_HEAD(&pool, pool_next);
- pool_size--;
+ Coroutine *co = NULL;
+
+ if (CONFIG_COROUTINE_POOL) {
+ qemu_mutex_lock(&pool_lock);
+ co = QSLIST_FIRST(&pool);
+ if (co) {
+ QSLIST_REMOVE_HEAD(&pool, pool_next);
+ pool_size--;
+ }
+ qemu_mutex_unlock(&pool_lock);
}
- qemu_mutex_unlock(&pool_lock);
if (!co) {
co = qemu_coroutine_new();
@@ -51,15 +53,17 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
static void coroutine_delete(Coroutine *co)
{
- qemu_mutex_lock(&pool_lock);
- if (pool_size < POOL_MAX_SIZE) {
- QSLIST_INSERT_HEAD(&pool, co, pool_next);
- co->caller = NULL;
- pool_size++;
+ if (CONFIG_COROUTINE_POOL) {
+ qemu_mutex_lock(&pool_lock);
+ if (pool_size < POOL_MAX_SIZE) {
+ QSLIST_INSERT_HEAD(&pool, co, pool_next);
+ co->caller = NULL;
+ pool_size++;
+ qemu_mutex_unlock(&pool_lock);
+ return;
+ }
qemu_mutex_unlock(&pool_lock);
- return;
}
- qemu_mutex_unlock(&pool_lock);
qemu_coroutine_delete(co);
}