[Qemu-devel] Re: [PATCH 01/11] Add hard build dependency on glib

2011-03-12 Thread Paolo Bonzini

On 03/11/2011 10:00 PM, Anthony Liguori wrote:

GLib is an extremely common library that has a portable thread implementation
along with tons of other goodies.

GLib and GObject have a fantastic amount of infrastructure we can leverage in
QEMU including an object oriented programming infrastructure.

Short term, it has a very nice thread pool implementation that we could leverage
in something like virtio-9p.  It also has a test harness implementation that
this series will use.

Signed-off-by: Anthony Liguorialigu...@us.ibm.com


This doesn't need to go in until there is use for it, which is IIRC for 
the QAPI tests?


Paolo



[Qemu-devel] Re: [PATCH 11/15] kvm: Rework inner loop of kvm_cpu_exec

2011-03-12 Thread Jan Kiszka
On 2011-03-11 22:34, Marcelo Tosatti wrote:
 On Sat, Mar 05, 2011 at 07:12:50PM +0100, Jan Kiszka wrote:
 @@ -956,7 +956,6 @@ int kvm_cpu_exec(CPUState *env)
  abort();
  }
  
 -ret = 0; /* exit loop */
  switch (run-exit_reason) {

 Better keep ret assignment here so default behaviour is to 
 exit loop? EXCP_INTERRUPT.

 There is no real default behavior: in two cases we stay in the loop, in
 two others we leave, and the rest obtains ret from a return value.
 Moreover, if a new case misses to set ret, the compiler will complain.

 Jan
 
 It will not complain because ret is used to store return value
 of KVM_RUN.
 

Right, I'll disentangle this duplicate use of 'ret' (writing patches is
likely much better than watching more news this morning...).

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Re: RFC: emulation of system flash

2011-03-12 Thread Jan Kiszka
On 2011-03-11 20:09, Jordan Justen wrote:
 On Thu, Mar 10, 2011 at 16:27, Carl-Daniel Hailfinger
 c-d.hailfinger.devel.2...@gmx.net wrote:
 Auf 11.03.2011 01:19, Jan Kiszka schrieb:
 At least it's an in-band interface, which is the better choice as we
 currently only have a PIIX3 southbridge for x86, predating even FWHs.


 Right, that pretty much kills the option of using SPI unless someone
 wants to emulate a flash translation controller (e.g. the ITE IT8716F
 Super I/O). Can be done, would work, but the IT8716F has some quirks
 (max 1 MB SPI flash chips) which make it a less desirable option for
 emulation.
 
 I don't much like this, but we might consider adding the SPI host
 controller MMIO just below the flash data.  For the firmware, we
 usually will know the size of firmware device that we've built for.
 It seems SPI flash is pretty common today, and it sounds like
 Carl-Daniel may have some SPI emulation code.

We don't emulate a chipset yet that includes SPI. Adding an artificial
SPI master is like PV - the guests will require special drivers.

 
 Am I understanding correctly that CFI is programmed via MMIO in the
 flash memory space?  How difficult would it be to emulate CFI?  Does

Check qemu/hw/pflash_cfi02.c.

 CFI have the same power-of-2 size flexibility as SPI?

Yes.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: fdc: refactor device creation causes guest kernel panic

2011-03-12 Thread Blue Swirl
On Wed, Mar 9, 2011 at 4:34 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 The following kernel panic occurs when the RHEL6 installer starts on
 qemu.git/master:

 BUG: unable to handle kernel NULL pointer dereference at (null)
 IP: [a0062ceb] floppy_ready+0xfb/0x730 [floppy]

 For full details see http://pastebin.com/SYE5A6LA.

 git-bisect revealed that the following commit causes this panic:

 commit 63ffb564dca94f8bda01ed6d209784104630a4d2
 Author: Blue Swirl blauwir...@gmail.com
 Date:   Sat Feb 5 16:32:23 2011 +

    fdc: refactor device creation

    Turn fdc_init_isa into an inline function.

    Get floppy geometry directly from the drives.

    Don't expose FDCtrl.

    Signed-off-by: Blue Swirl blauwir...@gmail.com

 The CMOS value at 0x10 has changed from 0x00 to 0x40 but I have not
 located the root cause of the problem.

 Blue Swirl: Any thoughts on this bug?

The logic for calculating the drive state in pc.c does not match fdc.c
logic. Please try this patch.

diff --git a/hw/pc.c b/hw/pc.c
index 5966bf1..4d67d9f 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -382,7 +382,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t
above_4g_mem_size,
 /* floppy type */
 for (i = 0; i  2; i++) {
 fd[i] = drive_get(IF_FLOPPY, 0, i);
-if (fd[i]) {
+if (fd[i]  bdrv_is_inserted(fd[i]-bdrv)) {
 bdrv_get_floppy_geometry_hint(fd[i]-bdrv, nb_heads, max_track,
   last_sect, FDRIVE_DRV_NONE,
   fd_type[i]);
From a008e6fd41a31d437670eaa0ddf12352e8a4a8fb Mon Sep 17 00:00:00 2001
Message-Id: a008e6fd41a31d437670eaa0ddf12352e8a4a8fb.1299926967.git.blauwir...@gmail.com
From: Blue Swirl blauwir...@gmail.com
Date: Sat, 12 Mar 2011 09:52:25 +
Subject: [PATCH] pc: fix wrong CMOS values for floppy drives

Before commit 63ffb564dca94f8bda01ed6d209784104630a4d2, states for
floppy drives were calculated in fdc.c:fd_revalidate(). There it is
also considered whether a disk is inserted or not. The commit didn't copy
the logic completely to pc.c, which caused a regression.

Fix by adding the same check also to pc.c.

Signed-off-by: Blue Swirl blauwir...@gmail.com
---
 hw/pc.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 5966bf1..4d67d9f 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -382,7 +382,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
 /* floppy type */
 for (i = 0; i  2; i++) {
 fd[i] = drive_get(IF_FLOPPY, 0, i);
-if (fd[i]) {
+if (fd[i]  bdrv_is_inserted(fd[i]-bdrv)) {
 bdrv_get_floppy_geometry_hint(fd[i]-bdrv, nb_heads, max_track,
   last_sect, FDRIVE_DRV_NONE,
   fd_type[i]);
-- 
1.7.2.3



Re: [Qemu-devel] [PATCH 03/11] add a generic Error object

2011-03-12 Thread Blue Swirl
On Fri, Mar 11, 2011 at 11:00 PM, Anthony Liguori aligu...@us.ibm.com wrote:
 The Error class is similar to QError (now deprecated) except that it supports
 propagation.  This allows for higher quality error handling.  It's losely
 modeled after glib style GErrors.

 Signed-off-by: Anthony Liguori aligu...@us.ibm.com

 diff --git a/Makefile.objs b/Makefile.objs
 index 0ba02c7..da31530 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -15,6 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o

  block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
  block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
 +block-obj-y += error.o
  block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o

 diff --git a/error.c b/error.c
 new file mode 100644
 index 000..5d84106
 --- /dev/null
 +++ b/error.c
 @@ -0,0 +1,122 @@
 +/*
 + * QEMU Error Objects
 + *
 + * Copyright IBM, Corp. 2011
 + *
 + * Authors:
 + *  Anthony Liguori   aligu...@us.ibm.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.  See
 + * the COPYING.LIB file in the top-level directory.
 + */
 +#include error.h
 +#include error_int.h
 +#include qemu-objects.h
 +#include qerror.h
 +#include assert.h
 +
 +struct Error
 +{
 +    QDict *obj;
 +    const char *fmt;
 +    char *msg;
 +};
 +
 +void error_set(Error **errp, const char *fmt, ...)
 +{
 +    Error *err;
 +    va_list ap;
 +
 +    if (errp == NULL) {
 +        return;
 +    }
 +
 +    err = qemu_mallocz(sizeof(*err));
 +
 +    va_start(ap, fmt);
 +    err-obj = qobject_to_qdict(qobject_from_jsonv(fmt, ap));
 +    va_end(ap);
 +    err-fmt = fmt;
 +
 +    *errp = err;
 +}
 +
 +bool error_is_set(Error **errp)
 +{
 +    return (errp  *errp);
 +}
 +
 +const char *error_get_pretty(Error *err)
 +{
 +    if (err-msg == NULL) {
 +        QString *str;
 +        str = qerror_format(err-fmt, err-obj);
 +        err-msg = qemu_strdup(qstring_get_str(str));
 +    }
 +
 +    return err-msg;
 +}
 +
 +const char *error_get_field(Error *err, const char *field)
 +{
 +    if (strcmp(field, class) == 0) {
 +        return qdict_get_str(err-obj, field);
 +    } else {
 +        QDict *dict = qdict_get_qdict(err-obj, data);
 +        return qdict_get_str(dict, field);
 +    }
 +}
 +
 +void error_free(Error *err)
 +{
 +    QDECREF(err-obj);
 +    qemu_free(err-msg);
 +    qemu_free(err);
 +}
 +
 +bool error_is_type(Error *err, const char *fmt)
 +{
 +    char *ptr;
 +    char *end;
 +    char classname[1024];
 +
 +    ptr = strstr(fmt, 'class': ');
 +    assert(ptr != NULL);
 +    ptr += strlen('class': ');
 +
 +    end = strchr(ptr, '\'');
 +    assert(end != NULL);
 +
 +    memcpy(classname, ptr, (end - ptr));
 +    classname[(end - ptr)] = 0;
 +
 +    return strcmp(classname, error_get_field(err, class)) == 0;
 +}
 +
 +void error_propagate(Error **dst_err, Error *local_err)
 +{
 +    if (dst_err) {
 +        *dst_err = local_err;
 +    } else if (local_err) {
 +        error_free(local_err);
 +    }
 +}
 +
 +QObject *error_get_qobject(Error *err)
 +{
 +    QINCREF(err-obj);
 +    return QOBJECT(err-obj);
 +}
 +
 +void error_set_qobject(Error **errp, QObject *obj)
 +{
 +    Error *err;
 +    if (errp == NULL) {
 +        return;
 +    }
 +    err = qemu_mallocz(sizeof(*err));
 +    err-obj = qobject_to_qdict(obj);
 +    qobject_incref(obj);
 +
 +    *errp = err;
 +}
 diff --git a/error.h b/error.h
 new file mode 100644

The name is too generic, it could conflict with system headers. At
least I have /usr/include/error.h.

 index 000..317d487
 --- /dev/null
 +++ b/error.h
 @@ -0,0 +1,65 @@
 +/*
 + * QEMU Error Objects
 + *
 + * Copyright IBM, Corp. 2011
 + *
 + * Authors:
 + *  Anthony Liguori   aligu...@us.ibm.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.  See
 + * the COPYING.LIB file in the top-level directory.
 + */
 +#ifndef ERROR_H
 +#define ERROR_H

This #define could also conflict with system headers. In my system,
_ERROR_H is used, but who knows all error.h files out there?



Re: [Qemu-devel] [PATCH 13/15] qapi: add code generator for libqmp (v2)

2011-03-12 Thread Blue Swirl
On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguori aligu...@us.ibm.com wrote:
 Signed-off-by: Anthony Liguori aligu...@us.ibm.com
 ---
 v1 - v2
  - update code generator to use multiline
  - proxy command support
  - async command support

 diff --git a/Makefile b/Makefile
 index 47a755d..5170675 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -4,7 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
  ifeq ($(TRACE_BACKEND),dtrace)
  GENERATED_HEADERS += trace-dtrace.h
  endif
 -GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h
 +GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h libqmp.h

  ifneq ($(wildcard config-host.mak),)
  # Put the all: rule here so that config-host.mak can contain dependencies.
 @@ -165,9 +165,16 @@ qmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
  qmp-marshal.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
        $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --body  $  $@,  
  GEN   $@)

 +libqmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
 +       $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --lib-header  $ 
  $@,   GEN   $@)
 +
 +libqmp.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
 +       $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --lib-body  $  
 $@,   GEN   $@)
 +
  qmp-types.o: qmp-types.c qmp-types.h
  qmp-marshal-types.o: qmp-marshal-types.c qmp-marshal-types.h qmp-types.h
  qmp-marshal.o: qmp-marshal.c qmp.h qmp-types.h qmp-marshal-types.h
 +libqmp.o: libqmp.c libqmp.h qmp-types.h

  version.o: $(SRC_PATH)/version.rc config-host.mak
        $(call quiet-command,$(WINDRES) -I. -o $@ $,  RC    $(TARGET_DIR)$@)
 diff --git a/libqmp-core.c b/libqmp-core.c
 new file mode 100644
 index 000..4613d4f
 --- /dev/null
 +++ b/libqmp-core.c
 @@ -0,0 +1,361 @@
 +/*
 + * QAPI
 + *
 + * Copyright IBM, Corp. 2011
 + *
 + * Authors:
 + *  Anthony Liguori   aligu...@us.ibm.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.  See
 + * the COPYING.LIB file in the top-level directory.
 + */
 +#include libqmp.h
 +#include libqmp-internal.h
 +#include libqmp-core.h
 +#include json-streamer.h
 +#include json-parser.h
 +#include dirent.h
 +#include sys/socket.h
 +#include sys/un.h
 +#include assert.h
 +
 +#ifndef container_of
 +#define offset_of(type, field) \
 +    ((unsigned long)(((type *)0)-field))
 +#define container_of(obj, type, field) \
 +    ((type *)(((char *)obj) - offsetof(type, field)))
 +#endif

Why not use the existing definitions?



Re: [Qemu-devel] [PATCH 07/15] qapi: add query-version QMP command

2011-03-12 Thread Blue Swirl
On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguori aligu...@us.ibm.com wrote:
 This is used internally by QMP.  It's also a pretty good example of a typical
 command conversion.

 Signed-off-by: Anthony Liguori aligu...@us.ibm.com

 diff --git a/Makefile.objs b/Makefile.objs
 index 5dae800..e1a2756 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -103,7 +103,7 @@ common-obj-y += block-migration.o
  common-obj-y += pflib.o
  common-obj-y += bitmap.o bitops.o
  common-obj-y += qmp-marshal-types.o qmp-marshal-types-core.o
 -common-obj-y += qmp-core.o qmp-marshal.o
 +common-obj-y += qmp-core.o qmp-marshal.o qmp.o

  common-obj-$(CONFIG_BRLAPI) += baum.o
  common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o 
 migration-fd.o
 diff --git a/qmp-schema.json b/qmp-schema.json
 index e69de29..e72bc18 100644
 --- a/qmp-schema.json
 +++ b/qmp-schema.json
 @@ -0,0 +1,90 @@
 +# *-*- Mode: Python -*-*
 +
 +##
 +# QMP Schema
 +#
 +# This file defines the types, commands, and events used by QMP.  It should
 +# fully describe the interface used by QMP.
 +#
 +# This file is designed to be loosely based on JSON although it's technical
 +# executable Python.  While dictionaries are used, they are parsed as
 +# OrderedDicts so that ordering is preserved.
 +#
 +# There are two basic syntaxes used.  The first syntax defines a type and is
 +# represented by a dictionary.  There are three kinds of types that are
 +# supported.
 +#
 +# A complex type is a dictionary containing a single key who's value is a
 +# dictionary.  This corresponds to a struct in C or an Object in JSON.  An
 +# example of a complex type is:
 +#
 +#  { 'type': 'MyType',
 +#    'data' { 'member1': 'str', 'member2': 'int', '*member3': 'str } }
 +#
 +# The use of '*' as a prefix to the name means the member is optional.  
 Optional
 +# members should always be added to the end of the dictionary to preserve
 +# backwards compatibility.
 +#
 +# An enumeration type is a dictionary containing a single key who's value is 
 a
 +# list of strings.  An example enumeration is:
 +#
 +#  { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] }
 +#
 +# A signal is similar in form to a complex type except the single key is
 +# entirely upper case instead of CamelCase.  An example signal is:
 +#
 +#  { 'event': 'MY_SIGNAL', 'data': { 'arg1': 'str', 'arg2': 'str' } }
 +#
 +# Generally speaking, complex types and enums should always use CamelCase for
 +# the type names.
 +#
 +# Commands are defined by using a list containing three members.  The first
 +# member is the command name, the second member is a dictionary containing
 +# arguments, and the third member is the return type.
 +#
 +# An example command is:
 +#
 +#  { 'command': 'my-command',
 +#    'data': { 'arg1': 'str', '*arg2': 'str' },
 +#    'returns': 'str' ]
 +#
 +# Command names should be all lower case with words separated by a hyphen.
 +
 +### 0.14.0 commands.  Do not modify. ###
 +
 +##
 +# @VersionInfo:
 +#
 +# A description of QEMU's version.
 +#
 +# @qemu.major:  The major version of QEMU
 +#
 +# @qemu.minor:  The minor version of QEMU
 +#
 +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
 +#               version of 50 signifies a development branch.  A micro 
 version
 +#               greater than or equal to 90 signifies a release candidate for
 +#               the next minor version.  A micro version of less than 50
 +#               signifies a stable release.
 +#
 +# @package:     QEMU will always set this field to an empty string.  
 Downstream
 +#               versions of QEMU should set this to a non-empty string.  The
 +#               exact format depends on the downstream however it highly
 +#               recommended that a unique name is used.
 +#
 +# Since: 0.14.0
 +##
 +{ 'type': 'VersionInfo',
 +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
 +           'package': 'str'} }
 +
 +##
 +# @query-version:
 +#
 +# Returns the current version of QEMU.
 +#
 +# Returns:  A @VersionInfo object describing the current version of QEMU.
 +#
 +# Since: 0.14.0
 +##
 +{ 'command': 'query-version', 'returns': 'VersionInfo' }
 diff --git a/qmp.c b/qmp.c
 new file mode 100644
 index 000..7b626f5
 --- /dev/null
 +++ b/qmp.c
 @@ -0,0 +1,31 @@
 +/*
 + * QAPI
 + *
 + * Copyright IBM, Corp. 2011
 + *
 + * Authors:
 + *  Anthony Liguori   aligu...@us.ibm.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.  See
 + * the COPYING.LIB file in the top-level directory.
 + */
 +#include qemu-common.h
 +#include qmp-core.h
 +#include qmp.h
 +
 +VersionInfo *qmp_query_version(Error **err)
 +{
 +    VersionInfo *info = qmp_alloc_version_info();
 +    const char *version = QEMU_VERSION;
 +    char *tmp;
 +
 +    info-qemu.major = strtol(version, tmp, 10);

Since all fields are int64_t, these should use strtoll(), otherwise
they may fail for versions like QEMU 2147483648.0.0. ;-)

 +    tmp++;
 +    info-qemu.minor = 

Re: [Qemu-devel] [PATCH 14/15] qapi: add test-libqmp

2011-03-12 Thread Blue Swirl
On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguori aligu...@us.ibm.com wrote:
 This provides a glib-test based testing framework for QMP

 Signed-off-by: Anthony Liguori aligu...@us.ibm.com

 diff --git a/Makefile b/Makefile
 index 5170675..1d363d7 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -72,6 +72,8 @@ defconfig:

  -include config-all-devices.mak

 +TOOLS += test-libqmp
 +
  build-all: $(DOCS) $(TOOLS) recurse-all

  config-host.h: config-host.h-timestamp
 @@ -205,6 +207,15 @@ check-qlist: check-qlist.o qlist.o qint.o 
 $(CHECK_PROG_DEPS)
  check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
  check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
 qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS)

 +LIBQMP_OBJS := qmp-types.o libqmp.o error.o libqmp-core.o
 +LIBQMP_OBJS += qmp-marshal-types-core.o qmp-marshal-types.o
 +LIBQMP_OBJS += qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o
 +LIBQMP_OBJS += qerror.o
 +LIBQMP_OBJS += json-streamer.o json-lexer.o json-parser.o
 +LIBQMP_OBJS += $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o
 +
 +test-libqmp: test-libqmp.o $(LIBQMP_OBJS) qemu-timer-common.o
 +
  clean:
  # avoid old build problems by removing potentially incorrect old files
        rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
 gen-op-arm.h
 diff --git a/test-libqmp.c b/test-libqmp.c
 new file mode 100644

I'd put this to tests/.

 index 000..9b73987
 --- /dev/null
 +++ b/test-libqmp.c
 @@ -0,0 +1,170 @@
 +/*
 + * QAPI
 + *
 + * Copyright IBM, Corp. 2011
 + *
 + * Authors:
 + *  Anthony Liguori   aligu...@us.ibm.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.  See
 + * the COPYING.LIB file in the top-level directory.
 + */
 +#include stdio.h
 +#include sys/socket.h
 +#include netinet/in.h
 +#include netinet/tcp.h
 +#include arpa/inet.h
 +#include sys/un.h
 +#include stdlib.h
 +#include glib.h
 +#include sys/wait.h
 +#include config-host.h
 +#include libqmp.h
 +#include qerror.h
 +
 +#define g_assert_noerr(err) g_assert(err == NULL);
 +#define g_assert_anyerr(err) g_assert(err != NULL);
 +#define g_assert_cmperr(err, op, type) do {                   \
 +    g_assert_anyerr(err);                                        \
 +    g_assert_cmpstr(error_get_field(err, class), op, type); \
 +} while (0)
 +
 +static pid_t last_qemu_pid = -1;
 +
 +static QmpSession *qemu(const char *fmt, ...)
 +{
 +    char buffer0[4096];
 +    char buffer1[4096];
 +    const char *pid_filename = /tmp/test-libqmp-qemu.pid;
 +    const char *path = /tmp/test-libqmp-qemu.sock;

Very insecure filenames.

 +    struct sockaddr_un addr;
 +    va_list ap;
 +    int ret;
 +    int fd;
 +
 +    va_start(ap, fmt);
 +    vsnprintf(buffer0, sizeof(buffer0), fmt, ap);
 +    va_end(ap);
 +
 +    snprintf(buffer1, sizeof(buffer1),
 +             i386-softmmu/qemu 
 +             -enable-kvm 
 +             -name test-libqmp 
 +             -qmp2 qmp 
 +             -chardev socket,id=qmp,path=%s,server=on,wait=off 
 +             -vnc none 
 +             -daemonize 
 +             -pidfile %s 
 +             %s, path, pid_filename, buffer0);
 +    g_test_message(Executing %s\n, buffer1);
 +    ret = system(buffer1);
 +    g_assert(ret != -1);
 +
 +    {
 +        FILE *f;
 +        char buffer[1024];
 +        char *ptr;
 +
 +        f = fopen(pid_filename, r);
 +        g_assert(f != NULL);
 +
 +        ptr = fgets(buffer, sizeof(buffer), f);
 +        g_assert(ptr != NULL);
 +
 +        fclose(f);
 +
 +        last_qemu_pid = atoi(buffer);
 +    }
 +
 +    fd = socket(PF_UNIX, SOCK_STREAM, 0);
 +    g_assert(fd != -1);
 +
 +    addr.sun_family = AF_UNIX;
 +    snprintf(addr.sun_path, sizeof(addr.sun_path), %s, path);
 +    ret = connect(fd, (struct sockaddr *)addr, sizeof(addr));
 +    g_assert(ret != -1);
 +
 +    return qmp_session_new(fd);
 +}
 +
 +static void wait_for_pid_exit(pid_t pid)
 +{
 +    FILE *f = NULL;
 +
 +    /* This is ugly but I don't know of a better way */

man waitpid?

 +    do {
 +        char buffer[1024];
 +
 +        if (f) {
 +            fclose(f);
 +            usleep(1);
 +        }
 +
 +        snprintf(buffer, sizeof(buffer), /proc/%d/stat, pid);
 +        f = fopen(buffer, r);
 +    } while (f);
 +}
 +
 +static void qemu_destroy(QmpSession *sess)
 +{
 +    wait_for_pid_exit(last_qemu_pid);
 +    last_qemu_pid = -1;
 +    qmp_session_destroy(sess);
 +}
 +
 +static void test_version(void)
 +{
 +    QmpSession *sess = NULL;
 +    VersionInfo *info;
 +    char version[1024];
 +    char *ptr, *end;
 +    int major, minor, micro;
 +
 +    /* Even though we use the same string as the source input, we do parse it
 +     * a little bit different for no other reason that to make sure we catch
 +     * potential bugs.
 +     */
 +    snprintf(version, sizeof(version), %s, QEMU_VERSION);
 +    ptr = version;
 +
 +    end = strchr(ptr, '.');
 +    g_assert(end != NULL);
 +    *end = 0;
 +    major 

Re: [Qemu-devel] [PATCH 01/15] qapi: add code generator for qmp-types (v2)

2011-03-12 Thread Blue Swirl
On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguori aligu...@us.ibm.com wrote:
 Only generate qmp-types.[ch].  These files contain the type definitions for
 QMP along with the alloc/free functions for these types.  Functions to convert
 enum values to integers and vice versa are also included.

 qmp-types is used both within QEMU and within libqmp

 Special alloc/free functions are provided to ensure that all structures are
 padded when allocated.  This makes sure that libqmp can provide a forward
 compatible interface since all additions to a structure will have a boolean
 enable flag.

 The free function is convenient since individual structures may have pointers
 that also require freeing.

 Signed-off-by: Anthony Liguori aligu...@us.ibm.com
 ---
 v1 - v2
  - modify code generator to use multiline strings instead of prints
  - support proxy commands
  - support async commands

 diff --git a/Makefile b/Makefile
 index 6b1d716..6b9fd69 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -4,6 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
  ifeq ($(TRACE_BACKEND),dtrace)
  GENERATED_HEADERS += trace-dtrace.h
  endif
 +GENERATED_HEADERS += qmp-types.h

  ifneq ($(wildcard config-host.mak),)
  # Put the all: rule here so that config-host.mak can contain dependencies.
 @@ -146,6 +147,14 @@ trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)

  simpletrace.o: simpletrace.c $(GENERATED_HEADERS)

 +qmp-types.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
 +       $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --types-body  $ 
  $@,   GEN   $@)
 +
 +qmp-types.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
 +       $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --types-header  
 $  $@,   GEN   $@)
 +
 +qmp-types.o: qmp-types.c qmp-types.h
 +
  version.o: $(SRC_PATH)/version.rc config-host.mak
        $(call quiet-command,$(WINDRES) -I. -o $@ $,  RC    $(TARGET_DIR)$@)

 diff --git a/Makefile.objs b/Makefile.objs
 index 69f0383..710d99f 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -15,7 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o

  block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
  block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
 -block-obj-y += error.o
 +block-obj-y += error.o qmp-types.o
  block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o

 diff --git a/ordereddict.py b/ordereddict.py
 new file mode 100644

