* [Qemu-devel] [PATCH 0/2] Hook into vcpu creation
@ 2008-12-30 14:52 Glauber Costa
2008-12-30 14:52 ` [Qemu-devel] [PATCH 1/2] simplify cpu_x86_register Glauber Costa
0 siblings, 1 reply; 3+ messages in thread
From: Glauber Costa @ 2008-12-30 14:52 UTC (permalink / raw)
To: qemu-devel; +Cc: Ian.Jackson, avi, kvm, stefano.stabellini
Hello fellow 2008-ers, soon to be 2009-ers.
It's time to say goodbye to the year that goes, which I do
by sending the last small series of the year.
This is another hook proposal for kvm, still in the ways to
make tcg optional.
I'm hooking vcpu creation in order to avoid tcg initialization
routines. In yet to be posted patches after those ones, I'm able
to get rid of most of cpu_exec_init_all, one of the main external
functions from exec.c
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 1/2] simplify cpu_x86_register
2008-12-30 14:52 [Qemu-devel] [PATCH 0/2] Hook into vcpu creation Glauber Costa
@ 2008-12-30 14:52 ` Glauber Costa
2008-12-30 14:52 ` [Qemu-devel] [PATCH 2/2] hook into vcpu creation Glauber Costa
0 siblings, 1 reply; 3+ messages in thread
From: Glauber Costa @ 2008-12-30 14:52 UTC (permalink / raw)
To: qemu-devel; +Cc: Ian.Jackson, avi, kvm, stefano.stabellini
We don't need to pass the model string by parameter,
since it ough to be part of the CPUState anyway at
the call time. Also, don't declare it as static,
so kvm can call it in the future.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
target-i386/cpu.h | 2 ++
target-i386/helper.c | 5 +++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index ce9b3fe..5235919 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -643,6 +643,8 @@ typedef struct CPUX86State {
} CPUX86State;
CPUX86State *cpu_x86_init(const char *cpu_model);
+int cpu_x86_register (CPUX86State *env);
+
int cpu_x86_exec(CPUX86State *s);
void cpu_x86_close(CPUX86State *s);
void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt,
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 7d3321a..1389a0a 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -368,9 +368,10 @@ void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
(*cpu_fprintf)(f, "x86 %16s\n", x86_defs[i].name);
}
-static int cpu_x86_register (CPUX86State *env, const char *cpu_model)
+int cpu_x86_register (CPUX86State *env)
{
x86_def_t def1, *def = &def1;
+ const char *cpu_model = env->cpu_model_str;
if (cpu_x86_find_by_name(def, cpu_model) < 0)
return -1;
@@ -1626,7 +1627,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
cpu_set_debug_excp_handler(breakpoint_handler);
#endif
}
- if (cpu_x86_register(env, cpu_model) < 0) {
+ if (cpu_x86_register(env) < 0) {
cpu_x86_close(env);
return NULL;
}
--
1.5.6.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] hook into vcpu creation
2008-12-30 14:52 ` [Qemu-devel] [PATCH 1/2] simplify cpu_x86_register Glauber Costa
@ 2008-12-30 14:52 ` Glauber Costa
0 siblings, 0 replies; 3+ messages in thread
From: Glauber Costa @ 2008-12-30 14:52 UTC (permalink / raw)
To: qemu-devel; +Cc: Ian.Jackson, avi, kvm, stefano.stabellini
Allow kvm to override vcpu creation. We need to grab
a minimal amount of code that is shared, but the big
part is highly kvm/tcg specific.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
kvm-all.c | 18 ++++++++++++++----
kvm.h | 2 +-
target-i386/helper.c | 12 +++++++++---
target-i386/kvm.c | 5 +++++
4 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index a279d6c..ebad664 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -104,12 +104,19 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)
}
-int kvm_init_vcpu(CPUState *env)
+CPUState *kvm_init_vcpu(const char *cpu_model)
{
KVMState *s = kvm_state;
long mmap_size;
int ret;
+ CPUState *env = qemu_mallocz(sizeof(*env));
+ if (!env)
+ return NULL;
+
+ cpu_exec_init(env);
+ env->cpu_model_str = cpu_model;
+
dprintf("kvm_init_vcpu\n");
ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index);
@@ -135,10 +142,13 @@ int kvm_init_vcpu(CPUState *env)
goto err;
}
- ret = kvm_arch_init_vcpu(env);
-
+ if (kvm_arch_init_vcpu(env))
+ goto err;
+
+ return env;
err:
- return ret;
+ qemu_free(env);
+ return NULL;
}
int kvm_sync_vcpus(void)
diff --git a/kvm.h b/kvm.h
index efce145..4ea679f 100644
--- a/kvm.h
+++ b/kvm.h
@@ -30,7 +30,7 @@ struct kvm_run;
int kvm_init(int smp_cpus);
-int kvm_init_vcpu(CPUState *env);
+CPUState *kvm_init_vcpu(const char *cpu_model);
int kvm_sync_vcpus(void);
int kvm_cpu_exec(CPUState *env);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 1389a0a..d8bed46 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1607,7 +1607,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
}
}
-CPUX86State *cpu_x86_init(const char *cpu_model)
+CPUX86State *cpu_x86_default_init(const char *cpu_model)
{
CPUX86State *env;
static int inited;
@@ -1635,7 +1635,13 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
#ifdef USE_KQEMU
kqemu_init(env);
#endif
- if (kvm_enabled())
- kvm_init_vcpu(env);
return env;
}
+
+CPUX86State *cpu_x86_init(const char *cpu_model)
+{
+ if (kvm_enabled())
+ return kvm_init_vcpu(cpu_model);
+ else
+ return cpu_x86_default_init(cpu_model);
+}
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 2412ae4..08a4416 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -44,6 +44,11 @@ int kvm_arch_init_vcpu(CPUState *env)
cpuid_i = 0;
+ if (cpu_x86_register(env) < 0) {
+ cpu_x86_close(env);
+ return -1;
+ }
+
cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx);
limit = eax;
--
1.5.6.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-30 14:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-30 14:52 [Qemu-devel] [PATCH 0/2] Hook into vcpu creation Glauber Costa
2008-12-30 14:52 ` [Qemu-devel] [PATCH 1/2] simplify cpu_x86_register Glauber Costa
2008-12-30 14:52 ` [Qemu-devel] [PATCH 2/2] hook into vcpu creation Glauber Costa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).