Message ID | 20220323171751.78612-8-philippe.mathieu.daude@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | accel: Fix vCPU memory leaks | expand |
On 3/23/22 10:17, Philippe Mathieu-Daudé wrote: > From: Philippe Mathieu-Daudé <f4bug@amsat.org> > > Introduce precheck/postcheck handlers which will help to > refactor code common to the various create_vcpu_thread() > implementations. > > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > include/sysemu/accel-ops.h | 4 ++++ > softmmu/cpus.c | 8 +++++++- > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h > index 6013c9444c..26b542d35c 100644 > --- a/include/sysemu/accel-ops.h > +++ b/include/sysemu/accel-ops.h > @@ -31,6 +31,10 @@ struct AccelOpsClass { > bool (*cpus_are_resettable)(void); > > void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ > + /* If non-NULL, return whether common vCPU thread must be created */ > + bool (*create_vcpu_thread_precheck)(CPUState *cpu); > + void (*create_vcpu_thread_postcheck)(CPUState *cpu); I don't think this is the correct trade-off. These new hooks are only used by rr, and at least in this patch set, incorrectly. I think you should keep the single create_vcpu_thread hook, and if null, use your new common_vcpu_thread_create. Leave rr to be the single accel setting the hook, and then it's easier not to break rr during the reorg as well. r~
diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index 6013c9444c..26b542d35c 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -31,6 +31,10 @@ struct AccelOpsClass { bool (*cpus_are_resettable)(void); void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ + /* If non-NULL, return whether common vCPU thread must be created */ + bool (*create_vcpu_thread_precheck)(CPUState *cpu); + void (*create_vcpu_thread_postcheck)(CPUState *cpu); + void (*kick_vcpu_thread)(CPUState *cpu); bool (*cpu_thread_is_idle)(CPUState *cpu); diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 7b75bb66d5..857e2081ba 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -637,7 +637,13 @@ void qemu_init_vcpu(CPUState *cpu) /* accelerators all implement the AccelOpsClass */ g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL); - cpus_accel->create_vcpu_thread(cpu); + if (cpus_accel->create_vcpu_thread_precheck == NULL + || cpus_accel->create_vcpu_thread_precheck(cpu)) { + cpus_accel->create_vcpu_thread(cpu); + } + if (cpus_accel->create_vcpu_thread_postcheck) { + cpus_accel->create_vcpu_thread_postcheck(cpu); + } while (!cpu->created) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);