Please put this into scripts/.

 index 000..e17269f
 --- /dev/null
 +++ b/ordereddict.py
 @@ -0,0 +1,128 @@
 +# Copyright (c) 2009 Raymond Hettinger
 +#
 +# 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.
 +
 +from UserDict import DictMixin
 +
 +class OrderedDict(dict, DictMixin):
 +
 +    def __init__(self, *args, **kwds):
 +        if len(args)  1:
 +            raise TypeError('expected at most 1 arguments, got %d' % 
 len(args))
 +        try:
 +            self.__end
 +        except AttributeError:
 +            self.clear()
 +        self.update(*args, **kwds)
 +
 +    def clear(self):
 +        self.__end = end = []
 +        end += [None, end, end]         # sentinel node for doubly linked 
 list
 +        self.__map = {}                 # key -- [key, prev, next]
 +        dict.clear(self)
 +
 +    def __setitem__(self, key, value):
 +        if key not in self:
 +            end = self.__end
 +            curr = end[1]
 +            curr[2] = end[1] = self.__map[key] = [key, curr, end]
 +        dict.__setitem__(self, key, value)
 +
 +    def __delitem__(self, key):
 +        dict.__delitem__(self, key)
 +        key, prev, next = self.__map.pop(key)
 +        prev[2] = next
 +        next[1] = prev
 +
 +    def __iter__(self):
 +        end = self.__end
 +        curr = end[2]
 +        while curr is not end:
 +            yield curr[0]
 +            curr = curr[2]
 +
 +    def __reversed__(self):
 +        

[Qemu-devel] Re: fdc: refactor device creation causes guest kernel panic

