From patchwork Sat Apr 9 10:51:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 695811 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p39ApOIb002447 for ; Sat, 9 Apr 2011 10:51:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754123Ab1DIKvL (ORCPT ); Sat, 9 Apr 2011 06:51:11 -0400 Received: from filtteri2.pp.htv.fi ([213.243.153.185]:52872 "EHLO filtteri2.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754030Ab1DIKvK (ORCPT ); Sat, 9 Apr 2011 06:51:10 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri2.pp.htv.fi (Postfix) with ESMTP id C532419B454; Sat, 9 Apr 2011 13:51:08 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp5.welho.com ([213.243.153.39]) by localhost (filtteri2.pp.htv.fi [213.243.153.185]) (amavisd-new, port 10024) with ESMTP id Ax7Lq1qjKW+i; Sat, 9 Apr 2011 13:51:08 +0300 (EEST) Received: from localhost.localdomain (cs181148025.pp.htv.fi [82.181.148.25]) by smtp5.welho.com (Postfix) with ESMTP id 78C735BC002; Sat, 9 Apr 2011 13:51:08 +0300 (EEST) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Asias He , Cyrill Gorcunov , Ingo Molnar Subject: [PATCH 1/2] kvm tools: Extract kvm_cpu__start() function Date: Sat, 9 Apr 2011 13:51:06 +0300 Message-Id: <1302346267-457-1-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 09 Apr 2011 10:51:24 +0000 (UTC) In preparation for threaded execution, separate kvm_cpu__start() function so it can be reused for multiple threads. Cc: Asias He Cc: Cyrill Gorcunov Cc: Ingo Molnar Signed-off-by: Pekka Enberg --- tools/kvm/include/kvm/kvm-cpu.h | 1 + tools/kvm/kvm-cpu.c | 59 +++++++++++++++++++++++++++++++++++++++ tools/kvm/kvm-run.c | 51 ++------------------------------- 3 files changed, 63 insertions(+), 48 deletions(-) diff --git a/tools/kvm/include/kvm/kvm-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h index d36dadf..b4e2134 100644 --- a/tools/kvm/include/kvm/kvm-cpu.h +++ b/tools/kvm/include/kvm/kvm-cpu.h @@ -25,6 +25,7 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *self); void kvm_cpu__setup_cpuid(struct kvm_cpu *self); void kvm_cpu__enable_singlestep(struct kvm_cpu *self); void kvm_cpu__run(struct kvm_cpu *self); +int kvm_cpu__start(struct kvm_cpu *cpu); void kvm_cpu__show_code(struct kvm_cpu *self); void kvm_cpu__show_registers(struct kvm_cpu *self); diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c index 374adb2..392fad3 100644 --- a/tools/kvm/kvm-cpu.c +++ b/tools/kvm/kvm-cpu.c @@ -1,5 +1,7 @@ #include "kvm/kvm-cpu.h" +#include "kvm/virtio-console.h" +#include "kvm/8250-serial.h" #include "kvm/util.h" #include "kvm/kvm.h" @@ -368,3 +370,60 @@ void kvm_cpu__run(struct kvm_cpu *self) if (err && (errno != EINTR && errno != EAGAIN)) die_perror("KVM_RUN failed"); } + +int kvm_cpu__start(struct kvm_cpu *cpu) +{ + for (;;) { + kvm_cpu__run(cpu); + + switch (cpu->kvm_run->exit_reason) { + case KVM_EXIT_DEBUG: + kvm_cpu__show_registers(cpu); + kvm_cpu__show_code(cpu); + break; + case KVM_EXIT_IO: { + bool ret; + + ret = kvm__emulate_io(cpu->kvm, + cpu->kvm_run->io.port, + (uint8_t *)cpu->kvm_run + + cpu->kvm_run->io.data_offset, + cpu->kvm_run->io.direction, + cpu->kvm_run->io.size, + cpu->kvm_run->io.count); + + if (!ret) + goto panic_kvm; + break; + } + case KVM_EXIT_MMIO: { + bool ret; + + ret = kvm__emulate_mmio(cpu->kvm, + cpu->kvm_run->mmio.phys_addr, + cpu->kvm_run->mmio.data, + cpu->kvm_run->mmio.len, + cpu->kvm_run->mmio.is_write); + + if (!ret) + goto panic_kvm; + break; + } + case KVM_EXIT_INTR: { + serial8250__inject_interrupt(cpu->kvm); + virtio_console__inject_interrupt(cpu->kvm); + break; + } + case KVM_EXIT_SHUTDOWN: + goto exit_kvm; + default: + goto panic_kvm; + } + } + +exit_kvm: + return 0; + +panic_kvm: + return 1; +} diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 9392818..9a0400b 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -177,54 +177,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) kvm__start_timer(kvm); - for (;;) { - kvm_cpu__run(cpu); - - switch (cpu->kvm_run->exit_reason) { - case KVM_EXIT_DEBUG: - kvm_cpu__show_registers(cpu); - kvm_cpu__show_code(cpu); - break; - case KVM_EXIT_IO: { - bool ret; - - ret = kvm__emulate_io(kvm, - cpu->kvm_run->io.port, - (uint8_t *)cpu->kvm_run + - cpu->kvm_run->io.data_offset, - cpu->kvm_run->io.direction, - cpu->kvm_run->io.size, - cpu->kvm_run->io.count); - - if (!ret) - goto panic_kvm; - break; - } - case KVM_EXIT_MMIO: { - bool ret; - - ret = kvm__emulate_mmio(kvm, - cpu->kvm_run->mmio.phys_addr, - cpu->kvm_run->mmio.data, - cpu->kvm_run->mmio.len, - cpu->kvm_run->mmio.is_write); - - if (!ret) - goto panic_kvm; - break; - } - case KVM_EXIT_INTR: { - serial8250__inject_interrupt(kvm); - virtio_console__inject_interrupt(kvm); - break; - } - case KVM_EXIT_SHUTDOWN: - goto exit_kvm; - default: - goto panic_kvm; - } - } -exit_kvm: + if (kvm_cpu__start(cpu)) + goto panic_kvm; + disk_image__close(kvm->disk_image); kvm__delete(kvm);