From: Glauber Costa <glommer@redhat.com>
To: qemu-devel@nongnu.org
Cc: Ian.Jackson@eu.citrix.com, avi@redhat.com, kvm@vger.kernel.org,
stefano.stabellini@eu.citrix.com
Subject: [Qemu-devel] [PATCH] hook cpu running at a higher level.
Date: Mon, 29 Dec 2008 13:29:22 -0500 [thread overview]
Message-ID: <1230575362-14485-1-git-send-email-glommer@redhat.com> (raw)
This patch removes the kvm_enabled() check from cpu-exec.c.
This file is highly tcg-specific, and we'll probably want it
out when tcg is not compiled in (coming soon, in a theathe near you)
Instead, we hook at the main loop level. The amount of code
duplication introduced is at worst, acceptable, and I believe
it pays. The tcg mainloop is likely to be different from the
hypervisors ones, since tcg runs all cpus in lockstep. KVM
(and probably xen), will be able to span threads out for its
vcpus.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
cpu-exec.c | 5 -----
kvm-all.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
vl.c | 16 ++++++++++------
3 files changed, 60 insertions(+), 11 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index ed1545b..be8ceac 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -333,11 +333,6 @@ int cpu_exec(CPUState *env1)
}
#endif
- if (kvm_enabled()) {
- kvm_cpu_exec(env);
- longjmp(env->jmp_env, 1);
- }
-
next_tb = 0; /* force lookup of first TB */
for(;;) {
interrupt_request = env->interrupt_request;
diff --git a/kvm-all.c b/kvm-all.c
index 11034df..a279d6c 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -663,3 +663,53 @@ int kvm_has_sync_mmu(void)
return 0;
}
+
+extern CPUState *cur_cpu;
+extern CPUState *next_cpu;
+
+extern int reset_requested;
+extern int shutdown_requested;
+extern int powerdown_requested;
+
+int kvm_main_loop(void)
+{
+
+ int ret, timeout;
+ CPUState *env;
+
+ cur_cpu = first_cpu;
+ next_cpu = first_cpu;
+ env = first_cpu;
+
+ for(;;) {
+ /* get next cpu */
+ cpu_single_env = env;
+ ret = kvm_cpu_exec(env);
+ cpu_single_env = NULL;
+
+ if (shutdown_requested)
+ break;
+ if (reset_requested) {
+ reset_requested = 0;
+ qemu_system_reset();
+ ret = EXCP_INTERRUPT;
+ }
+ if (powerdown_requested) {
+ powerdown_requested = 0;
+ qemu_system_powerdown();
+ ret = EXCP_INTERRUPT;
+ }
+
+ if (ret == EXCP_HALTED) {
+ timeout = 5000;
+ } else {
+ timeout = 0;
+ }
+
+ main_loop_wait(timeout);
+ }
+ cpu_disable_ticks();
+ return ret;
+}
+
+
diff --git a/vl.c b/vl.c
index 0a02151..bcaccc3 100644
--- a/vl.c
+++ b/vl.c
@@ -248,8 +248,8 @@ static struct drive_opt {
char opt[1024];
} drives_opt[MAX_DRIVES];
-static CPUState *cur_cpu;
-static CPUState *next_cpu;
+CPUState *cur_cpu;
+CPUState *next_cpu;
static int event_pending = 1;
/* Conversion factor from emulated instructions to virtual clock ticks. */
static int icount_time_shift;
@@ -3452,9 +3452,9 @@ typedef struct QEMUResetEntry {
} QEMUResetEntry;
static QEMUResetEntry *first_reset_entry;
-static int reset_requested;
-static int shutdown_requested;
-static int powerdown_requested;
+int reset_requested;
+int shutdown_requested;
+int powerdown_requested;
int qemu_shutdown_requested(void)
{
@@ -5535,7 +5535,11 @@ int main(int argc, char **argv, char **envp)
close(fd);
}
- main_loop();
+ if (kvm_enabled())
+ kvm_main_loop();
+ else
+ main_loop();
+
quit_timers();
net_cleanup();
--
1.5.6.5
next reply other threads:[~2008-12-29 18:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-29 18:29 Glauber Costa [this message]
2008-12-30 10:24 ` [Qemu-devel] Re: [PATCH] hook cpu running at a higher level Ian Jackson
2008-12-30 10:44 ` Avi Kivity
2008-12-30 13:45 ` Ian Jackson
2008-12-30 11:35 ` Glauber Costa
2008-12-30 17:25 ` Ian Jackson
2008-12-30 13:54 ` Avi Kivity
2008-12-30 14:44 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1230575362-14485-1-git-send-email-glommer@redhat.com \
--to=glommer@redhat.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).