2011-03-12 Thread Stefan Hajnoczi
On Sat, Mar 12, 2011 at 10:53 AM, Blue Swirl blauwir...@gmail.com wrote:
 The logic for calculating the drive state in pc.c does not match fdc.c
 logic. Please try this patch.

 diff --git a/hw/pc.c b/hw/pc.c
 index 5966bf1..4d67d9f 100644
 --- a/hw/pc.c
 +++ b/hw/pc.c
 @@ -382,7 +382,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t
 above_4g_mem_size,
     /* floppy type */
     for (i = 0; i  2; i++) {
         fd[i] = drive_get(IF_FLOPPY, 0, i);
 -        if (fd[i]) {
 +        if (fd[i]  bdrv_is_inserted(fd[i]-bdrv)) {
             bdrv_get_floppy_geometry_hint(fd[i]-bdrv, nb_heads, max_track,
                                           last_sect, FDRIVE_DRV_NONE,
                                           fd_type[i]);


This patch fixes the problem, thanks!

Tested-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: fdc: refactor device creation causes guest kernel panic

2011-03-12 Thread Blue Swirl
On Sat, Mar 12, 2011 at 2:58 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Sat, Mar 12, 2011 at 10:53 AM, Blue Swirl blauwir...@gmail.com wrote:
 The logic for calculating the drive state in pc.c does not match fdc.c
 logic. Please try this patch.

 diff --git a/hw/pc.c b/hw/pc.c
 index 5966bf1..4d67d9f 100644
 --- a/hw/pc.c
 +++ b/hw/pc.c
 @@ -382,7 +382,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t
 above_4g_mem_size,
     /* floppy type */
     for (i = 0; i  2; i++) {
         fd[i] = drive_get(IF_FLOPPY, 0, i);
 -        if (fd[i]) {
 +        if (fd[i]  bdrv_is_inserted(fd[i]-bdrv)) {
             bdrv_get_floppy_geometry_hint(fd[i]-bdrv, nb_heads, max_track,
                                           last_sect, FDRIVE_DRV_NONE,
                                           fd_type[i]);


 This patch fixes the problem, thanks!

 Tested-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Thank you for testing, applied.



[Qemu-devel] Can Qemu emulation Simultaneous Multi-Thread processor ?

2011-03-12 Thread wang sheng
Did  Qemu emulate the SMT processor ?   I have develop some method to
emulate an multi-thread ,  I  define single CPUState  variable,  the
CPUState contain  four  thread contexts.    every 1ms interval   ,
switching thread-context to emulate the threads.

How do you think  the way by which I used to emulate  Simultaneouse
Multi-Thread processor ?

I find  that Qemu can support SMP very well, should I emulate the SMT
using the way  for SMP ?



Re: [Qemu-devel] [PATCH 03/11] add a generic Error object

2011-03-12 Thread Anthony Liguori

On 03/12/2011 05:05 AM, Blue Swirl wrote:

On Fri, Mar 11, 2011 at 11:00 PM, Anthony Liguorialigu...@us.ibm.com  wrote:

The Error class is similar to QError (now deprecated) except that it supports
propagation.  This allows for higher quality error handling.  It's losely
modeled after glib style GErrors.

Signed-off-by: Anthony Liguorialigu...@us.ibm.com

diff --git a/Makefile.objs b/Makefile.objs
index 0ba02c7..da31530 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -15,6 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o

  block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
  block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
+block-obj-y += error.o
  block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o

diff --git a/error.c b/error.c
new file mode 100644
index 000..5d84106
--- /dev/null
+++ b/error.c
@@ -0,0 +1,122 @@
+/*
+ * QEMU Error Objects
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguorialigu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include error.h
+#include error_int.h
+#include qemu-objects.h
+#include qerror.h
+#includeassert.h
+
+struct Error
+{
+QDict *obj;
+const char *fmt;
+char *msg;
+};
+
+void error_set(Error **errp, const char *fmt, ...)
+{
+Error *err;
+va_list ap;
+
+if (errp == NULL) {
+return;
+}
+
+err = qemu_mallocz(sizeof(*err));
+
+va_start(ap, fmt);
+err-obj = qobject_to_qdict(qobject_from_jsonv(fmt,ap));
+va_end(ap);
+err-fmt = fmt;
+
+*errp = err;
+}
+
+bool error_is_set(Error **errp)
+{
+return (errp  *errp);
+}
+
+const char *error_get_pretty(Error *err)
+{
+if (err-msg == NULL) {
+QString *str;
+str = qerror_format(err-fmt, err-obj);
+err-msg = qemu_strdup(qstring_get_str(str));
+}
+
+return err-msg;
+}
+
+const char *error_get_field(Error *err, const char *field)
+{
+if (strcmp(field, class) == 0) {
+return qdict_get_str(err-obj, field);
+} else {
+QDict *dict = qdict_get_qdict(err-obj, data);
+return qdict_get_str(dict, field);
+}
+}
+
+void error_free(Error *err)
+{
+QDECREF(err-obj);
+qemu_free(err-msg);
+qemu_free(err);
+}
+
+bool error_is_type(Error *err, const char *fmt)
+{
+char *ptr;
+char *end;
+char classname[1024];
+
+ptr = strstr(fmt, 'class': ');
+assert(ptr != NULL);
+ptr += strlen('class': ');
+
+end = strchr(ptr, '\'');
+assert(end != NULL);
+
+memcpy(classname, ptr, (end - ptr));
+classname[(end - ptr)] = 0;
+
+return strcmp(classname, error_get_field(err, class)) == 0;
+}
+
+void error_propagate(Error **dst_err, Error *local_err)
+{
+if (dst_err) {
+*dst_err = local_err;
+} else if (local_err) {
+error_free(local_err);
+}
+}
+
+QObject *error_get_qobject(Error *err)
+{
+QINCREF(err-obj);
+return QOBJECT(err-obj);
+}
+
+void error_set_qobject(Error **errp, QObject *obj)
+{
+Error *err;
+if (errp == NULL) {
+return;
+}
+err = qemu_mallocz(sizeof(*err));
+err-obj = qobject_to_qdict(obj);
+qobject_incref(obj);
+
+*errp = err;
+}
diff --git a/error.h b/error.h
new file mode 100644

The name is too generic, it could conflict with system headers. At
least I have /usr/include/error.h.


index 000..317d487
--- /dev/null
+++ b/error.h
@@ -0,0 +1,65 @@
+/*
+ * QEMU Error Objects
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguorialigu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#ifndef ERROR_H
+#define ERROR_H

This #define could also conflict with system headers. In my system,
_ERROR_H is used, but who knows all error.h files out there?


Certainly a good point.  I'll use a different name.

Regards,

Anthony Liguori





Re: [Qemu-devel] Re: [PATCH 01/11] Add hard build dependency on glib

2011-03-12 Thread Anthony Liguori

On 03/12/2011 02:09 AM, Paolo Bonzini wrote:

On 03/11/2011 10:00 PM, Anthony Liguori wrote:
GLib is an extremely common library that has a portable thread 
implementation

along with tons of other goodies.

GLib and GObject have a fantastic amount of infrastructure we can 
leverage in

QEMU including an object oriented programming infrastructure.

Short term, it has a very nice thread pool implementation that we 
could leverage
in something like virtio-9p.  It also has a test harness 
implementation that

this series will use.

Signed-off-by: Anthony Liguorialigu...@us.ibm.com


This doesn't need to go in until there is use for it, which is IIRC 
for the QAPI tests?


Correct.  I mistakenly thought I still used it in Error but I removed 
that dependency.


Regards,

Anthony Liguori


Paolo






Re: [Qemu-devel] [PATCH 13/15] qapi: add code generator for libqmp (v2)

2011-03-12 Thread Anthony Liguori

On 03/12/2011 05:10 AM, Blue Swirl wrote:

On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguorialigu...@us.ibm.com  wrote:

Signed-off-by: Anthony Liguorialigu...@us.ibm.com
---
v1 -  v2
  - update code generator to use multiline
  - proxy command support
  - async command support

diff --git a/Makefile b/Makefile
index 47a755d..5170675 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
  ifeq ($(TRACE_BACKEND),dtrace)
  GENERATED_HEADERS += trace-dtrace.h
  endif
-GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h
+GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h libqmp.h

  ifneq ($(wildcard config-host.mak),)
  # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -165,9 +165,16 @@ qmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
  qmp-marshal.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
$(call quiet-command,python $(SRC_PATH)/qmp-gen.py --body  $$@,   
GEN   $@)

+libqmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --lib-header  $$@, 
  GEN   $@)
+
+libqmp.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --lib-body  $$@,  
 GEN   $@)
+
  qmp-types.o: qmp-types.c qmp-types.h
  qmp-marshal-types.o: qmp-marshal-types.c qmp-marshal-types.h qmp-types.h
  qmp-marshal.o: qmp-marshal.c qmp.h qmp-types.h qmp-marshal-types.h
+libqmp.o: libqmp.c libqmp.h qmp-types.h

  version.o: $(SRC_PATH)/version.rc config-host.mak
$(call quiet-command,$(WINDRES) -I. -o $@ $,  RC$(TARGET_DIR)$@)
diff --git a/libqmp-core.c b/libqmp-core.c
new file mode 100644
index 000..4613d4f
--- /dev/null
+++ b/libqmp-core.c
@@ -0,0 +1,361 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguorialigu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include libqmp.h
+#include libqmp-internal.h
+#include libqmp-core.h
+#include json-streamer.h
+#include json-parser.h
+#include dirent.h
+#includesys/socket.h
+#includesys/un.h
+#includeassert.h
+
+#ifndef container_of
+#define offset_of(type, field) \
+((unsigned long)(((type *)0)-field))
+#define container_of(obj, type, field) \
+((type *)(((char *)obj) - offsetof(type, field)))
+#endif

Why not use the existing definitions?


libqmp builds outside of the normal QEMU code base (it's a client library).

libqmp wants to be LGPL.  It's not clear what the license of the stuff 
in osdep is.


Regards,

Anthony Liguori





Re: [Qemu-devel] [PATCH 14/15] qapi: add test-libqmp

2011-03-12 Thread Anthony Liguori

On 03/12/2011 05:23 AM, Blue Swirl wrote:

On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguorialigu...@us.ibm.com  wrote:

This provides a glib-test based testing framework for QMP

Signed-off-by: Anthony Liguorialigu...@us.ibm.com

diff --git a/Makefile b/Makefile
index 5170675..1d363d7 100644
--- a/Makefile
+++ b/Makefile
@@ -72,6 +72,8 @@ defconfig:

  -include config-all-devices.mak

+TOOLS += test-libqmp
+
  build-all: $(DOCS) $(TOOLS) recurse-all

  config-host.h: config-host.h-timestamp
@@ -205,6 +207,15 @@ check-qlist: check-qlist.o qlist.o qint.o 
$(CHECK_PROG_DEPS)
  check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
  check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS)

+LIBQMP_OBJS := qmp-types.o libqmp.o error.o libqmp-core.o
+LIBQMP_OBJS += qmp-marshal-types-core.o qmp-marshal-types.o
+LIBQMP_OBJS += qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o
+LIBQMP_OBJS += qerror.o
+LIBQMP_OBJS += json-streamer.o json-lexer.o json-parser.o
+LIBQMP_OBJS += $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o
+
+test-libqmp: test-libqmp.o $(LIBQMP_OBJS) qemu-timer-common.o
+
  clean:
  # avoid old build problems by removing potentially incorrect old files
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
diff --git a/test-libqmp.c b/test-libqmp.c
new file mode 100644

I'd put this to tests/.


tests/ lives outside of the QEMU build system today.  It's also very TCG 
specific.


How about taking the current contents of tests/ and moving it to 
tests/tcg and moving test-libqmp and check-*.c to tests/?



index 000..9b73987
--- /dev/null
+++ b/test-libqmp.c
@@ -0,0 +1,170 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguorialigu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#includestdio.h
+#includesys/socket.h
+#includenetinet/in.h
+#includenetinet/tcp.h
+#includearpa/inet.h
+#includesys/un.h
+#includestdlib.h
+#includeglib.h
+#includesys/wait.h
+#include config-host.h
+#include libqmp.h
+#include qerror.h
+
+#define g_assert_noerr(err) g_assert(err == NULL);
+#define g_assert_anyerr(err) g_assert(err != NULL);
+#define g_assert_cmperr(err, op, type) do {   \
+g_assert_anyerr(err);\
+g_assert_cmpstr(error_get_field(err, class), op, type); \
+} while (0)
+
+static pid_t last_qemu_pid = -1;
+
+static QmpSession *qemu(const char *fmt, ...)
+{
+char buffer0[4096];
+char buffer1[4096];
+const char *pid_filename = /tmp/test-libqmp-qemu.pid;
+const char *path = /tmp/test-libqmp-qemu.sock;

Very insecure filenames.


This disappears in round 3 when I introduce discovery support in libqmp.

Even so, I don't think security is a major concern here.


+static void wait_for_pid_exit(pid_t pid)
+{
+FILE *f = NULL;
+
+/* This is ugly but I don't know of a better way */

man waitpid?


waitpid only works for child processes.  Since we launch with 
-daemonize, that the QEMU instance is no longer a child process.


We use -daemonize because it avoids the race condition where we try to 
connect to a QMP socket but QEMU hasn't created the socket yet.  It also 
means that we can just use system() to invoke QEMU which makes life a 
whole lot simpler.


Regards,

Anthony Liguori



Re: [Qemu-devel] [PATCH 01/15] qapi: add code generator for qmp-types (v2)

2011-03-12 Thread Anthony Liguori

On 03/12/2011 05:29 AM, Blue Swirl wrote:

On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguorialigu...@us.ibm.com  wrote:

Only generate qmp-types.[ch].  These files contain the type definitions for
QMP along with the alloc/free functions for these types.  Functions to convert
enum values to integers and vice versa are also included.

qmp-types is used both within QEMU and within libqmp

Special alloc/free functions are provided to ensure that all structures are
padded when allocated.  This makes sure that libqmp can provide a forward
compatible interface since all additions to a structure will have a boolean
enable flag.

The free function is convenient since individual structures may have pointers
that also require freeing.

Signed-off-by: Anthony Liguorialigu...@us.ibm.com
---
v1 -  v2
  - modify code generator to use multiline strings instead of prints
  - support proxy commands
  - support async commands

diff --git a/Makefile b/Makefile
index 6b1d716..6b9fd69 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
  ifeq ($(TRACE_BACKEND),dtrace)
  GENERATED_HEADERS += trace-dtrace.h
  endif
+GENERATED_HEADERS += qmp-types.h

  ifneq ($(wildcard config-host.mak),)
  # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -146,6 +147,14 @@ trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)

  simpletrace.o: simpletrace.c $(GENERATED_HEADERS)

+qmp-types.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --types-body  $$@, 
  GEN   $@)
+
+qmp-types.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --types-header  $$@, 
  GEN   $@)
+
+qmp-types.o: qmp-types.c qmp-types.h
+
  version.o: $(SRC_PATH)/version.rc config-host.mak
$(call quiet-command,$(WINDRES) -I. -o $@ $,  RC$(TARGET_DIR)$@)

diff --git a/Makefile.objs b/Makefile.objs
index 69f0383..710d99f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -15,7 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o

  block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
  block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
-block-obj-y += error.o
+block-obj-y += error.o qmp-types.o
  block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o

diff --git a/ordereddict.py b/ordereddict.py
new file mode 100644

Please put this into scripts/.


Sure.


+
+#includestdint.h
+#includestdbool.h
+#include error.h
+
+typedef struct QmpSignal QmpSignal;
+typedef struct QmpCommandState QmpCommandState;
+typedef struct QmpState QmpState;
+
+#define BUILD_ASSERT(cond) do { \
+(void)sizeof(int[-1+!!(cond)]); \

Spaces around '+'.

This could be useful elsewhere, how about putting it to some generic header?


Sure.

Regards,

Anthony Liguori


+} while (0)
+
+#define BUILD_BUG() BUILD_ASSERT(0)
+
+#endif
--
1.7.0.4








Re: [Qemu-devel] [PATCH 10/11] json-streamer: limit the maximum recursion depth and maximum token count

2011-03-12 Thread Anthony Liguori

On 03/11/2011 05:16 PM, Michael Roth wrote:

  parser-emit(parser, parser-tokens);
  QDECREF(parser-tokens);
  parser-tokens = qlist_new();
+parser-token_size = 0;
+} else if (parser-token_size  MAX_TOKEN_SIZE ||
+   parser-bracket_count  MAX_NESTING ||
+   parser-brace_count  MAX_NESTING) {
+/* Security consideration, we limit total memory allocated 
per object

+ * and the maximum recursion depth that a message can force.
+ */
+parser-brace_count = 0;
+parser-bracket_count = 0;
+parser-emit(parser, parser-tokens);
@@ -56,6 +61,19 @@ static void json_message_process_token(JSONLexer 
*lexer, QString *token, JSONTok


Should we even bother passing this to the parser? That's a lot stuff 
to churn on that we know isn't going to result in anything useful. If 
there was a proper object earlier in the stream it would've been 
emitted when brace/bracket count reached 0.


I think it might be nicer to do parser-emit(parser, NULL), and fix up 
json_parser_parse_err() to check for this and simply return NULL back 
to qmp_dispatch_err() or whoever is calling.


I think brace_count  0 || bracket_count  0 should get similar 
treatment.


I think the main advantage of doing it this way is that we can test the 
maximum stack usage by just doing a simple:


(while true; do echo {'key': ; done) | socat stdio 
unix:/path/to/qmp.sock  /dev/null


However, if we don't pass the token list to the parser, we need to know 
exactly what the maximum is and only generate that depth in order to 
test stack usage.


The parser needs to be robust against bad input so from a test 
perspective, I like the idea of passing something to the parser even if 
we know it's bad.


Regards,

Anthony Liguori



Re: [Qemu-devel] [PATCH 07/15] qapi: add query-version QMP command

2011-03-12 Thread Anthony Liguori

On 03/12/2011 05:19 AM, Blue Swirl wrote:

On Sat, Mar 12, 2011 at 1:05 AM, Anthony Liguorialigu...@us.ibm.com  wrote:

This is used internally by QMP.  It's also a pretty good example of a typical
command conversion.

Signed-off-by: Anthony Liguorialigu...@us.ibm.com

diff --git a/Makefile.objs b/Makefile.objs
index 5dae800..e1a2756 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -103,7 +103,7 @@ common-obj-y += block-migration.o
  common-obj-y += pflib.o
  common-obj-y += bitmap.o bitops.o
  common-obj-y += qmp-marshal-types.o qmp-marshal-types-core.o
-common-obj-y += qmp-core.o qmp-marshal.o
+common-obj-y += qmp-core.o qmp-marshal.o qmp.o

  common-obj-$(CONFIG_BRLAPI) += baum.o
  common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
diff --git a/qmp-schema.json b/qmp-schema.json
index e69de29..e72bc18 100644
--- a/qmp-schema.json
+++ b/qmp-schema.json
@@ -0,0 +1,90 @@
+# *-*- Mode: Python -*-*
+
+##
+# QMP Schema
+#
+# This file defines the types, commands, and events used by QMP.  It should
+# fully describe the interface used by QMP.
+#
+# This file is designed to be loosely based on JSON although it's technical
+# executable Python.  While dictionaries are used, they are parsed as
+# OrderedDicts so that ordering is preserved.
+#
+# There are two basic syntaxes used.  The first syntax defines a type and is
+# represented by a dictionary.  There are three kinds of types that are
+# supported.
+#
+# A complex type is a dictionary containing a single key who's value is a
+# dictionary.  This corresponds to a struct in C or an Object in JSON.  An
+# example of a complex type is:
+#
+#  { 'type': 'MyType',
+#'data' { 'member1': 'str', 'member2': 'int', '*member3': 'str } }
+#
+# The use of '*' as a prefix to the name means the member is optional.  
Optional
+# members should always be added to the end of the dictionary to preserve
+# backwards compatibility.
+#
+# An enumeration type is a dictionary containing a single key who's value is a
+# list of strings.  An example enumeration is:
+#
+#  { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] }
+#
+# A signal is similar in form to a complex type except the single key is
+# entirely upper case instead of CamelCase.  An example signal is:
+#
+#  { 'event': 'MY_SIGNAL', 'data': { 'arg1': 'str', 'arg2': 'str' } }
+#
+# Generally speaking, complex types and enums should always use CamelCase for
+# the type names.
+#
+# Commands are defined by using a list containing three members.  The first
+# member is the command name, the second member is a dictionary containing
+# arguments, and the third member is the return type.
+#
+# An example command is:
+#
+#  { 'command': 'my-command',
+#'data': { 'arg1': 'str', '*arg2': 'str' },
+#'returns': 'str' ]
+#
+# Command names should be all lower case with words separated by a hyphen.
+
+### 0.14.0 commands.  Do not modify. ###
+
+##
+# @VersionInfo:
+#
+# A description of QEMU's version.
+#
+# @qemu.major:  The major version of QEMU
+#
+# @qemu.minor:  The minor version of QEMU
+#
+# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
+#   version of 50 signifies a development branch.  A micro version
+#   greater than or equal to 90 signifies a release candidate for
+#   the next minor version.  A micro version of less than 50
+#   signifies a stable release.
+#
+# @package: QEMU will always set this field to an empty string.  Downstream
+#   versions of QEMU should set this to a non-empty string.  The
+#   exact format depends on the downstream however it highly
+#   recommended that a unique name is used.
+#
+# Since: 0.14.0
+##
+{ 'type': 'VersionInfo',
+  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
+   'package': 'str'} }
+
+##
+# @query-version:
+#
+# Returns the current version of QEMU.
+#
+# Returns:  A @VersionInfo object describing the current version of QEMU.
+#
+# Since: 0.14.0
+##
+{ 'command': 'query-version', 'returns': 'VersionInfo' }
diff --git a/qmp.c b/qmp.c
new file mode 100644
index 000..7b626f5
--- /dev/null
+++ b/qmp.c
@@ -0,0 +1,31 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguorialigu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include qemu-common.h
+#include qmp-core.h
+#include qmp.h
+
+VersionInfo *qmp_query_version(Error **err)
+{
+VersionInfo *info = qmp_alloc_version_info();
+const char *version = QEMU_VERSION;
+char *tmp;
+
+info-qemu.major = strtol(version,tmp, 10);

Since all fields are int64_t, these should use strtoll(), otherwise
they may fail for versions like QEMU 2147483648.0.0. ;-)


The fields are int64_t because that's what JSON supports.  I considered 
using more precise types and doing the conversions with range checking 

[Qemu-devel] [PATCH v4 upstream 00/21] Win32 iothread support

2011-03-12 Thread Paolo Bonzini
Here is again the full series for Win32 iothread support.  It should be
ready now.

Patches 1 to 5 are generic Win32 improvements, including the qemu-thread
implementation.  To simplify the dependencies, I think it's better if
this part is also routed through uq/master.

Patches 6 to 8 are generic threading improvements, including using
PTHREAD_MUTEX_ERRORCHECK as suggested by Jan.

Patches 9 to 16 eliminate polling, replacing condition variable
timedwait with wait.

Patch 17 removes a redundant condition from the TCG cpu_exec_all
function.

Patches 18 to 20 add all necessary stubs to make iothread compile
with Win32, except the IPI calls.  These are provided by patch 21.

Tested on Wine and Linux, not on real Windows.  The series introduces
a dependency on Windows 2K or newer.  I don't think either 95/98/ME
or Windows NT 3.x are reasonable host systems for QEMU, anyway.

v1-v2
I incorporated all suggestions from Jan, including his renaming patch
for qemu_*_is_self; sh4 now doesn't have a special cpu_halted anymore.

v2-v3
Fixed structure naming, renamed qemu_signalfd_init, dropped ownership
tracking in QemuMutex for now.

v3-v4
Consistently using qemu_free.

Jan Kiszka (1):
  Refactor thread retrieval and check

Paolo Bonzini (20):
  unlock iothread during WaitForMultipleObjects
  implement win32 dynticks timer
  use win32 timer queues
  add win32 qemu-thread implementation
  include qemu-thread.h early
  add assertions on the owner of a QemuMutex
  remove CONFIG_THREAD
  inline cpu_halted into sole caller
  always qemu_cpu_kick after unhalting a cpu
  exit round-robin vcpu loop if cpu-stopped is true
  always signal pause_cond after stopping a VCPU
  do not use timedwait on qemu_halt_cond
  do not use timedwait on qemu_system_cond
  do not use timedwait on qemu_pause_cond
  do not use timedwait on qemu_cpu_cond
  iothread stops the vcpu thread via IPI
  merge all signal initialization with qemu_signalfd_init, rename
  provide dummy signal init functions for win32
  protect qemu_cpu_kick_self for Win32
  add Win32 IPI service

 Makefile.objs|4 +-
 configure|2 -
 cpu-exec.c   |9 +-
 cpus.c   |  298 +-
 exec.c   |2 +-
 hw/ppc.c |2 +
 hw/sun4m.c   |   10 +-
 hw/sun4u.c   |4 +-
 os-win32.c   |2 +
 qemu-common.h|2 +-
 qemu-thread.c = qemu-thread-posix.c |   21 +--
 qemu-thread-posix.h  |   17 ++
 qemu-thread-win32.c  |  260 +
 qemu-thread-win32.h  |   21 +++
 qemu-thread.h|   31 ++--
 qemu-timer.c |   89 +--
 target-alpha/exec.h  |   11 --
 target-arm/exec.h|   13 --
 target-cris/exec.h   |   11 --
 target-i386/exec.h   |   12 --
 target-i386/kvm.c|4 +-
 target-m68k/exec.h   |   10 --
 target-microblaze/exec.h |   11 --
 target-mips/exec.h   |   11 --
 target-ppc/exec.h|   11 --
 target-s390x/exec.h  |   12 --
 target-s390x/kvm.c   |1 +
 target-sh4/exec.h|   10 --
 target-sparc/exec.h  |   10 --
 ui/vnc-jobs-async.c  |2 +-
 30 files changed, 541 insertions(+), 362 deletions(-)
 rename qemu-thread.c = qemu-thread-posix.c (90%)
 create mode 100644 qemu-thread-posix.h
 create mode 100644 qemu-thread-win32.c
 create mode 100644 qemu-thread-win32.h

-- 
1.7.4




[Qemu-devel] [PATCH v4 upstream 01/21] unlock iothread during WaitForMultipleObjects

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 os-win32.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index b214e6a..c971d92 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -140,7 +140,9 @@ void os_host_main_loop_wait(int *timeout)
 int err;
 WaitObjects *w = wait_objects;
 
+qemu_mutex_unlock_iothread();
 ret = WaitForMultipleObjects(w-num, w-events, FALSE, *timeout);
+qemu_mutex_lock_iothread();
 if (WAIT_OBJECT_0 + 0 = ret  ret = WAIT_OBJECT_0 + w-num - 1) {
 if (w-func[ret - WAIT_OBJECT_0])
 w-func[ret - WAIT_OBJECT_0](w-opaque[ret - WAIT_OBJECT_0]);
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 02/21] implement win32 dynticks timer

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 88c7b28..122e7ed 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -1004,6 +1004,7 @@ static void win32_stop_timer(struct qemu_alarm_timer *t)
 static void win32_rearm_timer(struct qemu_alarm_timer *t)
 {
 struct qemu_alarm_win32 *data = t-priv;
+int nearest_delta_ms;
 
 assert(alarm_has_dynticks(t));
 if (!active_timers[QEMU_CLOCK_REALTIME] 
@@ -1013,7 +1014,11 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t)
 
 timeKillEvent(data-timerId);
 
-data-timerId = timeSetEvent(1,
+nearest_delta_ms = (qemu_next_alarm_deadline() + 99) / 100;
+if (nearest_delta_ms  1) {
+nearest_delta_ms = 1;
+}
+data-timerId = timeSetEvent(nearest_delta_ms,
 data-period,
 host_alarm_handler,
 (DWORD)t,
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 04/21] Refactor thread retrieval and check

2011-03-12 Thread Paolo Bonzini
From: Jan Kiszka jan.kis...@siemens.com

We have qemu_cpu_self and qemu_thread_self. The latter is retrieving the
current thread, the former is checking for equality (using CPUState). We
also have qemu_thread_equal which is only used like qemu_cpu_self.

This refactors the interfaces, creating qemu_cpu_is_self and
qemu_thread_is_self as well ass qemu_thread_get_self.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c  |   22 --
 exec.c  |2 +-
 qemu-common.h   |2 +-
 qemu-thread.c   |6 +++---
 qemu-thread.h   |4 ++--
 target-i386/kvm.c   |4 ++--
 ui/vnc-jobs-async.c |2 +-
 7 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0f33945..09ce6fe 100644
--- a/cpus.c
+++ b/cpus.c
@@ -531,7 +531,7 @@ void qemu_init_vcpu(void *_env)
 }
 }
 
-int qemu_cpu_self(void *env)
+int qemu_cpu_is_self(void *env)
 {
 return 1;
 }
@@ -699,7 +699,7 @@ int qemu_init_main_loop(void)
 qemu_mutex_init(qemu_global_mutex);
 qemu_mutex_lock(qemu_global_mutex);
 
-qemu_thread_self(io_thread);
+qemu_thread_get_self(io_thread);
 
 return 0;
 }
@@ -714,7 +714,7 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), 
void *data)
 {
 struct qemu_work_item wi;
 
-if (qemu_cpu_self(env)) {
+if (qemu_cpu_is_self(env)) {
 func(data);
 return;
 }
@@ -808,7 +808,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
 int r;
 
 qemu_mutex_lock(qemu_global_mutex);
-qemu_thread_self(env-thread);
+qemu_thread_get_self(env-thread);
 
 r = kvm_init_vcpu(env);
 if (r  0) {
@@ -845,7 +845,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 CPUState *env = arg;
 
 qemu_tcg_init_cpu_signals();
-qemu_thread_self(env-thread);
+qemu_thread_get_self(env-thread);
 
 /* signal CPU creation */
 qemu_mutex_lock(qemu_global_mutex);
@@ -888,14 +888,11 @@ void qemu_cpu_kick_self(void)
 }
 }
 
-int qemu_cpu_self(void *_env)
+int qemu_cpu_is_self(void *_env)
 {
 CPUState *env = _env;
-QemuThread this;
 
-qemu_thread_self(this);
-
-return qemu_thread_equal(this, env-thread);
+return qemu_thread_is_self(env-thread);
 }
 
 void qemu_mutex_lock_iothread(void)
@@ -1023,10 +1020,7 @@ void cpu_stop_current(void)
 
 void vm_stop(int reason)
 {
-QemuThread me;
-qemu_thread_self(me);
-
-if (!qemu_thread_equal(me, io_thread)) {
+if (!qemu_thread_is_self(io_thread)) {
 qemu_system_vmstop_request(reason);
 /*
  * FIXME: should not return to device code in case
diff --git a/exec.c b/exec.c
index 81f08b7..3d78063 100644
--- a/exec.c
+++ b/exec.c
@@ -1640,7 +1640,7 @@ void cpu_interrupt(CPUState *env, int mask)
  * If called from iothread context, wake the target cpu in
  * case its halted.
  */
-if (!qemu_cpu_self(env)) {
+if (!qemu_cpu_is_self(env)) {
 qemu_cpu_kick(env);
 return;
 }
diff --git a/qemu-common.h b/qemu-common.h
index 18e648f..3fe1719 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -290,7 +290,7 @@ void qemu_notify_event(void);
 /* Unblock cpu */
 void qemu_cpu_kick(void *env);
 void qemu_cpu_kick_self(void);
-int qemu_cpu_self(void *env);
+int qemu_cpu_is_self(void *env);
 
 /* work queue */
 struct qemu_work_item {
diff --git a/qemu-thread.c b/qemu-thread.c
index fbc78fe..e307773 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -176,14 +176,14 @@ void qemu_thread_signal(QemuThread *thread, int sig)
 error_exit(err, __func__);
 }
 
-void qemu_thread_self(QemuThread *thread)
+void qemu_thread_get_self(QemuThread *thread)
 {
 thread-thread = pthread_self();
 }
 
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2)
+int qemu_thread_is_self(QemuThread *thread)
 {
-   return pthread_equal(thread1-thread, thread2-thread);
+   return pthread_equal(pthread_self(), thread-thread);
 }
 
 void qemu_thread_exit(void *retval)
diff --git a/qemu-thread.h b/qemu-thread.h
index 19bb30c..add97bf 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -37,8 +37,8 @@ void qemu_thread_create(QemuThread *thread,
void *(*start_routine)(void*),
void *arg);
 void qemu_thread_signal(QemuThread *thread, int sig);
-void qemu_thread_self(QemuThread *thread);
-int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2);
+void qemu_thread_get_self(QemuThread *thread);
+int qemu_thread_is_self(QemuThread *thread);
 void qemu_thread_exit(void *retval);
 
 #endif
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 0aa0a41..1f12cbf 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1355,7 +1355,7 @@ int kvm_arch_put_registers(CPUState *env, int level)
 {
 int ret;
 
-assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+assert(cpu_is_stopped(env) || qemu_cpu_is_self(env));
 
 ret = kvm_getput_regs(env, 1);
 if (ret  

[Qemu-devel] [PATCH v4 upstream 10/21] always qemu_cpu_kick after unhalting a cpu

2011-03-12 Thread Paolo Bonzini
This ensures env-halt_cond is broadcast, and the loop in
qemu_tcg_wait_io_event and qemu_kvm_wait_io_event is exited
naturally rather than through a timeout.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/ppc.c   |2 ++
 hw/sun4m.c |   10 --
 hw/sun4u.c |4 ++--
 target-s390x/kvm.c |1 +
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/hw/ppc.c b/hw/ppc.c
index 968aec1..de02d33 100644
--- a/hw/ppc.c
+++ b/hw/ppc.c
@@ -208,6 +208,7 @@ static void ppc970_set_irq (void *opaque, int pin, int 
level)
 } else {
 LOG_IRQ(%s: restart the CPU\n, __func__);
 env-halted = 0;
+qemu_cpu_kick(env);
 }
 break;
 case PPC970_INPUT_HRESET:
@@ -300,6 +301,7 @@ static void ppc40x_set_irq (void *opaque, int pin, int 
level)
 } else {
 LOG_IRQ(%s: restart the CPU\n, __func__);
 env-halted = 0;
+qemu_cpu_kick(env);
 }
 break;
 case PPC40x_INPUT_DEBUG:
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 30e8a21..df3aa32 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -253,15 +253,21 @@ void cpu_check_irqs(CPUState *env)
 }
 }
 
+static void cpu_kick_irq(CPUState *env)
+{
+env-halted = 0;
+cpu_check_irqs(env);
+qemu_cpu_kick(env);
+}
+
 static void cpu_set_irq(void *opaque, int irq, int level)
 {
 CPUState *env = opaque;
 
 if (level) {
 trace_sun4m_cpu_set_irq_raise(irq);
-env-halted = 0;
 env-pil_in |= 1  irq;
-cpu_check_irqs(env);
+cpu_kick_irq(env);
 } else {
 trace_sun4m_cpu_set_irq_lower(irq);
 env-pil_in = ~(1  irq);
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 90b1ce2..d282324 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -298,6 +298,7 @@ static void cpu_kick_irq(CPUState *env)
 {
 env-halted = 0;
 cpu_check_irqs(env);
+qemu_cpu_kick(env);
 }
 
 static void cpu_set_irq(void *opaque, int irq, int level)
@@ -306,9 +307,8 @@ static void cpu_set_irq(void *opaque, int irq, int level)
 
 if (level) {
 CPUIRQ_DPRINTF(Raise CPU IRQ %d\n, irq);
-env-halted = 0;
 env-pil_in |= 1  irq;
-cpu_check_irqs(env);
+cpu_kick_irq(env);
 } else {
 CPUIRQ_DPRINTF(Lower CPU IRQ %d\n, irq);
 env-pil_in = ~(1  irq);
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index b349812..6e94274 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -194,6 +194,7 @@ static void kvm_s390_interrupt_internal(CPUState *env, int 
type, uint32_t parm,
 
 env-halted = 0;
 env-exception_index = -1;
+qemu_cpu_kick(env);
 
 kvmint.type = type;
 kvmint.parm = parm;
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 03/21] use win32 timer queues

2011-03-12 Thread Paolo Bonzini
Multimedia timers are only useful for compatibility with Windows NT 4.0
and earlier.  Plus, the implementation in Wine is extremely heavyweight.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |   86 +++--
 1 files changed, 35 insertions(+), 51 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 122e7ed..1939d6b 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -200,11 +200,6 @@ static void qemu_rearm_alarm_timer(struct qemu_alarm_timer 
*t)
 
 #ifdef _WIN32
 
-struct qemu_alarm_win32 {
-MMRESULT timerId;
-unsigned int period;
-} alarm_win32_data = {0, 0};
-
 static int win32_start_timer(struct qemu_alarm_timer *t);
 static void win32_stop_timer(struct qemu_alarm_timer *t);
 static void win32_rearm_timer(struct qemu_alarm_timer *t);
@@ -298,9 +293,9 @@ static struct qemu_alarm_timer alarm_timers[] = {
 {unix, unix_start_timer, unix_stop_timer, NULL, NULL},
 #else
 {dynticks, win32_start_timer,
- win32_stop_timer, win32_rearm_timer, alarm_win32_data},
+ win32_stop_timer, win32_rearm_timer, NULL},
 {win32, win32_start_timer,
- win32_stop_timer, NULL, alarm_win32_data},
+ win32_stop_timer, NULL, NULL},
 #endif
 {NULL, }
 };
@@ -636,9 +631,7 @@ void qemu_run_all_timers(void)
 static int64_t qemu_next_alarm_deadline(void);
 
 #ifdef _WIN32
-static void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg,
-DWORD_PTR dwUser, DWORD_PTR dw1,
-DWORD_PTR dw2)
+static void CALLBACK host_alarm_handler(PVOID lpParam, BOOLEAN unused)
 #else
 static void host_alarm_handler(int host_signum)
 #endif
@@ -961,50 +954,45 @@ static void unix_stop_timer(struct qemu_alarm_timer *t)
 
 static int win32_start_timer(struct qemu_alarm_timer *t)
 {
-TIMECAPS tc;
-struct qemu_alarm_win32 *data = t-priv;
-UINT flags;
-
-memset(tc, 0, sizeof(tc));
-timeGetDevCaps(tc, sizeof(tc));
-
-data-period = tc.wPeriodMin;
-timeBeginPeriod(data-period);
-
-flags = TIME_CALLBACK_FUNCTION;
-if (alarm_has_dynticks(t))
-flags |= TIME_ONESHOT;
-else
-flags |= TIME_PERIODIC;
-
-data-timerId = timeSetEvent(1, // interval (ms)
-data-period,   // resolution
-host_alarm_handler, // function
-(DWORD)t,   // parameter
-flags);
-
-if (!data-timerId) {
+HANDLE hTimer;
+BOOLEAN success;
+
+/* If you call ChangeTimerQueueTimer on a one-shot timer (its period
+   is zero) that has already expired, the timer is not updated.  Since
+   creating a new timer is relatively expensive, set a bogus one-hour
+   interval in the dynticks case.  */
+success = CreateTimerQueueTimer(hTimer,
+  NULL,
+  host_alarm_handler,
+  t,
+  1,
+  alarm_has_dynticks(t) ? 360 : 1,
+  WT_EXECUTEINTIMERTHREAD);
+
+if (!success) {
 fprintf(stderr, Failed to initialize win32 alarm timer: %ld\n,
 GetLastError());
-timeEndPeriod(data-period);
 return -1;
 }
 
+t-priv = (PVOID) hTimer;
 return 0;
 }
 
 static void win32_stop_timer(struct qemu_alarm_timer *t)
 {
-struct qemu_alarm_win32 *data = t-priv;
+HANDLE hTimer = t-priv;
 
-timeKillEvent(data-timerId);
-timeEndPeriod(data-period);
+if (hTimer) {
+DeleteTimerQueueTimer(NULL, hTimer, NULL);
+}
 }
 
 static void win32_rearm_timer(struct qemu_alarm_timer *t)
 {
-struct qemu_alarm_win32 *data = t-priv;
+HANDLE hTimer = t-priv;
 int nearest_delta_ms;
+BOOLEAN success;
 
 assert(alarm_has_dynticks(t));
 if (!active_timers[QEMU_CLOCK_REALTIME] 
@@ -1012,25 +1000,21 @@ static void win32_rearm_timer(struct qemu_alarm_timer 
*t)
 !active_timers[QEMU_CLOCK_HOST])
 return;
 
-timeKillEvent(data-timerId);
-
 nearest_delta_ms = (qemu_next_alarm_deadline() + 99) / 100;
 if (nearest_delta_ms  1) {
 nearest_delta_ms = 1;
 }
-data-timerId = timeSetEvent(nearest_delta_ms,
-data-period,
-host_alarm_handler,
-(DWORD)t,
-TIME_ONESHOT | TIME_CALLBACK_FUNCTION);
-
-if (!data-timerId) {
-fprintf(stderr, Failed to re-arm win32 alarm timer %ld\n,
-GetLastError());
+success = ChangeTimerQueueTimer(NULL,
+hTimer,
+nearest_delta_ms,
+360);
 
-timeEndPeriod(data-period);
-exit(1);
+if (!success) {
+fprintf(stderr, Failed to rearm win32 alarm timer: %ld\n,
+GetLastError());
+

[Qemu-devel] [PATCH v4 upstream 06/21] include qemu-thread.h early

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 09ce6fe..c5743c4 100644
--- a/cpus.c
+++ b/cpus.c
@@ -32,6 +32,7 @@
 #include kvm.h
 #include exec-all.h
 
+#include qemu-thread.h
 #include cpus.h
 #include compatfd.h
 
@@ -592,8 +593,6 @@ void vm_stop(int reason)
 
 #else /* CONFIG_IOTHREAD */
 
-#include qemu-thread.h
-
 QemuMutex qemu_global_mutex;
 static QemuMutex qemu_fair_mutex;
 
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 17/21] iothread stops the vcpu thread via IPI

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index 4305184..32e9352 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1086,9 +1086,11 @@ bool cpu_exec_all(void)
 qemu_clock_enable(vm_clock,
   (env-singlestep_enabled  SSTEP_NOTIMER) == 0);
 
+#ifndef CONFIG_IOTHREAD
 if (qemu_alarm_pending()) {
 break;
 }
+#endif
 if (cpu_can_run(env)) {
 if (kvm_enabled()) {
 r = kvm_cpu_exec(env);
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 15/21] do not use timedwait on qemu_pause_cond

2011-03-12 Thread Paolo Bonzini
all_vcpus_paused can start returning true after penv-stopped changes
from 0 to 1.  When this is done, qemu_pause_cond is always signaled.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cpus.c b/cpus.c
index e367b3b..8f169ad 100644
--- a/cpus.c
+++ b/cpus.c
@@ -938,7 +938,7 @@ void pause_all_vcpus(void)
 }
 
 while (!all_vcpus_paused()) {
-qemu_cond_timedwait(qemu_pause_cond, qemu_global_mutex, 100);
+qemu_cond_wait(qemu_pause_cond, qemu_global_mutex);
 penv = first_cpu;
 while (penv) {
 qemu_cpu_kick(penv);
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 19/21] provide dummy signal init functions for win32

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |  143 ---
 1 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/cpus.c b/cpus.c
index 2b491a9..e0bcb5c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -196,6 +196,16 @@ static void cpu_handle_debug_exception(CPUState *env)
 #endif
 }
 
+#ifdef CONFIG_IOTHREAD
+static void cpu_signal(int sig)
+{
+if (cpu_single_env) {
+cpu_exit(cpu_single_env);
+}
+exit_request = 1;
+}
+#endif
+
 #ifdef CONFIG_LINUX
 static void sigbus_reraise(void)
 {
@@ -390,6 +400,61 @@ static int qemu_signal_init(void)
 return 0;
 }
 
+static void qemu_kvm_init_cpu_signals(CPUState *env)
+{
+int r;
+sigset_t set;
+struct sigaction sigact;
+
+memset(sigact, 0, sizeof(sigact));
+sigact.sa_handler = dummy_signal;
+sigaction(SIG_IPI, sigact, NULL);
+
+#ifdef CONFIG_IOTHREAD
+pthread_sigmask(SIG_BLOCK, NULL, set);
+sigdelset(set, SIG_IPI);
+sigdelset(set, SIGBUS);
+r = kvm_set_signal_mask(env, set);
+if (r) {
+fprintf(stderr, kvm_set_signal_mask: %s\n, strerror(-r));
+exit(1);
+}
+#else
+sigemptyset(set);
+sigaddset(set, SIG_IPI);
+sigaddset(set, SIGIO);
+sigaddset(set, SIGALRM);
+pthread_sigmask(SIG_BLOCK, set, NULL);
+
+pthread_sigmask(SIG_BLOCK, NULL, set);
+sigdelset(set, SIGIO);
+sigdelset(set, SIGALRM);
+#endif
+sigdelset(set, SIG_IPI);
+sigdelset(set, SIGBUS);
+r = kvm_set_signal_mask(env, set);
+if (r) {
+fprintf(stderr, kvm_set_signal_mask: %s\n, strerror(-r));
+exit(1);
+}
+}
+
+static void qemu_tcg_init_cpu_signals(void)
+{
+#ifdef CONFIG_IOTHREAD
+sigset_t set;
+struct sigaction sigact;
+
+memset(sigact, 0, sizeof(sigact));
+sigact.sa_handler = cpu_signal;
+sigaction(SIG_IPI, sigact, NULL);
+
+sigemptyset(set);
+sigaddset(set, SIG_IPI);
+pthread_sigmask(SIG_UNBLOCK, set, NULL);
+#endif
+}
+
 static void qemu_kvm_eat_signals(CPUState *env)
 {
 struct timespec ts = { 0, 0 };
@@ -470,39 +535,17 @@ static int qemu_signal_init(void)
 return 0;
 }
 
-#endif /* _WIN32 */
-
-#ifndef CONFIG_IOTHREAD
 static void qemu_kvm_init_cpu_signals(CPUState *env)
 {
-#ifndef _WIN32
-int r;
-sigset_t set;
-struct sigaction sigact;
-
-memset(sigact, 0, sizeof(sigact));
-sigact.sa_handler = dummy_signal;
-sigaction(SIG_IPI, sigact, NULL);
-
-sigemptyset(set);
-sigaddset(set, SIG_IPI);
-sigaddset(set, SIGIO);
-sigaddset(set, SIGALRM);
-pthread_sigmask(SIG_BLOCK, set, NULL);
+abort();
+}
 
-pthread_sigmask(SIG_BLOCK, NULL, set);
-sigdelset(set, SIG_IPI);
-sigdelset(set, SIGBUS);
-sigdelset(set, SIGIO);
-sigdelset(set, SIGALRM);
-r = kvm_set_signal_mask(env, set);
-if (r) {
-fprintf(stderr, kvm_set_signal_mask: %s\n, strerror(-r));
-exit(1);
-}
-#endif
+static void qemu_tcg_init_cpu_signals(void)
+{
 }
+#endif /* _WIN32 */
 
+#ifndef CONFIG_IOTHREAD
 int qemu_init_main_loop(void)
 {
 int ret;
@@ -536,6 +579,8 @@ void qemu_init_vcpu(void *_env)
 exit(1);
 }
 qemu_kvm_init_cpu_signals(env);
+} else {
+qemu_tcg_init_cpu_signals();
 }
 }
 
@@ -616,48 +661,6 @@ static QemuCond qemu_system_cond;
 static QemuCond qemu_pause_cond;
 static QemuCond qemu_work_cond;
 
-static void cpu_signal(int sig)
-{
-if (cpu_single_env) {
-cpu_exit(cpu_single_env);
-}
-exit_request = 1;
-}
-
-static void qemu_kvm_init_cpu_signals(CPUState *env)
-{
-int r;
-sigset_t set;
-struct sigaction sigact;
-
-memset(sigact, 0, sizeof(sigact));
-sigact.sa_handler = dummy_signal;
-sigaction(SIG_IPI, sigact, NULL);
-
-pthread_sigmask(SIG_BLOCK, NULL, set);
-sigdelset(set, SIG_IPI);
-sigdelset(set, SIGBUS);
-r = kvm_set_signal_mask(env, set);
-if (r) {
-fprintf(stderr, kvm_set_signal_mask: %s\n, strerror(-r));
-exit(1);
-}
-}
-
-static void qemu_tcg_init_cpu_signals(void)
-{
-sigset_t set;
-struct sigaction sigact;
-
-memset(sigact, 0, sizeof(sigact));
-sigact.sa_handler = cpu_signal;
-sigaction(SIG_IPI, sigact, NULL);
-
-sigemptyset(set);
-sigaddset(set, SIG_IPI);
-pthread_sigmask(SIG_UNBLOCK, set, NULL);
-}
-
 int qemu_init_main_loop(void)
 {
 int ret;
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 05/21] add win32 qemu-thread implementation

2011-03-12 Thread Paolo Bonzini
For now, qemu_cond_timedwait and qemu_mutex_timedlock are left as
POSIX-only functions.  They can be removed later, once the patches
that remove their uses are in.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 Makefile.objs|4 +-
 qemu-thread.c = qemu-thread-posix.c |0
 qemu-thread-posix.h  |   18 +++
 qemu-thread-win32.c  |  260 ++
 qemu-thread-win32.h  |   21 +++
 qemu-thread.h|   27 ++--
 6 files changed, 313 insertions(+), 17 deletions(-)
 rename qemu-thread.c = qemu-thread-posix.c (100%)
 create mode 100644 qemu-thread-posix.h
 create mode 100644 qemu-thread-win32.c
 create mode 100644 qemu-thread-win32.h

diff --git a/Makefile.objs b/Makefile.objs
index 9e98a66..a52f42f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -142,8 +142,8 @@ endif
 common-obj-y += $(addprefix ui/, $(ui-obj-y))
 
 common-obj-y += iov.o acl.o
-common-obj-$(CONFIG_THREAD) += qemu-thread.o
-common-obj-$(CONFIG_POSIX) += compatfd.o
+common-obj-$(CONFIG_POSIX) += qemu-thread-posix.o compatfd.o
+common-obj-$(CONFIG_WIN32) += qemu-thread-win32.o
 common-obj-y += notify.o event_notifier.o
 common-obj-y += qemu-timer.o qemu-timer-common.o
 
diff --git a/qemu-thread.c b/qemu-thread-posix.c
similarity index 100%
rename from qemu-thread.c
rename to qemu-thread-posix.c
diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
new file mode 100644
index 000..7af371c
--- /dev/null
+++ b/qemu-thread-posix.h
@@ -0,0 +1,18 @@
+#ifndef __QEMU_THREAD_POSIX_H
+#define __QEMU_THREAD_POSIX_H 1
+#include pthread.h
+
+struct QemuMutex {
+pthread_mutex_t lock;
+};
+
+struct QemuCond {
+pthread_cond_t cond;
+};
+
+struct QemuThread {
+pthread_t thread;
+};
+
+void qemu_thread_signal(QemuThread *thread, int sig);
+#endif
diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c
new file mode 100644
index 000..2edcb1a
--- /dev/null
+++ b/qemu-thread-win32.c
@@ -0,0 +1,260 @@
+/*
+ * Win32 implementation for mutex/cond/thread functions
+ *
+ * Copyright Red Hat, Inc. 2010
+ *
+ * Author:
+ *  Paolo Bonzini pbonz...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include qemu-common.h
+#include qemu-thread.h
+#include process.h
+#include assert.h
+#include limits.h
+
+static void error_exit(int err, const char *msg)
+{
+char *pstr;
+
+FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+  NULL, err, 0, (LPTSTR)pstr, 2, NULL);
+fprintf(stderr, qemu: %s: %s\n, msg, pstr);
+LocalFree(pstr);
+exit(1);
+}
+
+void qemu_mutex_init(QemuMutex *mutex)
+{
+mutex-owner = 0;
+InitializeCriticalSection(mutex-lock);
+}
+
+void qemu_mutex_lock(QemuMutex *mutex)
+{
+EnterCriticalSection(mutex-lock);
+
+/* Win32 CRITICAL_SECTIONs are recursive.  Assert that we're not
+ * using them as such.
+ */
+assert(mutex-owner == 0);
+mutex-owner = GetCurrentThreadId();
+}
+
+int qemu_mutex_trylock(QemuMutex *mutex)
+{
+int owned;
+
+owned = TryEnterCriticalSection(mutex-lock);
+if (owned) {
+assert(mutex-owner == 0);
+mutex-owner = GetCurrentThreadId();
+}
+return !owned;
+}
+
+void qemu_mutex_unlock(QemuMutex *mutex)
+{
+assert(mutex-owner == GetCurrentThreadId());
+mutex-owner = 0;
+LeaveCriticalSection(mutex-lock);
+}
+
+void qemu_cond_init(QemuCond *cond)
+{
+memset(cond, 0, sizeof(*cond));
+
+cond-sema = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
+if (!cond-sema) {
+error_exit(GetLastError(), __func__);
+}
+cond-continue_event = CreateEvent(NULL,/* security */
+   FALSE,   /* auto-reset */
+   FALSE,   /* not signaled */
+   NULL);   /* name */
+if (!cond-continue_event) {
+error_exit(GetLastError(), __func__);
+}
+}
+
+void qemu_cond_signal(QemuCond *cond)
+{
+DWORD result;
+
+/*
+ * Signal only when there are waiters.  cond-waiters is
+ * incremented by pthread_cond_wait under the external lock,
+ * so we are safe about that.
+ */
+if (cond-waiters == 0) {
+return;
+}
+
+/*
+ * Waiting threads decrement it outside the external lock, but
+ * only if another thread is executing pthread_cond_broadcast and
+ * has the mutex.  So, it also cannot be decremented concurrently
+ * with this particular access.
+ */
+cond-target = cond-waiters - 1;
+result = SignalObjectAndWait(cond-sema, cond-continue_event,
+ INFINITE, FALSE);
+if (result == WAIT_ABANDONED || result == WAIT_FAILED) {
+error_exit(GetLastError(), __func__);
+}
+}
+
+void qemu_cond_broadcast(QemuCond *cond)
+{
+BOOLEAN result;
+/*
+ * As in 

[Qemu-devel] [PATCH v4 upstream 12/21] always signal pause_cond after stopping a VCPU

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index 785a104..6cfb45b 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1012,8 +1012,10 @@ void qemu_notify_event(void)
 void cpu_stop_current(void)
 {
 if (cpu_single_env) {
+cpu_single_env-stop = 0;
 cpu_single_env-stopped = 1;
 cpu_exit(cpu_single_env);
+qemu_cond_signal(qemu_pause_cond);
 }
 }
 
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 21/21] add Win32 IPI service

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c  |   25 ++---
 qemu-thread-posix.c |9 -
 qemu-thread-posix.h |1 -
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/cpus.c b/cpus.c
index 7559a02..077729c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -854,13 +854,32 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 return NULL;
 }
 
+static void qemu_cpu_kick_thread(CPUState *env)
+{
+#ifndef _WIN32
+int err;
+
+err = pthread_kill(env-thread-thread, SIG_IPI);
+if (err) {
+fprintf(stderr, qemu:%s: %s, __func__, strerror(err));
+exit(1);
+}
+#else /* _WIN32 */
+if (!qemu_cpu_is_self(env)) {
+SuspendThread(env-thread-thread);
+cpu_signal(0);
+ResumeThread(env-thread-thread);
+}
+#endif
+}
+
 void qemu_cpu_kick(void *_env)
 {
 CPUState *env = _env;
 
 qemu_cond_broadcast(env-halt_cond);
 if (!env-thread_kicked) {
-qemu_thread_signal(env-thread, SIG_IPI);
+qemu_cpu_kick_thread(env);
 env-thread_kicked = true;
 }
 }
@@ -871,7 +890,7 @@ void qemu_cpu_kick_self(void)
 assert(cpu_single_env);
 
 if (!cpu_single_env-thread_kicked) {
-qemu_thread_signal(cpu_single_env-thread, SIG_IPI);
+qemu_cpu_kick_thread(cpu_single_env);
 cpu_single_env-thread_kicked = true;
 }
 #else
@@ -893,7 +912,7 @@ void qemu_mutex_lock_iothread(void)
 } else {
 qemu_mutex_lock(qemu_fair_mutex);
 if (qemu_mutex_trylock(qemu_global_mutex)) {
-qemu_thread_signal(tcg_cpu_thread, SIG_IPI);
+qemu_cpu_kick_thread(first_cpu);
 qemu_mutex_lock(qemu_global_mutex);
 }
 qemu_mutex_unlock(qemu_fair_mutex);
diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index 8b54cc0..87c1a9f 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -171,15 +171,6 @@ void qemu_thread_create(QemuThread *thread,
 pthread_sigmask(SIG_SETMASK, oldset, NULL);
 }
 
-void qemu_thread_signal(QemuThread *thread, int sig)
-{
-int err;
-
-err = pthread_kill(thread-thread, sig);
-if (err)
-error_exit(err, __func__);
-}
-
 void qemu_thread_get_self(QemuThread *thread)
 {
 thread-thread = pthread_self();
diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
index 7af371c..ee4618e 100644
--- a/qemu-thread-posix.h
+++ b/qemu-thread-posix.h
@@ -14,5 +14,4 @@ struct QemuThread {
 pthread_t thread;
 };
 
-void qemu_thread_signal(QemuThread *thread, int sig);
 #endif
-- 
1.7.4




[Qemu-devel] [PATCH v4 upstream 07/21] add assertions on the owner of a QemuMutex

2011-03-12 Thread Paolo Bonzini
These are already present in the Win32 implementation, add them to
the pthread wrappers as well.  Use PTHREAD_MUTEX_ERRORCHECK for mutex
operations. Later we'll add tracking of the owner for cond_signal/broadcast.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-thread-posix.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index e307773..8b54cc0 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -28,8 +28,12 @@ static void error_exit(int err, const char *msg)
 void qemu_mutex_init(QemuMutex *mutex)
 {
 int err;
+pthread_mutexattr_t mutexattr;
 
-err = pthread_mutex_init(mutex-lock, NULL);
+pthread_mutexattr_init(mutexattr);
+pthread_mutexattr_settype(mutexattr, PTHREAD_MUTEX_ERRORCHECK);
+err = pthread_mutex_init(mutex-lock, mutexattr);
+pthread_mutexattr_destroy(mutexattr);
 if (err)
 error_exit(err, __func__);
 }
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 14/21] do not use timedwait on qemu_system_cond

2011-03-12 Thread Paolo Bonzini
qemu_main_loop_start is the only place where qemu_system_ready is set
to 1.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 4c3837f..e367b3b 100644
--- a/cpus.c
+++ b/cpus.c
@@ -823,7 +823,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
 
 /* and wait for machine initialization */
 while (!qemu_system_ready) {
-qemu_cond_timedwait(qemu_system_cond, qemu_global_mutex, 100);
+qemu_cond_wait(qemu_system_cond, qemu_global_mutex);
 }
 
 while (1) {
@@ -855,7 +855,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 
 /* and wait for machine initialization */
 while (!qemu_system_ready) {
-qemu_cond_timedwait(qemu_system_cond, qemu_global_mutex, 100);
+qemu_cond_wait(qemu_system_cond, qemu_global_mutex);
 }
 
 while (1) {
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 11/21] exit round-robin vcpu loop if cpu-stopped is true

2011-03-12 Thread Paolo Bonzini
Sometimes vcpus are stopped directly without going through -stop = 1.
Exit the VCPU execution loop in this case as well.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cpus.c b/cpus.c
index c5743c4..785a104 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1098,7 +1098,7 @@ bool cpu_exec_all(void)
 cpu_handle_debug_exception(env);
 break;
 }
-} else if (env-stop) {
+} else if (env-stop || env-stopped) {
 break;
 }
 }
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 08/21] remove CONFIG_THREAD

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 configure |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 5513d3e..a166de0 100755
--- a/configure
+++ b/configure
@@ -2667,7 +2667,6 @@ if test $vnc_png != no ; then
 fi
 if test $vnc_thread != no ; then
   echo CONFIG_VNC_THREAD=y  $config_host_mak
