From patchwork Wed Sep 5 08:31:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406571 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id D94A23FC71 for ; Wed, 5 Sep 2012 08:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757963Ab2IEIgF (ORCPT ); Wed, 5 Sep 2012 04:36:05 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:40454 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765Ab2IEIgD (ORCPT ); Wed, 5 Sep 2012 04:36:03 -0400 Received: by weyx8 with SMTP id x8so223930wey.19 for ; Wed, 05 Sep 2012 01:36:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=yD1r3RWVC2306ov8kx00utkpugOcUE9ydbZqW4veL00=; b=rGKD2+qu6uf7OdUymwICn5d79iisb/O2t44y7et+BU5R/HCA/Xeni7r5HTzXEhajeS uwaSJWSZ8cdEJUEWaj8LOE555D842b0bZvIpcIgZap/ICrIQKoyB+3VWnHrkAXoDIojA a6kbD6oCTtTFpMozGi8dHXtZKtCzVQkANESDAm2P89chLsL9ifFQ/RjOjgYP1xBlKLvc IpC58Gl+uwAw+WiQ/gO7MTIIPE9VjKSNG6zbACq9PFmHomz52ajJ7z7a2etsqXxQvWRv LdK2mQCQ1SW/18cyZXEZTAB6dF4DgsKjvQcd+vI+NLNjNhscnktsHSk6u3lIw4/4pL8q CMAQ== Received: by 10.180.103.4 with SMTP id fs4mr36424736wib.16.1346834161883; Wed, 05 Sep 2012 01:36:01 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.35.11 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:36:01 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 16/33] kvm tools: timer cleanup Date: Wed, 5 Sep 2012 10:31:50 +0200 Message-Id: <1346833927-15740-17-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make the timer init/exit follow the rest of the code, and move it out of builtin-run. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 12 ++++++++++-- tools/kvm/include/kvm/kvm.h | 4 ++-- tools/kvm/kvm.c | 23 +++++++++++++++-------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index d83917f..f09aac8 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -1203,7 +1203,11 @@ static int kvm_cmd_run_init(int argc, const char **argv) * come after this (it may set up device trees etc.) */ - kvm__start_timer(kvm); + r = kvm_timer__init(kvm); + if (r < 0) { + pr_err("kvm_timer__init() failed with error %d\n", r); + goto fail; + } if (kvm->cfg.firmware_filename) { if (!kvm__load_firmware(kvm, kvm->cfg.firmware_filename)) @@ -1258,9 +1262,13 @@ static void kvm_cmd_run_exit(int guest_ret) if (r < 0) pr_warning("irq__exit() failed with error %d\n", r); + r = kvm_timer__exit(kvm); + if (r < 0) + pr_warning("kvm_timer__exit() failed with error %d\n", r); + r = fb__exit(kvm); if (r < 0) - pr_warning("fb__exit() failed with error %d\n", r); + pr_warning("kvm_timer__exit() failed with error %d\n", r); r = virtio_scsi_exit(kvm); if (r < 0) diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index d3b6dab..2cd30e4 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -68,8 +68,8 @@ int kvm__exit(struct kvm *kvm); bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename); bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename, const char *initrd_filename, const char *kernel_cmdline, u16 vidmode); -void kvm__start_timer(struct kvm *kvm); -void kvm__stop_timer(struct kvm *kvm); +int kvm_timer__init(struct kvm *kvm); +int kvm_timer__exit(struct kvm *kvm); void kvm__irq_line(struct kvm *kvm, int irq, int level); void kvm__irq_trigger(struct kvm *kvm, int irq); bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count); diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index eeac0f6..42a0f06 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -254,8 +254,6 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd)) int kvm__exit(struct kvm *kvm) { - kvm__stop_timer(kvm); - kvm__arch_delete_ram(kvm); kvm_ipc__stop(); kvm__remove_socket(kvm->cfg.guest_name); @@ -478,10 +476,11 @@ found_kernel: * userspace hypervisor into the guest at periodical intervals. Please note * that clock interrupt, for example, is not handled here. */ -void kvm__start_timer(struct kvm *kvm) +int kvm_timer__init(struct kvm *kvm) { struct itimerspec its; struct sigevent sev; + int r; memset(&sev, 0, sizeof(struct sigevent)); sev.sigev_value.sival_int = 0; @@ -489,25 +488,33 @@ void kvm__start_timer(struct kvm *kvm) sev.sigev_signo = SIGALRM; sev._sigev_un._tid = syscall(__NR_gettid); - if (timer_create(CLOCK_REALTIME, &sev, &kvm->timerid) < 0) - die("timer_create()"); + r = timer_create(CLOCK_REALTIME, &sev, &kvm->timerid); + if (r < 0) + return r; its.it_value.tv_sec = TIMER_INTERVAL_NS / 1000000000; its.it_value.tv_nsec = TIMER_INTERVAL_NS % 1000000000; its.it_interval.tv_sec = its.it_value.tv_sec; its.it_interval.tv_nsec = its.it_value.tv_nsec; - if (timer_settime(kvm->timerid, 0, &its, NULL) < 0) - die("timer_settime()"); + r = timer_settime(kvm->timerid, 0, &its, NULL); + if (r < 0) { + timer_delete(kvm->timerid); + return r; + } + + return 0; } -void kvm__stop_timer(struct kvm *kvm) +int kvm_timer__exit(struct kvm *kvm) { if (kvm->timerid) if (timer_delete(kvm->timerid) < 0) die("timer_delete()"); kvm->timerid = 0; + + return 0; } void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size)