From patchwork Wed Mar 31 14:56:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 49155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7F962B7CF4 for ; Thu, 1 Apr 2010 02:05:29 +1100 (EST) Received: from localhost ([127.0.0.1]:38964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwzTw-0005YA-45 for incoming@patchwork.ozlabs.org; Wed, 31 Mar 2010 11:05:24 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NwzR3-0004fl-2J for qemu-devel@nongnu.org; Wed, 31 Mar 2010 11:02:25 -0400 Received: from [140.186.70.92] (port=52171 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NwzLT-0003Ke-6l for qemu-devel@nongnu.org; Wed, 31 Mar 2010 11:02:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NwzL4-0007X4-Fs for qemu-devel@nongnu.org; Wed, 31 Mar 2010 10:56:19 -0400 Received: from mail-bw0-f218.google.com ([209.85.218.218]:35916) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NwzL4-0007Vo-5G for qemu-devel@nongnu.org; Wed, 31 Mar 2010 10:56:14 -0400 Received: by mail-bw0-f218.google.com with SMTP id 10so233589bwz.2 for ; Wed, 31 Mar 2010 07:56:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=UuRJuJcPd8/8LRVhGSY08dDoesIqOu26YhgEdQOuwnY=; b=jcpea765C8kszqMLckpbjCb8gjUjPXY+RYC5oqQFv/EFjXvgMbhkwCp3B6UWBPAFR5 VR7a4gs9r72jPKPkYUXdOnaFxSLxLx5X1f06IgepUdAPGAFlkESGsijZoOIvi4HNZjsX ETjDdInrFQHQ3IWki+ho+UimFA3Zh2lD2VBnI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=S/FfeJZBAxSAnef+VCMVc1brvTa1cwDnQCO2B69anfCrPSKGhnbzFdyBdtOthwnO12 UD7KIikEy5xsYqPkzuAN8kQzTy1BudkK/Crh6QGjOH+F24ZFEELiZTCP9fz71EAh+rUH +xHhwOT0tx6p2kosiE4HYkaVTIEPKWz6EQRqw= Received: by 10.204.133.146 with SMTP id f18mr9127780bkt.153.1270047373340; Wed, 31 Mar 2010 07:56:13 -0700 (PDT) Received: from localhost.localdomain (93-34-197-68.ip51.fastwebnet.it [93.34.197.68]) by mx.google.com with ESMTPS id 13sm3483258bwz.3.2010.03.31.07.56.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 31 Mar 2010 07:56:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 Mar 2010 16:56:03 +0200 Message-Id: <1270047363-12627-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1270047363-12627-1-git-send-email-pbonzini@redhat.com> References: <1270047363-12627-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- Makefile.target | 2 +- balloon.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ balloon.h | 7 +++ monitor.c | 85 -------------------------------- vl.c | 34 ------------- 5 files changed, 153 insertions(+), 120 deletions(-) create mode 100644 balloon.c diff --git a/Makefile.target b/Makefile.target index dbffe63..9ca6636 100644 --- a/Makefile.target +++ b/Makefile.target @@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER # System emulator target ifdef CONFIG_SOFTMMU -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o # virtio has to be here due to weird dependency between PCI and virtio-net. # need to fix this properly obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o diff --git a/balloon.c b/balloon.c new file mode 100644 index 0000000..016178f --- /dev/null +++ b/balloon.c @@ -0,0 +1,145 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "sysemu.h" +#include "monitor.h" +#include "qjson.h" +#include "qint.h" +#include "kvm.h" +#include "balloon.h" + + +static QEMUBalloonEvent *qemu_balloon_event; +void *qemu_balloon_event_opaque; + +void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) +{ + qemu_balloon_event = func; + qemu_balloon_event_opaque = opaque; +} + +int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) +{ + if (qemu_balloon_event) { + qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); + return 1; + } else { + return 0; + } +} + +int qemu_balloon_status(MonitorCompletion cb, void *opaque) +{ + if (qemu_balloon_event) { + qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque); + return 1; + } else { + return 0; + } +} + +static void print_balloon_stat(const char *key, QObject *obj, void *opaque) +{ + Monitor *mon = opaque; + + if (strcmp(key, "actual")) + monitor_printf(mon, ",%s=%" PRId64, key, + qint_get_int(qobject_to_qint(obj))); +} + +void monitor_print_balloon(Monitor *mon, const QObject *data) +{ + QDict *qdict; + + qdict = qobject_to_qdict(data); + if (!qdict_haskey(qdict, "actual")) + return; + + monitor_printf(mon, "balloon: actual=%" PRId64, + qdict_get_int(qdict, "actual") >> 20); + qdict_iter(qdict, print_balloon_stat, mon); + monitor_printf(mon, "\n"); +} + +/** + * do_info_balloon(): Balloon information + * + * Make an asynchronous request for balloon info. When the request completes + * a QDict will be returned according to the following specification: + * + * - "actual": current balloon value in bytes + * The following fields may or may not be present: + * - "mem_swapped_in": Amount of memory swapped in (bytes) + * - "mem_swapped_out": Amount of memory swapped out (bytes) + * - "major_page_faults": Number of major faults + * - "minor_page_faults": Number of minor faults + * - "free_mem": Total amount of free and unused memory (bytes) + * - "total_mem": Total amount of available memory (bytes) + * + * Example: + * + * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, + * "major_page_faults": 142, "minor_page_faults": 239245, + * "free_mem": 1014185984, "total_mem": 1044668416 } + */ +int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon_status(cb, opaque); + if (!ret) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + return 0; +} + +/** + * do_balloon(): Request VM to change its memory allocation + */ +int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); + if (ret == 0) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + cb(opaque, NULL); + return 0; +} diff --git a/balloon.h b/balloon.h index 8c019eb..d478e28 100644 --- a/balloon.h +++ b/balloon.h @@ -14,6 +14,8 @@ #ifndef _QEMU_BALLOON_H #define _QEMU_BALLOON_H +#include "monitor.h" + typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target, MonitorCompletion cb, void *cb_data); @@ -23,4 +25,9 @@ int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque); int qemu_balloon_status(MonitorCompletion cb, void *opaque); +void monitor_print_balloon(Monitor *mon, const QObject *data); +int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque); +int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque); + #endif diff --git a/monitor.c b/monitor.c index 822dc27..5659991 100644 --- a/monitor.c +++ b/monitor.c @@ -2266,91 +2266,6 @@ static void do_info_status(Monitor *mon, QObject **ret_data) vm_running, singlestep); } -static void print_balloon_stat(const char *key, QObject *obj, void *opaque) -{ - Monitor *mon = opaque; - - if (strcmp(key, "actual")) - monitor_printf(mon, ",%s=%" PRId64, key, - qint_get_int(qobject_to_qint(obj))); -} - -static void monitor_print_balloon(Monitor *mon, const QObject *data) -{ - QDict *qdict; - - qdict = qobject_to_qdict(data); - if (!qdict_haskey(qdict, "actual")) - return; - - monitor_printf(mon, "balloon: actual=%" PRId64, - qdict_get_int(qdict, "actual") >> 20); - qdict_iter(qdict, print_balloon_stat, mon); - monitor_printf(mon, "\n"); -} - -/** - * do_info_balloon(): Balloon information - * - * Make an asynchronous request for balloon info. When the request completes - * a QDict will be returned according to the following specification: - * - * - "actual": current balloon value in bytes - * The following fields may or may not be present: - * - "mem_swapped_in": Amount of memory swapped in (bytes) - * - "mem_swapped_out": Amount of memory swapped out (bytes) - * - "major_page_faults": Number of major faults - * - "minor_page_faults": Number of minor faults - * - "free_mem": Total amount of free and unused memory (bytes) - * - "total_mem": Total amount of available memory (bytes) - * - * Example: - * - * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, - * "major_page_faults": 142, "minor_page_faults": 239245, - * "free_mem": 1014185984, "total_mem": 1044668416 } - */ -static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) -{ - int ret; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; - } - - ret = qemu_balloon_status(cb, opaque); - if (!ret) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; - } - - return 0; -} - -/** - * do_balloon(): Request VM to change its memory allocation - */ -static int do_balloon(Monitor *mon, const QDict *params, - MonitorCompletion cb, void *opaque) -{ - int ret; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; - } - - ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); - if (ret == 0) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; - } - - cb(opaque, NULL); - return 0; -} - static qemu_acl *find_acl(Monitor *mon, const char *name) { qemu_acl *acl = qemu_acl_find(name); diff --git a/vl.c b/vl.c index 8828beb..e7192fc 100644 --- a/vl.c +++ b/vl.c @@ -146,7 +146,6 @@ int main(int argc, char **argv) #include "audio/audio.h" #include "migration.h" #include "kvm.h" -#include "balloon.h" #include "qemu-option.h" #include "qemu-config.h" #include "qemu-objects.h" @@ -307,39 +306,6 @@ static void set_proc_name(const char *s) #endif } -/***************/ -/* ballooning */ - -static QEMUBalloonEvent *qemu_balloon_event; -void *qemu_balloon_event_opaque; - -void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) -{ - qemu_balloon_event = func; - qemu_balloon_event_opaque = opaque; -} - -int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) -{ - if (qemu_balloon_event) { - qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); - return 1; - } else { - return 0; - } -} - -int qemu_balloon_status(MonitorCompletion cb, void *opaque) -{ - if (qemu_balloon_event) { - qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque); - return 1; - } else { - return 0; - } -} - - /***********************************************************/ /* real time host monotonic timer */