-  echo CONFIG_THREAD=y  $config_host_mak
 fi
 if test $fnmatch = yes ; then
   echo CONFIG_FNMATCH=y  $config_host_mak
@@ -2763,7 +2762,6 @@ if test $xen = yes ; then
 fi
 if test $io_thread = yes ; then
   echo CONFIG_IOTHREAD=y  $config_host_mak
-  echo CONFIG_THREAD=y  $config_host_mak
 fi
 if test $linux_aio = yes ; then
   echo CONFIG_LINUX_AIO=y  $config_host_mak
-- 
1.7.4





[Qemu-devel] [RFC PATCH 1/5] add more helper functions with explicit milli/nanosecond resolution

2011-03-12 Thread Paolo Bonzini
The code doesn't make much sense right now, but it will as
soon as timers will be able to scale their resolution arbitrarily.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.h |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/qemu-timer.h b/qemu-timer.h
index 8cd8f83..345feea 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -12,6 +12,10 @@
 
 /* timers */
 
+#define SCALE_MS 100
+#define SCALE_US 1000
+#define SCALE_NS 1
+
 typedef struct QEMUClock QEMUClock;
 typedef void QEMUTimerCB(void *opaque);
 
@@ -54,6 +58,25 @@ void init_clocks(void);
 int init_timer_alarm(void);
 void quit_timers(void);
 
+static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb,
+   void *opaque)
+{
+assert(clock != rt_clock);
+return qemu_new_timer(clock, cb, opaque);
+}
+
+static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, QEMUTimerCB *cb,
+   void *opaque)
+{
+assert(clock == rt_clock);
+return qemu_new_timer(clock, cb, opaque);
+}
+
+static inline int64_t qemu_get_clock_ms(QEMUClock *clock)
+{
+return qemu_get_clock_ns(clock) / SCALE_MS;
+}
+
 static inline int64_t get_ticks_per_sec(void)
 {
 return 10LL;
-- 
1.7.4





[Qemu-devel] [PATCH RESEND] hw/fmopl: Fix buffer access out-of-bounds errors

2011-03-12 Thread Stefan Weil
Index 75 is one too large for AR_TABLE[75], DR_TABLE[75].
This error was reported by cppcheck.

hw/fmopl.c:600: error: Buffer access out-of-bounds: OPL.AR_TABLE
hw/fmopl.c:601: error: Buffer access out-of-bounds: OPL.DR_TABLE

Fix this by limiting the access to the allowed range.
MultiArcadeMachineEmulator has newer versions of fmopl,
but using these requires more efforts.

Cc: Blue Swirl blauwir...@gmail.com
Reviewed-by: malc av1...@comtv.ru
Signed-off-by: Stefan Weil w...@mail.berlios.de
---
 hw/fmopl.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/hw/fmopl.c b/hw/fmopl.c
index 3df1806..d8a0f36 100644
--- a/hw/fmopl.c
+++ b/hw/fmopl.c
@@ -45,6 +45,10 @@
 #define PI 3.14159265358979323846
 #endif
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
 /*  for debug - */
 /* #define OPL_OUTPUT_LOG */
 #ifdef OPL_OUTPUT_LOG
@@ -595,7 +599,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int 
DRRATE )
OPL-AR_TABLE[i] = rate / ARRATE;
OPL-DR_TABLE[i] = rate / DRRATE;
}
-   for (i = 60;i  76;i++)
+   for (i = 60; i  ARRAY_SIZE(OPL-AR_TABLE); i++)
{
OPL-AR_TABLE[i] = EG_AED-1;
OPL-DR_TABLE[i] = OPL-DR_TABLE[60];
-- 
1.7.2.3




[Qemu-devel] [RFC PATCH 0/5] allow arbitrary scaling of timers

2011-03-12 Thread Paolo Bonzini
Right now, rt_clock timers are limited to millisecond resolutions;
other clocks are limited to nanoseconds.  This patch series removes
the limitation.

In order to ease transition, new functions are provided with
explicit resolution (milli/nanosecond).  The old qemu_get_clock
is removed.  The old qemu_new_timer is grown a new argument to
specify the resolution.

Most of the patch series (patches 2/3) is mechanical (sed).

Paolo Bonzini (5):
  add more helper functions with explicit milli/nanosecond resolution
  change all rt_clock references to use millisecond resolution
accessors
  change all other clock references to use nanosecond resolution
accessors
  add a generic scaling mechanism for timers
  remove qemu_get_clock

 audio/audio.c|4 +-
 audio/noaudio.c  |4 +-
 audio/spiceaudio.c   |4 +-
 audio/wavaudio.c |2 +-
 buffered_file.c  |6 ++--
 console.c|4 +-
 hw/acpi_piix4.c  |8 +++---
 hw/adlib.c   |2 +-
 hw/apic.c|8 +++---
 hw/arm_sysctl.c  |2 +-
 hw/armv7m_nvic.c |8 +++---
 hw/baum.c|4 +-
 hw/bt-hci-csr.c  |4 +-
 hw/bt-hci.c  |   12 +-
 hw/cuda.c|   24 ++--
 hw/dp8393x.c |6 ++--
 hw/etraxfs_timer.c   |2 +-
 hw/fdc.c |4 +-
 hw/hpet.c|   14 +-
 hw/i8254.c   |   12 +-
 hw/i8259.c   |4 +-
 hw/ide/core.c|4 +-
 hw/intel-hda.c   |2 +-
 hw/lan9118.c |4 +-
 hw/lm832x.c  |6 ++--
 hw/m48t59.c  |6 ++--
 hw/mc146818rtc.c |   16 ++--
 hw/mips_timer.c  |   10 
 hw/mpcore.c  |6 ++--
 hw/omap1.c   |   30 
 hw/omap_gptimer.c|   14 +-
 hw/omap_synctimer.c  |2 +-
 hw/pcnet.c   |6 ++--
 hw/pcspk.c   |2 +-
 hw/pflash_cfi01.c|2 +-
 hw/pflash_cfi02.c|6 ++--
 hw/pl031.c   |8 +++---
 hw/ppc.c |   52 +-
 hw/ppc405_uc.c   |6 ++--
 hw/ppc_prep.c|2 +-
 hw/ptimer.c  |   14 +-
 hw/pxa2xx.c  |   30 
 hw/pxa2xx_timer.c|   28 +++---
 hw/rc4030.c  |4 +-
 hw/rtl8139.c |   22 +-
 hw/sb16.c|4 +-
 hw/serial.c  |   20 
 hw/soc_dma.c |4 +-
 hw/spitz.c   |6 ++--
 hw/stellaris.c   |6 ++--
 hw/sun4u.c   |   12 +-
 hw/syborg_rtc.c  |2 +-
 hw/tsc2005.c |4 +-
 hw/tsc210x.c |   20 
 hw/tusb6010.c|8 +++---
 hw/twl92230.c|8 +++---
 hw/usb-hid.c |6 ++--
 hw/usb-musb.c|4 +-
 hw/usb-ohci.c|8 +++---
 hw/usb-uhci.c|6 ++--
 hw/vga.c |2 +-
 hw/virtio-net.c  |6 ++--
 hw/vt82c686.c|8 +++---
 hw/wdt_i6300esb.c|4 +-
 hw/wdt_ib700.c   |4 +-
 hw/xen_domainbuild.c |6 ++--
 monitor.c|4 +-
 net/dump.c   |2 +-
 qemu-char.c  |8 +++---
 qemu-timer.c |   60 +
 qemu-timer.h |   25 +++-
 savevm.c |6 ++--
 slirp/slirp.c|2 +-
 target-ppc/kvm.c |4 +-
 target-ppc/kvm_ppc.c |6 ++--
 ui/spice-core.c  |4 +-
 ui/vnc.c |   10 
 usb-linux.c  |4 +-
 vl.c |   12 +-
 79 files changed, 364 insertions(+), 351 deletions(-)

-- 
1.7.4




[Qemu-devel] [PATCH v4 upstream 09/21] inline cpu_halted into sole caller

2011-03-12 Thread Paolo Bonzini
All implementations are now the same, and there is only one caller,
so inline the function there.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpu-exec.c   |9 +++--
 target-alpha/exec.h  |   11 ---
 target-arm/exec.h|   13 -
 target-cris/exec.h   |   11 ---
 target-i386/exec.h   |   12 
 target-m68k/exec.h   |   10 --
 target-microblaze/exec.h |   11 ---
 target-mips/exec.h   |   11 ---
 target-ppc/exec.h|   11 ---
 target-s390x/exec.h  |   12 
 target-sh4/exec.h|   10 --
 target-sparc/exec.h  |   10 --
 12 files changed, 7 insertions(+), 124 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 70c3e5a..34eaedc 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -208,8 +208,13 @@ int cpu_exec(CPUState *env1)
 uint8_t *tc_ptr;
 unsigned long next_tb;
 
-if (cpu_halted(env1) == EXCP_HALTED)
-return EXCP_HALTED;
+if (env1-halted) {
+if (!cpu_has_work(env1)) {
+return EXCP_HALTED;
+}
+
+env1-halted = 0;
+}
 
 cpu_single_env = env1;
 
diff --git a/target-alpha/exec.h b/target-alpha/exec.h
index a8a38d2..6ae96d1 100644
--- a/target-alpha/exec.h
+++ b/target-alpha/exec.h
@@ -42,17 +42,6 @@ static inline int cpu_has_work(CPUState *env)
 return (env-interrupt_request  CPU_INTERRUPT_HARD);
 }
 
-static inline int cpu_halted(CPUState *env)
-{
-if (!env-halted)
-return 0;
-if (cpu_has_work(env)) {
-env-halted = 0;
-return 0;
-}
-return EXCP_HALTED;
-}
-
 static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
 {
 env-pc = tb-pc;
diff --git a/target-arm/exec.h b/target-arm/exec.h
index e4c35a3..44e1b55 100644
--- a/target-arm/exec.h
+++ b/target-arm/exec.h
@@ -32,19 +32,6 @@ static inline int cpu_has_work(CPUState *env)
 (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD | CPU_INTERRUPT_EXITTB));
 }
 
-static inline int cpu_halted(CPUState *env) {
-if (!env-halted)
-return 0;
-/* An interrupt wakes the CPU even if the I and F CPSR bits are
-   set.  We use EXITTB to silently wake CPU without causing an
-   actual interrupt.  */
-if (cpu_has_work(env)) {
-env-halted = 0;
-return 0;
-}
-return EXCP_HALTED;
-}
-
 #if !defined(CONFIG_USER_ONLY)
 #include softmmu_exec.h
 #endif
diff --git a/target-cris/exec.h b/target-cris/exec.h
index 34c0132..2d5d297 100644
--- a/target-cris/exec.h
+++ b/target-cris/exec.h
@@ -33,17 +33,6 @@ static inline int cpu_has_work(CPUState *env)
 return (env-interrupt_request  (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI));
 }
 
-static inline int cpu_halted(CPUState *env) {
-   if (!env-halted)
-   return 0;
-
-   if (cpu_has_work(env)) {
-   env-halted = 0;
-   return 0;
-   }
-   return EXCP_HALTED;
-}
-
 static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
 {
 env-pc = tb-pc;
diff --git a/target-i386/exec.h b/target-i386/exec.h
index fc8945b..3e7386e 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -304,18 +304,6 @@ static inline int cpu_has_work(CPUState *env)
 return work;
 }
 
-static inline int cpu_halted(CPUState *env) {
-/* handle exit of HALTED state */
-if (!env-halted)
-return 0;
-/* disable halt condition */
-if (cpu_has_work(env)) {
-env-halted = 0;
-return 0;
-}
-return EXCP_HALTED;
-}
-
 /* load efer and update the corresponding hflags. XXX: do consistency
checks with cpuid bits ? */
 static inline void cpu_load_efer(CPUState *env, uint64_t val)
diff --git a/target-m68k/exec.h b/target-m68k/exec.h
index f31e06e..91daa6b 100644
--- a/target-m68k/exec.h
+++ b/target-m68k/exec.h
@@ -33,16 +33,6 @@ static inline int cpu_has_work(CPUState *env)
 return (env-interrupt_request  (CPU_INTERRUPT_HARD));
 }
 
-static inline int cpu_halted(CPUState *env) {
-if (!env-halted)
-return 0;
-if (cpu_has_work(env)) {
-env-halted = 0;
-return 0;
-}
-return EXCP_HALTED;
-}
-
 static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
 {
 env-pc = tb-pc;
diff --git a/target-microblaze/exec.h b/target-microblaze/exec.h
index ab19828..1efff30 100644
--- a/target-microblaze/exec.h
+++ b/target-microblaze/exec.h
@@ -32,17 +32,6 @@ static inline int cpu_has_work(CPUState *env)
 return (env-interrupt_request  (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI));
 }
 
-static inline int cpu_halted(CPUState *env) {
-   if (!env-halted)
-   return 0;
-
-   if (cpu_has_work(env)) {
-   env-halted = 0;
-   return 0;
-   }
-   return EXCP_HALTED;
-}
-
 static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
 {
 env-sregs[SR_PC] = tb-pc;
diff --git a/target-mips/exec.h b/target-mips/exec.h
index 

[Qemu-devel] [RFC PATCH 5/5] remove qemu_get_clock

2011-03-12 Thread Paolo Bonzini
These patches are already not doing a great service to out-of-tree
modifications to QEMU.  However, at least we can warn them by getting
rid of the old confusing functions, or otherwise causing compilation
errors.  This patch removes qemu_get_clock; the previous one changed
qemu_new_timer's signature.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |   17 -
 qemu-timer.h |1 -
 2 files changed, 0 insertions(+), 18 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 1aed535..f6e059f 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -511,23 +511,6 @@ static void qemu_run_timers(QEMUClock *clock)
 }
 }
 
-int64_t qemu_get_clock(QEMUClock *clock)
-{
-switch(clock-type) {
-case QEMU_CLOCK_REALTIME:
-return get_clock() / 100;
-default:
-case QEMU_CLOCK_VIRTUAL:
-if (use_icount) {
-return cpu_get_icount();
-} else {
-return cpu_get_clock();
-}
-case QEMU_CLOCK_HOST:
-return get_clock_realtime();
-}
-}
-
 int64_t qemu_get_clock_ns(QEMUClock *clock)
 {
 switch(clock-type) {
diff --git a/qemu-timer.h b/qemu-timer.h
index 0ea77fb..75d5675 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -37,7 +37,6 @@ extern QEMUClock *vm_clock;
the virtual clock. */
 extern QEMUClock *host_clock;
 
-int64_t qemu_get_clock(QEMUClock *clock);
 int64_t qemu_get_clock_ns(QEMUClock *clock);
 void qemu_clock_enable(QEMUClock *clock, int enabled);
 
-- 
1.7.4




[Qemu-devel] [RFC PATCH 2/5] change all rt_clock references to use millisecond resolution accessors

2011-03-12 Thread Paolo Bonzini
This was done with:

sed -i '/get_clock\.*rt_clock/s/get_clock\/get_clock_ms/' \
$(git grep -l 'get_clock\.*rt_clock' )
sed -i '/new_timer\.*rt_clock/s/new_timer\/new_timer_ms/' \
$(git grep -l 'new_timer\.*rt_clock' )

after checking that get_clock and new_timer never occur twice
on the same line.  There were no missed occurrences; however, even
if there had been, they would have been caught by the compiler.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 buffered_file.c  |6 +++---
 console.c|4 ++--
 hw/omap1.c   |   10 +-
 hw/pxa2xx.c  |   28 ++--
 hw/twl92230.c|8 
 hw/xen_domainbuild.c |6 +++---
 qemu-char.c  |8 
 qemu-timer.c |6 +++---
 savevm.c |4 ++--
 slirp/slirp.c|2 +-
 ui/spice-core.c  |4 ++--
 ui/vnc.c |   10 +-
 usb-linux.c  |4 ++--
 vl.c |   12 ++--
 14 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 8435a31..b5e2baf 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -238,7 +238,7 @@ static void buffered_rate_tick(void *opaque)
 return;
 }
 
-qemu_mod_timer(s-timer, qemu_get_clock(rt_clock) + 100);
+qemu_mod_timer(s-timer, qemu_get_clock_ms(rt_clock) + 100);
 
 if (s-freeze_output)
 return;
@@ -274,9 +274,9 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
  buffered_set_rate_limit,
 buffered_get_rate_limit);
 
-s-timer = qemu_new_timer(rt_clock, buffered_rate_tick, s);
+s-timer = qemu_new_timer_ms(rt_clock, buffered_rate_tick, s);
 
-qemu_mod_timer(s-timer, qemu_get_clock(rt_clock) + 100);
+qemu_mod_timer(s-timer, qemu_get_clock_ms(rt_clock) + 100);
 
 return s-file;
 }
diff --git a/console.c b/console.c
index 57d6eb5..12407b3 100644
--- a/console.c
+++ b/console.c
@@ -1135,7 +1135,7 @@ static void kbd_send_chars(void *opaque)
 /* characters are pending: we send them a bit later (XXX:
horrible, should change char device API) */
 if (s-out_fifo.count  0) {
-qemu_mod_timer(s-kbd_timer, qemu_get_clock(rt_clock) + 1);
+qemu_mod_timer(s-kbd_timer, qemu_get_clock_ms(rt_clock) + 1);
 }
 }
 
@@ -1457,7 +1457,7 @@ static void text_console_do_init(CharDriverState *chr, 
DisplayState *ds)
 
 s-out_fifo.buf = s-out_fifo_buf;
 s-out_fifo.buf_size = sizeof(s-out_fifo_buf);
-s-kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
+s-kbd_timer = qemu_new_timer_ms(rt_clock, kbd_send_chars, s);
 s-ds = ds;
 
 if (!color_inited) {
diff --git a/hw/omap1.c b/hw/omap1.c
index d5e4dab..f2be4de 100644
--- a/hw/omap1.c
+++ b/hw/omap1.c
@@ -2802,7 +2802,7 @@ static void omap_rtc_reset(struct omap_rtc_s *s)
 s-pm_am = 0;
 s-auto_comp = 0;
 s-round = 0;
-s-tick = qemu_get_clock(rt_clock);
+s-tick = qemu_get_clock_ms(rt_clock);
 memset(s-alarm_tm, 0, sizeof(s-alarm_tm));
 s-alarm_tm.tm_mday = 0x01;
 s-status = 1  7;
@@ -2822,7 +2822,7 @@ static struct omap_rtc_s 
*omap_rtc_init(target_phys_addr_t base,
 
 s-irq = irq[0];
 s-alarm = irq[1];
-s-clk = qemu_new_timer(rt_clock, omap_rtc_tick, s);
+s-clk = qemu_new_timer_ms(rt_clock, omap_rtc_tick, s);
 
 omap_rtc_reset(s);
 
@@ -3399,9 +3399,9 @@ static void omap_lpg_tick(void *opaque)
 struct omap_lpg_s *s = opaque;
 
 if (s-cycle)
-qemu_mod_timer(s-tm, qemu_get_clock(rt_clock) + s-period - s-on);
+qemu_mod_timer(s-tm, qemu_get_clock_ms(rt_clock) + s-period - s-on);
 else
-qemu_mod_timer(s-tm, qemu_get_clock(rt_clock) + s-on);
+qemu_mod_timer(s-tm, qemu_get_clock_ms(rt_clock) + s-on);
 
 s-cycle = !s-cycle;
 printf(%s: LED is %s\n, __FUNCTION__, s-cycle ? on : off);
@@ -3516,7 +3516,7 @@ static struct omap_lpg_s 
*omap_lpg_init(target_phys_addr_t base, omap_clk clk)
 struct omap_lpg_s *s = (struct omap_lpg_s *)
 qemu_mallocz(sizeof(struct omap_lpg_s));
 
-s-tm = qemu_new_timer(rt_clock, omap_lpg_tick, s);
+s-tm = qemu_new_timer_ms(rt_clock, omap_lpg_tick, s);
 
 omap_lpg_reset(s);
 
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index 4c7b9e6..d75a817 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -921,7 +921,7 @@ static inline void pxa2xx_rtc_int_update(PXA2xxRTCState *s)
 
 static void pxa2xx_rtc_hzupdate(PXA2xxRTCState *s)
 {
-int64_t rt = qemu_get_clock(rt_clock);
+int64_t rt = qemu_get_clock_ms(rt_clock);
 s-last_rcnr += ((rt - s-last_hz)  15) /
 (1000 * ((s-rttr  0x) + 1));
 s-last_rdcr += ((rt - s-last_hz)  15) /
@@ -931,7 +931,7 @@ static void pxa2xx_rtc_hzupdate(PXA2xxRTCState *s)
 
 static void pxa2xx_rtc_swupdate(PXA2xxRTCState *s)
 {
-int64_t rt = qemu_get_clock(rt_clock);
+int64_t rt = qemu_get_clock_ms(rt_clock);
 if (s-rtsr  

[Qemu-devel] [PATCH v4 upstream 13/21] do not use timedwait on qemu_halt_cond

2011-03-12 Thread Paolo Bonzini
The following conditions can cause cpu_has_work(env) to become true:

- env-queued_work_first: run_on_cpu is already kicking the VCPU

- env-stop = 1: pause_all_vcpus is already kicking the VCPU

- env-stopped = 0: resume_all_vcpus is already kicking the VCPU

- vm_running = 1: vm_start is calling resume_all_vcpus

- env-halted = 0: see previous patch

- qemu_cpu_has_work(env): when it becomes true, board code should set
  env-halted = 0 too.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 6cfb45b..4c3837f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -771,7 +771,7 @@ static void qemu_tcg_wait_io_event(void)
 CPUState *env;
 
 while (all_cpu_threads_idle()) {
-qemu_cond_timedwait(tcg_halt_cond, qemu_global_mutex, 1000);
+qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
 }
 
 qemu_mutex_unlock(qemu_global_mutex);
@@ -794,7 +794,7 @@ static void qemu_tcg_wait_io_event(void)
 static void qemu_kvm_wait_io_event(CPUState *env)
 {
 while (cpu_thread_is_idle(env)) {
-qemu_cond_timedwait(env-halt_cond, qemu_global_mutex, 1000);
+qemu_cond_wait(env-halt_cond, qemu_global_mutex);
 }
 
 qemu_kvm_eat_signals(env);
-- 
1.7.4





[Qemu-devel] [RFC PATCH 4/5] add a generic scaling mechanism for timers

2011-03-12 Thread Paolo Bonzini
This enables rt_clock timers to use nanosecond resolution, just by
using the _ns functions; there is really no reason to forbid that.

Migrated timers are all using vm_clock (of course; but I checked that
anyway) so the timers in the savevm files are already in nanosecond
resolution.  So this patch makes no change to the migration format.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |   25 +
 qemu-timer.h |9 -
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index f171e9c..1aed535 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -153,12 +153,12 @@ void cpu_disable_ticks(void)
 struct QEMUClock {
 int type;
 int enabled;
-/* XXX: add frequency */
 };
 
 struct QEMUTimer {
 QEMUClock *clock;
-int64_t expire_time;
+int64_t expire_time;   /* in nanoseconds */
+int scale;
 QEMUTimerCB *cb;
 void *opaque;
 struct QEMUTimer *next;
@@ -391,7 +391,8 @@ void qemu_clock_enable(QEMUClock *clock, int enabled)
 clock-enabled = enabled;
 }
 
-QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque)
+QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
+  QEMUTimerCB *cb, void *opaque)
 {
 QEMUTimer *ts;
 
@@ -399,6 +400,7 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB 
*cb, void *opaque)
 ts-clock = clock;
 ts-cb = cb;
 ts-opaque = opaque;
+ts-scale = scale;
 return ts;
 }
 
@@ -429,7 +431,7 @@ void qemu_del_timer(QEMUTimer *ts)
 
 /* modify the current timer so that it will be fired when current_time
= expire_time. The corresponding callback will be called. */
-void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
+static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
 {
 QEMUTimer **pt, *t;
 
@@ -462,6 +464,13 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
 }
 }
 
+/* modify the current timer so that it will be fired when current_time
+   = expire_time. The corresponding callback will be called. */
+void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
+{
+qemu_mod_timer_ns(ts, expire_time * ts-scale);
+}
+
 int qemu_timer_pending(QEMUTimer *ts)
 {
 QEMUTimer *t;
@@ -476,7 +485,7 @@ int qemu_timer_expired(QEMUTimer *timer_head, int64_t 
current_time)
 {
 if (!timer_head)
 return 0;
-return (timer_head-expire_time = current_time);
+return (timer_head-expire_time = current_time * timer_head-scale);
 }
 
 static void qemu_run_timers(QEMUClock *clock)
@@ -487,7 +496,7 @@ static void qemu_run_timers(QEMUClock *clock)
 if (!clock-enabled)
 return;
 
-current_time = qemu_get_clock (clock);
+current_time = qemu_get_clock_ns(clock);
 ptimer_head = active_timers[clock-type];
 for(;;) {
 ts = *ptimer_head;
@@ -564,7 +573,7 @@ void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
 
 expire_time = qemu_get_be64(f);
 if (expire_time != -1) {
-qemu_mod_timer(ts, expire_time);
+qemu_mod_timer_ns(ts, expire_time);
 } else {
 qemu_del_timer(ts);
 }
@@ -724,7 +733,7 @@ static int64_t qemu_next_alarm_deadline(void)
 delta = hdelta;
 }
 if (active_timers[QEMU_CLOCK_REALTIME]) {
-rtdelta = (active_timers[QEMU_CLOCK_REALTIME]-expire_time * 100 -
+rtdelta = (active_timers[QEMU_CLOCK_REALTIME]-expire_time -
  qemu_get_clock_ns(rt_clock));
 if (rtdelta  delta)
 delta = rtdelta;
diff --git a/qemu-timer.h b/qemu-timer.h
index 345feea..0ea77fb 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -41,7 +41,8 @@ int64_t qemu_get_clock(QEMUClock *clock);
 int64_t qemu_get_clock_ns(QEMUClock *clock);
 void qemu_clock_enable(QEMUClock *clock, int enabled);
 
-QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
+QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
+  QEMUTimerCB *cb, void *opaque);
 void qemu_free_timer(QEMUTimer *ts);
 void qemu_del_timer(QEMUTimer *ts);
 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
@@ -61,15 +62,13 @@ void quit_timers(void);
 static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb,
void *opaque)
 {
-assert(clock != rt_clock);
-return qemu_new_timer(clock, cb, opaque);
+return qemu_new_timer(clock, SCALE_NS, cb, opaque);
 }
 
 static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, QEMUTimerCB *cb,
void *opaque)
 {
-assert(clock == rt_clock);
-return qemu_new_timer(clock, cb, opaque);
+return qemu_new_timer(clock, SCALE_MS, cb, opaque);
 }
 
 static inline int64_t qemu_get_clock_ms(QEMUClock *clock)
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 16/21] do not use timedwait on qemu_cpu_cond

2011-03-12 Thread Paolo Bonzini
Whenever env-created becomes true, qemu_cpu_cond is signaled by
{kvm,tcg}_cpu_thread_fn.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8f169ad..4305184 100644
--- a/cpus.c
+++ b/cpus.c
@@ -970,7 +970,7 @@ static void qemu_tcg_init_vcpu(void *_env)
 qemu_cond_init(env-halt_cond);
 qemu_thread_create(env-thread, qemu_tcg_cpu_thread_fn, env);
 while (env-created == 0) {
-qemu_cond_timedwait(qemu_cpu_cond, qemu_global_mutex, 100);
+qemu_cond_wait(qemu_cpu_cond, qemu_global_mutex);
 }
 tcg_cpu_thread = env-thread;
 tcg_halt_cond = env-halt_cond;
@@ -987,7 +987,7 @@ static void qemu_kvm_start_vcpu(CPUState *env)
 qemu_cond_init(env-halt_cond);
 qemu_thread_create(env-thread, qemu_kvm_cpu_thread_fn, env);
 while (env-created == 0) {
-qemu_cond_timedwait(qemu_cpu_cond, qemu_global_mutex, 100);
+qemu_cond_wait(qemu_cpu_cond, qemu_global_mutex);
 }
 }
 
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 18/21] merge all signal initialization with qemu_signalfd_init, rename

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |   87 ++-
 1 files changed, 36 insertions(+), 51 deletions(-)

diff --git a/cpus.c b/cpus.c
index 32e9352..2b491a9 100644
--- a/cpus.c
+++ b/cpus.c
@@ -346,11 +346,37 @@ static void sigfd_handler(void *opaque)
 }
 }
 
-static int qemu_signalfd_init(sigset_t mask)
+static int qemu_signal_init(void)
 {
 int sigfd;
+sigset_t set;
 
-sigfd = qemu_signalfd(mask);
+#ifdef CONFIG_IOTHREAD
+/* SIGUSR2 used by posix-aio-compat.c */
+sigemptyset(set);
+sigaddset(set, SIGUSR2);
+pthread_sigmask(SIG_UNBLOCK, set, NULL);
+
+sigemptyset(set);
+sigaddset(set, SIGIO);
+sigaddset(set, SIGALRM);
+sigaddset(set, SIG_IPI);
+sigaddset(set, SIGBUS);
+pthread_sigmask(SIG_BLOCK, set, NULL);
+#else
+sigemptyset(set);
+sigaddset(set, SIGBUS);
+if (kvm_enabled()) {
+/*
+ * We need to process timer signals synchronously to avoid a race
+ * between exit_request check and KVM vcpu entry.
+ */
+sigaddset(set, SIGIO);
+sigaddset(set, SIGALRM);
+}
+#endif
+
+sigfd = qemu_signalfd(set);
 if (sigfd == -1) {
 fprintf(stderr, failed to create signalfd\n);
 return -errno;
@@ -438,6 +464,12 @@ static void qemu_event_increment(void)
 static void qemu_kvm_eat_signals(CPUState *env)
 {
 }
+
+static int qemu_signal_init(void)
+{
+return 0;
+}
+
 #endif /* _WIN32 */
 
 #ifndef CONFIG_IOTHREAD
@@ -471,39 +503,14 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
 #endif
 }
 
-#ifndef _WIN32
-static sigset_t block_synchronous_signals(void)
-{
-sigset_t set;
-
-sigemptyset(set);
-sigaddset(set, SIGBUS);
-if (kvm_enabled()) {
-/*
- * We need to process timer signals synchronously to avoid a race
- * between exit_request check and KVM vcpu entry.
- */
-sigaddset(set, SIGIO);
-sigaddset(set, SIGALRM);
-}
-
-return set;
-}
-#endif
-
 int qemu_init_main_loop(void)
 {
-#ifndef _WIN32
-sigset_t blocked_signals;
 int ret;
 
-blocked_signals = block_synchronous_signals();
-
-ret = qemu_signalfd_init(blocked_signals);
+ret = qemu_signal_init();
 if (ret) {
 return ret;
 }
-#endif
 
 qemu_init_sigbus();
 
@@ -651,35 +658,13 @@ static void qemu_tcg_init_cpu_signals(void)
 pthread_sigmask(SIG_UNBLOCK, set, NULL);
 }
 
-static sigset_t block_io_signals(void)
-{
-sigset_t set;
-
-/* SIGUSR2 used by posix-aio-compat.c */
-sigemptyset(set);
-sigaddset(set, SIGUSR2);
-pthread_sigmask(SIG_UNBLOCK, set, NULL);
-
-sigemptyset(set);
-sigaddset(set, SIGIO);
-sigaddset(set, SIGALRM);
-sigaddset(set, SIG_IPI);
-sigaddset(set, SIGBUS);
-pthread_sigmask(SIG_BLOCK, set, NULL);
-
-return set;
-}
-
 int qemu_init_main_loop(void)
 {
 int ret;
-sigset_t blocked_signals;
 
 qemu_init_sigbus();
 
-blocked_signals = block_io_signals();
-
-ret = qemu_signalfd_init(blocked_signals);
+ret = qemu_signal_init();
 if (ret) {
 return ret;
 }
-- 
1.7.4





[Qemu-devel] [PATCH v4 upstream 20/21] protect qemu_cpu_kick_self for Win32

2011-03-12 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index e0bcb5c..7559a02 100644
--- a/cpus.c
+++ b/cpus.c
@@ -867,12 +867,16 @@ void qemu_cpu_kick(void *_env)
 
 void qemu_cpu_kick_self(void)
 {
+#ifndef _WIN32
 assert(cpu_single_env);
 
 if (!cpu_single_env-thread_kicked) {
 qemu_thread_signal(cpu_single_env-thread, SIG_IPI);
 cpu_single_env-thread_kicked = true;
 }
+#else
+abort();
+#endif
 }
 
 int qemu_cpu_is_self(void *_env)
-- 
1.7.4





Re: [Qemu-devel] [PATCH 19/22] qapi: add QMP put-event command

2011-03-12 Thread Avi Kivity

On 03/10/2011 06:42 PM, Anthony Liguori wrote:
Maybe for QMPv2, but for QMPv1, this is going to introduce an 
extremely incompatible change.


Why?  It's 100% backwards compatible.



It's a very significant change for clients.  While technical 
compatible, it would require a change to the client infrastructure to 
support the new feature.


Yes.  That's generally a good thing, you implement something at the 
infrastructure level once instead of at a higher level N times.



I'm not saying we shouldn't make a change like this, but we should 
minimize these type of changes.


I agree, so we should design the protocol well, without planned 
obsolescence.  We'll make some mistakes, but at least they'll be unplanned.


--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.




Re: [Qemu-devel] [PATCH 19/22] qapi: add QMP put-event command

2011-03-12 Thread Avi Kivity

On 03/10/2011 06:04 PM, Anthony Liguori wrote:

On 03/10/2011 09:45 AM, Avi Kivity wrote:


btw2, I now nominate subscribe and unsubscribe as replacements for 
get and put.


Subscribe implies sub/pub in my mind and we're not publishing events 
so I don't think it fits the model.


A pub/sub event model would be interesting to think through but 
without a global namespace and object model, I don't think we can 
make it fit well.


I feel we're still not communicating.  What does 'get-*-event' mean?

I think you're using some nomenclature that is unfamiliar to me.


No, I'm just defending something that I think fundamentally sucks.

I very purposefully am trying to avoid heavy protocol visible changes 
at this stage.  The only reason I added signal accessors is that the 
current event model is unusable from a C API.


I am in full agreement that the current signal model needs to be 
rethought and should be changed at the protocol level.  I just don't 
want to do that right now because there are a ton of internal 
improvements that can be made by without doing that.


The signal accessors are ugly but they're just a handful of commands 
that can be deprecated over time.  We should revisit events but we 
should take the time to design it and plan for a protocol addition for 
0.16.


It would be much better to avoid introducing deprecated commands.  
They're a maintenance burden for both server and client, and a testing 
burden as well.  I feel it's better to spend more time to get something 
we truly like.







That's why I'm using signal/slots.  It's much more conducive to a 
procedural model.


I still don't follow.  We have a connection, over which we ask the 
other side to let us know when something happens, then that other 
side lets us know when it happens, then we ask it to stop, then it 
stops.  There are no signals or slots anywhere.  If there are in the 
code, let's not mix it up with the protocol.


Dropping my legacy baggage, here's what I'd like to see us do from a 
protocol perspective.  I'd like to first introduce class hinting and 
switch all of the string handles that we use today to class handles.   
So:


{ execute: query-block }
{ return: [ { __jsonclass__: 'BlockDevice', id=ide0-hd0 }, { 
__jsonclass__: 'BlockDevice', id=ide1-cd0 } ] }


{ execute: connect, arguments: { 'obj': { __jsonclass__: BlockDevice, 
id=ide0-hd0 }, 'signal': 'io-error' } }

{ return: { __jsonclass__: Connection, id=1 } }

{ signal: 'io-error', connection: { __jsonclass__: Connection, id=1 }, 
arguments: { action='stop', ... } }


{ execute: disconnect, arguments: { 'connection': { __jsonclass__: 
Connection, id=1 } } }

{ return: null }

The advantages here are many.  You get much stronger typing in C.  If 
the schema is done right, it trivially maps to an object model in Python.


I note that connect is not protocol level (i.e. execute: connect, 
signal: io-error instead of connect; io-error).


Regarding class hinting, I don't object to that, but I feel that the 
schema provides all of the benefits already.


--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.




Re: [Qemu-devel] [PATCH 19/22] qapi: add QMP put-event command

2011-03-12 Thread Anthony Liguori

On 03/12/2011 02:42 PM, Avi Kivity wrote:

On 03/10/2011 06:04 PM, Anthony Liguori wrote:

On 03/10/2011 09:45 AM, Avi Kivity wrote:


btw2, I now nominate subscribe and unsubscribe as replacements for 
get and put.


Subscribe implies sub/pub in my mind and we're not publishing 
events so I don't think it fits the model.


A pub/sub event model would be interesting to think through but 
without a global namespace and object model, I don't think we can 
make it fit well.


I feel we're still not communicating.  What does 'get-*-event' mean?

I think you're using some nomenclature that is unfamiliar to me.


No, I'm just defending something that I think fundamentally sucks.

I very purposefully am trying to avoid heavy protocol visible changes 
at this stage.  The only reason I added signal accessors is that the 
current event model is unusable from a C API.


I am in full agreement that the current signal model needs to be 
rethought and should be changed at the protocol level.  I just don't 
want to do that right now because there are a ton of internal 
improvements that can be made by without doing that.


The signal accessors are ugly but they're just a handful of commands 
that can be deprecated over time.  We should revisit events but we 
should take the time to design it and plan for a protocol addition 
for 0.16.


It would be much better to avoid introducing deprecated commands.  
They're a maintenance burden for both server and client, and a testing 
burden as well.  I feel it's better to spend more time to get 
something we truly like.


I'm really not interested in getting something I like.  We're at a 
deadlock right now with QMP.  It's essentially not usable on its own 
because there are so few commands implemented.  As we speak, the libvirt 
guys are adding new features based on monitor commands because they've 
waited too long for the QMP versions to show up.


And more monitor commands keep getting added often without a QMP 
version.  There's almost no incentive to care about QMP because it's not 
that useful.  We need to break the deadlock and make QMP useful.  That's 
the goal of this effort.


The only reason I even touched events is because the current event 
infrastructure is so broken.  They cannot be consumed internally in any 
meaningful way which means they fall into the not useful bucket.


If there was an obvious alternative, I'd switch to it.  But it's not as 
easy as it sounds.  If you have a protocol level connect, then you need 
a way to expose events at the protocol level to a client.  You could use 
an accessor and return a signal object but then you have a complicated 
life cycle.


When you return a signal object to a QMP client, the object needs to 
persist until 1) the session goes away 2) the object is explicitly 
released by the client.  On top of this, you also have connections which 
introduce a second life cycle.


In reality, do you ever want to get a handle to a signal without 
connecting to it?  I doubt it.  So if you make connecting to an signal 
implicit in accessing it, then you only have to deal with one life 
cycle, the signal connection.  This is the current implementation.


There are nicer models but they really require having an object model 
whereas the signals are properties of the objects.  That means you don't 
have to deal with an extra life cycle (because there is no explicit 
signal object).


But really, this is one of the least important things we need to worry 
about.  The number of commands we have with extremely hard to use 
semantics are alarming.  The change command caused us a CVE because it's 
semantics are so subtle.  device_del has caused device detach to be 
fundamentally broken in libvirt because it's semantics are subtle and 
undocumented.   These are the important problems to solve.  It's not as 
sexy as a JSON RPC signalling model, but it's far more important.


Regards,

Anthony Liguori



Re: [Qemu-devel] [RFC PATCH 0/5] allow arbitrary scaling of timers

2011-03-12 Thread Anthony Liguori

On 03/12/2011 11:04 AM, Paolo Bonzini wrote:

Right now, rt_clock timers are limited to millisecond resolutions;
other clocks are limited to nanoseconds.  This patch series removes
the limitation.

In order to ease transition, new functions are provided with
explicit resolution (milli/nanosecond).  The old qemu_get_clock
is removed.  The old qemu_new_timer is grown a new argument to
specify the resolution.

Most of the patch series (patches 2/3) is mechanical (sed).


Really nice series.

The whole thing Reviewed-by: Anthony Liguori aligu...@us.ibm.com

Did you really mean to RFC this?  I don't think there's any sort of 
problem applying this as it's mostly mechanical.


Regards,

Anthony Liguori


Paolo Bonzini (5):
   add more helper functions with explicit milli/nanosecond resolution
   change all rt_clock references to use millisecond resolution
 accessors
   change all other clock references to use nanosecond resolution
 accessors
   add a generic scaling mechanism for timers
   remove qemu_get_clock

  audio/audio.c|4 +-
  audio/noaudio.c  |4 +-
  audio/spiceaudio.c   |4 +-
  audio/wavaudio.c |2 +-
  buffered_file.c  |6 ++--
  console.c|4 +-
  hw/acpi_piix4.c  |8 +++---
  hw/adlib.c   |2 +-
  hw/apic.c|8 +++---
  hw/arm_sysctl.c  |2 +-
  hw/armv7m_nvic.c |8 +++---
  hw/baum.c|4 +-
  hw/bt-hci-csr.c  |4 +-
  hw/bt-hci.c  |   12 +-
  hw/cuda.c|   24 ++--
  hw/dp8393x.c |6 ++--
  hw/etraxfs_timer.c   |2 +-
  hw/fdc.c |4 +-
  hw/hpet.c|   14 +-
  hw/i8254.c   |   12 +-
  hw/i8259.c   |4 +-
  hw/ide/core.c|4 +-
  hw/intel-hda.c   |2 +-
  hw/lan9118.c |4 +-
  hw/lm832x.c  |6 ++--
  hw/m48t59.c  |6 ++--
  hw/mc146818rtc.c |   16 ++--
  hw/mips_timer.c  |   10 
  hw/mpcore.c  |6 ++--
  hw/omap1.c   |   30 
  hw/omap_gptimer.c|   14 +-
  hw/omap_synctimer.c  |2 +-
  hw/pcnet.c   |6 ++--
  hw/pcspk.c   |2 +-
  hw/pflash_cfi01.c|2 +-
  hw/pflash_cfi02.c|6 ++--
  hw/pl031.c   |8 +++---
  hw/ppc.c |   52 +-
  hw/ppc405_uc.c   |6 ++--
  hw/ppc_prep.c|2 +-
  hw/ptimer.c  |   14 +-
  hw/pxa2xx.c  |   30 
  hw/pxa2xx_timer.c|   28 +++---
  hw/rc4030.c  |4 +-
  hw/rtl8139.c |   22 +-
  hw/sb16.c|4 +-
  hw/serial.c  |   20 
  hw/soc_dma.c |4 +-
  hw/spitz.c   |6 ++--
  hw/stellaris.c   |6 ++--
  hw/sun4u.c   |   12 +-
  hw/syborg_rtc.c  |2 +-
  hw/tsc2005.c |4 +-
  hw/tsc210x.c |   20 
  hw/tusb6010.c|8 +++---
  hw/twl92230.c|8 +++---
  hw/usb-hid.c |6 ++--
  hw/usb-musb.c|4 +-
  hw/usb-ohci.c|8 +++---
  hw/usb-uhci.c|6 ++--
  hw/vga.c |2 +-
  hw/virtio-net.c  |6 ++--
  hw/vt82c686.c|8 +++---
  hw/wdt_i6300esb.c|4 +-
  hw/wdt_ib700.c   |4 +-
  hw/xen_domainbuild.c |6 ++--
  monitor.c|4 +-
  net/dump.c   |2 +-
  qemu-char.c  |8 +++---
  qemu-timer.c |   60 +
  qemu-timer.h |   25 +++-
  savevm.c |6 ++--
  slirp/slirp.c|2 +-
  target-ppc/kvm.c |4 +-
  target-ppc/kvm_ppc.c |6 ++--
  ui/spice-core.c  |4 +-
  ui/vnc.c |   10 
  usb-linux.c  |4 +-
  vl.c |   12 +-
  79 files changed, 364 insertions(+), 351 deletions(-)






[Qemu-devel] Message de Corentin Chary

2011-03-12 Thread Corentin Chary
viadeoBonjour,

Je vous invite à rejoindre mon réseau de contacts sur Viadeo.

Cordialement,Corentin Chary Confirmer que vous connaissez Corentin 
http://www.viadeo.com/action/index.jsp?actionId=0021xn1x7dm9pjk8urlId=0021v1e4bjtkdcp0utm_source=Viadeomail-FRutm_medium=emailutm_term=Etpl:SignUp,Ep:boxbody,Ety:txtlink,En:,utm_content=v2_071210utm_campaign=Cn:1,Ce:B2C,Cp:MKG-acqui,om_cmpid=vd-inv-fr
©viadeo 2011 | Message de Corentin Chary
http://www.viadeo.com/action/index.jsp?actionId=0021xn1x7dm9pjk8urlId=0021v1e4bjtkdcp0utm_source=Viadeomail-FRutm_medium=emailutm_term=Etpl:SignUp,Ep:boxbody,Ety:txtlink,En:,utm_content=v2_071210utm_campaign=Cn:1,Ce:B2C,Cp:MKG-acqui,om_cmpid=vd-inv-fr


Re: [Qemu-devel] Re: Strategic decision: COW format

2011-03-12 Thread Chunqiang Tang
 It seems that there is great interest in QCOW2's
 internal snapshot feature. If we really want to do that, the right 
solution is
 to follow VMDK's approach of storing each snapshot as a separate COW 
file (see 
 http://www.vmware.com/app/vmdk/?src=vmdk ), rather than using the 
reference 
 count table. VMDK’s approach can be easily implemented for any COW 
format, or 
 even as a function of the generic block layer, without complicating any 
COW 
 format or hurting its performance. 

After the heated debate, I thought more about the right approach of 
implementing snapshot, and it becomes clear to me that there are major 
limitations with both VMDK's external snapshot approach (which stores each 
snapshot as a separate CoW file) and QCOW2's internal snapshot approach 
(which stores all snapshots in one file and uses a reference count table 
to keep track of them). I just posted to the mailing list a patch that 
implements internal snapshot in FVD but does it in a way without the 
limitations of VMDK and QCOW2. 

Let's first list the properties of an ideal virtual disk snapshot 
solution, and then discuss how to achieve them.

G1: Do no harm (or avoid being a misfeature), i.e., the added snapshot 
code should not slow down the runtime performance of an image that has no 
snapshots.  This implies that an image without snapshot should not cache 
the reference count table in memory and should not update the on-disk 
reference count table.

G2: Even better, an image with 1 snapshot runs as fast as an image without 
snapshot.

G3: Even even better, an image with 1,000 snapshots runs as fast as an 
image without snapshot. This basically means getting the snapshot feature 
for free.

G4: An image with 1,000 snapshots consumes no more memory than an image 
without snapshot. This again means getting the snapshot feature for free.

G5: Regardless of the number of existing snapshots, creating a new 
snapshot is fast, e.g., taking no more than 1 second.

G6: Regardless of the number of existing snapshots, deleting a snapshot is 
fast, e.g., taking no more than 1 second.

Now let's evaluate VMDK and QCOW2 against these ideal properties. 

G1: VMDK good; QCOW2 poor
G2: VMDK ok; QCOW2 poor
G3: VMDK very poor; QCOW2 poor
G4: VMDK very poor; QCOW2 poor
G5: VMDK good; QCOW2 good
G6: VMDK poor; QCOW2 good

The evaluation above assumes a straightforward VMDK implementation that, 
when handling a long chain of snapshots, s0-s1-s2- … -s1000, it uses a 
chain of 1,000 VMDK driver instances to represent the chain of backing 
files. This is slow and consumes a lot of memory, but it is the behavior 
of QEMU's block device architecture today.

Even if the QEMU architecture can be revised and the VMDK implementation 
is optimized to extreme, a fundamental limitation of VMDK (by design 
instead of by implementation) is G6, i.e., deleting a snapshot X in the 
middle of a snapshot chain is slow (this is also what I observed with the 
VMware software). Because each snapshot is stored as a separate file, when 
a snapshot X is deleted, part of X's data blocks that are still needed by 
its children Y must be physically copied from file X to file Y, which is 
slow and the VM is halted during the copy operation. QCOW2's internal 
snapshot approach avoids this problem. Since all snapshots are stored in 
one file, when a snapshot is deleted, QCOW2 only needs to update its 
reference count table without physically moving data blocks.

On the other hand, QCOW'2 internal snapshot has two major limitations that 
hurt runtime performance: caching the reference count table in memory and 
updating the on-disk reference count table. If we can eliminate both, then 
it is an ideal solution. This is exactly what FVD's internal snapshot 
solution does. Below is the key observation on why FVD can do it so 
efficiently.

In an internal snapshot implementation, the reference count table is used 
to track used blocks and free blocks. It serves no other purposes. In FVD, 
its static reference count table only tracks blocks used by (static) 
snapshots, and it does not track blocks (dynamically) allocated (on a 
write) or freed (on a trim) for the running VM. This is a simple but 
fundamental difference w.r.t. to QCOW2, whose reference count table tracks 
both the static content and the dynamic content. Because data blocks used 
by snapshots are static and do not change unless a snapshot is created or 
deleted, there is no need to update FVD's static reference count table 
when a VM runs, and actually there is even no need to cache it in memory. 
Data blocks that are dynamically allocated or freed for a running VM are 
already tracked by FVD's one-level lookup table (which is similar to 
QCOW2's two-level table, but in FVD it is much smaller and faster) even 
before introducing the snapshot feature, and hence it comes for free. 
Updating FVD's one-level lookup table is efficient because of FVD's 
journal.

When the VM boots, FVD scans the reference count table