Re: [Qemu-devel] [PATCH v3 1/2] target-i386: KVM: add basic Intel LMCE support

2016-06-08 Thread Haozhong Zhang
On 06/08/16 13:34, Paolo Bonzini wrote:
> 
> 
> On 05/06/2016 17:41, Haozhong Zhang wrote:
> > On 06/04/16 12:34, Boris Petkov wrote:
> >> Haozhong Zhang  wrote:
> >>
> >>> This patch adds the support to inject SRAR and SRAO as LMCE, i.e. they
> >>> will be injected to only one VCPU rather than broadcast to all
> >>> VCPUs. As KVM reports LMCE support on Intel platforms, this features is
> >>> only available on Intel platforms.
> >>>
> >>> Signed-off-by: Ashok Raj 
> >>> Signed-off-by: Haozhong Zhang 
> >>> ---
> >>> Cc: Paolo Bonzini 
> >>> Cc: Richard Henderson 
> >>> Cc: Eduardo Habkost 
> >>> Cc: Marcelo Tosatti 
> >>> Cc: Boris Petkov 
> >>> Cc: k...@vger.kernel.org
> >>> Cc: Tony Luck 
> >>> Cc: Andi Kleen 
> >>> ---
> >>> target-i386/cpu.c | 26 ++
> >>> target-i386/cpu.h | 13 -
> >>> target-i386/kvm.c | 35 +++
> >>> 3 files changed, 69 insertions(+), 5 deletions(-)
> >>
> >> ...
> >>
> >>> @@ -1173,6 +1182,8 @@ struct X86CPU {
> >>>  */
> >>> bool enable_pmu;
> >>>
> >>> +bool enable_lmce;
> >>
> >> That struct would go fat pretty fast if it grows a bool per CPU feature. 
> >> Perhaps a more clever, a-bit-per-featurebit scheme would be in order.
> > 
> > OK, I'll use a 64-bit integer for current and future features.
> 
> No, please keep this as is for now.  It can be refactored later.
>

OK

Thanks,
Haozhong



Re: [Qemu-devel] [PATCH v2 2/2] vl: Eliminate usb_enabled()

2016-06-08 Thread Thomas Huth
On 08.06.2016 22:50, Eduardo Habkost wrote:
> This wrapper for machine_usb(current_machine) is not necessary,
> replace all usages of usb_enabled() with machine_usb().
> 
> Cc: Peter Maydell 
> Cc: "Michael S. Tsirkin" 
> Cc: Alexander Graf 
> Cc: qemu-...@nongnu.org
> Cc: qemu-...@nongnu.org
> Signed-off-by: Eduardo Habkost 
> ---
> Changes v1 -> v2:
> * pxa2xx doesn't have a usb_enabled() check anymore
> ---
>  hw/arm/nseries.c|  2 +-
>  hw/arm/realview.c   |  2 +-
>  hw/arm/versatilepb.c|  2 +-
>  hw/i386/pc_piix.c   |  2 +-
>  hw/i386/pc_q35.c|  2 +-
>  hw/ppc/mac_oldworld.c   |  2 +-
>  hw/ppc/prep.c   |  2 +-
>  include/sysemu/sysemu.h |  1 -
>  vl.c| 11 +++
>  9 files changed, 10 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
> index d4eb141..fea911e 100644
> --- a/hw/arm/nseries.c
> +++ b/hw/arm/nseries.c
> @@ -1351,7 +1351,7 @@ static void n8x0_init(MachineState *machine,
>  n8x0_dss_setup(s);
>  n8x0_cbus_setup(s);
>  n8x0_uart_setup(s);
> -if (usb_enabled()) {
> +if (machine_usb(machine)) {
>  n8x0_usb_setup(s);
>  }
>  
> diff --git a/hw/arm/realview.c b/hw/arm/realview.c
> index 7d0aa6f..8eafcca 100644
> --- a/hw/arm/realview.c
> +++ b/hw/arm/realview.c
> @@ -254,7 +254,7 @@ static void realview_init(MachineState *machine,
>  sysbus_connect_irq(busdev, 2, pic[50]);
>  sysbus_connect_irq(busdev, 3, pic[51]);
>  pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
> -if (usb_enabled()) {
> +if (machine_usb(machine)) {
>  pci_create_simple(pci_bus, -1, "pci-ohci");
>  }
>  n = drive_get_max_bus(IF_SCSI);
> diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
> index 20dd356..8ae5392 100644
> --- a/hw/arm/versatilepb.c
> +++ b/hw/arm/versatilepb.c
> @@ -276,7 +276,7 @@ static void versatile_init(MachineState *machine, int 
> board_id)
>  pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
>  }
>  }
> -if (usb_enabled()) {
> +if (machine_usb(machine)) {
>  pci_create_simple(pci_bus, -1, "pci-ohci");
>  }
>  n = drive_get_max_bus(IF_SCSI);
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 14dd0cc..82c7c0a 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -262,7 +262,7 @@ static void pc_init1(MachineState *machine,
>  
>  pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
>  
> -if (pcmc->pci_enabled && usb_enabled()) {
> +if (pcmc->pci_enabled && machine_usb(machine)) {
>  pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
>  }
>  
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 04aae89..31a6a59 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -234,7 +234,7 @@ static void pc_q35_init(MachineState *machine)
>  ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
>  ahci_ide_create_devs(ahci, hd);
>  
> -if (usb_enabled()) {
> +if (machine_usb(machine)) {
>  /* Should we create 6 UHCI according to ich9 spec? */
>  ehci_create_ich9_with_companions(host_bus, 0x1d);
>  }
> diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
> index a9bb1c2..4479487 100644
> --- a/hw/ppc/mac_oldworld.c
> +++ b/hw/ppc/mac_oldworld.c
> @@ -309,7 +309,7 @@ static void ppc_heathrow_init(MachineState *machine)
>  dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
>  qdev_init_nofail(dev);
>  
> -if (usb_enabled()) {
> +if (machine_usb(machine)) {
>  pci_create_simple(pci_bus, -1, "pci-ohci");
>  }
>  
> diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
> index 07ffe72..054af1e 100644
> --- a/hw/ppc/prep.c
> +++ b/hw/ppc/prep.c
> @@ -649,7 +649,7 @@ static void ppc_prep_init(MachineState *machine)
>  memory_region_add_subregion(sysmem, 0xFEFF, xcsr);
>  #endif
>  
> -if (usb_enabled()) {
> +if (machine_usb(machine)) {
>  pci_create_simple(pci_bus, -1, "pci-ohci");
>  }
>  
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 9428141..7313673 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -233,7 +233,6 @@ void qemu_boot_set(const char *boot_order, Error **errp);
>  QemuOpts *qemu_get_machine_opts(void);
>  
>  bool defaults_enabled(void);
> -bool usb_enabled(void);
>  
>  extern QemuOptsList qemu_legacy_drive_opts;
>  extern QemuOptsList qemu_common_drive_opts;
> diff --git a/vl.c b/vl.c
> index b0bcc25..45eff56 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1072,11 +1072,6 @@ bool defaults_enabled(void)
>  return has_defaults;
>  }
>  
> -bool usb_enabled(void)
> -{
> -return machine_usb(current_machine);
> -}
> -
>  #ifndef _WIN32
>  static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
>  {
> @@ -1393,7 +1388,7 @@ static int usb_device_add(const char *devname)
>  const char *p;
>  #endif
>  
> -if (!usb_enabled()) {
> +if (!machine_usb(curren

[Qemu-devel] [Bug 955379] Re: cmake hangs with qemu-arm-static

2016-06-08 Thread Riku Voipio
A prebuilt package of qemu-user built statically at:

http://repo.linaro.org/ubuntu/linaro-tools/pool/main/q/qemu/qemu-user-
static_2.6.0+git931+g9bbbf64-1linarojessie1_amd64.deb

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/955379

Title:
  cmake hangs with qemu-arm-static

Status in QEMU:
  Confirmed
Status in Linaro QEMU:
  Confirmed
Status in qemu-linaro package in Ubuntu:
  Confirmed

Bug description:
  I'm using git commit 3e7ecd976b06f... configured with --target-list
  =arm-linux-user --static in a chroot environment to compile some
  things. I ran into this problem with both pcl and opencv-2.3.1. cmake
  consistently freezes at some point during its execution, though in a
  different spot each time, usually during a step when it's searching
  for some libraries. For instance, pcl most commonly stops after:

  [snip]
  -- Boost version: 1.46.1
  -- Found the following Boost libraries:
  --   system
  --   filesystem
  --   thread
  --   date_time
  -- checking for module 'eigen3'
  --   found eigen3, version 3.0.1

  which is perplexing because it freezes after finding what it wants,
  not during the search. When it does get past that point, it does so
  almost immediately but freezes somewhere else.

  I'm using 64-bit Ubuntu 11.10 with kernel release 3.0.0-16-generic
  with an Intel i5.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/955379/+subscriptions



Re: [Qemu-devel] [PATCH v2 2/2] vl: Eliminate usb_enabled()

2016-06-08 Thread Marcel Apfelbaum

On 06/08/2016 11:50 PM, Eduardo Habkost wrote:

This wrapper for machine_usb(current_machine) is not necessary,
replace all usages of usb_enabled() with machine_usb().

Cc: Peter Maydell 
Cc: "Michael S. Tsirkin" 
Cc: Alexander Graf 
Cc: qemu-...@nongnu.org
Cc: qemu-...@nongnu.org
Signed-off-by: Eduardo Habkost 
---
Changes v1 -> v2:
* pxa2xx doesn't have a usb_enabled() check anymore
---
  hw/arm/nseries.c|  2 +-
  hw/arm/realview.c   |  2 +-
  hw/arm/versatilepb.c|  2 +-
  hw/i386/pc_piix.c   |  2 +-
  hw/i386/pc_q35.c|  2 +-
  hw/ppc/mac_oldworld.c   |  2 +-
  hw/ppc/prep.c   |  2 +-
  include/sysemu/sysemu.h |  1 -
  vl.c| 11 +++
  9 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
index d4eb141..fea911e 100644
--- a/hw/arm/nseries.c
+++ b/hw/arm/nseries.c
@@ -1351,7 +1351,7 @@ static void n8x0_init(MachineState *machine,
  n8x0_dss_setup(s);
  n8x0_cbus_setup(s);
  n8x0_uart_setup(s);
-if (usb_enabled()) {
+if (machine_usb(machine)) {
  n8x0_usb_setup(s);
  }

diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 7d0aa6f..8eafcca 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -254,7 +254,7 @@ static void realview_init(MachineState *machine,
  sysbus_connect_irq(busdev, 2, pic[50]);
  sysbus_connect_irq(busdev, 3, pic[51]);
  pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
-if (usb_enabled()) {
+if (machine_usb(machine)) {
  pci_create_simple(pci_bus, -1, "pci-ohci");
  }
  n = drive_get_max_bus(IF_SCSI);
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index 20dd356..8ae5392 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -276,7 +276,7 @@ static void versatile_init(MachineState *machine, int 
board_id)
  pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
  }
  }
-if (usb_enabled()) {
+if (machine_usb(machine)) {
  pci_create_simple(pci_bus, -1, "pci-ohci");
  }
  n = drive_get_max_bus(IF_SCSI);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 14dd0cc..82c7c0a 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -262,7 +262,7 @@ static void pc_init1(MachineState *machine,

  pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);

-if (pcmc->pci_enabled && usb_enabled()) {
+if (pcmc->pci_enabled && machine_usb(machine)) {
  pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
  }

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 04aae89..31a6a59 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -234,7 +234,7 @@ static void pc_q35_init(MachineState *machine)
  ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
  ahci_ide_create_devs(ahci, hd);

-if (usb_enabled()) {
+if (machine_usb(machine)) {
  /* Should we create 6 UHCI according to ich9 spec? */
  ehci_create_ich9_with_companions(host_bus, 0x1d);
  }
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index a9bb1c2..4479487 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -309,7 +309,7 @@ static void ppc_heathrow_init(MachineState *machine)
  dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
  qdev_init_nofail(dev);

-if (usb_enabled()) {
+if (machine_usb(machine)) {
  pci_create_simple(pci_bus, -1, "pci-ohci");
  }

diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 07ffe72..054af1e 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -649,7 +649,7 @@ static void ppc_prep_init(MachineState *machine)
  memory_region_add_subregion(sysmem, 0xFEFF, xcsr);
  #endif

-if (usb_enabled()) {
+if (machine_usb(machine)) {
  pci_create_simple(pci_bus, -1, "pci-ohci");
  }

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 9428141..7313673 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -233,7 +233,6 @@ void qemu_boot_set(const char *boot_order, Error **errp);
  QemuOpts *qemu_get_machine_opts(void);

  bool defaults_enabled(void);
-bool usb_enabled(void);

  extern QemuOptsList qemu_legacy_drive_opts;
  extern QemuOptsList qemu_common_drive_opts;
diff --git a/vl.c b/vl.c
index b0bcc25..45eff56 100644
--- a/vl.c
+++ b/vl.c
@@ -1072,11 +1072,6 @@ bool defaults_enabled(void)
  return has_defaults;
  }

-bool usb_enabled(void)
-{
-return machine_usb(current_machine);
-}
-
  #ifndef _WIN32
  static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
  {
@@ -1393,7 +1388,7 @@ static int usb_device_add(const char *devname)
  const char *p;
  #endif

-if (!usb_enabled()) {
+if (!machine_usb(current_machine)) {
  return -1;
  }

@@ -1425,7 +1420,7 @@ static int usb_device_del(const char *devname)
  return -1;
  }

-if (!usb_enabled()) {
+if (!machine_usb(current_machine)) {
  return -1;
  }

@@ -4501,7 +

[Qemu-devel] [Bug 955379] Re: cmake hangs with qemu-arm-static

2016-06-08 Thread Riku Voipio
Please try the latest qemu git HEAD, Timothys and Peters fixes have been
merged in.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/955379

Title:
  cmake hangs with qemu-arm-static

Status in QEMU:
  Confirmed
Status in Linaro QEMU:
  Confirmed
Status in qemu-linaro package in Ubuntu:
  Confirmed

Bug description:
  I'm using git commit 3e7ecd976b06f... configured with --target-list
  =arm-linux-user --static in a chroot environment to compile some
  things. I ran into this problem with both pcl and opencv-2.3.1. cmake
  consistently freezes at some point during its execution, though in a
  different spot each time, usually during a step when it's searching
  for some libraries. For instance, pcl most commonly stops after:

  [snip]
  -- Boost version: 1.46.1
  -- Found the following Boost libraries:
  --   system
  --   filesystem
  --   thread
  --   date_time
  -- checking for module 'eigen3'
  --   found eigen3, version 3.0.1

  which is perplexing because it freezes after finding what it wants,
  not during the search. When it does get past that point, it does so
  almost immediately but freezes somewhere else.

  I'm using 64-bit Ubuntu 11.10 with kernel release 3.0.0-16-generic
  with an Intel i5.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/955379/+subscriptions



Re: [Qemu-devel] [QEMU RFC PATCH v4 1/6] migration: alternative way to set instance_id in SaveStateEntry

2016-06-08 Thread David Gibson
On Wed, Jun 08, 2016 at 04:06:52PM -0700, Jianjun Duan wrote:
> In QOM(QEMU Object Model) migrated objects are identified with instance_id
> which is calculated automatically using their path in the QOM composition
> tree. For some objects, this path could change from source to target in
> migration. To migrate such objects, we need to make sure the instance_id does
> not change from source to target. We add a hook in DeviceClass to do 
> customized
> instance_id calculation in such cases.
> 
> As a result, in these cases compat will not be set in the concerned
> SaveStateEntry. This will prevent the inconsistent idstr to be sent over in
> migration. We could have set alias_id in a similar way. But that will be
> overloading the purpose of alias_id.
> 
> The first application will be setting instance_id for DRC using its unique
> index. Doing this makes the instance_id of DRC to be consistent across 
> migration
> and supports flexible management of DRC objects in migration.
> 
> Signed-off-by: Jianjun Duan 

Ah, ok.  I misunderstood your earlier comment - I didn't realise you
needed a change to the migration core in order to set the instance
ids.

That said, I think being able to customize the instance ids could give
better ability to future-proof migration data, at least for certain
buses and devices.

Juan, Dave, what do you think?

> ---
>  include/hw/qdev-core.h |  6 ++
>  migration/savevm.c | 20 ++--
>  2 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 1ce02b2..28173a7 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -139,6 +139,12 @@ typedef struct DeviceClass {
>  qdev_initfn init; /* TODO remove, once users are converted to realize */
>  qdev_event exit; /* TODO remove, once users are converted to unrealize */
>  const char *bus_type;
> +
> +/* When this field is set, qemu will use it to get an unique instance_id
> + * instead of calculating an auto idstr and instanc_id for the relevant
> + * SaveStateEntry
> + */
> +int (*dev_get_instance_id)(DeviceState *dev);
>  } DeviceClass;
>  
>  typedef struct NamedGPIOList NamedGPIOList;
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 6c21231..f7e7c68 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -494,6 +494,11 @@ int register_savevm_live(DeviceState *dev,
>   void *opaque)
>  {
>  SaveStateEntry *se;
> +/* when it is a device and it provides a way to get instance_id,
> + * we will use it and skip setting idstr and compat.
> + */
> +bool flag = (dev != NULL) &&
> +(DEVICE_GET_CLASS(dev)->dev_get_instance_id != NULL);
>  
>  se = g_new0(SaveStateEntry, 1);
>  se->version_id = version_id;
> @@ -506,7 +511,7 @@ int register_savevm_live(DeviceState *dev,
>  se->is_ram = 1;
>  }
>  
> -if (dev) {
> +if (dev && !flag) {
>  char *id = qdev_get_dev_path(dev);
>  if (id) {
>  pstrcpy(se->idstr, sizeof(se->idstr), id);
> @@ -522,6 +527,9 @@ int register_savevm_live(DeviceState *dev,
>  }
>  pstrcat(se->idstr, sizeof(se->idstr), idstr);
>  
> +if (flag) {
> +instance_id = DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev);
> +}
>  if (instance_id == -1) {
>  se->instance_id = calculate_new_instance_id(se->idstr);
>  } else {
> @@ -579,6 +587,11 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
> instance_id,
> int required_for_version)
>  {
>  SaveStateEntry *se;
> +/* when it is a device and it provides a way to get instance_id,
> + * we will use it and skip setting idstr and compat.
> + */
> +bool flag = (dev != NULL) &&
> +(DEVICE_GET_CLASS(dev)->dev_get_instance_id != NULL);
>  
>  /* If this triggers, alias support can be dropped for the vmsd. */
>  assert(alias_id == -1 || required_for_version >= 
> vmsd->minimum_version_id);
> @@ -590,7 +603,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
> instance_id,
>  se->vmsd = vmsd;
>  se->alias_id = alias_id;
>  
> -if (dev) {
> +if (dev && !flag) {
>  char *id = qdev_get_dev_path(dev);
>  if (id) {
>  pstrcpy(se->idstr, sizeof(se->idstr), id);
> @@ -606,6 +619,9 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
> instance_id,
>  }
>  pstrcat(se->idstr, sizeof(se->idstr), vmsd->name);
>  
> +if (flag) {
> +instance_id = DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev);
> +}
>  if (instance_id == -1) {
>  se->instance_id = calculate_new_instance_id(se->idstr);
>  } else {

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.oz

Re: [Qemu-devel] [PATCH qemu v17 11/12] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW)

2016-06-08 Thread David Gibson
On Wed, Jun 08, 2016 at 04:09:57PM +1000, Alexey Kardashevskiy wrote:
> On 08/06/16 15:57, David Gibson wrote:
> > On Mon, Jun 06, 2016 at 06:12:58PM +1000, Alexey Kardashevskiy wrote:
> >> On 06/06/16 15:57, David Gibson wrote:
> >>> On Wed, Jun 01, 2016 at 06:57:42PM +1000, Alexey Kardashevskiy wrote:
>  This adds support for Dynamic DMA Windows (DDW) option defined by
>  the SPAPR specification which allows to have additional DMA window(s)
> 
>  The "ddw" property is enabled by default on a PHB but for compatibility
>  the pseries-2.5 machine (TODO: update version) and older disable it.
> >>>
> >>> Looks like your todo is now todone, but you need to update the commit
> >>> message.
> >>>
>  This also creates a single DMA window for the older machines to
>  maintain backward migration.
> 
>  This implements DDW for PHB with emulated and VFIO devices. The host
>  kernel support is required. The advertised IOMMU page sizes are 4K and
>  64K; 16M pages are supported but not advertised by default, in order to
>  enable them, the user has to specify "pgsz" property for PHB and
>  enable huge pages for RAM.
> 
>  The existing linux guests try creating one additional huge DMA window
>  with 64K or 16MB pages and map the entire guest RAM to. If succeeded,
>  the guest switches to dma_direct_ops and never calls TCE hypercalls
>  (H_PUT_TCE,...) again. This enables VFIO devices to use the entire RAM
>  and not waste time on map/unmap later. This adds a "dma64_win_addr"
>  property which is a bus address for the 64bit window and by default
>  set to 0x800... as this is what the modern POWER8 hardware
>  uses and this allows having emulated and VFIO devices on the same bus.
> 
>  This adds 4 RTAS handlers:
>  * ibm,query-pe-dma-window
>  * ibm,create-pe-dma-window
>  * ibm,remove-pe-dma-window
>  * ibm,reset-pe-dma-window
>  These are registered from type_init() callback.
> 
>  These RTAS handlers are implemented in a separate file to avoid polluting
>  spapr_iommu.c with PCI.
> 
>  This changes sPAPRPHBState::dma_liobn to an array to allow 2 LIOBNs.
> 
>  Signed-off-by: Alexey Kardashevskiy 
> >>>
> >>> Looks pretty close to ready.
> >>>
> >>> There are a handful of nits and one real error noted below.
> >>>
>  ---
>  Changes:
>  v17:
>  * fixed: "query" did return non-page-shifted value when memory hotplug 
>  is enabled
> 
>  v16:
>  * s/dma_liobn/dma_liobn[SPAPR_PCI_DMA_MAX_WINDOWS]/
>  * s/SPAPR_PCI_LIOBN()/dma_liobn[]/
> 
>  v15:
>  * moved page mask filtering to PHB realize(), use "-mempath" to know
>  if there are huge pages
>  * fixed error reporting in RTAS handlers
>  * max window size accounts now hotpluggable memory boundaries
>  ---
>   hw/ppc/Makefile.objs|   1 +
>   hw/ppc/spapr.c  |   5 +
>   hw/ppc/spapr_pci.c  |  77 +---
>   hw/ppc/spapr_rtas_ddw.c | 293 
>  
>   include/hw/pci-host/spapr.h |   8 +-
>   include/hw/ppc/spapr.h  |  16 ++-
>   trace-events|   4 +
>   7 files changed, 383 insertions(+), 21 deletions(-)
>   create mode 100644 hw/ppc/spapr_rtas_ddw.c
> 
>  diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
>  index c1ffc77..986b36f 100644
>  --- a/hw/ppc/Makefile.objs
>  +++ b/hw/ppc/Makefile.objs
>  @@ -7,6 +7,7 @@ obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o 
>  spapr_drc.o spapr_rng.o
>   ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
>   obj-y += spapr_pci_vfio.o
>   endif
>  +obj-$(CONFIG_PSERIES) += spapr_rtas_ddw.o
>   # PowerPC 4xx boards
>   obj-y += ppc405_boards.o ppc4xx_devs.o ppc405_uc.o ppc440_bamboo.o
>   obj-y += ppc4xx_pci.o
>  diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
>  index 44e401a..6ddcda9 100644
>  --- a/hw/ppc/spapr.c
>  +++ b/hw/ppc/spapr.c
>  @@ -2366,6 +2366,11 @@ DEFINE_SPAPR_MACHINE(2_6, "2.6", true);
>   .driver   = "spapr-vlan", \
>   .property = "use-rx-buffer-pools", \
>   .value= "off", \
>  +}, \
>  +{\
>  +.driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,\
>  +.property = "ddw",\
>  +.value= stringify(off),\
>   },
>   
>   static void spapr_machine_2_5_instance_options(MachineState *machine)
>  diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
>  index 68de523..bcf0360 100644
>  --- a/hw/ppc/spapr_pci.c
>  +++ b/hw/ppc/spapr_pci.c
>  @@ -35,6 +35,7 @@
>   #include "hw/ppc/spapr.h"
>   #include "hw/pci-host/spapr.h"
>   #include "exec/address-spaces.h"
>  +#include "exec/ram_addr.h"
>   #include 
>   #include "trace.h"
>   #include "qemu/error-re

Re: [Qemu-devel] [PATCH v4 4/9] target-avr: adding instructions encodings

2016-06-08 Thread Richard Henderson

On 06/08/2016 02:15 PM, Michael Rolnik wrote:

I can send the sources, of my generator if you want.
However I have not time to make it a part of AVR patch right now.
let's finish with AVR cores and then when I have time I will be happy to
QEMUify the generator.



I think you should add the generator even if it's not (currently) run as part 
of the normal build process.


Perhaps put the build commands you used in the target-avr/Makefile, commented 
out.


r~



Re: [Qemu-devel] [PATCH v4 2/9] target-avr: adding AVR CPU features/flavors

2016-06-08 Thread Richard Henderson

On 06/08/2016 01:53 PM, Michael Rolnik wrote:

Richard, do you want to delete all empty lines?


Huh?  No.  Indeed, in this case I want you to add empty lines.


r~



Re: [Qemu-devel] [PATCH v4 1/9] target-avr: AVR cores support is added. 1. basic CPU structure 2. registers 3. no instructions

2016-06-08 Thread Richard Henderson

On 06/08/2016 12:49 PM, Michael Rolnik wrote:

Hi Richard.

how can I test it?


The easiest way is with the "savevm" / "loadvm" monitor commands.

It does require that you have a device attached that can create snapshots (e.g. 
a disk with qcow2 format).  While AVR doesn't normally have disks, you ought to 
be able to connect a disk with -drive, even if it isn't accessible to the 
actual avr cpu.



r~



Re: [Qemu-devel] [PATCH v4 13/28] qapi: Add new clone visitor

2016-06-08 Thread Eric Blake
On 06/02/2016 07:43 AM, Markus Armbruster wrote:
> Eric Blake  writes:
> 
>> We have a couple places in the code base that want to deep-clone
>> one QAPI object into another, and they were resorting to serializing
>> the struct out to QObject then reparsing it.  A much more efficient
>> version can be done by adding a new clone visitor.
>>

> [...]
> * If an error is detected during visit_type_FOO() with an input
> * visitor, then *@obj will be NULL for pointer types, and left
> * unchanged for scalar types.  Using an output visitor with an
> * incomplete object has undefined behavior (other than a special case
> * for visit_type_str() treating NULL like ""), while the dealloc
> * visitor safely handles incomplete objects.  Since input visitors
> * never produce an incomplete object, such an object is possible only
> * by manual construction.
> 
> What about the clone visitor?

Probably safest to document it as undefined on incomplete objects.

>/*
> * Start visiting an object @obj (struct or union).
> *
> * @name expresses the relationship of this object to its parent
> * container; see the general description of @name above.
> *
> * @obj must be non-NULL for a real walk, in which case @size
> * determines how much memory an input visitor will allocate into
> * *@obj.  @obj may also be NULL for a virtual walk, in which case
> * @size is ignored.
> 
> What about the clone visitor?

Yes, clone visitors also use size.

> 
> *
> * @errp obeys typical error usage, and reports failures such as a
> * member @name is not present, or present but not an object.  On
> * error, input visitors set *@obj to NULL.
> 
> What about the clone visitor?

Never sets an error (ie. it can't fail on a complete source object, if
you don't include abort-due-to-OOM scenarios), so I'm not sure I need to
word anything differently here.

> * Start visiting a list.
> *
> * @name expresses the relationship of this list to its parent
> * container; see the general description of @name above.
> *
> * @list must be non-NULL for a real walk, in which case @size
> * determines how much memory an input visitor will allocate into
> * *@list (at least sizeof(GenericList)).  Some visitors also allow
> * @list to be NULL for a virtual walk, in which case @size is
> * ignored.
> 
> What about the clone visitor?
> 
> *
> * @errp obeys typical error usage, and reports failures such as a
> * member @name is not present, or present but not a list.  On error,
> * input visitors set *@list to NULL.
> 
> What about the clone visitor?

Same as for start_struct.

>/*
> * Does optional struct member @name need visiting?
> *
> * @name must not be NULL.  This function is only useful between
> * visit_start_struct() and visit_end_struct(), since only objects
> * have optional keys.
> *
> * @present points to the address of the optional member's has_ flag.
> *
> * Input visitors set *@present according to input; other visitors
> * leave it unchanged.  In either case, return *@present for
> * convenience.
> 
> I guess this is correct for the clone visitor.

Clone visitor leaves it alone (it is reading *@present on the dest,
which was already set earlier during the g_memdup() of visit_start_*).

>/*
> * Visit an enum value.
> *
> * @name expresses the relationship of this enum to its parent
> * container; see the general description of @name above.
> *
> * @obj must be non-NULL.  Input visitors parse input and set *@obj to
> * the enumeration value, leaving @obj unchanged on error; other
> * visitors use *@obj but leave it unchanged.
> 
> I guess this is correct for the clone visitor.

It's a bit of a stretch, but "use *@obj" can certainly mean "do nothing
with it, because it is a scalar that was already set earlier during the
g_memdup() of visit_start_*".  So yes, the clone visitor wants
visit_type_enum() to be a no-op.


> 
>/*
> * Check if visitor is an input visitor.
> 
> Does the clone visitor count as input visitor here?  Should it?

No, and probably no.  A clone visitor never sets errp, and therefore
there is no reason to clean up after a failed clone; and our current use
of visit_is_input() is only for cleaning up after failures in an input
visitor.

> 
> */
>bool visit_is_input(Visitor *v);
> 
>/*** Visiting built-in types ***/
> 
>/*
> * Visit an integer value.
> *
> * @name expresses the relationship of this integer to its parent
> * container; see the general description of @name above.
> *
> * @obj must be non-NULL.  Input visitors set *@obj to the value;
> * other visitors will leave *@obj unchanged.
> 
> I guess this is correct for the clone visitor.

Again correct - the clone visitor doesn't set anything at this point,
because the integer was already copied earlier during 

Re: [Qemu-devel] [PATCH v3] spapr: Ensure all LMBs are represented in ibm, dynamic-memory

2016-06-08 Thread David Gibson
On Wed, Jun 08, 2016 at 11:09:11AM -0500, Michael Roth wrote:
> Quoting Bharata B Rao (2016-06-08 10:50:03)
> > On Wed, Jun 08, 2016 at 10:05:12AM -0500, Michael Roth wrote:
> > > Quoting Bharata B Rao (2016-06-07 21:35:54)
> > > > On Tue, Jun 07, 2016 at 06:37:28PM -0500, Michael Roth wrote:
> > > > > Quoting Bharata B Rao (2016-06-07 00:19:03)
> > > > > > Memory hotplug can fail for some combinations of RAM and maxmem when
> > > > > > DDW is enabled in the presence of devices like nec-usb-xhci. DDW 
> > > > > > depends
> > > > > > on maximum addressable memory returned by guest and this value is 
> > > > > > currently
> > > > > > being calculated wrongly by the guest kernel routine 
> > > > > > memory_hotplug_max().
> > > > > > While there is an attempt to fix the guest kernel, this patch works
> > > > > > around the problem within QEMU itself.
> > > > > > 
> > > > > > memory_hotplug_max() routine in the guest kernel arrives at max
> > > > > > addressable memory by multiplying lmb-size with the lmb-count 
> > > > > > obtained
> > > > > > from ibm,dynamic-memory property. There are two assumptions here:
> > > > > > 
> > > > > > - All LMBs are part of ibm,dynamic memory: This is not true for 
> > > > > > PowerKVM
> > > > > >   where only hot-pluggable LMBs are present in this property.
> > > > > > - The memory area comprising of RAM and hotplug region is 
> > > > > > contiguous: This
> > > > > >   needn't be true always for PowerKVM as there can be gap between
> > > > > >   boot time RAM and hotplug region.
> > > > > > 
> > > > > > To work around this guest kernel bug, ensure that ibm,dynamic-memory
> > > > > > has information about all the LMBs (RMA, boot-time LMBs, future
> > > > > > hotpluggable LMBs, and dummy LMBs to cover the gap between RAM and
> > > > > > hotpluggable region).
> > > > > > 
> > > > > > RMA is represented separately by memory@0 node. Hence mark RMA LMBs
> > > > > > and also the LMBs for the gap b/n RAM and hotpluggable region as
> > > > > > reserved so that these LMBs are not recounted/counted by guest.
> > > > > > 
> > > > > > Signed-off-by: Bharata B Rao 
> > > > > > ---
> > > > > > Changes in v3:
> > > > > > 
> > > > > > - Not touching spapr_create_lmb_dr_connectors() so that we continue
> > > > > >   to have DRC objects for only hotpluggable LMBs.
> > > > > > - Simplified the logic of creating dynamic-memory node based on 
> > > > > > comments
> > > > > >   from Michael Roth and David Gibson.
> > > > > > 
> > > > > > v2: 
> > > > > > https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01316.html
> > > > > > 
> > > > > >  hw/ppc/spapr.c | 51 
> > > > > > --
> > > > > >  include/hw/ppc/spapr.h |  5 +++--
> > > > > >  2 files changed, 36 insertions(+), 20 deletions(-)
> > > > > > 
> > > > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > > > > index 0636642..9d1d43d 100644
> > > > > > --- a/hw/ppc/spapr.c
> > > > > > +++ b/hw/ppc/spapr.c
> > > > > > @@ -762,14 +762,17 @@ static int 
> > > > > > spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt)
> > > > > >  int ret, i, offset;
> > > > > >  uint64_t lmb_size = SPAPR_MEMORY_BLOCK_SIZE;
> > > > > >  uint32_t prop_lmb_size[] = {0, cpu_to_be32(lmb_size)};
> > > > > > -uint32_t nr_lmbs = (machine->maxram_size - 
> > > > > > machine->ram_size)/lmb_size;
> > > > > > +uint32_t hotplug_lmb_start = spapr->hotplug_memory.base / 
> > > > > > lmb_size;
> > > > > > +uint32_t nr_lmbs = (spapr->hotplug_memory.base +
> > > > > > +   
> > > > > > memory_region_size(&spapr->hotplug_memory.mr)) /
> > > > > > +   lmb_size;
> > > > > >  uint32_t *int_buf, *cur_index, buf_len;
> > > > > >  int nr_nodes = nb_numa_nodes ? nb_numa_nodes : 1;
> > > > > > 
> > > > > >  /*
> > > > > > - * Don't create the node if there are no DR LMBs.
> > > > > > + * Don't create the node if there is no hotpluggable memory
> > > > > >   */
> > > > > > -if (!nr_lmbs) {
> > > > > > +if (machine->ram_size == machine->maxram_size) {
> > > > > >  return 0;
> > > > > >  }
> > > > > > 
> > > > > > @@ -805,24 +808,36 @@ static int 
> > > > > > spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt)
> > > > > >  for (i = 0; i < nr_lmbs; i++) {
> > > > > >  sPAPRDRConnector *drc;
> > > > > >  sPAPRDRConnectorClass *drck;
> > > > > 
> > > > > Since these ^ are only used if (i >= hotplug_lmb_start), it might be
> > > > > clearer to move them there now.
> > > > 
> > > > Yes.
> > > > 
> > > > > 
> > > > > > -uint64_t addr = i * lmb_size + spapr->hotplug_memory.base;;
> > > > > > +uint64_t addr = i * lmb_size;
> > > > > >  uint32_t *dynamic_memory = cur_index;
> > > > > > 
> > > > > > -drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB,
> > > > > > -   addr/lmb_size);
> > > > > > -g_assert(drc);

Re: [Qemu-devel] [PATCH v3] spapr: Ensure all LMBs are represented in ibm, dynamic-memory

2016-06-08 Thread David Gibson
On Wed, Jun 08, 2016 at 10:05:12AM -0500, Michael Roth wrote:
> Quoting Bharata B Rao (2016-06-07 21:35:54)
> > On Tue, Jun 07, 2016 at 06:37:28PM -0500, Michael Roth wrote:
> > > Quoting Bharata B Rao (2016-06-07 00:19:03)
> > > > Memory hotplug can fail for some combinations of RAM and maxmem when
> > > > DDW is enabled in the presence of devices like nec-usb-xhci. DDW depends
> > > > on maximum addressable memory returned by guest and this value is 
> > > > currently
> > > > being calculated wrongly by the guest kernel routine 
> > > > memory_hotplug_max().
> > > > While there is an attempt to fix the guest kernel, this patch works
> > > > around the problem within QEMU itself.
> > > > 
> > > > memory_hotplug_max() routine in the guest kernel arrives at max
> > > > addressable memory by multiplying lmb-size with the lmb-count obtained
> > > > from ibm,dynamic-memory property. There are two assumptions here:
> > > > 
> > > > - All LMBs are part of ibm,dynamic memory: This is not true for PowerKVM
> > > >   where only hot-pluggable LMBs are present in this property.
> > > > - The memory area comprising of RAM and hotplug region is contiguous: 
> > > > This
> > > >   needn't be true always for PowerKVM as there can be gap between
> > > >   boot time RAM and hotplug region.
> > > > 
> > > > To work around this guest kernel bug, ensure that ibm,dynamic-memory
> > > > has information about all the LMBs (RMA, boot-time LMBs, future
> > > > hotpluggable LMBs, and dummy LMBs to cover the gap between RAM and
> > > > hotpluggable region).
> > > > 
> > > > RMA is represented separately by memory@0 node. Hence mark RMA LMBs
> > > > and also the LMBs for the gap b/n RAM and hotpluggable region as
> > > > reserved so that these LMBs are not recounted/counted by guest.
> > > > 
> > > > Signed-off-by: Bharata B Rao 
> > > > ---
> > > > Changes in v3:
> > > > 
> > > > - Not touching spapr_create_lmb_dr_connectors() so that we continue
> > > >   to have DRC objects for only hotpluggable LMBs.
> > > > - Simplified the logic of creating dynamic-memory node based on comments
> > > >   from Michael Roth and David Gibson.
> > > > 
> > > > v2: https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg01316.html
> > > > 
> > > >  hw/ppc/spapr.c | 51 
> > > > --
> > > >  include/hw/ppc/spapr.h |  5 +++--
> > > >  2 files changed, 36 insertions(+), 20 deletions(-)
> > > > 
> > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > > index 0636642..9d1d43d 100644
> > > > --- a/hw/ppc/spapr.c
> > > > +++ b/hw/ppc/spapr.c
> > > > @@ -762,14 +762,17 @@ static int 
> > > > spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt)
> > > >  int ret, i, offset;
> > > >  uint64_t lmb_size = SPAPR_MEMORY_BLOCK_SIZE;
> > > >  uint32_t prop_lmb_size[] = {0, cpu_to_be32(lmb_size)};
> > > > -uint32_t nr_lmbs = (machine->maxram_size - 
> > > > machine->ram_size)/lmb_size;
> > > > +uint32_t hotplug_lmb_start = spapr->hotplug_memory.base / lmb_size;
> > > > +uint32_t nr_lmbs = (spapr->hotplug_memory.base +
> > > > +   memory_region_size(&spapr->hotplug_memory.mr)) /
> > > > +   lmb_size;
> > > >  uint32_t *int_buf, *cur_index, buf_len;
> > > >  int nr_nodes = nb_numa_nodes ? nb_numa_nodes : 1;
> > > > 
> > > >  /*
> > > > - * Don't create the node if there are no DR LMBs.
> > > > + * Don't create the node if there is no hotpluggable memory
> > > >   */
> > > > -if (!nr_lmbs) {
> > > > +if (machine->ram_size == machine->maxram_size) {
> > > >  return 0;
> > > >  }
> > > > 
> > > > @@ -805,24 +808,36 @@ static int 
> > > > spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt)
> > > >  for (i = 0; i < nr_lmbs; i++) {
> > > >  sPAPRDRConnector *drc;
> > > >  sPAPRDRConnectorClass *drck;
> > > 
> > > Since these ^ are only used if (i >= hotplug_lmb_start), it might be
> > > clearer to move them there now.
> > 
> > Yes.
> > 
> > > 
> > > > -uint64_t addr = i * lmb_size + spapr->hotplug_memory.base;;
> > > > +uint64_t addr = i * lmb_size;
> > > >  uint32_t *dynamic_memory = cur_index;
> > > > 
> > > > -drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB,
> > > > -   addr/lmb_size);
> > > > -g_assert(drc);
> > > > -drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
> > > > -
> > > > -dynamic_memory[0] = cpu_to_be32(addr >> 32);
> > > > -dynamic_memory[1] = cpu_to_be32(addr & 0x);
> > > > -dynamic_memory[2] = cpu_to_be32(drck->get_index(drc));
> > > > -dynamic_memory[3] = cpu_to_be32(0); /* reserved */
> > > > -dynamic_memory[4] = cpu_to_be32(numa_get_node(addr, NULL));
> > > > -if (addr < machine->ram_size ||
> > > > -memory_region_present(get_system_memory(), addr)) {
> > > > -dynamic_mem

Re: [Qemu-devel] [for-2.7 PATCH v3 07/15] spapr: Abstract CPU core device and type specific core devices

2016-06-08 Thread David Gibson
On Wed, Jun 08, 2016 at 03:12:42PM +0530, Bharata B Rao wrote:
> On Fri, Jun 03, 2016 at 03:25:08PM +1000, David Gibson wrote:
> > On Thu, May 12, 2016 at 09:18:17AM +0530, Bharata B Rao wrote:
> > > Add sPAPR specific abastract CPU core device that is based on generic
> > > CPU core device. Use this as base type to create sPAPR CPU specific core
> > > devices.
> > > 
> > > TODO:
> > > - Add core types for other remaining CPU types
> > > - Handle CPU model alias correctly
> > > 
> > > Signed-off-by: Bharata B Rao 
> > 
> > This is looking pretty cood, but there's some minor changes I'd like
> > to see.
> > 
> > > ---
> > >  hw/ppc/Makefile.objs|   1 +
> > >  hw/ppc/spapr.c  |   3 +-
> > >  hw/ppc/spapr_cpu_core.c | 168 
> > > 
> > >  include/hw/ppc/spapr.h  |   1 +
> > >  include/hw/ppc/spapr_cpu_core.h |  28 +++
> > >  5 files changed, 199 insertions(+), 2 deletions(-)
> > >  create mode 100644 hw/ppc/spapr_cpu_core.c
> > >  create mode 100644 include/hw/ppc/spapr_cpu_core.h
> > > 
> > > diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
> > > index c1ffc77..5cc6608 100644
> > > --- a/hw/ppc/Makefile.objs
> > > +++ b/hw/ppc/Makefile.objs
> > > @@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o
> > >  obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o
> > >  obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
> > >  obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
> > > +obj-$(CONFIG_PSERIES) += spapr_cpu_core.o
> > >  ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
> > >  obj-y += spapr_pci_vfio.o
> > >  endif
> > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > index b69995e..95db047 100644
> > > --- a/hw/ppc/spapr.c
> > > +++ b/hw/ppc/spapr.c
> > > @@ -1605,8 +1605,7 @@ static void spapr_boot_set(void *opaque, const char 
> > > *boot_device,
> > >  machine->boot_order = g_strdup(boot_device);
> > >  }
> > >  
> > > -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> > > -   Error **errp)
> > > +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error 
> > > **errp)
> > 
> > I think this function should actually move into spapr_cpu_core.c
> 
> Actually, this is a CPU thread specific routine and will be called from
> spapr.c too. But I moved this to spapr_cpu_core.c as you suggest.

Yes, I realize it will be called from spapr.c as well.  The idea is to
make the core based initialization the clean path, even if the
thread-based initialization needed for backwards compat needs some
awkward cross-module calls and exports.

> > >  {
> > >  CPUPPCState *env = &cpu->env;
> > >  
> > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> > > new file mode 100644
> > > index 000..af63ed9
> > > --- /dev/null
> > > +++ b/hw/ppc/spapr_cpu_core.c
> > > @@ -0,0 +1,168 @@
> > > +/*
> > > + * sPAPR CPU core device, acts as container of CPU thread devices.
> > > + *
> > > + * Copyright (C) 2016 Bharata B Rao 
> > > + *
> > > + * 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 "hw/cpu/core.h"
> > > +#include "hw/ppc/spapr_cpu_core.h"
> > > +#include "hw/ppc/spapr.h"
> > > +#include "hw/boards.h"
> > > +#include "qapi/error.h"
> > > +#include 
> > > +#include "target-ppc/kvm_ppc.h"
> > > +
> > > +static void spapr_cpu_core_create_threads(DeviceState *dev, int threads,
> > > +  Error **errp)
> > 
> > This function could be folded into spapr_cpu_core_realize(), that's
> > the only caller and they're both fairly short.
> 
> Ok done.
> 
> > 
> > > +{
> > > +int i;
> > > +Error *local_err = NULL;
> > > +sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
> > > +
> > > +for (i = 0; i < threads; i++) {
> > > +char id[32];
> > > +
> > > +object_initialize(&core->threads[i], sizeof(core->threads[i]),
> > > +  object_class_get_name(core->cpu));
> > 
> > Given we have to go from the class pointer to the class name to
> > actually use it here, maybe we would be better off storing the name
> > rather than a class pointer.  Up to you, I'm happy either way.
> 
> I was doing typename initially and there were suggestions to move to
> ObjectClass. May be I will leave it like this while I fix all the other
> things and finally revisit this ?

Yes, that makes sense.  As I say it's not really a big deal either
way.

Could you use object_initialize_with_type() to avoid going via the
type name?

> > > +snprintf(id, sizeof(id), "thread[%d]", i);
> > > +object_property_add_child(OBJECT(core), id, 
> > > OBJECT(&core->threads[i]),
> > > +  &local_err);
> > > +if (local_err) {
> > > +goto err;
> > > +}
> > > +}
> > > +return;
> > > +

Re: [Qemu-devel] [PATCH v6 00/13] data-driven device registers

2016-06-08 Thread Alistair Francis
On Thu, May 12, 2016 at 3:45 PM, Alistair Francis
 wrote:
> This patch series is based on Peter C's original register API. His
> original cover letter is below.

Ping!

>
> Future work: Allow support for memory attributes.
>
> V6:
>  - Small changes to the API based on Alex's comments
>  - Remove 'register: Add support for decoding information' patch
>  - Move prefix and debug into the RegisterInfoArray as it is the same
>for every register.
> V5:
>  - Only create a single memory region instead of a memory region for
>each register
>  - General tidyups based on Alex's comments
> V4:
>  - Rebase and fix build issue
>  - Simplify the register write logic
>  - Other small fixes suggested by Alex Bennee
> V3:
>  - Small changes reported by Fred
> V2:
>  - Rebase
>  - Fix up IOU SLCR connections
>  - Add the memory_region_add_subregion_no_print() function and use it
>for the registers
> Changes since RFC:
>  - Connect the ZynqMP IOU SLCR device
>  - Rebase
>
> Original cover letter From Peter:
> Hi All. This is a new scheme I've come up with handling device registers in a
> data driven way. My motivation for this is to factor out a lot of the access
> checking that seems to be replicated in every device. See P1 commit message 
> for
> further discussion.
>
> P1 is the main patch, adds the register definition functionality
> P2-3,6 add helpers that glue the register API to the Memory API
> P4 Defines a set of macros that minimise register and field definitions
> P5 is QOMfication
> P7 is a trivial
> P10-13 Work up to GPIO support
> P8,9,14 add new devices (the Xilinx Zynq devcfg & ZynqMP SLCR) that use this
> scheme.
> P15: Connect the ZynqMP SLCR device
>
> This Zynq devcfg device was particularly finnicky with per-bit restrictions.
> I'm also looking for a higher-than-usual modelling fidelity
> on the register space, with semantics defined for random reserved bits
> in-between otherwise consistent fields.
>
> Here's an example of the qemu_log output for the devcfg device. This is 
> produced
> by now generic sharable code:
>
> /machine/unattached/device[44]:Addr 0x08:CFG: write of value 0508
> /machine/unattached/device[44]:Addr 0x80:MCTRL: write of value 00800010
> /machine/unattached/device[44]:Addr 0x10:INT_MASK: write of value 
> /machine/unattached/device[44]:Addr :CTRL: write of value 0c00607f
>
> And an example of a rogue guest banging on a bad bit:
>
> /machine/unattached/device[44]:Addr 0x14:STATUS bits 0x01 may not be \
> written to 1
>
> A future feature I am interested in is implementing TCG optimisation of
> side-effectless registers. The register API allows clear definition of
> what registers have txn side effects and which ones don't. You could even
> go a step further and translate such side-effectless accesses based on the
> data pointer for the register.
>
>
> Alistair Francis (6):
>   bitops: Add MAKE_64BIT_MASK macro
>   register: Add Register API
>   register: Add Memory API glue
>   dma: Add Xilinx Zynq devcfg device model
>   register: Add GPIO API
>   xlnx-zynqmp: Connect the ZynqMP IOU SLCR
>
> Peter Crosthwaite (7):
>   register: Define REG and FIELD macros
>   register: QOMify
>   register: Add block initialise helper
>   xilinx_zynq: Connect devcfg to the Zynq machine model
>   qdev: Define qdev_get_gpio_out
>   irq: Add opaque setter routine
>   misc: Introduce ZynqMP IOU SLCR
>
>  default-configs/arm-softmmu.mak|   1 +
>  hw/arm/xilinx_zynq.c   |   8 +
>  hw/arm/xlnx-zynqmp.c   |  13 ++
>  hw/core/Makefile.objs  |   1 +
>  hw/core/irq.c  |   5 +
>  hw/core/qdev.c |  12 +
>  hw/core/register.c | 376 +++
>  hw/dma/Makefile.objs   |   1 +
>  hw/dma/xlnx-zynq-devcfg.c  | 396 
> +
>  hw/misc/Makefile.objs  |   1 +
>  hw/misc/xlnx-zynqmp-iou-slcr.c | 115 ++
>  include/hw/arm/xlnx-zynqmp.h   |   2 +
>  include/hw/dma/xlnx-zynq-devcfg.h  |  62 ++
>  include/hw/irq.h   |   2 +
>  include/hw/misc/xlnx-zynqmp-iou-slcr.h |  47 
>  include/hw/qdev-core.h |   2 +
>  include/hw/register.h  | 262 ++
>  include/qemu/bitops.h  |   3 +
>  18 files changed, 1309 insertions(+)
>  create mode 100644 hw/core/register.c
>  create mode 100644 hw/dma/xlnx-zynq-devcfg.c
>  create mode 100644 hw/misc/xlnx-zynqmp-iou-slcr.c
>  create mode 100644 include/hw/dma/xlnx-zynq-devcfg.h
>  create mode 100644 include/hw/misc/xlnx-zynqmp-iou-slcr.h
>  create mode 100644 include/hw/register.h
>
> --
> 2.7.4
>
>



[Qemu-devel] [QEMU RFC PATCH v4 5/6] migration: migrate ccs_list in spapr state

2016-06-08 Thread Jianjun Duan
ccs_list in spapr state maintains the device tree related
information on the rtas side for hotplugged devices. In racing
situations between hotplug events and migration operation, a rtas
hotplug event could be migrated from the source guest to target
guest, or the source guest could have not yet finished fetching
the device tree when migration is started, the target will try
to finish fetching the device tree. By migrating ccs_list, the
target can fetch the device tree properly.

ccs_list is put in a subsection in the spapr state VMSD to make
sure migration across different versions is not broken.

Signed-off-by: Jianjun Duan 
---
 hw/ppc/spapr.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 0636642..54a8af6 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1266,6 +1266,36 @@ static bool version_before_3(void *opaque, int 
version_id)
 return version_id < 3;
 }
 
+static bool spapr_ccs_list_needed(void *opaque)
+{
+sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
+return !QTAILQ_EMPTY(&spapr->ccs_list);
+}
+
+static const VMStateDescription vmstate_spapr_ccs = {
+.name = "spaprconfigureconnectorstate",
+.version_id = 1,
+.minimum_version_id = 1,
+.fields = (VMStateField[]) {
+VMSTATE_UINT32(drc_index, sPAPRConfigureConnectorState),
+VMSTATE_INT32(fdt_offset, sPAPRConfigureConnectorState),
+VMSTATE_INT32(fdt_depth, sPAPRConfigureConnectorState),
+VMSTATE_END_OF_LIST()
+},
+};
+
+static const VMStateDescription vmstate_spapr_ccs_list = {
+.name = "spaprccslist",
+.version_id = 1,
+.minimum_version_id = 1,
+.needed = spapr_ccs_list_needed,
+.fields = (VMStateField[]) {
+VMSTATE_QTAILQ_V(ccs_list, sPAPRMachineState, 1,
+ vmstate_spapr_ccs, sPAPRConfigureConnectorState, 
next),
+VMSTATE_END_OF_LIST()
+},
+};
+
 static const VMStateDescription vmstate_spapr = {
 .name = "spapr",
 .version_id = 3,
@@ -1281,6 +1311,10 @@ static const VMStateDescription vmstate_spapr = {
 VMSTATE_PPC_TIMEBASE_V(tb, sPAPRMachineState, 2),
 VMSTATE_END_OF_LIST()
 },
+.subsections = (const VMStateDescription*[]) {
+&vmstate_spapr_ccs_list,
+NULL
+}
 };
 
 static int htab_save_setup(QEMUFile *f, void *opaque)
-- 
1.9.1




[Qemu-devel] [QEMU RFC PATCH v4 6/6] migration: migrate pending_events of spapr state

2016-06-08 Thread Jianjun Duan
In racing situations between hotplug events and migration operation,
a rtas hotplug event could have not yet be delivered to the source
guest when migration is started. In this case the pending_events of
spapr state need be transmitted to the target so that the hotplug
event can be finished on the target.

All the different fields of the events are encoded as defined by
PAPR. We can migrate them as uint8_t binary stream without any
concerns about data padding or endianess.

pending_events is put in a subsection in the spapr state VMSD to make
sure migration across different versions is not broken.

Signed-off-by: Jianjun Duan 
---
 hw/ppc/spapr.c | 33 +
 hw/ppc/spapr_events.c  | 22 +-
 include/hw/ppc/spapr.h |  3 ++-
 3 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 54a8af6..ecff138 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1266,12 +1266,32 @@ static bool version_before_3(void *opaque, int 
version_id)
 return version_id < 3;
 }
 
+static bool spapr_pending_events_needed(void *opaque)
+{
+sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
+return !QTAILQ_EMPTY(&spapr->pending_events);
+}
+
 static bool spapr_ccs_list_needed(void *opaque)
 {
 sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
 return !QTAILQ_EMPTY(&spapr->ccs_list);
 }
 
+static const VMStateDescription vmstate_spapr_event_entry = {
+.name = "spapreventlogentry",
+.version_id = 1,
+.minimum_version_id = 1,
+.fields = (VMStateField[]) {
+VMSTATE_INT32(log_type, sPAPREventLogEntry),
+VMSTATE_BOOL(exception, sPAPREventLogEntry),
+VMSTATE_UINT32(data_size, sPAPREventLogEntry),
+VMSTATE_VARRAY_UINT32_ALLOC(data, sPAPREventLogEntry, data_size,
+0, vmstate_info_uint8, uint8_t),
+VMSTATE_END_OF_LIST()
+  },
+};
+
 static const VMStateDescription vmstate_spapr_ccs = {
 .name = "spaprconfigureconnectorstate",
 .version_id = 1,
@@ -1284,6 +1304,18 @@ static const VMStateDescription vmstate_spapr_ccs = {
 },
 };
 
+static const VMStateDescription vmstate_spapr_pending_events = {
+.name = "spaprpendingevents",
+.version_id = 1,
+.minimum_version_id = 1,
+.needed = spapr_pending_events_needed,
+.fields = (VMStateField[]) {
+VMSTATE_QTAILQ_V(pending_events, sPAPRMachineState, 1,
+ vmstate_spapr_event_entry, sPAPREventLogEntry, next),
+VMSTATE_END_OF_LIST()
+},
+};
+
 static const VMStateDescription vmstate_spapr_ccs_list = {
 .name = "spaprccslist",
 .version_id = 1,
@@ -1312,6 +1344,7 @@ static const VMStateDescription vmstate_spapr = {
 VMSTATE_END_OF_LIST()
 },
 .subsections = (const VMStateDescription*[]) {
+&vmstate_spapr_pending_events,
 &vmstate_spapr_ccs_list,
 NULL
 }
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
index 049fb1b..1680c08 100644
--- a/hw/ppc/spapr_events.c
+++ b/hw/ppc/spapr_events.c
@@ -239,7 +239,8 @@ void spapr_events_fdt_skel(void *fdt, uint32_t 
check_exception_irq)
 _FDT((fdt_end_node(fdt)));
 }
 
-static void rtas_event_log_queue(int log_type, void *data, bool exception)
+static void rtas_event_log_queue(int log_type, void *data, bool exception,
+int data_size)
 {
 sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
 sPAPREventLogEntry *entry = g_new(sPAPREventLogEntry, 1);
@@ -248,6 +249,7 @@ static void rtas_event_log_queue(int log_type, void *data, 
bool exception)
 entry->log_type = log_type;
 entry->exception = exception;
 entry->data = data;
+entry->data_size = data_size;
 QTAILQ_INSERT_TAIL(&spapr->pending_events, entry, next);
 }
 
@@ -350,6 +352,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
 struct rtas_event_log_v6_mainb *mainb;
 struct rtas_event_log_v6_epow *epow;
 struct epow_log_full *new_epow;
+uint32_t data_size;
 
 new_epow = g_malloc0(sizeof(*new_epow));
 hdr = &new_epow->hdr;
@@ -358,13 +361,13 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
 mainb = &new_epow->mainb;
 epow = &new_epow->epow;
 
+data_size = sizeof(*new_epow);
 hdr->summary = cpu_to_be32(RTAS_LOG_VERSION_6
| RTAS_LOG_SEVERITY_EVENT
| RTAS_LOG_DISPOSITION_NOT_RECOVERED
| RTAS_LOG_OPTIONAL_PART_PRESENT
| RTAS_LOG_TYPE_EPOW);
-hdr->extended_length = cpu_to_be32(sizeof(*new_epow)
-   - sizeof(new_epow->hdr));
+hdr->extended_length = cpu_to_be32(data_size - sizeof(new_epow->hdr));
 
 spapr_init_v6hdr(v6hdr);
 spapr_init_maina(maina, 3 /* Main-A, Main-B and EPOW */);
@@ -384,7 +387,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
  

[Qemu-devel] [QEMU RFC PATCH v4 4/6] migration: migrate QTAILQ

2016-06-08 Thread Jianjun Duan
Currently we cannot directly transfer a QTAILQ instance because of the
limitation in the migration code. Here we introduce an approach to
transfer such structures. In our approach such a structure is tagged
with VMS_LINKED. We then modified vmstate_save_state and vmstate_load_state
so that when VMS_LINKED is encountered, put and get from VMStateInfo are
called respectively. We created VMStateInfo vmstate_info_qtailq for QTAILQ.
Similar VMStateInfo can be created for other data structures such as list.
This approach will be used to transfer pending_events and ccs_list in spapr
state.

We also create some macros in qemu/queue.h to access a QTAILQ using pointer
arithmetic. This ensures that we do not depend on the implementation
details about QTAILQ in the migration code.

Signed-off-by: Jianjun Duan 
---
 include/migration/vmstate.h | 26 ++
 include/qemu/queue.h| 32 ++
 migration/vmstate.c | 66 +
 trace-events|  4 +++
 4 files changed, 128 insertions(+)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 56a4171..bce911f 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -185,6 +185,12 @@ enum VMStateFlags {
  * to determine the number of entries in the array. Only valid in
  * combination with one of VMS_VARRAY*. */
 VMS_MULTIPLY_ELEMENTS = 0x4000,
+/* For fields which need customized handling, such as QTAILQ in queue.h.
+ * When this flag is set in VMStateField, info->get/put will
+ * be used in vmstate_load/save_state instead of recursive call.
+ * User should implement set info to handle the concerned data structure.
+ */
+VMS_LINKED= 0x8000,
 };
 
 struct VMStateField {
@@ -245,6 +251,7 @@ extern const VMStateInfo vmstate_info_timer;
 extern const VMStateInfo vmstate_info_buffer;
 extern const VMStateInfo vmstate_info_unused_buffer;
 extern const VMStateInfo vmstate_info_bitmap;
+extern const VMStateInfo vmstate_info_qtailq;
 
 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
@@ -656,6 +663,25 @@ extern const VMStateInfo vmstate_info_bitmap;
 .offset   = offsetof(_state, _field),\
 }
 
+/* For QTAILQ that need customized handling
+ * _type: type of QTAILQ element
+ * _next: name of QTAILQ entry field in QTAILQ element
+ * _vmsd: VMSD for QTAILQ element
+ * size: size of QTAILQ element
+ * start: offset of QTAILQ entry in QTAILQ element
+ */
+#define VMSTATE_QTAILQ_V(_field, _state, _version, _vmsd, _type, _next)  \
+{\
+.name = (stringify(_field)), \
+.version_id   = (_version),  \
+.vmsd = &(_vmsd),\
+.size = sizeof(_type),   \
+.info = &vmstate_info_qtailq,\
+.flags= VMS_LINKED,  \
+.offset   = offsetof(_state, _field),\
+.start= offsetof(_type, _next),  \
+}
+
 /* _f : field name
_f_n : num of elements field_name
_n : num of elements
diff --git a/include/qemu/queue.h b/include/qemu/queue.h
index f781aa2..003e368 100644
--- a/include/qemu/queue.h
+++ b/include/qemu/queue.h
@@ -437,3 +437,35 @@ struct {   
 \
 (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
 
 #endif  /* !QEMU_SYS_QUEUE_H_ */
+
+/*
+ * Offsets of layout of a tail queue head.
+ */
+#define QTAILQ_FIRST_OFFSET 0
+#define QTAILQ_LAST_OFFSET (sizeof(void *))
+
+/*
+ * Offsets of layout of a tail queue element.
+ */
+#define QTAILQ_NEXT_OFFSET 0
+#define QTAILQ_PREV_OFFSET (sizeof(void *))
+
+/*
+ * Tail queue tranversal using pointer arithmetic.
+ */
+#define QTAILQ_RAW_FOREACH(elm, head, entry)   
\
+for ((elm) = *((void **) ((char *) (head) + QTAILQ_FIRST_OFFSET)); 
\
+ (elm);
\
+ (elm) =   
\
+ *((void **) ((char *) (elm) + (entry) + QTAILQ_NEXT_OFFSET)))
+/*
+ * Tail queue insertion using pointer arithmetic.
+ */
+#define QTAILQ_RAW_INSERT_TAIL(head, elm, entry) do {  
\
+*((void **) ((char *) (elm) + (entry) + QTAILQ_NEXT_OFFSET)) = NULL;   
\
+*((void **) ((char *) (elm) + (entry) + QTAILQ_PREV_OFFSET)) = 
\
+*((void **) ((char *) (head) +QTAILQ_LAST_OFFSET));
\
+**((void ***)((char *) (head) +QTAILQ_LAST_OFFSET)) = (elm);   

[Qemu-devel] [QEMU RFC PATCH v4 1/6] migration: alternative way to set instance_id in SaveStateEntry

2016-06-08 Thread Jianjun Duan
In QOM(QEMU Object Model) migrated objects are identified with instance_id
which is calculated automatically using their path in the QOM composition
tree. For some objects, this path could change from source to target in
migration. To migrate such objects, we need to make sure the instance_id does
not change from source to target. We add a hook in DeviceClass to do customized
instance_id calculation in such cases.

As a result, in these cases compat will not be set in the concerned
SaveStateEntry. This will prevent the inconsistent idstr to be sent over in
migration. We could have set alias_id in a similar way. But that will be
overloading the purpose of alias_id.

The first application will be setting instance_id for DRC using its unique
index. Doing this makes the instance_id of DRC to be consistent across migration
and supports flexible management of DRC objects in migration.

Signed-off-by: Jianjun Duan 
---
 include/hw/qdev-core.h |  6 ++
 migration/savevm.c | 20 ++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 1ce02b2..28173a7 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -139,6 +139,12 @@ typedef struct DeviceClass {
 qdev_initfn init; /* TODO remove, once users are converted to realize */
 qdev_event exit; /* TODO remove, once users are converted to unrealize */
 const char *bus_type;
+
+/* When this field is set, qemu will use it to get an unique instance_id
+ * instead of calculating an auto idstr and instanc_id for the relevant
+ * SaveStateEntry
+ */
+int (*dev_get_instance_id)(DeviceState *dev);
 } DeviceClass;
 
 typedef struct NamedGPIOList NamedGPIOList;
diff --git a/migration/savevm.c b/migration/savevm.c
index 6c21231..f7e7c68 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -494,6 +494,11 @@ int register_savevm_live(DeviceState *dev,
  void *opaque)
 {
 SaveStateEntry *se;
+/* when it is a device and it provides a way to get instance_id,
+ * we will use it and skip setting idstr and compat.
+ */
+bool flag = (dev != NULL) &&
+(DEVICE_GET_CLASS(dev)->dev_get_instance_id != NULL);
 
 se = g_new0(SaveStateEntry, 1);
 se->version_id = version_id;
@@ -506,7 +511,7 @@ int register_savevm_live(DeviceState *dev,
 se->is_ram = 1;
 }
 
-if (dev) {
+if (dev && !flag) {
 char *id = qdev_get_dev_path(dev);
 if (id) {
 pstrcpy(se->idstr, sizeof(se->idstr), id);
@@ -522,6 +527,9 @@ int register_savevm_live(DeviceState *dev,
 }
 pstrcat(se->idstr, sizeof(se->idstr), idstr);
 
+if (flag) {
+instance_id = DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev);
+}
 if (instance_id == -1) {
 se->instance_id = calculate_new_instance_id(se->idstr);
 } else {
@@ -579,6 +587,11 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
instance_id,
int required_for_version)
 {
 SaveStateEntry *se;
+/* when it is a device and it provides a way to get instance_id,
+ * we will use it and skip setting idstr and compat.
+ */
+bool flag = (dev != NULL) &&
+(DEVICE_GET_CLASS(dev)->dev_get_instance_id != NULL);
 
 /* If this triggers, alias support can be dropped for the vmsd. */
 assert(alias_id == -1 || required_for_version >= vmsd->minimum_version_id);
@@ -590,7 +603,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
instance_id,
 se->vmsd = vmsd;
 se->alias_id = alias_id;
 
-if (dev) {
+if (dev && !flag) {
 char *id = qdev_get_dev_path(dev);
 if (id) {
 pstrcpy(se->idstr, sizeof(se->idstr), id);
@@ -606,6 +619,9 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
instance_id,
 }
 pstrcat(se->idstr, sizeof(se->idstr), vmsd->name);
 
+if (flag) {
+instance_id = DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev);
+}
 if (instance_id == -1) {
 se->instance_id = calculate_new_instance_id(se->idstr);
 } else {
-- 
1.9.1




[Qemu-devel] [QEMU RFC PATCH v4 0/6] migration: ensure hotplug and migration work together

2016-06-08 Thread Jianjun Duan
v4: - Introduce a way to set customized instance_id in SaveStateEntry. Use it
  to set instance_id for DRC using its unique index to address David 
  Gibson's concern.
- Rename VMS_CSTM to VMS_LINKED based on Paolo Bonzini's suggestions.
- Clean up qjson stuff in put_qtailq. 
- Add trace for put_qtailq and get_qtailq based on David Gilbert's 
  suggestion.

It is based on David's ppc-for-2.7. Comments are welcome. Previous versions are:

v3: - Simplify overall design followng discussion with Paolo. No longer need
  metadata to migrate QTAILQ.
- Extend VMStateInfo instead of adding similar fields to VMStateField.
- Clean up macros in qemu/queue.h.
(link: https://lists.nongnu.org/archive/html/qemu-devel/2016-05/msg05695.html)

v2: - Introduce a general approach to migrate QTAILQ in qemu/queue.h.
- Migrate signalled field in the DRC state.
- Put the newly added migrating fields in subsections so that backward 
  migration is not broken.  
- Set detach_cb field right after migration so that a migrated hot-unplug
  event could finish its course.
(link: https://lists.nongnu.org/archive/html/qemu-devel/2016-05/msg04188.html)

v1: - Inital version.
(link: https://lists.nongnu.org/archive/html/qemu-devel/2016-04/msg02601.html)

To make guest device (PCI, CPU and memory) hotplug work together 
with guest migration, spapr drc state needs be transmitted in
migration. This patch defines the VMStateDescription struct for
spapr drc state to enable it.

To fix the potential racing between hotplug events on guest and 
guest migration, ccs_list and pending_events of spapr state need be 
transmitted in migration. This patch also takes care of it.

Jianjun Duan (6):
  migration: alternative way to set instance_id in SaveStateEntry
  migration: defined VMStateDescription struct for spapr_drc
  migration: extend VMStateInfo
  migration: migrate QTAILQ
  migration: migrate ccs_list in spapr state
  migration: migrate pending_events of spapr state

 hw/net/vmxnet3.c|  18 +++--
 hw/nvram/eeprom93xx.c   |   6 +-
 hw/nvram/fw_cfg.c   |   6 +-
 hw/pci/msix.c   |   6 +-
 hw/pci/pci.c|  12 ++--
 hw/pci/shpc.c   |   5 +-
 hw/ppc/spapr.c  |  67 ++
 hw/ppc/spapr_drc.c  |  69 +++
 hw/ppc/spapr_events.c   |  22 +++---
 hw/ppc/spapr_pci.c  |  22 ++
 hw/scsi/scsi-bus.c  |   6 +-
 hw/timer/twl92230.c |   6 +-
 hw/usb/redirect.c   |  18 +++--
 hw/virtio/virtio-pci.c  |   6 +-
 hw/virtio/virtio.c  |   6 +-
 include/hw/ppc/spapr.h  |   3 +-
 include/hw/ppc/spapr_drc.h  |   9 +++
 include/hw/qdev-core.h  |   6 ++
 include/migration/vmstate.h |  36 --
 include/qemu/queue.h|  32 +
 migration/savevm.c  |  25 +--
 migration/vmstate.c | 161 ++--
 target-alpha/machine.c  |   5 +-
 target-arm/machine.c|  12 ++--
 target-i386/machine.c   |  21 --
 target-mips/machine.c   |  10 +--
 target-ppc/machine.c|  10 +--
 target-sparc/machine.c  |   5 +-
 trace-events|   4 ++
 29 files changed, 505 insertions(+), 109 deletions(-)

-- 
1.9.1




[Qemu-devel] [QEMU RFC PATCH v4 3/6] migration: extend VMStateInfo

2016-06-08 Thread Jianjun Duan
Current migration code cannot handle some data structures such as
QTAILQ in qemu/queue.h. Here we extend the signatures of put/get
in VMStateInfo so that customized handling is supported.

Signed-off-by: Jianjun Duan 
---
 hw/net/vmxnet3.c| 18 ++---
 hw/nvram/eeprom93xx.c   |  6 ++-
 hw/nvram/fw_cfg.c   |  6 ++-
 hw/pci/msix.c   |  6 ++-
 hw/pci/pci.c| 12 --
 hw/pci/shpc.c   |  5 ++-
 hw/scsi/scsi-bus.c  |  6 ++-
 hw/timer/twl92230.c |  6 ++-
 hw/usb/redirect.c   | 18 ++---
 hw/virtio/virtio-pci.c  |  6 ++-
 hw/virtio/virtio.c  |  6 ++-
 include/migration/vmstate.h | 10 +++--
 migration/savevm.c  |  5 ++-
 migration/vmstate.c | 95 -
 target-alpha/machine.c  |  5 ++-
 target-arm/machine.c| 12 --
 target-i386/machine.c   | 21 ++
 target-mips/machine.c   | 10 +++--
 target-ppc/machine.c| 10 +++--
 target-sparc/machine.c  |  5 ++-
 20 files changed, 171 insertions(+), 97 deletions(-)

diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 16645e6..7ddec0b 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2445,7 +2445,8 @@ static void vmxnet3_put_tx_stats_to_file(QEMUFile *f,
 qemu_put_be64(f, tx_stat->pktsTxDiscard);
 }
 
-static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size)
+static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size,
+VMStateField *field)
 {
 Vmxnet3TxqDescr *r = pv;
 
@@ -2459,7 +2460,8 @@ static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, 
size_t size)
 return 0;
 }
 
-static void vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size)
+static void vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size,
+VMStateField *field, QJSON *vmdesc)
 {
 Vmxnet3TxqDescr *r = pv;
 
@@ -2506,7 +2508,8 @@ static void vmxnet3_put_rx_stats_to_file(QEMUFile *f,
 qemu_put_be64(f, rx_stat->pktsRxError);
 }
 
-static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, size_t size)
+static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, size_t size,
+VMStateField *field)
 {
 Vmxnet3RxqDescr *r = pv;
 int i;
@@ -2524,7 +2527,8 @@ static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, 
size_t size)
 return 0;
 }
 
-static void vmxnet3_put_rxq_descr(QEMUFile *f, void *pv, size_t size)
+static void vmxnet3_put_rxq_descr(QEMUFile *f, void *pv, size_t size,
+VMStateField *field, QJSON *vmdesc)
 {
 Vmxnet3RxqDescr *r = pv;
 int i;
@@ -2569,7 +2573,8 @@ static const VMStateInfo rxq_descr_info = {
 .put = vmxnet3_put_rxq_descr
 };
 
-static int vmxnet3_get_int_state(QEMUFile *f, void *pv, size_t size)
+static int vmxnet3_get_int_state(QEMUFile *f, void *pv, size_t size,
+VMStateField *field)
 {
 Vmxnet3IntState *r = pv;
 
@@ -2580,7 +2585,8 @@ static int vmxnet3_get_int_state(QEMUFile *f, void *pv, 
size_t size)
 return 0;
 }
 
-static void vmxnet3_put_int_state(QEMUFile *f, void *pv, size_t size)
+static void vmxnet3_put_int_state(QEMUFile *f, void *pv, size_t size,
+VMStateField *field, QJSON *vmdesc)
 {
 Vmxnet3IntState *r = pv;
 
diff --git a/hw/nvram/eeprom93xx.c b/hw/nvram/eeprom93xx.c
index 2c16fc2..76d5f41 100644
--- a/hw/nvram/eeprom93xx.c
+++ b/hw/nvram/eeprom93xx.c
@@ -94,14 +94,16 @@ struct _eeprom_t {
This is a Big hack, but it is how the old state did it.
  */
 
-static int get_uint16_from_uint8(QEMUFile *f, void *pv, size_t size)
+static int get_uint16_from_uint8(QEMUFile *f, void *pv, size_t size,
+ VMStateField *field)
 {
 uint16_t *v = pv;
 *v = qemu_get_ubyte(f);
 return 0;
 }
 
-static void put_unused(QEMUFile *f, void *pv, size_t size)
+static void put_unused(QEMUFile *f, void *pv, size_t size, VMStateField *field,
+   QJSON *vmdesc)
 {
 fprintf(stderr, "uint16_from_uint8 is used only for backwards 
compatibility.\n");
 fprintf(stderr, "Never should be used to write a new state.\n");
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index cdbdfb5..c294f9a 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -524,14 +524,16 @@ static void fw_cfg_reset(DeviceState *d)
Or we broke compatibility in the state, or we can't use struct tm
  */
 
-static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size)
+static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size,
+VMStateField *field)
 {
 uint32_t *v = pv;
 *v = qemu_get_be16(f);
 return 0;
 }
 
-static void put_unused(QEMUFile *f, void *pv, size_t size)
+static void put_unused(QEMUFile *f, void *pv, size_t size, VMStateField *field,
+   QJSON *vmdesc)
 {
 fprintf(stderr, "uint32_as_uint16 is only used for backward 
compatibility.\n");
 fprintf(stderr, "This functions shouldn't be called.\n");
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index 0ec1cb1..69e7

[Qemu-devel] [QEMU RFC PATCH v4 2/6] migration: defined VMStateDescription struct for spapr_drc

2016-06-08 Thread Jianjun Duan
To manage hotplug/unplug of dynamic resources such as PCI cards,
memory, and CPU on sPAPR guests, a firmware abstraction known as
a Dynamic Resource Connector (DRC) is used to assign a particular
dynamic resource to the guest, and provide an interface for the
guest to manage configuration/removal of the resource associated
with it.

To migrate the hotplugged resources in migration, the
associated DRC state need be migrated. To migrate the DRC state,
we defined the VMStateDescription struct for spapr_drc to enable
the transmission of spapr_drc state in migration.

Not all the elements in the DRC state are migrated. Only those
ones modifiable or needed by guest actions or device add/remove
operation are migrated. From the perspective of device
hotplugging, if we hotplug a device on the source, we need to
"coldplug" it on the target. The states across two hosts for the
same device are not the same. Ideally we want the states be same
after migration so that the device would function as hotplugged
on the target. For example we can unplug it. The minimum DRC
state we need to transfer should cover all the pieces changed by
hotplugging. Out of the elements of the DRC state, isolation_state,
allocation_sate, and configured are involved in the DR state
transition diagram from PAPR+ 2.7, 13.4. configured and signalled
are needed in attaching and detaching devices. indicator_state
provides users with hardware state information. These 6 elements
are migrated.

detach_cb in the DRC state is a function pointer that cannot be
migrated. We set it right after DRC state is migrated so that
a migrated hot-unplug event could finish its work.

The instance_id is used to identify objects in migration. We set
instance_id of DRC using the unique index so that it is the same
across migration.

Signed-off-by: Jianjun Duan 
---
 hw/ppc/spapr_drc.c | 69 ++
 hw/ppc/spapr_pci.c | 22 +++
 include/hw/ppc/spapr_drc.h |  9 ++
 3 files changed, 100 insertions(+)

diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 94c875d..7e6161d 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -617,6 +617,71 @@ static void spapr_dr_connector_instance_init(Object *obj)
 NULL, NULL, NULL, NULL);
 }
 
+static bool spapr_drc_needed(void *opaque)
+{
+sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;
+sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
+bool rc = false;
+sPAPRDREntitySense value;
+
+drck->entity_sense(drc, &value);
+/* If no dev is plugged in there is no need to migrate the DRC state */
+if (value != SPAPR_DR_ENTITY_SENSE_PRESENT) {
+return false;
+}
+/*
+ * If there is dev plugged in, we need to migrate the DRC state when
+ * it is different from cold-plugged state
+ */
+switch(drc->type) {
+/* for PCI type */
+case SPAPR_DR_CONNECTOR_TYPE_PCI:
+rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) &&
+   (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) &&
+   drc->configured && drc->signalled && !drc->awaiting_release);
+break;
+/* for LMB type */
+case SPAPR_DR_CONNECTOR_TYPE_LMB:
+rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) &&
+   (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) &&
+   drc->configured && drc->signalled && !drc->awaiting_release);
+break;
+default:
+;
+}
+
+return rc;
+}
+
+/* detach_cb needs be set since it is not migrated */
+static void postmigrate_set_detach_cb(sPAPRDRConnector *drc,
+  spapr_drc_detach_cb *detach_cb)
+{
+drc->detach_cb = detach_cb;
+}
+
+/* return the unique drc index as instance_id for qom interfaces*/
+static int get_instance_id(DeviceState *dev)
+{
+return (int)get_index(SPAPR_DR_CONNECTOR(OBJECT(dev)));
+}
+
+static const VMStateDescription vmstate_spapr_drc = {
+.name = "spapr_drc",
+.version_id = 1,
+.minimum_version_id = 1,
+.needed = spapr_drc_needed,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32(isolation_state, sPAPRDRConnector),
+VMSTATE_UINT32(allocation_state, sPAPRDRConnector),
+VMSTATE_UINT32(indicator_state, sPAPRDRConnector),
+VMSTATE_BOOL(configured, sPAPRDRConnector),
+VMSTATE_BOOL(awaiting_release, sPAPRDRConnector),
+VMSTATE_BOOL(signalled, sPAPRDRConnector),
+VMSTATE_END_OF_LIST()
+}
+};
+
 static void spapr_dr_connector_class_init(ObjectClass *k, void *data)
 {
 DeviceClass *dk = DEVICE_CLASS(k);
@@ -625,6 +690,8 @@ static void spapr_dr_connector_class_init(ObjectClass *k, 
void *data)
 dk->reset = reset;
 dk->realize = realize;
 dk->unrealize = unrealize;
+dk->vmsd = &vmstate_spapr_drc;
+dk->dev_get_instance_id = get_instance_id;
 drck->set_isolation_state = set_iso

[Qemu-devel] [PATCH] gtk: fix vte version check

2016-06-08 Thread Olaf Hering
vte_terminal_set_encoding takes 3 args since 0.38.0.
This fixes commit fba958c6 ("gtk: implement set_echo")

Signed-off-by: Olaf Hering 
---
 ui/gtk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 01b8216..58d20ee 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1748,7 +1748,7 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, 
VirtualConsole *vc,
 /* The documentation says that the default is UTF-8, but actually it is
  * 7-bit ASCII at least in VTE 0.38.
  */
-#if VTE_CHECK_VERSION(0, 40, 0)
+#if VTE_CHECK_VERSION(0, 38, 0)
 vte_terminal_set_encoding(VTE_TERMINAL(vc->vte.terminal), "UTF-8", NULL);
 #else
 vte_terminal_set_encoding(VTE_TERMINAL(vc->vte.terminal), "UTF-8");



Re: [Qemu-devel] [PATCH v7 13/15] qht: add test-qht-par to invoke qht-bench from 'check' target

2016-06-08 Thread Sergey Fedorov
On 08/06/16 21:55, Emilio G. Cota wrote:
> Signed-off-by: Emilio G. Cota 

Acked-by: Sergey Fedorov 

> ---
>  tests/.gitignore |  1 +
>  tests/Makefile   |  5 -
>  tests/test-qht-par.c | 56 
> 
>  3 files changed, 61 insertions(+), 1 deletion(-)
>  create mode 100644 tests/test-qht-par.c
>
> diff --git a/tests/.gitignore b/tests/.gitignore
> index d19023e..840ea39 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -52,6 +52,7 @@ test-qemu-opts
>  test-qdist
>  test-qga
>  test-qht
> +test-qht-par
>  test-qmp-commands
>  test-qmp-commands.h
>  test-qmp-event
> diff --git a/tests/Makefile b/tests/Makefile
> index 7b00301..7d63d16 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -74,6 +74,8 @@ check-unit-y += tests/test-qdist$(EXESUF)
>  gcov-files-test-qdist-y = util/qdist.c
>  check-unit-y += tests/test-qht$(EXESUF)
>  gcov-files-test-qht-y = util/qht.c
> +check-unit-y += tests/test-qht-par$(EXESUF)
> +gcov-files-test-qht-par-y = util/qht.c
>  check-unit-y += tests/test-bitops$(EXESUF)
>  check-unit-$(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) += 
> tests/test-qdev-global-props$(EXESUF)
>  check-unit-y += tests/check-qom-interface$(EXESUF)
> @@ -400,7 +402,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
> tests/check-qdict.o \
>   tests/test-opts-visitor.o tests/test-qmp-event.o \
>   tests/rcutorture.o tests/test-rcu-list.o \
>   tests/test-qdist.o \
> - tests/test-qht.o tests/qht-bench.o
> + tests/test-qht.o tests/qht-bench.o tests/test-qht-par.o
>  
>  $(test-obj-y): QEMU_INCLUDES += -Itests
>  QEMU_CFLAGS += -I$(SRC_PATH)/tests
> @@ -441,6 +443,7 @@ tests/rcutorture$(EXESUF): tests/rcutorture.o 
> $(test-util-obj-y)
>  tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y)
>  tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y)
>  tests/test-qht$(EXESUF): tests/test-qht.o $(test-util-obj-y)
> +tests/test-qht-par$(EXESUF): tests/test-qht-par.o tests/qht-bench$(EXESUF) 
> $(test-util-obj-y)
>  tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y)
>  
>  tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
> diff --git a/tests/test-qht-par.c b/tests/test-qht-par.c
> new file mode 100644
> index 000..f09e004
> --- /dev/null
> +++ b/tests/test-qht-par.c
> @@ -0,0 +1,56 @@
> +/*
> + * Copyright (C) 2016, Emilio G. Cota 
> + *
> + * License: GNU GPL, version 2 or later.
> + *   See the COPYING file in the top-level directory.
> + */
> +#include "qemu/osdep.h"
> +#include 
> +
> +#define TEST_QHT_STRING "tests/qht-bench 1>/dev/null 2>&1 -R -S0.1 -D1 
> -N1 "
> +
> +static void test_qht(int n_threads, int update_rate, int duration)
> +{
> +char *str;
> +int rc;
> +
> +str = g_strdup_printf(TEST_QHT_STRING "-n %d -u %d -d %d",
> +  n_threads, update_rate, duration);
> +rc = system(str);
> +g_free(str);
> +g_assert_cmpint(rc, ==, 0);
> +}
> +
> +static void test_2th0u1s(void)
> +{
> +test_qht(2, 0, 1);
> +}
> +
> +static void test_2th20u1s(void)
> +{
> +test_qht(2, 20, 1);
> +}
> +
> +static void test_2th0u5s(void)
> +{
> +test_qht(2, 0, 5);
> +}
> +
> +static void test_2th20u5s(void)
> +{
> +test_qht(2, 20, 5);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +g_test_init(&argc, &argv, NULL);
> +
> +if (g_test_quick()) {
> +g_test_add_func("/qht/parallel/2threads-0%updates-1s", test_2th0u1s);
> +g_test_add_func("/qht/parallel/2threads-20%updates-1s", 
> test_2th20u1s);
> +} else {
> +g_test_add_func("/qht/parallel/2threads-0%updates-5s", test_2th0u5s);
> +g_test_add_func("/qht/parallel/2threads-20%updates-5s", 
> test_2th20u5s);
> +}
> +return g_test_run();
> +}




Re: [Qemu-devel] [PATCH v7 12/15] qht: add qht-bench, a performance benchmark

2016-06-08 Thread Sergey Fedorov
On 08/06/16 21:55, Emilio G. Cota wrote:
> This serves as a performance benchmark as well as a stress test
> for QHT. We can tweak quite a number of things, including the
> number of resize threads and how frequently resizes are triggered.
>
> A performance comparison of QHT vs CLHT[1] and ck_hs[2] using
> this same benchmark program can be found here:
>   http://imgur.com/a/0Bms4
>
> The tests are run on a 64-core AMD Opteron 6376, pinning threads
> to cores favoring same-socket cores. For each run, qht-bench is
> invoked with:
>   $ tests/qht-bench -d $duration -n $n -u $u -g $range
> , where $duration is in seconds, $n is the number of threads,
> $u is the update rate (0.0 to 100.0), and $range is the number
> of keys.
>
> Note that ck_hs's performance drops significantly as writes go
> up, since it requires an external lock (I used a ck_spinlock)
> around every write.
>
> Also, note that CLHT instead of using a seqlock, relies on an
> allocator that does not ever return the same address during the
> same read-critical section. This gives it a slight performance
> advantage over QHT on read-heavy workloads, since the seqlock
> writes aren't there.
>
> [1] CLHT: https://github.com/LPD-EPFL/CLHT
>   https://infoscience.epfl.ch/record/207109/files/ascy_asplos15.pdf
>
> [2] ck_hs: http://concurrencykit.org/
>http://backtrace.io/blog/blog/2015/03/13/workload-specialization/
>
> A few of those plots are shown in text here, since that site
> might not be online forever. Throughput is on Mops/s on the Y axis.
>
>  200K keys, 0 % updates
>
>   450 ++--+--+--+---+---+---+---+--+---+--++
>   |   +  +  +   +   +   +   +  +  +N+  |
>   400 ++   ---+E+ ++
>   |   +++  |
>   350 ++  9 ++--+--++   --+E+-+H+ ++
>   | |  +H+- | -+N+    +++  |
>   300 ++  8 ++ +E+ ++ -+E+  --+H+ ++
>   | |  +++  | -+N+-+H+--   |
>   250 ++  7 ++--+--++  +++-+E+++
>   200 ++1 -+E+-+H+++
>   |    qht +-E--+  |
>   150 ++  -+E+clht +-H--+ ++
>   |     ck +-N--+  |
>   100 ++   +E+++
>   ||
>50 ++   -+E+   ++
>   |   +E+E+  +  +   +   +   +   +  +   +   |
> 0 ++--E--+--+---+---+---+---+--+---+--++
>   1  8  16  24  32  40  48 56  64
> Number of threads
>
>  200K keys, 1 % updates
>
>   350 ++--+--+--+---+---+---+---+--+---+--++
>   |   +  +  +   +   +   +   +  + -+E+  |
>   300 ++ -+H+ ++
>   |   +E+--|
>   |   9 ++--+--++  +++ |
>   250 ++|  +E+   -- | -+E+++
>   |   8 ++ --  ++  |
>   200 ++|  +++- |  +++  ---+E+++
>   |   7 ++--N--++ -+E+--   qht +-E--+  |
>   | 1  +++clht +-H--+  |
>   150 ++  -+E+  ck +-N--+ ++
>   |    |
>   100 ++   +E+++
>   ||
>   |-+E+|
>50 +++H+-+N++N+-+N+--  ++
>   |   +E+E+  +  +   +  +N+-+N+-+N++N+-+N+  |
> 0 ++--E--+--+---+---+---+---+--+---+--++
>   1  8  16  24  32  40  48 56  64
> Number of threads
>
>  200K keys, 20 % updates
>
>   300 ++--+--+--+---+---+---+---+--+---+--++
>   |   +  +  +   +   +   +   +  +   +   |
>   |   

Re: [Qemu-devel] [PATCH v7 10/15] qht: QEMU's fast, resizable and scalable Hash Table

2016-06-08 Thread Sergey Fedorov
On 08/06/16 21:55, Emilio G. Cota wrote:
> This is a fast, scalable chained hash table with optional auto-resizing, 
> allowing
> reads that are concurrent with reads, and reads/writes that are concurrent
> with writes to separate buckets.
>
> A hash table with these features will be necessary for the scalability
> of the ongoing MTTCG work; before those changes arrive we can already
> benefit from the single-threaded speedup that qht also provides.
>
> Signed-off-by: Emilio G. Cota 

Reviewed-by: Sergey Fedorov 

> ---
>  include/qemu/qht.h | 183 
>  util/Makefile.objs |   1 +
>  util/qht.c | 833 
> +
>  3 files changed, 1017 insertions(+)
>  create mode 100644 include/qemu/qht.h
>  create mode 100644 util/qht.c
>
> diff --git a/include/qemu/qht.h b/include/qemu/qht.h
> new file mode 100644
> index 000..aec60aa
> --- /dev/null
> +++ b/include/qemu/qht.h
> @@ -0,0 +1,183 @@
> +/*
> + * Copyright (C) 2016, Emilio G. Cota 
> + *
> + * License: GNU GPL, version 2 or later.
> + *   See the COPYING file in the top-level directory.
> + */
> +#ifndef QEMU_QHT_H
> +#define QEMU_QHT_H
> +
> +#include "qemu/osdep.h"
> +#include "qemu/seqlock.h"
> +#include "qemu/thread.h"
> +#include "qemu/qdist.h"
> +
> +struct qht {
> +struct qht_map *map;
> +QemuMutex lock; /* serializes setters of ht->map */
> +unsigned int mode;
> +};
> +
> +/**
> + * struct qht_stats - Statistics of a QHT
> + * @head_buckets: number of head buckets
> + * @used_head_buckets: number of non-empty head buckets
> + * @entries: total number of entries
> + * @chain: frequency distribution representing the number of buckets in each
> + * chain, excluding empty chains.
> + * @occupancy: frequency distribution representing chain occupancy rate.
> + * Valid range: from 0.0 (empty) to 1.0 (full occupancy).
> + *
> + * An entry is a pointer-hash pair.
> + * Each bucket can host several entries.
> + * Chains are chains of buckets, whose first link is always a head bucket.
> + */
> +struct qht_stats {
> +size_t head_buckets;
> +size_t used_head_buckets;
> +size_t entries;
> +struct qdist chain;
> +struct qdist occupancy;
> +};
> +
> +typedef bool (*qht_lookup_func_t)(const void *obj, const void *userp);
> +typedef void (*qht_iter_func_t)(struct qht *ht, void *p, uint32_t h, void 
> *up);
> +
> +#define QHT_MODE_AUTO_RESIZE 0x1 /* auto-resize when heavily loaded */
> +
> +/**
> + * qht_init - Initialize a QHT
> + * @ht: QHT to be initialized
> + * @n_elems: number of entries the hash table should be optimized for.
> + * @mode: bitmask with OR'ed QHT_MODE_*
> + */
> +void qht_init(struct qht *ht, size_t n_elems, unsigned int mode);
> +
> +/**
> + * qht_destroy - destroy a previously initialized QHT
> + * @ht: QHT to be destroyed
> + *
> + * Call only when there are no readers/writers left.
> + */
> +void qht_destroy(struct qht *ht);
> +
> +/**
> + * qht_insert - Insert a pointer into the hash table
> + * @ht: QHT to insert to
> + * @p: pointer to be inserted
> + * @hash: hash corresponding to @p
> + *
> + * Attempting to insert a NULL @p is a bug.
> + * Inserting the same pointer @p with different @hash values is a bug.
> + *
> + * Returns true on sucess.
> + * Returns false if the @p-@hash pair already exists in the hash table.
> + */
> +bool qht_insert(struct qht *ht, void *p, uint32_t hash);
> +
> +/**
> + * qht_lookup - Look up a pointer in a QHT
> + * @ht: QHT to be looked up
> + * @func: function to compare existing pointers against @userp
> + * @userp: pointer to pass to @func
> + * @hash: hash of the pointer to be looked up
> + *
> + * Needs to be called under an RCU read-critical section.
> + *
> + * The user-provided @func compares pointers in QHT against @userp.
> + * If the function returns true, a match has been found.
> + *
> + * Returns the corresponding pointer when a match is found.
> + * Returns NULL otherwise.
> + */
> +void *qht_lookup(struct qht *ht, qht_lookup_func_t func, const void *userp,
> + uint32_t hash);
> +
> +/**
> + * qht_remove - remove a pointer from the hash table
> + * @ht: QHT to remove from
> + * @p: pointer to be removed
> + * @hash: hash corresponding to @p
> + *
> + * Attempting to remove a NULL @p is a bug.
> + *
> + * Just-removed @p pointers cannot be immediately freed; they need to remain
> + * valid until the end of the RCU grace period in which qht_remove() is 
> called.
> + * This guarantees that concurrent lookups will always compare against valid
> + * data.
> + *
> + * Returns true on success.
> + * Returns false if the @p-@hash pair was not found.
> + */
> +bool qht_remove(struct qht *ht, const void *p, uint32_t hash);
> +
> +/**
> + * qht_reset - reset a QHT
> + * @ht: QHT to be reset
> + *
> + * All entries in the hash table are reset. No resizing is performed.
> + *
> + * If concurrent readers may exist, the objects pointed to by the hash table
> + * must remain va

Re: [Qemu-devel] [PATCH v4 4/9] target-avr: adding instructions encodings

2016-06-08 Thread Michael Rolnik
I can send the sources, of my generator if you want.
However I have not time to make it a part of AVR patch right now.
let's finish with AVR cores and then when I have time I will be happy to
QEMUify the generator.

On Tue, Jun 7, 2016 at 1:06 AM, Peter Maydell 
wrote:

> On 6 June 2016 at 22:38, Richard Henderson  wrote:
> > On 06/06/2016 03:37 AM, Michael Rolnik wrote:
> >>
> >> Signed-off-by: Michael Rolnik 
> >> ---
> >>  target-avr/translate-inst.h | 730
> >> 
> >>  1 file changed, 730 insertions(+)
> >>  create mode 100644 target-avr/translate-inst.h
> >
> >
> > Reviewed-by: Richard Henderson 
> >
> > Although of course it would be better to have the generator
> > and source instead of the generated code.
>
> Yes, definitely. (Especially since the GPL wants the 'preferred form
> of the work for making modifications'...)
>
> thanks
> -- PMM
>



-- 
Best Regards,
Michael Rolnik


[Qemu-devel] [PATCH v5 10/10] target-avr: saving sreg, rampD, rampX, rampY, rampD, eind in HW representation saving cpu features

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/machine.c | 105 ---
 1 file changed, 84 insertions(+), 21 deletions(-)

diff --git a/target-avr/machine.c b/target-avr/machine.c
index 39f1ee6..9659c04 100644
--- a/target-avr/machine.c
+++ b/target-avr/machine.c
@@ -23,31 +23,94 @@
 #include "cpu.h"
 #include "hw/boards.h"
 #include "machine.h"
+#include "migration/qemu-file.h"
+
+static int get_sreg(QEMUFile *f, void *opaque, size_t size)
+{
+CPUAVRState* env = opaque;
+uint8_t sreg;
+
+qemu_get_8s(f, &sreg);
+cpu_set_sreg(env, sreg);
+return 0;
+}
+
+static void put_sreg(QEMUFile *f, void *opaque, size_t size)
+{
+CPUAVRState* env = opaque;
+uint8_t sreg = cpu_get_sreg(env);
+
+qemu_put_8s(f, &sreg);
+}
+
+static const VMStateInfo vmstate_sreg = {
+.name = "sreg",
+.get  = get_sreg,
+.put  = put_sreg,
+};
+
+static int get_segment(QEMUFile *f, void *opaque, size_t size)
+{
+uint32_t *ramp = opaque;
+uint8_t temp = *ramp >> 16;
+
+qemu_get_8s(f, &temp);
+return 0;
+}
+
+static void put_segment(QEMUFile *f, void *opaque, size_t size)
+{
+uint32_t *ramp = opaque;
+uint8_t temp;
+
+qemu_put_8s(f, &temp);
+*ramp = ((uint32_t)temp) << 16;
+}
+
+static const VMStateInfo vmstate_rampD = {
+.name = "rampD",
+.get  = get_segment,
+.put  = put_segment,
+};
+static const VMStateInfo vmstate_rampX = {
+.name = "rampX",
+.get  = get_segment,
+.put  = put_segment,
+};
+static const VMStateInfo vmstate_rampY = {
+.name = "rampY",
+.get  = get_segment,
+.put  = put_segment,
+};
+static const VMStateInfo vmstate_rampZ = {
+.name = "rampZ",
+.get  = get_segment,
+.put  = put_segment,
+};
+static const VMStateInfo vmstate_eind = {
+.name = "eind",
+.get  = get_segment,
+.put  = put_segment,
+};
 
 const VMStateDescription vmstate_avr_cpu = {
 .name   = "cpu",
-.version_id = 1,
-.minimum_version_id = 1,
+.version_id = 0,
+.minimum_version_id = 0,
 .fields = (VMStateField[]) {
-VMSTATE_UINT32_ARRAY(r, CPUAVRState, 32),
-
-VMSTATE_UINT32(sregC, CPUAVRState),
-VMSTATE_UINT32(sregZ, CPUAVRState),
-VMSTATE_UINT32(sregN, CPUAVRState),
-VMSTATE_UINT32(sregV, CPUAVRState),
-VMSTATE_UINT32(sregS, CPUAVRState),
-VMSTATE_UINT32(sregH, CPUAVRState),
-VMSTATE_UINT32(sregT, CPUAVRState),
-VMSTATE_UINT32(sregI, CPUAVRState),
-
-VMSTATE_UINT32(rampD, CPUAVRState),
-VMSTATE_UINT32(rampX, CPUAVRState),
-VMSTATE_UINT32(rampY, CPUAVRState),
-VMSTATE_UINT32(rampZ, CPUAVRState),
-
-VMSTATE_UINT32(eind, CPUAVRState),
-VMSTATE_UINT32(sp, CPUAVRState),
-VMSTATE_UINT32(pc_w, CPUAVRState),
+VMSTATE_UINT32(env.features, AVRCPU),
+VMSTATE_UINT32(env.pc_w, AVRCPU),
+VMSTATE_UINT32(env.sp, AVRCPU),
+
+VMSTATE_UINT32_ARRAY(env.r, AVRCPU, 32),
+VMSTATE_UINT32_ARRAY(env.io, AVRCPU, 64),
+
+VMSTATE_SINGLE_TEST(env, AVRCPU, NULL, 0, vmstate_sreg, CPUAVRState),
+VMSTATE_SINGLE_TEST(env.rampD, AVRCPU, NULL, 0, vmstate_rampD, 
uint32_t),
+VMSTATE_SINGLE_TEST(env.rampX, AVRCPU, NULL, 0, vmstate_rampX, 
uint32_t),
+VMSTATE_SINGLE_TEST(env.rampY, AVRCPU, NULL, 0, vmstate_rampY, 
uint32_t),
+VMSTATE_SINGLE_TEST(env.rampZ, AVRCPU, NULL, 0, vmstate_rampZ, 
uint32_t),
+VMSTATE_SINGLE_TEST(env.eind, AVRCPU, NULL, 0, vmstate_eind, uint32_t),
 
 VMSTATE_END_OF_LIST()
 }
-- 
2.4.9 (Apple Git-60)




[Qemu-devel] [PATCH v5 09/10] target-avr: updating translate.c to use instructions translation

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/Makefile.objs |   4 +-
 target-avr/translate.c   | 148 +--
 2 files changed, 69 insertions(+), 83 deletions(-)

diff --git a/target-avr/Makefile.objs b/target-avr/Makefile.objs
index 2a10104..9757721 100644
--- a/target-avr/Makefile.objs
+++ b/target-avr/Makefile.objs
@@ -18,6 +18,8 @@
 #  
 #
 
-obj-y   += translate.o cpu.o helper.o
+obj-y   += translate.o helper.o cpu.o translate-inst.o
 obj-y   += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += machine.o
+
+obj-y   += decode.o
diff --git a/target-avr/translate.c b/target-avr/translate.c
index 81ee44e..28babc9 100644
--- a/target-avr/translate.c
+++ b/target-avr/translate.c
@@ -18,60 +18,30 @@
  *  
  */
 
-#include "qemu/osdep.h"
-
-#include "cpu.h"
-#include "exec/exec-all.h"
-#include "disas/disas.h"
-#include "tcg-op.h"
-#include "exec/cpu_ldst.h"
-
-#include "exec/helper-proto.h"
-#include "exec/helper-gen.h"
-#include "exec/log.h"
-
-typedef struct DisasContext DisasContext;
-typedef struct InstInfo InstInfo;
-
-/*This is the state at translation time.  */
-struct DisasContext {
-struct TranslationBlock*tb;
-
-/*Routine used to access memory */
-int memidx;
-int bstate;
-int singlestep;
-};
-
-enum {
-BS_NONE = 0,/*  Nothing special (none of the below  */
-BS_STOP = 1,/*  We want to stop translation for any reason  */
-BS_BRANCH = 2,/*  A branch condition is reached   */
-BS_EXCP = 3,/*  An exception condition is reached   */
-};
-
-static TCGv_env cpu_env;
-
-static TCGv cpu_pc;
-
-static TCGv cpu_Cf;
-static TCGv cpu_Zf;
-static TCGv cpu_Nf;
-static TCGv cpu_Vf;
-static TCGv cpu_Sf;
-static TCGv cpu_Hf;
-static TCGv cpu_Tf;
-static TCGv cpu_If;
-
-static TCGv cpu_rampD;
-static TCGv cpu_rampX;
-static TCGv cpu_rampY;
-static TCGv cpu_rampZ;
-
-static TCGv cpu_io[64];
-static TCGv cpu_r[32];
-static TCGv cpu_eind;
-static TCGv cpu_sp;
+#include "translate.h"
+
+TCGv_env cpu_env;
+
+TCGv cpu_pc;
+
+TCGv cpu_Cf;
+TCGv cpu_Zf;
+TCGv cpu_Nf;
+TCGv cpu_Vf;
+TCGv cpu_Sf;
+TCGv cpu_Hf;
+TCGv cpu_Tf;
+TCGv cpu_If;
+
+TCGv cpu_rampD;
+TCGv cpu_rampX;
+TCGv cpu_rampY;
+TCGv cpu_rampZ;
+
+TCGv cpu_io[64];
+TCGv cpu_r[32];
+TCGv cpu_eind;
+TCGv cpu_sp;
 
 #include "exec/gen-icount.h"
 #define REG(x)  (cpu_r[x])
@@ -120,25 +90,32 @@ void avr_translate_init(void)
 done_init = 1;
 }
 
-static inline void gen_goto_tb(CPUAVRState *env, DisasContext *ctx, int n,
-target_ulong dest)
+static void decode_opc(AVRCPU *cpu, DisasContext *ctx, InstInfo *inst)
 {
-TranslationBlock   *tb;
-
-tb = ctx->tb;
-
-if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)
-&&  (ctx->singlestep == 0)) {
-tcg_gen_goto_tb(n);
-tcg_gen_movi_i32(cpu_pc, dest);
-tcg_gen_exit_tb((uintptr_t)tb + n);
-} else {
-tcg_gen_movi_i32(cpu_pc, dest);
-
-if (ctx->singlestep) {
-gen_helper_debug(cpu_env);
-}
-tcg_gen_exit_tb(0);
+CPUAVRState*env = &cpu->env;
+
+inst->opcode = cpu_ldl_code(env, inst->cpc * 2);/*  pc points to words  */
+/*  target is defined as bigendian for push_ret/pop_ret
+optimization. but my decode assumes instruction to be in little
+endian format, hence bswap
+*/
+inst->opcode = bswap32(inst->opcode);
+inst->length = 16;
+inst->translate = NULL;
+
+/*  the following function looks onto the opcode as a string of bytes   */
+avr_decode(inst->cpc, &inst->length, inst->opcode, &inst->translate);
+
+if (inst->length == 16) {
+inst->npc = inst->cpc + 1;
+/*  get opcode as 16bit value   */
+inst->opcode = inst->opcode & 0x;
+}
+if (inst->length == 32) {
+inst->npc = inst->cpc + 2;
+/*  get opcode as 32bit value   */
+inst->opcode = (inst->opcode << 16)
+ | (inst->opcode >> 16);
 }
 }
 
@@ -172,18 +149,21 @@ void gen_intermediate_code(CPUAVRState *env, struct 
TranslationBlock *tb)
 gen_tb_start(tb);
 
 /*  decode first instruction*/
-cpc = pc_start;
-npc = cpc + 1;
+ctx.inst[0].cpc = pc_start;
+decode_opc(cpu, &ctx, &ctx.inst[0]);
 do {
-/*  translate current instruction   */
+/*  set curr/next PCs   */
+cpc = ctx.inst[0].cpc;
+npc = ctx.inst[0].npc;
+
+/*  decode next instruction */
+ctx.inst[1].cpc = ctx.inst[0].npc;
+decode_opc(cpu, &ctx, &ctx.inst[1]);
+
+/*  translate current instruction */
   

[Qemu-devel] [PATCH v5 05/10] target-avr: adding AVR interrupt handling

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/helper.c | 59 -
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/target-avr/helper.c b/target-avr/helper.c
index ad8f83e..f96fa27 100644
--- a/target-avr/helper.c
+++ b/target-avr/helper.c
@@ -31,11 +31,68 @@
 
 bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
 {
-return  false;
+CPUClass *cc = CPU_GET_CLASS(cs);
+AVRCPU *cpu = AVR_CPU(cs);
+CPUAVRState *env = &cpu->env;
+
+bool ret = false;
+
+if (interrupt_request & CPU_INTERRUPT_RESET) {
+if (cpu_interrupts_enabled(env)) {
+cs->exception_index = EXCP_RESET;
+cc->do_interrupt(cs);
+
+cs->interrupt_request   &= ~CPU_INTERRUPT_RESET;
+
+ret = true;
+}
+}
+if (interrupt_request & CPU_INTERRUPT_HARD) {
+if (cpu_interrupts_enabled(env) && env->intsrc != 0) {
+int index = ctz32(env->intsrc);
+cs->exception_index = EXCP_INT(index);
+cc->do_interrupt(cs);
+
+env->intsrc &= env->intsrc - 1; /* clear the interrupt */
+cs->interrupt_request &= ~CPU_INTERRUPT_HARD;
+
+ret = true;
+}
+}
+return ret;
 }
 
 void avr_cpu_do_interrupt(CPUState *cs)
 {
+AVRCPU *cpu = AVR_CPU(cs);
+CPUAVRState*env = &cpu->env;
+
+uint32_t ret = env->pc_w;
+int vector = 0;
+int size = avr_feature(env, AVR_FEATURE_JMP_CALL) ? 2 : 1;
+int base = 0;/* TODO: where to get it */
+
+if (cs->exception_index == EXCP_RESET) {
+vector = 0;
+} else if (env->intsrc != 0) {
+vector = ctz32(env->intsrc) + 1;
+}
+
+if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) {
+stb_phys(cs->as, env->sp--, (ret & 0xff));
+stb_phys(cs->as, env->sp--, (ret & 0x00ff00) >>  8);
+stb_phys(cs->as, env->sp--, (ret & 0xff) >> 16);
+} else if (avr_feature(env, AVR_FEATURE_2_BYTE_PC)) {
+stb_phys(cs->as, env->sp--, (ret & 0xff));
+stb_phys(cs->as, env->sp--, (ret & 0x00ff00) >>  8);
+} else {
+stb_phys(cs->as, env->sp--, (ret & 0xff));
+}
+
+env->pc_w = base + vector * size;
+env->sregI = 0;/*  clear Global Interrupt Flag */
+
+cs->exception_index = -1;
 }
 
 int avr_cpu_memory_rw_debug(CPUState *cs, vaddr addr, uint8_t *buf,
-- 
2.4.9 (Apple Git-60)




[Qemu-devel] [PATCH v5 06/10] target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported instructions

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/helper.c | 145 
 target-avr/helper.h |   5 ++
 2 files changed, 140 insertions(+), 10 deletions(-)

diff --git a/target-avr/helper.c b/target-avr/helper.c
index f96fa27..9e2b52a 100644
--- a/target-avr/helper.c
+++ b/target-avr/helper.c
@@ -42,14 +42,14 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int 
interrupt_request)
 cs->exception_index = EXCP_RESET;
 cc->do_interrupt(cs);
 
-cs->interrupt_request   &= ~CPU_INTERRUPT_RESET;
+cs->interrupt_request &= ~CPU_INTERRUPT_RESET;
 
 ret = true;
 }
 }
 if (interrupt_request & CPU_INTERRUPT_HARD) {
 if (cpu_interrupts_enabled(env) && env->intsrc != 0) {
-int index = ctz32(env->intsrc);
+int index = ctz32(env->intsrc);
 cs->exception_index = EXCP_INT(index);
 cc->do_interrupt(cs);
 
@@ -64,8 +64,8 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int 
interrupt_request)
 
 void avr_cpu_do_interrupt(CPUState *cs)
 {
-AVRCPU *cpu = AVR_CPU(cs);
-CPUAVRState*env = &cpu->env;
+AVRCPU *cpu = AVR_CPU(cs);
+CPUAVRState *env = &cpu->env;
 
 uint32_t ret = env->pc_w;
 int vector = 0;
@@ -79,14 +79,14 @@ void avr_cpu_do_interrupt(CPUState *cs)
 }
 
 if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) {
-stb_phys(cs->as, env->sp--, (ret & 0xff));
-stb_phys(cs->as, env->sp--, (ret & 0x00ff00) >>  8);
-stb_phys(cs->as, env->sp--, (ret & 0xff) >> 16);
+cpu_stb_data(env, env->sp--, (ret & 0xff));
+cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >>  8);
+cpu_stb_data(env, env->sp--, (ret & 0xff) >> 16);
 } else if (avr_feature(env, AVR_FEATURE_2_BYTE_PC)) {
-stb_phys(cs->as, env->sp--, (ret & 0xff));
-stb_phys(cs->as, env->sp--, (ret & 0x00ff00) >>  8);
+cpu_stb_data(env, env->sp--, (ret & 0xff));
+cpu_stb_data(env, env->sp--, (ret & 0x00ff00) >>  8);
 } else {
-stb_phys(cs->as, env->sp--, (ret & 0xff));
+cpu_stb_data(env, env->sp--, (ret & 0xff));
 }
 
 env->pc_w = base + vector * size;
@@ -133,6 +133,28 @@ void tlb_fill(CPUState *cs, target_ulong vaddr, int 
is_write,
 
 tlb_set_page_with_attrs(cs, vaddr, paddr, attrs, prot, mmu_idx, page_size);
 }
+void helper_sleep(CPUAVRState *env)
+{
+CPUState *cs = CPU(avr_env_get_cpu(env));
+
+cs->exception_index = EXCP_HLT;
+cpu_loop_exit(cs);
+}
+void helper_unsupported(CPUAVRState *env)
+{
+CPUState *cs = CPU(avr_env_get_cpu(env));
+
+/*
+I count not find what happens on the real platform, so
+it's EXCP_DEBUG for meanwhile
+*/
+cs->exception_index = EXCP_DEBUG;
+if (qemu_loglevel_mask(LOG_UNIMP)) {
+qemu_log("UNSUPPORTED\n");
+cpu_dump_state(cs, qemu_logfile, fprintf, 0);
+}
+cpu_loop_exit(cs);
+}
 
 void helper_debug(CPUAVRState *env)
 {
@@ -142,3 +164,106 @@ void helper_debug(CPUAVRState *env)
 cpu_loop_exit(cs);
 }
 
+void helper_wdr(CPUAVRState *env)
+{
+CPUState *cs = CPU(avr_env_get_cpu(env));
+
+/*
+WD is not implemented yet, placeholder
+*/
+cs->exception_index = EXCP_DEBUG;
+cpu_loop_exit(cs);
+}
+
+target_ulong helper_inb(CPUAVRState *env, uint32_t port)
+{
+qemu_log("in: io[%02x]\n", port);
+
+switch (port) {
+case0x38: {
+return  0xff & (env->rampD >> 16);  /*  RAMPD   */
+}
+case0x39: {
+return  0xff & (env->rampX >> 16);  /*  RAMPX   */
+}
+case0x3a: {
+return  0xff & (env->rampY >> 16);  /*  RAMPY   */
+}
+case0x3b: {
+return  0xff & (env->rampZ >> 16);  /*  RAMPZ   */
+}
+case0x3c: {
+return  0xff & (env->eind  >> 16);  /*  EIND*/
+}
+case0x3d: { /*  SPL */
+return  env->sp & 0x00ff;
+}
+case0x3e: { /*  SPH */
+return  env->sp >> 8;
+}
+case0x3f: { /*  SREG*/
+return cpu_get_sreg(env);
+}
+}
+return  0;
+}
+
+void helper_outb(CPUAVRState *env, uint32_t port, uint32_t data)
+{
+qemu_log("out:%02x -> io[%02x]\n", data, port);
+
+data&= 0x00ff;
+
+switch (port) {
+case0x04: {
+qemu_irqirq;
+CPUState   *cpu = CPU(avr_env_get_cpu(env));
+irq = qdev_get_gpio_in(DEVICE(cpu), 3);
+qemu_set_irq(irq, 1);
+break;
+}
+case0x38: {
+if (avr_feature(env, AVR_FEATURE_RAMPD)) {
+env->rampD = (data & 0xff) << 16;   /*  RAMPD   */
+}
+break;
+}
+case  

[Qemu-devel] [PATCH v5 08/10] target-avr: adding instruction translation

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/translate-inst.c | 2624 +++
 target-avr/translate.h  |  119 ++
 2 files changed, 2743 insertions(+)
 create mode 100644 target-avr/translate-inst.c
 create mode 100644 target-avr/translate.h

diff --git a/target-avr/translate-inst.c b/target-avr/translate-inst.c
new file mode 100644
index 000..c225743
--- /dev/null
+++ b/target-avr/translate-inst.c
@@ -0,0 +1,2624 @@
+/*
+ *  QEMU AVR CPU
+ *
+ *  Copyright (c) 2016 Michael Rolnik
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, see
+ *  
+ */
+
+#include "translate.h"
+#include "translate-inst.h"
+#include "qemu/bitops.h"
+
+static void gen_add_CHf(TCGv R, TCGv Rd, TCGv Rr);
+static void gen_add_Vf(TCGv R, TCGv Rd, TCGv Rr);
+static void gen_sub_CHf(TCGv R, TCGv Rd, TCGv Rr);
+static void gen_sub_Vf(TCGv R, TCGv Rd, TCGv Rr);
+static void gen_ZNSf(TCGv R);
+static void gen_push_ret(CPUAVRState *env, int ret);
+static void gen_pop_ret(CPUAVRState *env, TCGv ret);
+static void gen_jmp_ez(void);
+static void gen_jmp_z(void);
+
+/*
+in the following 2 functions
+H assumed to be in 0x00ff format
+M assumed to be in 0x00ff format
+L assumed to be in 0x00ff format
+*/
+static void gen_set_addr(TCGv addr, TCGv H, TCGv M, TCGv l); /* H:M:L = addr */
+static TCGv gen_get_addr(TCGv H, TCGv M, TCGv L);/* addr = H:M:L */
+
+static void gen_set_xaddr(TCGv addr);
+static void gen_set_yaddr(TCGv addr);
+static void gen_set_zaddr(TCGv addr);
+
+static TCGv gen_get_xaddr(void);
+static TCGv gen_get_yaddr(void);
+static TCGv gen_get_zaddr(void);
+
+void gen_add_CHf(TCGv R, TCGv Rd, TCGv Rr)
+{
+TCGv t1 = tcg_temp_new_i32();
+TCGv t2 = tcg_temp_new_i32();
+TCGv t3 = tcg_temp_new_i32();
+
+tcg_gen_and_tl(t1, Rd, Rr); /*  t1 = Rd & Rr  */
+tcg_gen_andc_tl(t2, Rd, R); /*  t2 = Rd & ~R  */
+tcg_gen_andc_tl(t3, Rr, R); /*  t3 = Rr & ~R  */
+tcg_gen_or_tl(t1, t1, t2);  /*  t1 = t1 | t2 | t3  */
+tcg_gen_or_tl(t1, t1, t3);
+
+tcg_gen_shri_tl(cpu_Cf, t1, 7); /*  Cf = t1(7)  */
+tcg_gen_shri_tl(cpu_Hf, t1, 3); /*  Hf = t1(3)  */
+tcg_gen_andi_tl(cpu_Hf, cpu_Hf, 1);
+
+tcg_temp_free_i32(t3);
+tcg_temp_free_i32(t2);
+tcg_temp_free_i32(t1);
+}
+
+void gen_add_Vf(TCGv R, TCGv Rd, TCGv Rr)
+{
+TCGv t1 = tcg_temp_new_i32();
+TCGv t2 = tcg_temp_new_i32();
+
+/*  t1 = Rd & Rr & ~R | ~Rd & ~Rr & R = (Rd ^ R) & ~(Rd ^ Rr)   */
+tcg_gen_xor_tl(t1, Rd, R);
+tcg_gen_xor_tl(t2, Rd, Rr);
+tcg_gen_andc_tl(t1, t1, t2);
+
+tcg_gen_shri_tl(cpu_Vf, t1, 7); /*  Vf = t1(7)  */
+
+tcg_temp_free_i32(t2);
+tcg_temp_free_i32(t1);
+}
+
+void gen_sub_CHf(TCGv R, TCGv Rd, TCGv Rr)
+{
+TCGv t1 = tcg_temp_new_i32();
+TCGv t2 = tcg_temp_new_i32();
+TCGv t3 = tcg_temp_new_i32();
+
+/*  Cf & Hf  */
+tcg_gen_not_tl(t1, Rd); /*  t1 = ~Rd  */
+tcg_gen_and_tl(t2, t1, Rr); /*  t2 = ~Rd & Rr  */
+tcg_gen_or_tl(t3, t1, Rr);  /*  t3 = (~Rd | Rr) & R  */
+tcg_gen_and_tl(t3, t3, R);
+tcg_gen_or_tl(t2, t2, t3);  /*  t2 = ~Rd & Rr | ~Rd & R | R & Rr  
*/
+tcg_gen_shri_tl(cpu_Cf, t2, 7); /*  Cf = t2(7)  */
+tcg_gen_shri_tl(cpu_Hf, t2, 3); /*  Hf = t2(3)  */
+tcg_gen_andi_tl(cpu_Hf, cpu_Hf, 1);
+
+tcg_temp_free_i32(t3);
+tcg_temp_free_i32(t2);
+tcg_temp_free_i32(t1);
+}
+
+void gen_sub_Vf(TCGv R, TCGv Rd, TCGv Rr)
+{
+TCGv t1 = tcg_temp_new_i32();
+TCGv t2 = tcg_temp_new_i32();
+
+/*  Vf  */
+/*  t1 = Rd & ~Rr & ~R | ~Rd & Rr & R  = (Rd ^ R) & (Rd ^ R)*/
+tcg_gen_xor_tl(t1, Rd, R);
+tcg_gen_xor_tl(t2, Rd, Rr);
+tcg_gen_and_tl(t1, t1, t2);
+tcg_gen_shri_tl(cpu_Vf, t1, 7); /*  Vf = t1(7)  */
+
+tcg_temp_free_i32(t2);
+tcg_temp_free_i32(t1);
+}
+
+void gen_ZNSf(TCGv R)
+{
+tcg_gen_mov_tl(cpu_Zf, R);  /*  Zf = R  */
+tcg_gen_shri_tl(cpu_Nf, R, 7);  /*  Nf = R(7)  */
+tcg_gen_xor_tl(cpu_Sf, cpu_Nf, cpu_Vf); /*  Sf = Nf ^ Vf  */
+}
+
+void gen_push_ret(CPUAVRState *env, int ret)
+{
+if (avr_feature(env, AVR_FEATURE_1_BYTE_PC)) {
+
+TCGv t0 = tcg_const_i32((ret & 0xff));
+
+tcg_g

[Qemu-devel] [PATCH v5 01/10] target-avr: AVR cores support is added. 1. basic CPU structure 2. registers 3. no instructions

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 arch_init.c |   2 +
 configure   |   7 +-
 default-configs/avr-softmmu.mak |  21 +++
 include/disas/bfd.h |   6 +
 include/sysemu/arch_init.h  |   1 +
 target-avr/Makefile.objs|  23 +++
 target-avr/cpu-qom.h|  84 +++
 target-avr/cpu.c| 304 
 target-avr/cpu.h| 158 +
 target-avr/gdbstub.c|  99 +
 target-avr/helper.c |  87 
 target-avr/helper.h |  21 +++
 target-avr/machine.c|  54 +++
 target-avr/machine.h|  21 +++
 target-avr/translate.c  | 290 ++
 15 files changed, 1177 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/avr-softmmu.mak
 create mode 100644 target-avr/Makefile.objs
 create mode 100644 target-avr/cpu-qom.h
 create mode 100644 target-avr/cpu.c
 create mode 100644 target-avr/cpu.h
 create mode 100644 target-avr/gdbstub.c
 create mode 100644 target-avr/helper.c
 create mode 100644 target-avr/helper.h
 create mode 100644 target-avr/machine.c
 create mode 100644 target-avr/machine.h
 create mode 100644 target-avr/translate.c

diff --git a/arch_init.c b/arch_init.c
index fa05973..be6e6de 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -80,6 +80,8 @@ int graphic_depth = 32;
 #define QEMU_ARCH QEMU_ARCH_UNICORE32
 #elif defined(TARGET_TRICORE)
 #define QEMU_ARCH QEMU_ARCH_TRICORE
+#elif defined(TARGET_AVR)
+#define QEMU_ARCH QEMU_ARCH_AVR
 #endif
 
 const uint32_t arch_type = QEMU_ARCH;
diff --git a/configure b/configure
index 8c2f90b..41e550e 100755
--- a/configure
+++ b/configure
@@ -5603,7 +5603,7 @@ target_name=$(echo $target | cut -d '-' -f 1)
 target_bigendian="no"
 
 case "$target_name" in
-  
armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
+  
avr|armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
   target_bigendian=yes
   ;;
 esac
@@ -5652,6 +5652,8 @@ case "$target_name" in
   x86_64)
 TARGET_BASE_ARCH=i386
   ;;
+  avr)
+  ;;
   alpha)
   ;;
   arm|armeb)
@@ -5848,6 +5850,9 @@ disas_config() {
 
 for i in $ARCH $TARGET_BASE_ARCH ; do
   case "$i" in
+  avr)
+disas_config "AVR"
+  ;;
   alpha)
 disas_config "ALPHA"
   ;;
diff --git a/default-configs/avr-softmmu.mak b/default-configs/avr-softmmu.mak
new file mode 100644
index 000..003465d
--- /dev/null
+++ b/default-configs/avr-softmmu.mak
@@ -0,0 +1,21 @@
+#
+#  QEMU AVR CPU
+#
+#  Copyright (c) 2016 Michael Rolnik
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, see
+#  
+#
+
+# Default configuration for avr-softmmu
diff --git a/include/disas/bfd.h b/include/disas/bfd.h
index a112e9c..b13fc53 100644
--- a/include/disas/bfd.h
+++ b/include/disas/bfd.h
@@ -213,6 +213,12 @@ enum bfd_architecture
 #define bfd_mach_m32r  0  /* backwards compatibility */
   bfd_arch_mn10200,/* Matsushita MN10200 */
   bfd_arch_mn10300,/* Matsushita MN10300 */
+  bfd_arch_avr,   /* Atmel AVR microcontrollers.  */
+#define bfd_mach_avr1  1
+#define bfd_mach_avr2  2
+#define bfd_mach_avr3  3
+#define bfd_mach_avr4  4
+#define bfd_mach_avr5  5
   bfd_arch_cris,   /* Axis CRIS */
 #define bfd_mach_cris_v0_v10   255
 #define bfd_mach_cris_v32  32
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index d690dfa..8c75777 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -23,6 +23,7 @@ enum {
 QEMU_ARCH_UNICORE32 = (1 << 14),
 QEMU_ARCH_MOXIE = (1 << 15),
 QEMU_ARCH_TRICORE = (1 << 16),
+QEMU_ARCH_AVR = (1 << 17),
 };
 
 extern const uint32_t arch_type;
diff --git a/target-avr/Makefile.objs b/target-avr/Makefile.objs
new file mode 100644
index 000..2a10104
--- /dev/null
+++ b/target-avr/Makefile.objs
@@ -0,0 +1,23 @@
+#
+#  QEMU AVR CPU
+#
+#  Copyright (c) 2016 Michael Rolnik
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the F

[Qemu-devel] [PATCH v5 07/10] target-avr: adding instruction decoder

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/decode.c | 693 
 1 file changed, 693 insertions(+)
 create mode 100644 target-avr/decode.c

diff --git a/target-avr/decode.c b/target-avr/decode.c
new file mode 100644
index 000..44a5815
--- /dev/null
+++ b/target-avr/decode.c
@@ -0,0 +1,693 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2016 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * 
+ */
+
+
+#include 
+#include "translate.h"
+
+void avr_decode(uint32_t pc, uint32_t *l, uint32_t c, translate_function_t *t)
+{
+uint32_t opc  = extract32(c, 0, 16);
+switch (opc & 0xd000) {
+case 0x: {
+switch (opc & 0x2c00) {
+case 0x: {
+switch (opc & 0x0300) {
+case 0x: {
+*l = 16;
+*t = &avr_translate_NOP;
+break;
+}
+case 0x0100: {
+*l = 16;
+*t = &avr_translate_MOVW;
+break;
+}
+case 0x0200: {
+*l = 16;
+*t = &avr_translate_MULS;
+break;
+}
+case 0x0300: {
+switch (opc & 0x0088) {
+case 0x: {
+*l = 16;
+*t = &avr_translate_MULSU;
+break;
+}
+case 0x0008: {
+*l = 16;
+*t = &avr_translate_FMUL;
+break;
+}
+case 0x0080: {
+*l = 16;
+*t = &avr_translate_FMULS;
+break;
+}
+case 0x0088: {
+*l = 16;
+*t = &avr_translate_FMULSU;
+break;
+}
+}
+break;
+}
+}
+break;
+}
+case 0x0400: {
+*l = 16;
+*t = &avr_translate_CPC;
+break;
+}
+case 0x0800: {
+*l = 16;
+*t = &avr_translate_SBC;
+break;
+}
+case 0x0c00: {
+*l = 16;
+*t = &avr_translate_ADD;
+break;
+}
+case 0x2000: {
+*l = 16;
+*t = &avr_translate_AND;
+break;
+}
+case 0x2400: {
+*l = 16;
+*t = &avr_translate_EOR;
+break;
+}
+case 0x2800: {
+*l = 16;
+*t = &avr_translate_OR;
+break;
+}
+case 0x2c00: {
+*l = 16;
+*t = &avr_translate_MOV;
+break;
+}
+}
+break;
+}
+case 0x1000: {
+switch (opc & 0x2000) {
+case 0x: {
+switch (opc & 0x0c00) {
+case 0x: {
+*l = 16;
+*t = &avr_translate_CPSE;
+break;
+}
+case 0x0400: {
+*l = 16;
+*t = &avr_translate_CP;
+

[Qemu-devel] [PATCH v5 02/10] target-avr: adding AVR CPU features/flavors

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/cpu.c | 307 ++-
 target-avr/cpu.h |  53 ++
 2 files changed, 359 insertions(+), 1 deletion(-)

diff --git a/target-avr/cpu.c b/target-avr/cpu.c
index 99bd788..197f9ac 100644
--- a/target-avr/cpu.c
+++ b/target-avr/cpu.c
@@ -203,6 +203,296 @@ static void avr_cpu_class_init(ObjectClass *oc, void 
*data)
 dc->cannot_destroy_with_object_finalize_yet = true;
 }
 
+static void avr_avr1_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+}
+static void avr_avr2_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+}
+
+static void avr_avr25_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_LPMX);
+avr_set_feature(env, AVR_FEATURE_MOVW);
+}
+
+static void avr_avr3_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+static void avr_avr31_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_RAMPZ);
+avr_set_feature(env, AVR_FEATURE_ELPM);
+avr_set_feature(env, AVR_FEATURE_JMP_CALL);
+}
+
+static void avr_avr35_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_JMP_CALL);
+avr_set_feature(env, AVR_FEATURE_LPMX);
+avr_set_feature(env, AVR_FEATURE_MOVW);
+}
+
+static void avr_avr4_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_LPMX);
+avr_set_feature(env, AVR_FEATURE_MOVW);
+avr_set_feature(env, AVR_FEATURE_MUL);
+}
+
+static void avr_avr5_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_feature(env, AVR_FEATURE_SRAM);
+avr_set_feature(env, AVR_FEATURE_BREAK);
+
+avr_set_feature(env, AVR_FEATURE_2_BYTE_PC);
+avr_set_feature(env, AVR_FEATURE_2_BYTE_SP);
+avr_set_feature(env, AVR_FEATURE_JMP_CALL);
+avr_set_feature(env, AVR_FEATURE_LPMX);
+avr_set_feature(env, AVR_FEATURE_MOVW);
+avr_set_feature(env, AVR_FEATURE_MUL);
+}
+
+static void avr_avr51_initfn(Object *obj)
+{
+AVRCPU *cpu = AVR_CPU(obj);
+CPUAVRState *env = &cpu->env;
+
+avr_set_feature(env, AVR_FEATURE_LPM);
+avr_set_feature(env, AVR_FEATURE_IJMP_ICALL);
+avr_set_feature(env, AVR_FEATURE_ADIW_SBIW);
+avr_set_f

[Qemu-devel] [PATCH v5 04/10] target-avr: adding instructions encodings

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 target-avr/translate-inst.h | 762 
 1 file changed, 762 insertions(+)
 create mode 100644 target-avr/translate-inst.h

diff --git a/target-avr/translate-inst.h b/target-avr/translate-inst.h
new file mode 100644
index 000..0c082d3
--- /dev/null
+++ b/target-avr/translate-inst.h
@@ -0,0 +1,762 @@
+/*
+ *  QEMU AVR CPU
+ *
+ *  Copyright (c) 2016 Michael Rolnik
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, see
+ *  
+ */
+
+
+#ifndef AVR_TRANSLATE_INST_H_
+#define AVR_TRANSLATE_INST_H_
+
+typedef struct DisasContextDisasContext;
+
+int avr_translate_NOP(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+
+int avr_translate_MOVW(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t MOVW_Rr(uint32_t opcode)
+{
+return extract32(opcode, 0, 4);
+}
+static inline uint32_t MOVW_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 4);
+}
+
+int avr_translate_MULS(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t MULS_Rr(uint32_t opcode)
+{
+return extract32(opcode, 0, 4);
+}
+static inline uint32_t MULS_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 4);
+}
+
+int avr_translate_MULSU(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t MULSU_Rr(uint32_t opcode)
+{
+return extract32(opcode, 0, 3);
+}
+static inline uint32_t MULSU_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 3);
+}
+
+int avr_translate_FMUL(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t FMUL_Rr(uint32_t opcode)
+{
+return extract32(opcode, 0, 3);
+}
+static inline uint32_t FMUL_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 3);
+}
+
+int avr_translate_FMULS(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t FMULS_Rr(uint32_t opcode)
+{
+return extract32(opcode, 0, 3);
+}
+static inline uint32_t FMULS_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 3);
+}
+
+int avr_translate_FMULSU(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t FMULSU_Rr(uint32_t opcode)
+{
+return extract32(opcode, 0, 3);
+}
+static inline uint32_t FMULSU_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 3);
+}
+
+int avr_translate_CPC(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t CPC_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 5);
+}
+static inline uint32_t CPC_Rr(uint32_t opcode)
+{
+return (extract32(opcode, 9, 1) << 4) |
+(extract32(opcode, 0, 4));
+}
+
+int avr_translate_SBC(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t SBC_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 5);
+}
+static inline uint32_t SBC_Rr(uint32_t opcode)
+{
+return (extract32(opcode, 9, 1) << 4) |
+(extract32(opcode, 0, 4));
+}
+
+int avr_translate_ADD(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t ADD_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 5);
+}
+static inline uint32_t ADD_Rr(uint32_t opcode)
+{
+return (extract32(opcode, 9, 1) << 4) |
+(extract32(opcode, 0, 4));
+}
+
+int avr_translate_AND(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t AND_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 5);
+}
+static inline uint32_t AND_Rr(uint32_t opcode)
+{
+return (extract32(opcode, 9, 1) << 4) |
+(extract32(opcode, 0, 4));
+}
+
+int avr_translate_EOR(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t EOR_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 5);
+}
+static inline uint32_t EOR_Rr(uint32_t opcode)
+{
+return (extract32(opcode, 9, 1) << 4) |
+(extract32(opcode, 0, 4));
+}
+
+int avr_translate_OR(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t OR_Rd(uint32_t opcode)
+{
+return extract32(opcode, 4, 5);
+}
+static inline uint32_t OR_Rr(uint32_t opcode)
+{
+return (extract32(opcode, 9, 1) << 4) |
+(extract32(opcode, 0, 4));
+}
+
+int avr_translate_MOV(CPUAVRState *env, DisasContext* ctx, uint32_t opcode);
+static inline uint32_t MOV_Rd(uint32_t opcode)
+{
+ret

[Qemu-devel] [PATCH v5 03/10] target-avr: adding a sample AVR board

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

From: Michael Rolnik 

Signed-off-by: Michael Rolnik 
---
 hw/Makefile.objs |   1 +
 hw/avr/Makefile.objs |  21 +
 hw/avr/sample-io.c   | 215 +++
 hw/avr/sample.c  | 118 
 4 files changed, 355 insertions(+)
 create mode 100644 hw/avr/Makefile.objs
 create mode 100644 hw/avr/sample-io.c
 create mode 100644 hw/avr/sample.c

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 4a07ed4..262ca15 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -33,6 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
 devices-dirs-$(CONFIG_SOFTMMU) += xen/
 devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/
 devices-dirs-$(CONFIG_SMBIOS) += smbios/
+devices-dirs-$(CONFIG_SOFTMMU) += avr/
 devices-dirs-y += core/
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
new file mode 100644
index 000..c080e4e
--- /dev/null
+++ b/hw/avr/Makefile.objs
@@ -0,0 +1,21 @@
+#
+#  QEMU AVR CPU
+#
+#  Copyright (c) 2016 Michael Rolnik
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, see
+#  
+#
+
+obj-y   += sample.o sample-io.o
diff --git a/hw/avr/sample-io.c b/hw/avr/sample-io.c
new file mode 100644
index 000..e0fee77
--- /dev/null
+++ b/hw/avr/sample-io.c
@@ -0,0 +1,215 @@
+/*
+ *  QEMU AVR CPU
+ *
+ *  Copyright (c) 2016 Michael Rolnik
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, see
+ *  
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu-common.h"
+#include "cpu.h"
+#include "include/hw/sysbus.h"
+
+#define TYPE_SAMPLEIO   "SampleIO"
+#define SAMPLEIO(obj)   OBJECT_CHECK(SAMPLEIOState, (obj), TYPE_SAMPLEIO)
+
+#ifndef DEBUG_SAMPLEIO
+#define DEBUG_SAMPLEIO 1
+#endif
+
+#define DPRINTF(fmt, args...) \
+do {  \
+if (DEBUG_SAMPLEIO) { \
+fprintf(stderr, "[%s]%s: " fmt , TYPE_SAMPLEIO, __func__, ##args);\
+} \
+} \
+while (0)
+
+#define AVR_IO_CPU_REGS_SIZE0x0020
+#define AVR_IO_CPU_IO_SIZE  0x0040
+#define AVR_IO_EXTERN_IO_SIZE   0x00a0
+#define AVR_IO_SIZE (AVR_IO_CPU_REGS_SIZE   \
++ AVR_IO_CPU_IO_SIZE\
++ AVR_IO_EXTERN_IO_SIZE)
+
+#define AVR_IO_CPU_REGS_BASE0x
+#define AVR_IO_CPU_IO_BASE  (AVR_IO_CPU_REGS_BASE   \
++ AVR_IO_CPU_REGS_SIZE)
+#define AVR_IO_EXTERN_IO_BASE   (AVR_IO_CPU_IO_BASE \
++ AVR_IO_CPU_IO_SIZE)
+
+
+typedef struct SAMPLEIOState {
+SysBusDeviceparent;
+
+MemoryRegioniomem;
+
+AVRCPU *cpu;
+
+uint8_t io[0x40];
+uint8_t exio[0xa0];
+} SAMPLEIOState;
+
+static uint64_t sample_io_read(void *opaque, hwaddr offset, unsigned size);
+static void sample_io_write(void *opaque, hwaddr offset, uint64_t value,
+unsigned size);
+static int sample_io_init(DeviceState *sbd);
+static void sample_io_class_init(ObjectClass *klass, void *data);
+static void sample_io_register_types(void);
+
+static void write_Rx(CPUAVRState *env, int inst, uint8_t data);
+static uint8_t read_Rx(CPUAVRState *env, int inst);
+
+static const MemoryRegionOps sample_io_ops = {
+.read = sample_io_read,
+.write = sample_io_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static Propert

[Qemu-devel] [PATCH v5 00/10] 8bit AVR cores

2016-06-08 Thread Michael Rolnik
From: Michael Rolnik 

This series of patches adds 8bit AVR cores to QEMU.
All instruction, except BREAK/DES/SPM/SPMX, are implemented. Not fully tested 
yet.
However I was able to execute simple code with functions. e.g fibonacci 
calculation.
This series of patches include a non real, sample board.
No fuses support yet. PC is set to 0 at reset.

the patches include the following
1. just a basic 8bit AVR CPU, without instruction decoding or translation
2. CPU features which allow define the following 8bit AVR cores
 avr1
 avr2 avr25
 avr3 avr31 avr35
 avr4
 avr5 avr51
 avr6
 xmega2 xmega4 xmega5 xmega6 xmega7
3. a definition of sample machine with SRAM, FLASH and CPU which allows to 
execute simple code
4. encoding for all AVR instructions
5. interrupt handling
6. helpers for IN, OUT, SLEEP, WBR & unsupported instructions
7. a decoder which given an opcode decides what istruction it is
8. translation of AVR instruction into TCG
9. all features together

changes since v3
1. rampD/X/Y/Z registers are encoded as 0x00ff (instead of 0x00ff) for 
faster address manipulaton
2. ffs changed to ctz32
3. duplicate code removed at avr_cpu_do_interrupt
4. using andc instead of not + and
5. fixing V flag calculation in varios instructions
6. freeing local variables in PUSH
7. tcg_const_local_i32 -> tcg_const_i32
8. using sextract32 instead of my implementation
9. fixing BLD instruction
10.xor(r) instead of 0xff - r at COM
11.fixing MULS/MULSU not to modify inputs' content
12.using SUB for NEG
13.fixing tcg_gen_qemu_ld/st call in XCH

changes since v4
1. target is now defined as big endian in order to optimize push_ret/pop_ret
2. all style warnings are fixed
3. adding cpu_set/get_sreg functions
4. simplifying gen_goto_tb as there is no real paging
5. env->pc -> env->pc_w
6. making flag dump more compact
7. more spacing
8. renaming CODE/DATA_INDEX -> MMU_CODE/DATA_IDX
9. removing avr_set_feature
10. SPL/SPH set bug fix
11. switching stb_phys to cpu_stb_data
12. cleaning up avr_decode
13. saving sreg, rampD/X/Y/Z, eind in HW format (savevm)
14. saving CPU features (savevm)

Michael Rolnik (10):
  target-avr: AVR cores support is added. 1. basic CPU
structure 2. registers 3. no instructions
  target-avr: adding AVR CPU features/flavors
  target-avr: adding a sample AVR board
  target-avr: adding instructions encodings
  target-avr: adding AVR interrupt handling
  target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported
instructions
  target-avr: adding instruction decoder
  target-avr: adding instruction translation
  target-avr: updating translate.c to use instructions translation
  target-avr: saving sreg, rampD, rampX, rampY, rampD, eind in HW
representation saving cpu features

 arch_init.c |2 +
 configure   |7 +-
 default-configs/avr-softmmu.mak |   21 +
 hw/Makefile.objs|1 +
 hw/avr/Makefile.objs|   21 +
 hw/avr/sample-io.c  |  215 
 hw/avr/sample.c |  118 ++
 include/disas/bfd.h |6 +
 include/sysemu/arch_init.h  |1 +
 target-avr/Makefile.objs|   25 +
 target-avr/cpu-qom.h|   84 ++
 target-avr/cpu.c|  609 +
 target-avr/cpu.h|  211 
 target-avr/decode.c |  693 +++
 target-avr/gdbstub.c|   99 ++
 target-avr/helper.c |  269 
 target-avr/helper.h |   26 +
 target-avr/machine.c|  117 ++
 target-avr/machine.h|   21 +
 target-avr/translate-inst.c | 2624 +++
 target-avr/translate-inst.h |  762 
 target-avr/translate.c  |  274 
 target-avr/translate.h  |  119 ++
 23 files changed, 6324 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/avr-softmmu.mak
 create mode 100644 hw/avr/Makefile.objs
 create mode 100644 hw/avr/sample-io.c
 create mode 100644 hw/avr/sample.c
 create mode 100644 target-avr/Makefile.objs
 create mode 100644 target-avr/cpu-qom.h
 create mode 100644 target-avr/cpu.c
 create mode 100644 target-avr/cpu.h
 create mode 100644 target-avr/decode.c
 create mode 100644 target-avr/gdbstub.c
 create mode 100644 target-avr/helper.c
 create mode 100644 target-avr/helper.h
 create mode 100644 target-avr/machine.c
 create mode 100644 target-avr/machine.h
 create mode 100644 target-avr/translate-inst.c
 create mode 100644 target-avr/translate-inst.h
 create mode 100644 target-avr/translate.c
 create mode 100644 target-avr/translate.h

-- 
2.4.9 (Apple Git-60)




Re: [Qemu-devel] [PATCH v4 2/9] target-avr: adding AVR CPU features/flavors

2016-06-08 Thread Michael Rolnik
Richard, do you want to delete all empty lines?

On Mon, Jun 6, 2016 at 11:25 PM, Richard Henderson  wrote:

> On 06/06/2016 03:37 AM, Michael Rolnik wrote:
>
>> @@ -55,12 +55,14 @@ static void avr_cpu_reset(CPUState *s)
>>  AVRCPU *cpu = AVR_CPU(s);
>>  AVRCPUClass *mcc = AVR_CPU_GET_CLASS(cpu);
>>  CPUAVRState *env = &cpu->env;
>> +uint32_t features = env->features;
>>
>>  mcc->parent_reset(s);
>>
>>  memset(env, 0, sizeof(CPUAVRState));
>>  env->pc = 0;
>>  env->sregI = 1;
>> +env->features = features;
>>
>
> Didn't fix the memset issue I pointed out.
>
> +}
>> +static void avr_avr6_initfn(Object *obj)
>>
>
> Spacing.
>
> +}
>> +static void avr_xmega2_initfn(Object *obj)
>>
>
> Spacing.
>
> +}
>> +static void avr_xmega4_initfn(Object *obj)
>>
>
> Spacing.
>
> +}
>> +static void avr_xmega5_initfn(Object *obj)
>>
>
> Spacing.
>
> +}
>> +static void avr_xmega7_initfn(Object *obj)
>>
>
> Spacing.
>
> +static inline void  avr_del_feature(
>> +CPUAVRState*env,
>> +int feature)
>> +{
>> +env->features   &= ~(1Ul << feature);
>> +}
>>
>
> Dead code.
>
>
> r~
>
>


-- 
Best Regards,
Michael Rolnik


[Qemu-devel] [PATCH v2 0/2] Eliminate usb_enabled()

2016-06-08 Thread Eduardo Habkost
usb_enabled() is just a wrapper for machine_usb(current_machine)
and is not necessary, replace all usages of usb_enabled() with
machine_usb().

In the case of pxa2xx, just remove usb_enabled() usage
completely.

Eduardo Habkost (2):
  pxa2xx: Unconditionally enable USB controller
  vl: Eliminate usb_enabled()

 hw/arm/nseries.c|  2 +-
 hw/arm/pxa2xx.c | 12 
 hw/arm/realview.c   |  2 +-
 hw/arm/versatilepb.c|  2 +-
 hw/i386/pc_piix.c   |  2 +-
 hw/i386/pc_q35.c|  2 +-
 hw/ppc/mac_oldworld.c   |  2 +-
 hw/ppc/prep.c   |  2 +-
 include/sysemu/sysemu.h |  1 -
 vl.c| 11 +++
 10 files changed, 14 insertions(+), 24 deletions(-)

-- 
2.5.5




[Qemu-devel] [PATCH v2 2/2] vl: Eliminate usb_enabled()

2016-06-08 Thread Eduardo Habkost
This wrapper for machine_usb(current_machine) is not necessary,
replace all usages of usb_enabled() with machine_usb().

Cc: Peter Maydell 
Cc: "Michael S. Tsirkin" 
Cc: Alexander Graf 
Cc: qemu-...@nongnu.org
Cc: qemu-...@nongnu.org
Signed-off-by: Eduardo Habkost 
---
Changes v1 -> v2:
* pxa2xx doesn't have a usb_enabled() check anymore
---
 hw/arm/nseries.c|  2 +-
 hw/arm/realview.c   |  2 +-
 hw/arm/versatilepb.c|  2 +-
 hw/i386/pc_piix.c   |  2 +-
 hw/i386/pc_q35.c|  2 +-
 hw/ppc/mac_oldworld.c   |  2 +-
 hw/ppc/prep.c   |  2 +-
 include/sysemu/sysemu.h |  1 -
 vl.c| 11 +++
 9 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
index d4eb141..fea911e 100644
--- a/hw/arm/nseries.c
+++ b/hw/arm/nseries.c
@@ -1351,7 +1351,7 @@ static void n8x0_init(MachineState *machine,
 n8x0_dss_setup(s);
 n8x0_cbus_setup(s);
 n8x0_uart_setup(s);
-if (usb_enabled()) {
+if (machine_usb(machine)) {
 n8x0_usb_setup(s);
 }
 
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 7d0aa6f..8eafcca 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -254,7 +254,7 @@ static void realview_init(MachineState *machine,
 sysbus_connect_irq(busdev, 2, pic[50]);
 sysbus_connect_irq(busdev, 3, pic[51]);
 pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
-if (usb_enabled()) {
+if (machine_usb(machine)) {
 pci_create_simple(pci_bus, -1, "pci-ohci");
 }
 n = drive_get_max_bus(IF_SCSI);
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index 20dd356..8ae5392 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -276,7 +276,7 @@ static void versatile_init(MachineState *machine, int 
board_id)
 pci_nic_init_nofail(nd, pci_bus, "rtl8139", NULL);
 }
 }
-if (usb_enabled()) {
+if (machine_usb(machine)) {
 pci_create_simple(pci_bus, -1, "pci-ohci");
 }
 n = drive_get_max_bus(IF_SCSI);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 14dd0cc..82c7c0a 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -262,7 +262,7 @@ static void pc_init1(MachineState *machine,
 
 pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
 
-if (pcmc->pci_enabled && usb_enabled()) {
+if (pcmc->pci_enabled && machine_usb(machine)) {
 pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
 }
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 04aae89..31a6a59 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -234,7 +234,7 @@ static void pc_q35_init(MachineState *machine)
 ide_drive_get(hd, ICH_AHCI(ahci)->ahci.ports);
 ahci_ide_create_devs(ahci, hd);
 
-if (usb_enabled()) {
+if (machine_usb(machine)) {
 /* Should we create 6 UHCI according to ich9 spec? */
 ehci_create_ich9_with_companions(host_bus, 0x1d);
 }
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index a9bb1c2..4479487 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -309,7 +309,7 @@ static void ppc_heathrow_init(MachineState *machine)
 dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
 qdev_init_nofail(dev);
 
-if (usb_enabled()) {
+if (machine_usb(machine)) {
 pci_create_simple(pci_bus, -1, "pci-ohci");
 }
 
diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 07ffe72..054af1e 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -649,7 +649,7 @@ static void ppc_prep_init(MachineState *machine)
 memory_region_add_subregion(sysmem, 0xFEFF, xcsr);
 #endif
 
-if (usb_enabled()) {
+if (machine_usb(machine)) {
 pci_create_simple(pci_bus, -1, "pci-ohci");
 }
 
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 9428141..7313673 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -233,7 +233,6 @@ void qemu_boot_set(const char *boot_order, Error **errp);
 QemuOpts *qemu_get_machine_opts(void);
 
 bool defaults_enabled(void);
-bool usb_enabled(void);
 
 extern QemuOptsList qemu_legacy_drive_opts;
 extern QemuOptsList qemu_common_drive_opts;
diff --git a/vl.c b/vl.c
index b0bcc25..45eff56 100644
--- a/vl.c
+++ b/vl.c
@@ -1072,11 +1072,6 @@ bool defaults_enabled(void)
 return has_defaults;
 }
 
-bool usb_enabled(void)
-{
-return machine_usb(current_machine);
-}
-
 #ifndef _WIN32
 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
 {
@@ -1393,7 +1388,7 @@ static int usb_device_add(const char *devname)
 const char *p;
 #endif
 
-if (!usb_enabled()) {
+if (!machine_usb(current_machine)) {
 return -1;
 }
 
@@ -1425,7 +1420,7 @@ static int usb_device_del(const char *devname)
 return -1;
 }
 
-if (!usb_enabled()) {
+if (!machine_usb(current_machine)) {
 return -1;
 }
 
@@ -4501,7 +4496,7 @@ int main(int argc, char **argv, char **envp)
 }
 
 /* init USB devices */
-

[Qemu-devel] [PATCH v2 1/2] pxa2xx: Unconditionally enable USB controller

2016-06-08 Thread Eduardo Habkost
Simplify initialization logic by removing the usb_enabled()
check. The USB controller is part of the SoC, so it doesn't make
sense to create a system where it is not present.

Cc: Peter Maydell 
Cc: Andrzej Zaborowski 
Cc: qemu-...@nongnu.org,
Signed-off-by: Eduardo Habkost 
---
 hw/arm/pxa2xx.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
index e41a7c9..cb55704 100644
--- a/hw/arm/pxa2xx.c
+++ b/hw/arm/pxa2xx.c
@@ -2165,10 +2165,8 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
 s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
 }
 
-if (usb_enabled()) {
-sysbus_create_simple("sysbus-ohci", 0x4c00,
-qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
-}
+sysbus_create_simple("sysbus-ohci", 0x4c00,
+ qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
 
 s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x2000);
 s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x3000);
@@ -2298,10 +2296,8 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, 
unsigned int sdram_size)
 s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
 }
 
-if (usb_enabled()) {
-sysbus_create_simple("sysbus-ohci", 0x4c00,
-qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
-}
+sysbus_create_simple("sysbus-ohci", 0x4c00,
+ qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
 
 s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x2000);
 s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x3000);
-- 
2.5.5




Re: [Qemu-devel] [PATCH v7 08/15] qdist: add module to represent frequency distributions of data

2016-06-08 Thread Sergey Fedorov
On 08/06/16 21:55, Emilio G. Cota wrote:
> Sometimes it is useful to have a quick histogram to represent a certain
> distribution -- for example, when investigating a performance regression
> in a hash table due to inadequate hashing.
>
> The appended allows us to easily represent a distribution using Unicode
> characters. Further, the data structure keeping track of the distribution
> is so simple that obtaining its values for off-line processing is trivial.
>
> Example, taking the last 10 commits to QEMU:
>
>  Characters in commit title  Count
> ---
>  39  1
>  48  1
>  53  1
>  54  2
>  57  1
>  61  1
>  67  1
>  78  1
>  80  1
> qdist_init(&dist);
> qdist_inc(&dist, 39);
> [...]
> qdist_inc(&dist, 80);
>
> char *str = qdist_pr(&dist, 9, QDIST_PR_LABELS);
> // -> [39.0,43.6)▂▂ █▂ ▂ ▄[75.4,80.0]
> g_free(str);
>
> char *str = qdist_pr(&dist, 4, QDIST_PR_LABELS);
> // -> [39.0,49.2)▁█▁▁[69.8,80.0]
> g_free(str);
>
> Reviewed-by: Richard Henderson 
> Signed-off-by: Emilio G. Cota 

Reviewed-by: Sergey Fedorov 


> ---
>  include/qemu/qdist.h |  63 
>  util/Makefile.objs   |   1 +
>  util/qdist.c | 395 
> +++
>  3 files changed, 459 insertions(+)
>  create mode 100644 include/qemu/qdist.h
>  create mode 100644 util/qdist.c
>
> diff --git a/include/qemu/qdist.h b/include/qemu/qdist.h
> new file mode 100644
> index 000..f30050c
> --- /dev/null
> +++ b/include/qemu/qdist.h
> @@ -0,0 +1,63 @@
> +/*
> + * Copyright (C) 2016, Emilio G. Cota 
> + *
> + * License: GNU GPL, version 2 or later.
> + *   See the COPYING file in the top-level directory.
> + */
> +#ifndef QEMU_QDIST_H
> +#define QEMU_QDIST_H
> +
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "qemu/bitops.h"
> +
> +/*
> + * Samples with the same 'x value' end up in the same qdist_entry,
> + * e.g. inc(0.1) and inc(0.1) end up as {x=0.1, count=2}.
> + *
> + * Binning happens only at print time, so that we retain the flexibility to
> + * choose the binning. This might not be ideal for workloads that do not care
> + * much about precision and insert many samples all with different x values;
> + * in that case, pre-binning (e.g. entering both 0.115 and 0.097 as 0.1)
> + * should be considered.
> + */
> +struct qdist_entry {
> +double x;
> +unsigned long count;
> +};
> +
> +struct qdist {
> +struct qdist_entry *entries;
> +size_t n;
> +size_t size;
> +};
> +
> +#define QDIST_PR_BORDER BIT(0)
> +#define QDIST_PR_LABELS BIT(1)
> +/* the remaining options only work if PR_LABELS is set */
> +#define QDIST_PR_NODECIMAL  BIT(2)
> +#define QDIST_PR_PERCENTBIT(3)
> +#define QDIST_PR_100X   BIT(4)
> +#define QDIST_PR_NOBINRANGE BIT(5)
> +
> +void qdist_init(struct qdist *dist);
> +void qdist_destroy(struct qdist *dist);
> +
> +void qdist_add(struct qdist *dist, double x, long count);
> +void qdist_inc(struct qdist *dist, double x);
> +double qdist_xmin(const struct qdist *dist);
> +double qdist_xmax(const struct qdist *dist);
> +double qdist_avg(const struct qdist *dist);
> +unsigned long qdist_sample_count(const struct qdist *dist);
> +size_t qdist_unique_entries(const struct qdist *dist);
> +
> +/* callers must free the returned string with g_free() */
> +char *qdist_pr_plain(const struct qdist *dist, size_t n_groups);
> +
> +/* callers must free the returned string with g_free() */
> +char *qdist_pr(const struct qdist *dist, size_t n_groups, uint32_t opt);
> +
> +/* Only qdist code and test code should ever call this function */
> +void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t 
> n);
> +
> +#endif /* QEMU_QDIST_H */
> diff --git a/util/Makefile.objs b/util/Makefile.objs
> index a8a777e..702435e 100644
> --- a/util/Makefile.objs
> +++ b/util/Makefile.objs
> @@ -32,3 +32,4 @@ util-obj-y += buffer.o
>  util-obj-y += timed-average.o
>  util-obj-y += base64.o
>  util-obj-y += log.o
> +util-obj-y += qdist.o
> diff --git a/util/qdist.c b/util/qdist.c
> new file mode 100644
> index 000..4ea2e34
> --- /dev/null
> +++ b/util/qdist.c
> @@ -0,0 +1,395 @@
> +/*
> + * qdist.c - QEMU helpers for handling frequency distributions of data.
> + *
> + * Copyright (C) 2016, Emilio G. Cota 
> + *
> + * License: GNU GPL, version 2 or later.
> + *   See the COPYING file in the top-level directory.
> + */
> +#include "qemu/qdist.h"
> +
> +#include 
> +#ifndef NAN
> +#define NAN (0.0 / 0.0)
> +#endif
> +
> +void qdist_init(struct qdist *dist)
> +{
> +dist->entries = g_malloc(sizeof(*dist->entries));
> +dist->size = 1;
> +dist->n = 0;
> +}
> +
> +void qdist_destroy(struct qdist *dist)
> +{
> +g_free(dist->entries);
> +}
> +
> +static inline in

Re: [Qemu-devel] [Qemu-devel [RFC] [WIP] v2] Keeping the Source side alive incase of network failure (Migration recovery from network failure)

2016-06-08 Thread Eric Blake
On 06/08/2016 12:13 PM, Md Haris Iqbal wrote:

The subject line is long, and has a typo (s/incase/in case/).  Also, the
mailing list automatically prepends [Qemu-devel], so you shouldn't
repeat it manually.  Better might have been a short subject line then a
longer commit body:

migration: keep source alive on network failure

Details about what was failing, and why this code improves it

Missing a Signed-off-by: attribution; without that, we can't take it.

> ---

You marked this patch as v2, but in the same minute sent another email
with subject line v1, and didn't say what changed to need a v2. Here
after the --- divider is a good place for that.

>  include/migration/migration.h |  1 +
>  migration/migration.c | 76 
> ---
>  qapi-schema.json  | 11 +--
>  vl.c  |  4 +++
>  4 files changed, 85 insertions(+), 7 deletions(-)
> 

> @@ -1726,11 +1755,32 @@ static void *migration_thread(void *opaque)
>  }
>  }
>  
> -if (qemu_file_get_error(s->to_dst_file)) {
> -migrate_set_state(&s->state, current_active_state,
> -  MIGRATION_STATUS_FAILED);
> -trace_migration_thread_file_err();
> -break;
> +if ((ret = qemu_file_get_error(s->to_dst_file))) {
> +fprintf(stderr, "1 : Error %s %d\n", strerror(-ret), -ret);

fprintf() is rather awkward for errors; can we use qemu's Error mechanism?

> +
> +/*  This check is based on how the error is set during the 
> network
> + *  recv(). When recv() returns 0 (i.e. no data to read), the 
> error
> + *  is set to -EIO. For all other network errors, it is set
> + *  according to the return value received.
> + */
> +if (ret != -EIO && s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) 
> {
> +/* Network Failure during postcopy */
> +
> +current_active_state = MIGRATION_STATUS_POSTCOPY_RECOVERY;
> +runstate_set(RUN_STATE_POSTMIGRATE_RECOVERY);
> +fprintf(stderr, "1.1 : Error %s %d\n", strerror(-ret), -ret);

Does the end user really need to see "1.1 :"


> +++ b/qapi-schema.json
> @@ -154,12 +154,14 @@
>  # @watchdog: the watchdog action is configured to pause and has been 
> triggered
>  #
>  # @guest-panicked: guest has been panicked as a result of guest OS panic
> +#
> +# @postmigrate-recovery: guest is paused for recovery after a network failure

Not your fault that the overall enum is missing an overall line:

# Since: 1.4

nor that guest-panicked is missing a "(since 1.5)" hint, but at least
your addition should have a "(since 2.7)" hint.

>  ##
>  { 'enum': 'RunState',
>'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused',
>  'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm',
>  'running', 'save-vm', 'shutdown', 'suspended', 'watchdog',
> -'guest-panicked' ] }
> +'guest-panicked', 'postmigrate-recovery' ] }

Adding new enums can cause existing clients like libvirt to do weird
things if they aren't expecting the new state. Are we sure we want to do
it?  Is it a state that cannot be entered by default, but only in
response to a client request that proves the client is new enough to
expect the new state?

>  
>  ##
>  # @StatusInfo:
> @@ -434,12 +436,15 @@
>  #
>  # @failed: some error occurred during migration process.
>  #
> +# @postcopy-recovery: in recovery mode, after a network failure.
> +#

Missing a "(since 2.7)" hint.

>  # Since: 2.3
>  #
>  ##
>  { 'enum': 'MigrationStatus',
>'data': [ 'none', 'setup', 'cancelling', 'cancelled',
> -'active', 'postcopy-active', 'completed', 'failed' ] }
> +'active', 'postcopy-active', 'completed', 'failed',
> +'postcopy-recovery' ] }
>  
>  ##
>  # @MigrationInfo
> @@ -2058,6 +2063,8 @@
>  #
>  # @uri: the Uniform Resource Identifier of the destination VM
>  #
> +# @recover: #optional recover from a broken migration
> +#

I don't see any 'recover' parameter added to the 'migrate' command to
match this added documentation.

>  # @blk: #optional do block migration (full disk copy)
>  #
>  # @inc: #optional incremental disk copy migration
> diff --git a/vl.c b/vl.c
> index 5fd22cb..c237140 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -618,6 +618,10 @@ static const RunStateTransition 
> runstate_transitions_def[] = {
>  { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
>  { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
>  { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
> +{ RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE_RECOVERY },
> +
> +{ RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_FINISH_MIGRATE },
> +{ RUN_STATE_POSTMIGRATE_RECOVERY, RUN_STATE_SHUTDOWN },
>  
>  { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
>  { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
> 

--

[Qemu-devel] [PATCH] maint: Ignore generated version file

2016-06-08 Thread Eric Blake
Commit 67a1de0d created a generated version file, and, in some
circumstances, also a temporary file.  Make sure 'git add .'
won't check them into the repository.

Signed-off-by: Eric Blake 
---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitignore b/.gitignore
index 38ee1c5..7a4ee01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,6 +52,8 @@
 /qemu-bridge-helper
 /qemu-monitor.texi
 /qemu-monitor-info.texi
+/qemu-version.h
+/qemu-version.h.tmp
 /qmp-commands.txt
 /vscclient
 /fsdev/virtfs-proxy-helper
-- 
2.5.5




[Qemu-devel] [PATCH 1/5] linux-user: add socketcall() strace

2016-06-08 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 include/exec/user/abitypes.h |  23 ++
 linux-user/strace.c  | 550 +++
 linux-user/strace.list   |   2 +-
 linux-user/syscall_defs.h|  22 +-
 4 files changed, 592 insertions(+), 5 deletions(-)

diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
index 80eedac..e33b1f8 100644
--- a/include/exec/user/abitypes.h
+++ b/include/exec/user/abitypes.h
@@ -46,6 +46,15 @@ static inline abi_ulong tswapal(abi_ulong v)
 return tswap32(v);
 }
 
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+return v;
+#else
+return bswap_32(v);
+#endif
+}
+
 #else
 typedef target_ulong abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
 typedef target_long abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
@@ -62,5 +71,19 @@ static inline abi_ulong tswapal(abi_ulong v)
 return tswapl(v);
 }
 
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+return v;
+#else
+#if TARGET_LONG_SIZE == 4
+return bswap_32(v);
+#else
+return bswap_64(v);
+#endif
+#endif
+}
+
+
 #endif
 #endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0810c85..a7b24e2 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -6,6 +6,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include "qemu.h"
 
@@ -58,10 +61,15 @@ UNUSED static void print_open_flags(abi_long, int);
 UNUSED static void print_syscall_prologue(const struct syscallname *);
 UNUSED static void print_syscall_epilogue(const struct syscallname *);
 UNUSED static void print_string(abi_long, int);
+UNUSED static void print_buf(abi_long addr, abi_long len, int last);
 UNUSED static void print_raw_param(const char *, abi_long, int);
 UNUSED static void print_timeval(abi_ulong, int);
 UNUSED static void print_number(abi_long, int);
 UNUSED static void print_signal(abi_ulong, int);
+UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen);
+UNUSED static void print_socket_domain(int domain);
+UNUSED static void print_socket_type(int type);
+UNUSED static void print_socket_protocol(int domain, int type, int protocol);
 
 /*
  * Utility functions
@@ -147,6 +155,165 @@ print_signal(abi_ulong arg, int last)
 gemu_log("%s%s", signal_name, get_comma(last));
 }
 
+static void
+print_sockaddr(abi_ulong addr, abi_long addrlen)
+{
+struct target_sockaddr *sa;
+int i;
+int sa_family;
+
+sa = lock_user(VERIFY_READ, addr, addrlen, 1);
+if (sa) {
+sa_family = tswap16(sa->sa_family);
+switch (sa_family) {
+case AF_UNIX: {
+struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
+int i;
+gemu_log("{sun_family=AF_UNIX,sun_path=\"");
+for (i = 0; i < addrlen -
+offsetof(struct target_sockaddr_un, sun_path) &&
+ un->sun_path[i]; i++) {
+gemu_log("%c", un->sun_path[i]);
+}
+gemu_log("\"}");
+break;
+}
+case AF_INET: {
+struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
+uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
+gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
+ ntohs(in->sin_port));
+gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
+ c[0], c[1], c[2], c[3]);
+gemu_log("}");
+break;
+}
+case AF_PACKET: {
+struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
+uint8_t *c = (uint8_t *)&ll->sll_addr;
+gemu_log("{sll_family=AF_PACKET,"
+ "sll_protocol=htons(0x%04x),if%d,pkttype=",
+ ntohs(ll->sll_protocol), ll->sll_ifindex);
+switch (ll->sll_pkttype) {
+case PACKET_HOST:
+gemu_log("PACKET_HOST");
+break;
+case PACKET_BROADCAST:
+gemu_log("PACKET_BROADCAST");
+break;
+case PACKET_MULTICAST:
+gemu_log("PACKET_MULTICAST");
+break;
+case PACKET_OTHERHOST:
+gemu_log("PACKET_OTHERHOST");
+break;
+case PACKET_OUTGOING:
+gemu_log("PACKET_OUTGOING");
+break;
+default:
+gemu_log("%d", ll->sll_pkttype);
+break;
+}
+gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
+ c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
+gemu_log("}");
+break;
+}
+default:
+gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
+for (i = 0; i < 13; i++) {
+gemu_log("%02x, ", sa->sa_data[i]);
+}
+gemu_log

[Qemu-devel] [PATCH 2/5] linux-user: correct setsockopt() strace.

2016-06-08 Thread Laurent Vivier
From: Laurent Vivier 

Parameter of SO_RCVTIMEO and SO_SNDTIMEO is timeval, not int.

To test this, you can use :

QEMU_STRACE= ping localhost 2>&1 |grep TIMEO
568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0
568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0

Signed-off-by: Laurent Vivier 
---
 linux-user/strace.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index a7b24e2..398e56e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1486,10 +1486,12 @@ print_optint:
 goto print_optint;
 case TARGET_SO_RCVTIMEO:
 gemu_log("SO_RCVTIMEO,");
-goto print_optint;
+print_timeval(optval, 0);
+break;
 case TARGET_SO_SNDTIMEO:
 gemu_log("SO_SNDTIMEO,");
-goto print_optint;
+print_timeval(optval, 0);
+break;
 case TARGET_SO_ATTACH_FILTER: {
 struct target_sock_fprog *fprog;
 
-- 
2.5.5




[Qemu-devel] [PATCH 5/5] linux-user: update get_thread_area/set_thread_area strace

2016-06-08 Thread Laurent Vivier
   int get_thread_area(struct user_desc *u_info);
   int set_thread_area(struct user_desc *u_info);

Signed-off-by: Laurent Vivier 
---
 linux-user/strace.list | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 7c54dc6..9c0259c 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -337,7 +337,7 @@
 { TARGET_NR_getsockopt, "getsockopt" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_get_thread_area
-{ TARGET_NR_get_thread_area, "get_thread_area" , NULL, NULL, NULL },
+{ TARGET_NR_get_thread_area, "get_thread_area", "%s(%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_gettid
 { TARGET_NR_gettid, "gettid" , NULL, NULL, NULL },
@@ -1234,7 +1234,7 @@
 { TARGET_NR_setsockopt, "setsockopt" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_set_thread_area
-{ TARGET_NR_set_thread_area, "set_thread_area" , NULL, NULL, NULL },
+{ TARGET_NR_set_thread_area, "set_thread_area", "%s(%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_set_tid_address
 { TARGET_NR_set_tid_address, "set_tid_address" , NULL, NULL, NULL },
-- 
2.5.5




[Qemu-devel] [PATCH 3/5] linux-user: add socket() strace

2016-06-08 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/strace.c| 24 
 linux-user/strace.list |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 398e56e..0c3675c 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1221,6 +1221,30 @@ print__llseek(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_socket)
+static void
+print_socket(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+abi_ulong domain = arg0, type = arg1, protocol = arg2;
+
+print_syscall_prologue(name);
+print_socket_domain(domain);
+gemu_log(",");
+print_socket_type(type);
+gemu_log(",");
+if (domain == AF_PACKET ||
+type == TARGET_SOCK_PACKET) {
+protocol = tswapal(protocol); /* restore network endian long */
+protocol = abi_ntohl(protocol); /* a host endian long */
+}
+print_socket_protocol(domain, type, protocol);
+print_syscall_epilogue(name);
+}
+
+#endif
+
 #if defined(TARGET_NR_socketcall)
 static void
 print_socketcall(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index b379497..7c54dc6 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1291,7 +1291,7 @@
 { TARGET_NR_sigsuspend, "sigsuspend" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_socket
-{ TARGET_NR_socket, "socket" , NULL, NULL, NULL },
+{ TARGET_NR_socket, "socket" , NULL, print_socket, NULL },
 #endif
 #ifdef TARGET_NR_socketcall
 { TARGET_NR_socketcall, "socketcall" , NULL, print_socketcall, NULL },
-- 
2.5.5




[Qemu-devel] [PATCH 4/5] linux-user: fix clone() strace

2016-06-08 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/strace.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0c3675c..ec39750 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -964,27 +964,30 @@ print_clone(const struct syscallname *name,
 abi_long arg3, abi_long arg4, abi_long arg5)
 {
 print_syscall_prologue(name);
-#if defined(TARGET_M68K)
+#if defined(TARGET_MICROBLAZE)
 print_flags(clone_flags, arg0, 0);
-print_raw_param("newsp=0x" TARGET_ABI_FMT_lx, arg1, 1);
-#elif defined(TARGET_SH4) || defined(TARGET_ALPHA)
+print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
+print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
+print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg5, 0);
+print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
+#elif defined(TARGET_CLONE_BACKWARDS)
 print_flags(clone_flags, arg0, 0);
 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
-print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 0);
-print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 1);
-#elif defined(TARGET_CRIS)
-print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
+print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
+print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
+#elif defined(TARGET_CLONE_BACKWARDS2)
 print_flags(clone_flags, arg1, 0);
+print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg0, 0);
 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
-print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
-print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
+print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 0);
+print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 1);
 #else
 print_flags(clone_flags, arg0, 0);
 print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, arg1, 0);
 print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, arg2, 0);
-print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg3, 0);
-print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg4, 1);
+print_raw_param("tls=0x" TARGET_ABI_FMT_lx, arg4, 0);
+print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, arg3, 1);
 #endif
 print_syscall_epilogue(name);
 }
-- 
2.5.5




[Qemu-devel] [PATCH 0/5] linux-user: some strace improvements

2016-06-08 Thread Laurent Vivier
These patches for linux-user strace are living for years in my tree.

Laurent Vivier (5):
  linux-user: add socketcall() strace
  linux-user: correct setsockopt() strace.
  linux-user: add socket() strace
  linux-user: fix clone() strace
  linux-user: update get_thread_area/set_thread_area strace

 include/exec/user/abitypes.h |  23 ++
 linux-user/strace.c  | 601 ++-
 linux-user/strace.list   |   8 +-
 linux-user/syscall_defs.h|  22 +-
 4 files changed, 635 insertions(+), 19 deletions(-)

-- 
2.5.5




Re: [Qemu-devel] [PATCH] pc: Add 2.7 machine

2016-06-08 Thread Eduardo Habkost
On Fri, May 27, 2016 at 03:55:35PM -0300, Eduardo Habkost wrote:
> From: Igor Mammedov 
> 
> Signed-off-by: Igor Mammedov 
> Reviewed-by: Eduardo Habkost 
> Signed-off-by: Eduardo Habkost 
> ---
> This is blocking some patches from getting included (e.g.  the
> CPUID[0xB] patch from Radim), so I'm submitting Igor's RFC as
> [PATCH].
> 
> I will add it to my x86-next queue so I can queue x86 patches
> that depend on it. But I plan to wait until it gets merged
> through the PC tree and rebase before sending a x86 pull request.

Since it was not merged in the PC tree yet and x86 patches depend
on it, I will include it in my next x86 pull request.

-- 
Eduardo



Re: [Qemu-devel] [RFC PATCH] configure: Enable -Werror for MinGW builds, too

2016-06-08 Thread Stefan Weil
Am 08.06.2016 um 20:55 schrieb Peter Maydell:
> On 8 June 2016 at 15:09, Stefan Hajnoczi  wrote:
>> On Wed, Jun 08, 2016 at 10:13:26AM +0200, Thomas Huth wrote:
>>> MinGW seems to compile currently without warnings, so it should
>>> be safe to enable -Werror now for this environment, too.
>>>
>>> Signed-off-by: Thomas Huth 
>>> ---
>>>  ... at least it compiles without errors for me here. I hope that's
>>>  also true for different versions of MinGW ... would be great if
>>>  everybody who has such a compiler installed could give it a try!
>>>
>>>  configure | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> mingw 5.2.0-1.fc23 does not produce any warnings anymore.
>>
>> Tested-by: Stefan Hajnoczi 
> 
> My w32/w64 builds need -Wno-unused-local-typedefs to build
> with -Werror, but that's the fault of the glib headers I build
> against and I already configure like that in order to use -Werror.
> 
> We should check whether we can enable -Werror for OSX too.
> 
> thanks
> -- PMM

The last time when I tried OS X there were some deprecation warnings.
If those are fixed now we can enable -Werror for all target platforms
(we could do that anyway because in case of problems it's always
possible to disable it for individual builds).

Stefan





signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v4 1/9] target-avr: AVR cores support is added. 1. basic CPU structure 2. registers 3. no instructions

2016-06-08 Thread Michael Rolnik
Hi Richard.

how can I test it?

On Tue, Jun 7, 2016 at 5:28 PM, Richard Henderson  wrote:

> On 06/06/2016 11:32 PM, Michael Rolnik wrote:
> > Hi Richard,
> >
> > /Consider making the vm save state reflect the actual hardware format.
> That
> > way you can change the qemu internal format while retaining migration
> > compatibility./
> >
> > How it can be done? how can I modify a value passed to VMSTATE_UINT32?
>
> There are two different ways.  You can see both of them in use in
> target-i386.
>
> The first is to manually describe the field, using custom get and put
> fields.
> For example:
>
> static const VMStateInfo vmstate_fpreg = {
> .name = "fpreg",
> .get  = get_fpreg,
> .put  = put_fpreg,
> };
>
>
> The second is to reserve extra space for the external representation and
> then
> use the pre_save / post_load hooks.  For i386, see the cpu_pre_save, where
> we
> take the fpus, fpstt, and fptags fields and store them into the
> fpus_vmstate
> field.  It is then the vmstate field that is mentioned in vmstate_x86_cpu.
>
> I personally prefer the get/put fields, but I admit they can be tricky to
> use.
>
>
> r~
>



-- 
Best Regards,
Michael Rolnik


[Qemu-devel] [PATCH v7 02/15] seqlock: remove optional mutex

2016-06-08 Thread Emilio G. Cota
This option is unused; besides, it bloats the struct when not needed.
Let's just let writers define their own locks elsewhere.

Reviewed-by: Sergey Fedorov 
Reviewed-by: Alex Bennée 
Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 cpus.c |  2 +-
 include/qemu/seqlock.h | 10 +-
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/cpus.c b/cpus.c
index 326742f..1c92362 100644
--- a/cpus.c
+++ b/cpus.c
@@ -621,7 +621,7 @@ int cpu_throttle_get_percentage(void)
 
 void cpu_ticks_init(void)
 {
-seqlock_init(&timers_state.vm_clock_seqlock, NULL);
+seqlock_init(&timers_state.vm_clock_seqlock);
 vmstate_register(NULL, 0, &vmstate_timers, &timers_state);
 throttle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,
cpu_throttle_timer_tick, NULL);
diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h
index 70b01fd..e673482 100644
--- a/include/qemu/seqlock.h
+++ b/include/qemu/seqlock.h
@@ -19,22 +19,17 @@
 typedef struct QemuSeqLock QemuSeqLock;
 
 struct QemuSeqLock {
-QemuMutex *mutex;
 unsigned sequence;
 };
 
-static inline void seqlock_init(QemuSeqLock *sl, QemuMutex *mutex)
+static inline void seqlock_init(QemuSeqLock *sl)
 {
-sl->mutex = mutex;
 sl->sequence = 0;
 }
 
 /* Lock out other writers and update the count.  */
 static inline void seqlock_write_lock(QemuSeqLock *sl)
 {
-if (sl->mutex) {
-qemu_mutex_lock(sl->mutex);
-}
 ++sl->sequence;
 
 /* Write sequence before updating other fields.  */
@@ -47,9 +42,6 @@ static inline void seqlock_write_unlock(QemuSeqLock *sl)
 smp_wmb();
 
 ++sl->sequence;
-if (sl->mutex) {
-qemu_mutex_unlock(sl->mutex);
-}
 }
 
 static inline unsigned seqlock_read_begin(QemuSeqLock *sl)
-- 
2.5.0




Re: [Qemu-devel] [Qemu-stable] [PATCH V2] net: fix qemu_announce_self not emitting packets

2016-06-08 Thread Peter Lieven
Am 08.06.2016 um 12:23 schrieb Paolo Bonzini:
>
> - Original Message -
>> From: "Jason Wang" 
>> To: "Peter Lieven" , qemu-devel@nongnu.org
>> Cc: pbonz...@redhat.com, qemu-sta...@nongnu.org, "hongyang yang" 
>> 
>> Sent: Wednesday, June 8, 2016 9:54:53 AM
>> Subject: Re: [Qemu-devel] [Qemu-stable] [PATCH V2] net: fix 
>> qemu_announce_self not emitting packets
>>
>>
>>
>> On 2016年06月08日 15:13, Peter Lieven wrote:
>>> Am 08.06.2016 um 08:39 schrieb Jason Wang:
 On 2016年06月07日 21:00, Peter Lieven wrote:
> commit fefe2a78 accidently dropped the code path for injecting
> raw packets. This feature is needed for sending gratuitous ARPs
> after an incoming migration has completed. The result is increased
> network downtime for vservers where the network card is not virtio-net
> with the VIRTIO_NET_F_GUEST_ANNOUNCE feature.
>
> Fixes: fefe2a78abde932e0f340b21bded2c86def1d242
> Cc: qemu-sta...@nongnu.org
> Cc: hongyang.y...@easystack.cn
> Signed-off-by: Peter Lieven 
> ---
> v1->v2: assert that only raw packets with a plain buffer come in. [Paolo]
>
>net/net.c | 10 +-
>1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/net/net.c b/net/net.c
> index 5f3e5a9..5e1b5fa 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -714,6 +714,11 @@ ssize_t qemu_deliver_packet_iov(NetClientState
> *sender,
>NetClientState *nc = opaque;
>int ret;
>+/* we currently only support sending raw packets via
>qemu_send_packet_raw.
> + * If we want generic raw iov support we need to implement something
> like
> + * .receive_raw_iov in NetClientInfo first. */
> +assert(!(flags & QEMU_NET_PACKET_FLAG_RAW) || iovcnt == 1);
> +
>if (nc->link_down) {
>return iov_size(iov, iovcnt);
>}
> @@ -722,7 +727,10 @@ ssize_t qemu_deliver_packet_iov(NetClientState
> *sender,
>return 0;
>}
>-if (nc->info->receive_iov) {
> +if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {
> +/* this is required for qemu_announce_self() */
> +ret = nc->info->receive_raw(nc, iov[0].iov_base,
> iov[0].iov_len);
> +} else  if (nc->info->receive_iov) {
>ret = nc->info->receive_iov(nc, iov, iovcnt);
>} else {
>ret = nc_sendv_compat(nc, iov, iovcnt, flags);
 We still have raw packet support in nv_sendv_compat, can we use it? (and
 then there's no need for the assert above).
>>> Okay, so Version 1 of the patch is more appropiate. I would either use V1
>>> or revert fefe2a78. The issue is quite serious
>>> for live migration.
> Or you can do even simpler:
>
> if (nc->info->receive_iov && !(flags & QEMU_NET_PACKET_FLAG_RAW)))
> nc->info->receive_iov
> else
> nc_sendv_compat

I should have looked into this nc_sendv_compat function before ;-)
This indeed is the best solution I think.

Will send a v3 tomorrow.

Peter




[Qemu-devel] [PATCH v7 00/15] tb hash improvements

2016-06-08 Thread Emilio G. Cota
v6 on qemu-devel:
  https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg04251.html

All changes in this iteration come from comments by Sergey
unless otherwise noted. All patches are checkpatch-clean
once false positives are taken into account.

Changes from v6:

- Add reviewed-by tags from v6.

- Rebase on top of current master 6ed5546f to accommodate the addition
  of include/exec/tb-context.h (pointed out by Alex)

- qht:
  + use call_rcu instead of call_rcu1
  + remove forward declaration of qht_grow_maybe
  + s/fill_hole/remove_entry/
  + use do..while() in insert__locked instead of for(;;)
  + trivial: fix a couple of whitespace issues

- qht-bench:
  + call rcu_register_thread before waiting for test_start to be set
  + use offset param in the thread function
  + start tests only after all of them have been initialised
  + Update qht-bench commit message to describe how the data for
the plots is generated (suggested by Alex)
  + add -g option to set -s,-k,-K,-l,-r at once (Emilio)

- test-qht-par: fix invocation of qht-bench

- qdist:
  + use g_new instead of g_malloc where appropriate
  + use pairwise summation for calculating the average, with 8 as the
base case
  + double size on each expansion instead of just adding one element
  + shorten the binning loop by using while() instead of for()
  + bug fix: for certain counts, max was being printed as 7/8 instead of
8/8. (Emilio)

- test-qdist:
  + add test to check for the qdist bug fixed above (Emilio)

Thanks,

Emilio




[Qemu-devel] [PATCH v7 05/15] qemu-thread: add simple test-and-set spinlock

2016-06-08 Thread Emilio G. Cota
From: Guillaume Delbergue 

Reviewed-by: Sergey Fedorov 
Signed-off-by: Guillaume Delbergue 
[Rewritten. - Paolo]
Signed-off-by: Paolo Bonzini 
[Emilio's additions: use TAS instead of atomic_xchg; emit acquire/release
 barriers; return bool from trylock; call cpu_relax() while spinning;
 optimize for uncontended locks by acquiring the lock with TAS instead
 of TATAS; add qemu_spin_locked().]
Signed-off-by: Emilio G. Cota 
---
 include/qemu/thread.h | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/include/qemu/thread.h b/include/qemu/thread.h
index bdae6df..c5d71cf 100644
--- a/include/qemu/thread.h
+++ b/include/qemu/thread.h
@@ -1,6 +1,8 @@
 #ifndef __QEMU_THREAD_H
 #define __QEMU_THREAD_H 1
 
+#include "qemu/processor.h"
+#include "qemu/atomic.h"
 
 typedef struct QemuMutex QemuMutex;
 typedef struct QemuCond QemuCond;
@@ -60,4 +62,37 @@ struct Notifier;
 void qemu_thread_atexit_add(struct Notifier *notifier);
 void qemu_thread_atexit_remove(struct Notifier *notifier);
 
+typedef struct QemuSpin {
+int value;
+} QemuSpin;
+
+static inline void qemu_spin_init(QemuSpin *spin)
+{
+__sync_lock_release(&spin->value);
+}
+
+static inline void qemu_spin_lock(QemuSpin *spin)
+{
+while (unlikely(__sync_lock_test_and_set(&spin->value, true))) {
+while (atomic_read(&spin->value)) {
+cpu_relax();
+}
+}
+}
+
+static inline bool qemu_spin_trylock(QemuSpin *spin)
+{
+return __sync_lock_test_and_set(&spin->value, true);
+}
+
+static inline bool qemu_spin_locked(QemuSpin *spin)
+{
+return atomic_read(&spin->value);
+}
+
+static inline void qemu_spin_unlock(QemuSpin *spin)
+{
+__sync_lock_release(&spin->value);
+}
+
 #endif
-- 
2.5.0




[Qemu-devel] [PATCH v7 15/15] translate-all: add tb hash bucket info to 'info jit' dump

2016-06-08 Thread Emilio G. Cota
Examples:

- Good hashing, i.e. tb_hash_func5(phys_pc, pc, flags):
TB count715135/2684354
[...]
TB hash buckets 388775/524288 (74.15% head buckets used)
TB hash occupancy   33.04% avg chain occ. Histogram: [0,10)%|▆ █  
▅▁▃▁▁|[90,100]%
TB hash avg chain   1.017 buckets. Histogram: 1|█▁▁|3

- Not-so-good hashing, i.e. tb_hash_func5(phys_pc, pc, 0):
TB count712636/2684354
[...]
TB hash buckets 344924/524288 (65.79% head buckets used)
TB hash occupancy   31.64% avg chain occ. Histogram: [0,10)%|█ ▆  
▅▁▃▁▂|[90,100]%
TB hash avg chain   1.047 buckets. Histogram: 1|█▁▁▁|4

- Bad hashing, i.e. tb_hash_func5(phys_pc, 0, 0):
TB count702818/2684354
[...]
TB hash buckets 112741/524288 (21.50% head buckets used)
TB hash occupancy   10.15% avg chain occ. Histogram: [0,10)%|█ ▁  
▁|[90,100]%
TB hash avg chain   2.107 buckets. Histogram: [1.0,10.2)|█▁|[83.8,93.0]

- Good hashing, but no auto-resize:
TB count715634/2684354
TB hash buckets 8192/8192 (100.00% head buckets used)
TB hash occupancy   98.30% avg chain occ. Histogram: 
[95.3,95.8)%|▁▁▃▄▃▄▁▇▁█|[99.5,100.0]%
TB hash avg chain   22.070 buckets. Histogram: 
[15.0,16.7)|▁▂▅▄█▅|[30.3,32.0]

Acked-by: Sergey Fedorov 
Suggested-by: Richard Henderson 
Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 translate-all.c | 36 
 1 file changed, 36 insertions(+)

diff --git a/translate-all.c b/translate-all.c
index 4edea75..625411f 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -1667,6 +1667,10 @@ void dump_exec_info(FILE *f, fprintf_function 
cpu_fprintf)
 int i, target_code_size, max_target_code_size;
 int direct_jmp_count, direct_jmp2_count, cross_page;
 TranslationBlock *tb;
+struct qht_stats hst;
+uint32_t hgram_opts;
+size_t hgram_bins;
+char *hgram;
 
 target_code_size = 0;
 max_target_code_size = 0;
@@ -1717,6 +1721,38 @@ void dump_exec_info(FILE *f, fprintf_function 
cpu_fprintf)
 direct_jmp2_count,
 tcg_ctx.tb_ctx.nb_tbs ? (direct_jmp2_count * 100) /
 tcg_ctx.tb_ctx.nb_tbs : 0);
+
+qht_statistics_init(&tcg_ctx.tb_ctx.htable, &hst);
+
+cpu_fprintf(f, "TB hash buckets %zu/%zu (%0.2f%% head buckets used)\n",
+hst.used_head_buckets, hst.head_buckets,
+(double)hst.used_head_buckets / hst.head_buckets * 100);
+
+hgram_opts =  QDIST_PR_BORDER | QDIST_PR_LABELS;
+hgram_opts |= QDIST_PR_100X   | QDIST_PR_PERCENT;
+if (qdist_xmax(&hst.occupancy) - qdist_xmin(&hst.occupancy) == 1) {
+hgram_opts |= QDIST_PR_NODECIMAL;
+}
+hgram = qdist_pr(&hst.occupancy, 10, hgram_opts);
+cpu_fprintf(f, "TB hash occupancy   %0.2f%% avg chain occ. Histogram: 
%s\n",
+qdist_avg(&hst.occupancy) * 100, hgram);
+g_free(hgram);
+
+hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS;
+hgram_bins = qdist_xmax(&hst.chain) - qdist_xmin(&hst.chain);
+if (hgram_bins > 10) {
+hgram_bins = 10;
+} else {
+hgram_bins = 0;
+hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE;
+}
+hgram = qdist_pr(&hst.chain, hgram_bins, hgram_opts);
+cpu_fprintf(f, "TB hash avg chain   %0.3f buckets. Histogram: %s\n",
+qdist_avg(&hst.chain), hgram);
+g_free(hgram);
+
+qht_statistics_destroy(&hst);
+
 cpu_fprintf(f, "\nStatistics:\n");
 cpu_fprintf(f, "TB flush count  %d\n", tcg_ctx.tb_ctx.tb_flush_count);
 cpu_fprintf(f, "TB invalidate count %d\n",
-- 
2.5.0




[Qemu-devel] [PATCH v7 12/15] qht: add qht-bench, a performance benchmark

2016-06-08 Thread Emilio G. Cota
This serves as a performance benchmark as well as a stress test
for QHT. We can tweak quite a number of things, including the
number of resize threads and how frequently resizes are triggered.

A performance comparison of QHT vs CLHT[1] and ck_hs[2] using
this same benchmark program can be found here:
  http://imgur.com/a/0Bms4

The tests are run on a 64-core AMD Opteron 6376, pinning threads
to cores favoring same-socket cores. For each run, qht-bench is
invoked with:
  $ tests/qht-bench -d $duration -n $n -u $u -g $range
, where $duration is in seconds, $n is the number of threads,
$u is the update rate (0.0 to 100.0), and $range is the number
of keys.

Note that ck_hs's performance drops significantly as writes go
up, since it requires an external lock (I used a ck_spinlock)
around every write.

Also, note that CLHT instead of using a seqlock, relies on an
allocator that does not ever return the same address during the
same read-critical section. This gives it a slight performance
advantage over QHT on read-heavy workloads, since the seqlock
writes aren't there.

[1] CLHT: https://github.com/LPD-EPFL/CLHT
  https://infoscience.epfl.ch/record/207109/files/ascy_asplos15.pdf

[2] ck_hs: http://concurrencykit.org/
   http://backtrace.io/blog/blog/2015/03/13/workload-specialization/

A few of those plots are shown in text here, since that site
might not be online forever. Throughput is on Mops/s on the Y axis.

 200K keys, 0 % updates

  450 ++--+--+--+---+---+---+---+--+---+--++
  |   +  +  +   +   +   +   +  +  +N+  |
  400 ++   ---+E+ ++
  |   +++  |
  350 ++  9 ++--+--++   --+E+-+H+ ++
  | |  +H+- | -+N+    +++  |
  300 ++  8 ++ +E+ ++ -+E+  --+H+ ++
  | |  +++  | -+N+-+H+--   |
  250 ++  7 ++--+--++  +++-+E+++
  200 ++1 -+E+-+H+++
  |    qht +-E--+  |
  150 ++  -+E+clht +-H--+ ++
  |     ck +-N--+  |
  100 ++   +E+++
  ||
   50 ++   -+E+   ++
  |   +E+E+  +  +   +   +   +   +  +   +   |
0 ++--E--+--+---+---+---+---+--+---+--++
  1  8  16  24  32  40  48 56  64
Number of threads

 200K keys, 1 % updates

  350 ++--+--+--+---+---+---+---+--+---+--++
  |   +  +  +   +   +   +   +  + -+E+  |
  300 ++ -+H+ ++
  |   +E+--|
  |   9 ++--+--++  +++ |
  250 ++|  +E+   -- | -+E+++
  |   8 ++ --  ++  |
  200 ++|  +++- |  +++  ---+E+++
  |   7 ++--N--++ -+E+--   qht +-E--+  |
  | 1  +++clht +-H--+  |
  150 ++  -+E+  ck +-N--+ ++
  |    |
  100 ++   +E+++
  ||
  |-+E+|
   50 +++H+-+N++N+-+N+--  ++
  |   +E+E+  +  +   +  +N+-+N+-+N++N+-+N+  |
0 ++--E--+--+---+---+---+---+--+---+--++
  1  8  16  24  32  40  48 56  64
Number of threads

 200K keys, 20 % updates

  300 ++--+--+--+---+---+---+---+--+---+--++
  |   +  +  +   +   +   +   +  +   +   |
  |  -+H+  |
  250 ++  ++
  |   9 ++--+--++   

[Qemu-devel] [PATCH v7 10/15] qht: QEMU's fast, resizable and scalable Hash Table

2016-06-08 Thread Emilio G. Cota
This is a fast, scalable chained hash table with optional auto-resizing, 
allowing
reads that are concurrent with reads, and reads/writes that are concurrent
with writes to separate buckets.

A hash table with these features will be necessary for the scalability
of the ongoing MTTCG work; before those changes arrive we can already
benefit from the single-threaded speedup that qht also provides.

Signed-off-by: Emilio G. Cota 
---
 include/qemu/qht.h | 183 
 util/Makefile.objs |   1 +
 util/qht.c | 833 +
 3 files changed, 1017 insertions(+)
 create mode 100644 include/qemu/qht.h
 create mode 100644 util/qht.c

diff --git a/include/qemu/qht.h b/include/qemu/qht.h
new file mode 100644
index 000..aec60aa
--- /dev/null
+++ b/include/qemu/qht.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_QHT_H
+#define QEMU_QHT_H
+
+#include "qemu/osdep.h"
+#include "qemu/seqlock.h"
+#include "qemu/thread.h"
+#include "qemu/qdist.h"
+
+struct qht {
+struct qht_map *map;
+QemuMutex lock; /* serializes setters of ht->map */
+unsigned int mode;
+};
+
+/**
+ * struct qht_stats - Statistics of a QHT
+ * @head_buckets: number of head buckets
+ * @used_head_buckets: number of non-empty head buckets
+ * @entries: total number of entries
+ * @chain: frequency distribution representing the number of buckets in each
+ * chain, excluding empty chains.
+ * @occupancy: frequency distribution representing chain occupancy rate.
+ * Valid range: from 0.0 (empty) to 1.0 (full occupancy).
+ *
+ * An entry is a pointer-hash pair.
+ * Each bucket can host several entries.
+ * Chains are chains of buckets, whose first link is always a head bucket.
+ */
+struct qht_stats {
+size_t head_buckets;
+size_t used_head_buckets;
+size_t entries;
+struct qdist chain;
+struct qdist occupancy;
+};
+
+typedef bool (*qht_lookup_func_t)(const void *obj, const void *userp);
+typedef void (*qht_iter_func_t)(struct qht *ht, void *p, uint32_t h, void *up);
+
+#define QHT_MODE_AUTO_RESIZE 0x1 /* auto-resize when heavily loaded */
+
+/**
+ * qht_init - Initialize a QHT
+ * @ht: QHT to be initialized
+ * @n_elems: number of entries the hash table should be optimized for.
+ * @mode: bitmask with OR'ed QHT_MODE_*
+ */
+void qht_init(struct qht *ht, size_t n_elems, unsigned int mode);
+
+/**
+ * qht_destroy - destroy a previously initialized QHT
+ * @ht: QHT to be destroyed
+ *
+ * Call only when there are no readers/writers left.
+ */
+void qht_destroy(struct qht *ht);
+
+/**
+ * qht_insert - Insert a pointer into the hash table
+ * @ht: QHT to insert to
+ * @p: pointer to be inserted
+ * @hash: hash corresponding to @p
+ *
+ * Attempting to insert a NULL @p is a bug.
+ * Inserting the same pointer @p with different @hash values is a bug.
+ *
+ * Returns true on sucess.
+ * Returns false if the @p-@hash pair already exists in the hash table.
+ */
+bool qht_insert(struct qht *ht, void *p, uint32_t hash);
+
+/**
+ * qht_lookup - Look up a pointer in a QHT
+ * @ht: QHT to be looked up
+ * @func: function to compare existing pointers against @userp
+ * @userp: pointer to pass to @func
+ * @hash: hash of the pointer to be looked up
+ *
+ * Needs to be called under an RCU read-critical section.
+ *
+ * The user-provided @func compares pointers in QHT against @userp.
+ * If the function returns true, a match has been found.
+ *
+ * Returns the corresponding pointer when a match is found.
+ * Returns NULL otherwise.
+ */
+void *qht_lookup(struct qht *ht, qht_lookup_func_t func, const void *userp,
+ uint32_t hash);
+
+/**
+ * qht_remove - remove a pointer from the hash table
+ * @ht: QHT to remove from
+ * @p: pointer to be removed
+ * @hash: hash corresponding to @p
+ *
+ * Attempting to remove a NULL @p is a bug.
+ *
+ * Just-removed @p pointers cannot be immediately freed; they need to remain
+ * valid until the end of the RCU grace period in which qht_remove() is called.
+ * This guarantees that concurrent lookups will always compare against valid
+ * data.
+ *
+ * Returns true on success.
+ * Returns false if the @p-@hash pair was not found.
+ */
+bool qht_remove(struct qht *ht, const void *p, uint32_t hash);
+
+/**
+ * qht_reset - reset a QHT
+ * @ht: QHT to be reset
+ *
+ * All entries in the hash table are reset. No resizing is performed.
+ *
+ * If concurrent readers may exist, the objects pointed to by the hash table
+ * must remain valid for the existing RCU grace period -- see qht_remove().
+ * See also: qht_reset_size()
+ */
+void qht_reset(struct qht *ht);
+
+/**
+ * qht_reset_size - reset and resize a QHT
+ * @ht: QHT to be reset and resized
+ * @n_elems: number of entries the resized hash table should be optimized for.
+ *
+ * Returns true if the resize was necessary and therefore performed

Re: [Qemu-devel] [PATCH] hw/arm: virt uart fix

2016-06-08 Thread Peter Maydell
On 8 June 2016 at 07:23, Jérôme Forissier  wrote:
>
>
> On 06/08/2016 04:30 AM, xiaoqiang zhao wrote:
>> commit f0d1d2c115dffc1fbaf954d0b449db05c5eb79b1
>> ("hw/char: QOM'ify pl011 model") break qemu-system-arm virt machine
>> if option '-machine secure=on' is provided.
>>
>> The function create_uart is called twice. So make CharDriverState pointer
>> a parameter to create_uart instead of hardcoded.
>>
>> Signed-off-by: xiaoqiang zhao 
>> ---
>>  hw/arm/virt.c | 8 
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> FWIW,
>
> Tested-by: Jerome Forissier 

Applied to master, thanks.

-- PMM



[Qemu-devel] [PATCH v7 08/15] qdist: add module to represent frequency distributions of data

2016-06-08 Thread Emilio G. Cota
Sometimes it is useful to have a quick histogram to represent a certain
distribution -- for example, when investigating a performance regression
in a hash table due to inadequate hashing.

The appended allows us to easily represent a distribution using Unicode
characters. Further, the data structure keeping track of the distribution
is so simple that obtaining its values for off-line processing is trivial.

Example, taking the last 10 commits to QEMU:

 Characters in commit title  Count
---
 39  1
 48  1
 53  1
 54  2
 57  1
 61  1
 67  1
 78  1
 80  1
qdist_init(&dist);
qdist_inc(&dist, 39);
[...]
qdist_inc(&dist, 80);

char *str = qdist_pr(&dist, 9, QDIST_PR_LABELS);
// -> [39.0,43.6)▂▂ █▂ ▂ ▄[75.4,80.0]
g_free(str);

char *str = qdist_pr(&dist, 4, QDIST_PR_LABELS);
// -> [39.0,49.2)▁█▁▁[69.8,80.0]
g_free(str);

Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 include/qemu/qdist.h |  63 
 util/Makefile.objs   |   1 +
 util/qdist.c | 395 +++
 3 files changed, 459 insertions(+)
 create mode 100644 include/qemu/qdist.h
 create mode 100644 util/qdist.c

diff --git a/include/qemu/qdist.h b/include/qemu/qdist.h
new file mode 100644
index 000..f30050c
--- /dev/null
+++ b/include/qemu/qdist.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_QDIST_H
+#define QEMU_QDIST_H
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/bitops.h"
+
+/*
+ * Samples with the same 'x value' end up in the same qdist_entry,
+ * e.g. inc(0.1) and inc(0.1) end up as {x=0.1, count=2}.
+ *
+ * Binning happens only at print time, so that we retain the flexibility to
+ * choose the binning. This might not be ideal for workloads that do not care
+ * much about precision and insert many samples all with different x values;
+ * in that case, pre-binning (e.g. entering both 0.115 and 0.097 as 0.1)
+ * should be considered.
+ */
+struct qdist_entry {
+double x;
+unsigned long count;
+};
+
+struct qdist {
+struct qdist_entry *entries;
+size_t n;
+size_t size;
+};
+
+#define QDIST_PR_BORDER BIT(0)
+#define QDIST_PR_LABELS BIT(1)
+/* the remaining options only work if PR_LABELS is set */
+#define QDIST_PR_NODECIMAL  BIT(2)
+#define QDIST_PR_PERCENTBIT(3)
+#define QDIST_PR_100X   BIT(4)
+#define QDIST_PR_NOBINRANGE BIT(5)
+
+void qdist_init(struct qdist *dist);
+void qdist_destroy(struct qdist *dist);
+
+void qdist_add(struct qdist *dist, double x, long count);
+void qdist_inc(struct qdist *dist, double x);
+double qdist_xmin(const struct qdist *dist);
+double qdist_xmax(const struct qdist *dist);
+double qdist_avg(const struct qdist *dist);
+unsigned long qdist_sample_count(const struct qdist *dist);
+size_t qdist_unique_entries(const struct qdist *dist);
+
+/* callers must free the returned string with g_free() */
+char *qdist_pr_plain(const struct qdist *dist, size_t n_groups);
+
+/* callers must free the returned string with g_free() */
+char *qdist_pr(const struct qdist *dist, size_t n_groups, uint32_t opt);
+
+/* Only qdist code and test code should ever call this function */
+void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n);
+
+#endif /* QEMU_QDIST_H */
diff --git a/util/Makefile.objs b/util/Makefile.objs
index a8a777e..702435e 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -32,3 +32,4 @@ util-obj-y += buffer.o
 util-obj-y += timed-average.o
 util-obj-y += base64.o
 util-obj-y += log.o
+util-obj-y += qdist.o
diff --git a/util/qdist.c b/util/qdist.c
new file mode 100644
index 000..4ea2e34
--- /dev/null
+++ b/util/qdist.c
@@ -0,0 +1,395 @@
+/*
+ * qdist.c - QEMU helpers for handling frequency distributions of data.
+ *
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#include "qemu/qdist.h"
+
+#include 
+#ifndef NAN
+#define NAN (0.0 / 0.0)
+#endif
+
+void qdist_init(struct qdist *dist)
+{
+dist->entries = g_malloc(sizeof(*dist->entries));
+dist->size = 1;
+dist->n = 0;
+}
+
+void qdist_destroy(struct qdist *dist)
+{
+g_free(dist->entries);
+}
+
+static inline int qdist_cmp_double(double a, double b)
+{
+if (a > b) {
+return 1;
+} else if (a < b) {
+return -1;
+}
+return 0;
+}
+
+static int qdist_cmp(const void *ap, const void *bp)
+{
+const struct qdist_entry *a = ap;
+const struct qdist_entry *b = bp;
+
+return qdist_cmp_double(a->x, b->x);
+}
+
+void qdist_add(struct qdist *dist, double x, lon

[Qemu-devel] [PATCH v7 04/15] include/processor.h: define cpu_relax()

2016-06-08 Thread Emilio G. Cota
Taken from the linux kernel.

Reviewed-by: Sergey Fedorov 
Reviewed-by: Richard Henderson 
Reviewed-by: Alex Bennée 
Signed-off-by: Emilio G. Cota 
---
 include/qemu/processor.h | 30 ++
 1 file changed, 30 insertions(+)
 create mode 100644 include/qemu/processor.h

diff --git a/include/qemu/processor.h b/include/qemu/processor.h
new file mode 100644
index 000..42bcc99
--- /dev/null
+++ b/include/qemu/processor.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2.
+ *   See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_PROCESSOR_H
+#define QEMU_PROCESSOR_H
+
+#include "qemu/atomic.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+# define cpu_relax() asm volatile("rep; nop" ::: "memory")
+
+#elif defined(__ia64__)
+# define cpu_relax() asm volatile("hint @pause" ::: "memory")
+
+#elif defined(__aarch64__)
+# define cpu_relax() asm volatile("yield" ::: "memory")
+
+#elif defined(__powerpc64__)
+/* set Hardware Multi-Threading (HMT) priority to low; then back to medium */
+# define cpu_relax() asm volatile("or 1, 1, 1;"
+  "or 2, 2, 2;" ::: "memory")
+
+#else
+# define cpu_relax() barrier()
+#endif
+
+#endif /* QEMU_PROCESSOR_H */
-- 
2.5.0




[Qemu-devel] [PATCH v7 14/15] tb hash: track translated blocks with qht

2016-06-08 Thread Emilio G. Cota
Having a fixed-size hash table for keeping track of all translation blocks
is suboptimal: some workloads are just too big or too small to get maximum
performance from the hash table. The MRU promotion policy helps improve
performance when the hash table is a little undersized, but it cannot
make up for severely undersized hash tables.

Furthermore, frequent MRU promotions result in writes that are a scalability
bottleneck. For scalability, lookups should only perform reads, not writes.
This is not a big deal for now, but it will become one once MTTCG matures.

The appended fixes these issues by using qht as the implementation of
the TB hash table. This solution is superior to other alternatives considered,
namely:

- master: implementation in QEMU before this patchset
- xxhash: before this patch, i.e. fixed buckets + xxhash hashing + MRU.
- xxhash-rcu: fixed buckets + xxhash + RCU list + MRU.
  MRU is implemented here by adding an intermediate struct
  that contains the u32 hash and a pointer to the TB; this
  allows us, on an MRU promotion, to copy said struct (that is not
  at the head), and put this new copy at the head. After a grace
  period, the original non-head struct can be eliminated, and
  after another grace period, freed.
- qht-fixed-nomru: fixed buckets + xxhash + qht without auto-resize +
   no MRU for lookups; MRU for inserts.
The appended solution is the following:
- qht-dyn-nomru: dynamic number of buckets + xxhash + qht w/ auto-resize +
 no MRU for lookups; MRU for inserts.

The plots below compare the considered solutions. The Y axis shows the
boot time (in seconds) of a debian jessie image with arm-softmmu; the X axis
sweeps the number of buckets (or initial number of buckets for qht-autoresize).
The plots in PNG format (and with errorbars) can be seen here:
  http://imgur.com/a/Awgnq

Each test runs 5 times, and the entire QEMU process is pinned to a
single core for repeatability of results.

Host: Intel Xeon E5-2690

  28 +++-+-+-+++
 A*+ + + master **A*** +
  27 ++* xxhash ##B###++
 |  A**A**   xxhash-rcu $$C$$$ |
  26 C$$  A**A**qht-fixed-nomru*%%D%%%++
 D%%$$  A**A**A*qht-dyn-mru A*EA
  25 ++ %%$$  qht-dyn-nomru &&F&&&++
 B#%   |
  24 ++#C$++
 |  B###  $|
 |  ## C$$ |
  23 ++   #   C$$ ++
 | B##   C$$%%%D
  22 ++  %B##   C$$C$$C$$C$$C$$C
 |D%%B##  @E@@%%%D%%%@@@E@@E
  21 E@@E@@F&&&@@@E@@@&&&D%%B##B##B##B##B##B
 + E@@@   F&&&   +  E@ +  F&&&   + +
  20 +++-+-+-+++
 141618202224
 log2 number of buckets

 Host: Intel i7-4790K

  14.5 ++++-++++
   A**   ++ +master **A*** +
14 ++ ** xxhash ##B###++
  13.5 ++   **   xxhash-rcu $$C$$$++
   |qht-fixed-nomru %%D%%% |
13 ++ A**   qht-dyn-mru @@E@@@++
   | A*A**A** qht-dyn-nomru &&F&&& |
  12.5 C$$   A**A**A*A*****A
12 ++ $$A***  ++
   D%%% $$ |
  11.5 ++  %% ++
   B###  %C$$  |
11 ++  ## D% C$   ++
   | #  %  C$$ |
  10.5 F&&B##D%   C$$C$$C$$C$C$$$$$C
10 E@@E@@B#B##B##E@@E@@@%%%D%D%%%###B##B
   + F&&  D%%B##B##B#B###@@@D%%%   +
   9.5 ++---

[Qemu-devel] [PATCH v7 03/15] seqlock: rename write_lock/unlock to write_begin/end

2016-06-08 Thread Emilio G. Cota
It is a more appropriate name, now that the mutex embedded
in the seqlock is gone.

Reviewed-by: Sergey Fedorov 
Reviewed-by: Alex Bennée 
Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 cpus.c | 28 ++--
 include/qemu/seqlock.h |  4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/cpus.c b/cpus.c
index 1c92362..84c3520 100644
--- a/cpus.c
+++ b/cpus.c
@@ -249,13 +249,13 @@ int64_t cpu_get_clock(void)
 void cpu_enable_ticks(void)
 {
 /* Here, the really thing protected by seqlock is cpu_clock_offset. */
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 if (!timers_state.cpu_ticks_enabled) {
 timers_state.cpu_ticks_offset -= cpu_get_host_ticks();
 timers_state.cpu_clock_offset -= get_clock();
 timers_state.cpu_ticks_enabled = 1;
 }
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 }
 
 /* disable cpu_get_ticks() : the clock is stopped. You must not call
@@ -265,13 +265,13 @@ void cpu_enable_ticks(void)
 void cpu_disable_ticks(void)
 {
 /* Here, the really thing protected by seqlock is cpu_clock_offset. */
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 if (timers_state.cpu_ticks_enabled) {
 timers_state.cpu_ticks_offset += cpu_get_host_ticks();
 timers_state.cpu_clock_offset = cpu_get_clock_locked();
 timers_state.cpu_ticks_enabled = 0;
 }
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 }
 
 /* Correlation between real and virtual time is always going to be
@@ -294,7 +294,7 @@ static void icount_adjust(void)
 return;
 }
 
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 cur_time = cpu_get_clock_locked();
 cur_icount = cpu_get_icount_locked();
 
@@ -315,7 +315,7 @@ static void icount_adjust(void)
 last_delta = delta;
 timers_state.qemu_icount_bias = cur_icount
   - (timers_state.qemu_icount << 
icount_time_shift);
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 }
 
 static void icount_adjust_rt(void *opaque)
@@ -355,7 +355,7 @@ static void icount_warp_rt(void)
 return;
 }
 
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 if (runstate_is_running()) {
 int64_t clock = REPLAY_CLOCK(REPLAY_CLOCK_VIRTUAL_RT,
  cpu_get_clock_locked());
@@ -374,7 +374,7 @@ static void icount_warp_rt(void)
 timers_state.qemu_icount_bias += warp_delta;
 }
 vm_clock_warp_start = -1;
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 
 if (qemu_clock_expired(QEMU_CLOCK_VIRTUAL)) {
 qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
@@ -399,9 +399,9 @@ void qtest_clock_warp(int64_t dest)
 int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
 int64_t warp = qemu_soonest_timeout(dest - clock, deadline);
 
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 timers_state.qemu_icount_bias += warp;
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 
 qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
 timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]);
@@ -468,9 +468,9 @@ void qemu_start_warp_timer(void)
  * It is useful when we want a deterministic execution time,
  * isolated from host latencies.
  */
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 timers_state.qemu_icount_bias += deadline;
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
 } else {
 /*
@@ -481,11 +481,11 @@ void qemu_start_warp_timer(void)
  * you will not be sending network packets continuously instead of
  * every 100ms.
  */
-seqlock_write_lock(&timers_state.vm_clock_seqlock);
+seqlock_write_begin(&timers_state.vm_clock_seqlock);
 if (vm_clock_warp_start == -1 || vm_clock_warp_start > clock) {
 vm_clock_warp_start = clock;
 }
-seqlock_write_unlock(&timers_state.vm_clock_seqlock);
+seqlock_write_end(&timers_state.vm_clock_seqlock);
 timer_mod_anticipate(i

[Qemu-devel] [PATCH v7 09/15] qdist: add test program

2016-06-08 Thread Emilio G. Cota
Acked-by: Sergey Fedorov 
Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 tests/.gitignore   |   1 +
 tests/Makefile |   6 +-
 tests/test-qdist.c | 384 +
 3 files changed, 390 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-qdist.c

diff --git a/tests/.gitignore b/tests/.gitignore
index a06a8ba..7c0d156 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -48,6 +48,7 @@ test-qapi-types.[ch]
 test-qapi-visit.[ch]
 test-qdev-global-props
 test-qemu-opts
+test-qdist
 test-qga
 test-qmp-commands
 test-qmp-commands.h
diff --git a/tests/Makefile b/tests/Makefile
index a3e20e3..2948945 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -70,6 +70,8 @@ check-unit-y += tests/rcutorture$(EXESUF)
 gcov-files-rcutorture-y = util/rcu.c
 check-unit-y += tests/test-rcu-list$(EXESUF)
 gcov-files-test-rcu-list-y = util/rcu.c
+check-unit-y += tests/test-qdist$(EXESUF)
+gcov-files-test-qdist-y = util/qdist.c
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-$(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) += 
tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
@@ -394,7 +396,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-qmp-commands.o tests/test-visitor-serialization.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
tests/test-opts-visitor.o tests/test-qmp-event.o \
-   tests/rcutorture.o tests/test-rcu-list.o
+   tests/rcutorture.o tests/test-rcu-list.o \
+   tests/test-qdist.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -433,6 +436,7 @@ tests/test-cutils$(EXESUF): tests/test-cutils.o 
util/cutils.o
 tests/test-int128$(EXESUF): tests/test-int128.o
 tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y)
 tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y)
+tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y)
 
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\
diff --git a/tests/test-qdist.c b/tests/test-qdist.c
new file mode 100644
index 000..a67f260
--- /dev/null
+++ b/tests/test-qdist.c
@@ -0,0 +1,384 @@
+/*
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include 
+#include "qemu/qdist.h"
+
+#include 
+
+struct entry_desc {
+double x;
+unsigned long count;
+
+/* 0 prints a space, 1-8 prints from qdist_blocks[] */
+int fill_code;
+};
+
+/* See: https://en.wikipedia.org/wiki/Block_Elements */
+static const gunichar qdist_blocks[] = {
+0x2581,
+0x2582,
+0x2583,
+0x2584,
+0x2585,
+0x2586,
+0x2587,
+0x2588
+};
+
+#define QDIST_NR_BLOCK_CODES ARRAY_SIZE(qdist_blocks)
+
+static char *pr_hist(const struct entry_desc *darr, size_t n)
+{
+GString *s = g_string_new("");
+size_t i;
+
+for (i = 0; i < n; i++) {
+int fill = darr[i].fill_code;
+
+if (fill) {
+assert(fill <= QDIST_NR_BLOCK_CODES);
+g_string_append_unichar(s, qdist_blocks[fill - 1]);
+} else {
+g_string_append_c(s, ' ');
+}
+}
+return g_string_free(s, FALSE);
+}
+
+static void
+histogram_check(const struct qdist *dist, const struct entry_desc *darr,
+size_t n, size_t n_bins)
+{
+char *pr = qdist_pr_plain(dist, n_bins);
+char *str = pr_hist(darr, n);
+
+g_assert_cmpstr(pr, ==, str);
+g_free(pr);
+g_free(str);
+}
+
+static void histogram_check_single_full(const struct qdist *dist, size_t 
n_bins)
+{
+struct entry_desc desc = { .fill_code = 8 };
+
+histogram_check(dist, &desc, 1, n_bins);
+}
+
+static void
+entries_check(const struct qdist *dist, const struct entry_desc *darr, size_t 
n)
+{
+size_t i;
+
+for (i = 0; i < n; i++) {
+struct qdist_entry *e = &dist->entries[i];
+
+g_assert_cmpuint(e->count, ==, darr[i].count);
+}
+}
+
+static void
+entries_insert(struct qdist *dist, const struct entry_desc *darr, size_t n)
+{
+size_t i;
+
+for (i = 0; i < n; i++) {
+qdist_add(dist, darr[i].x, darr[i].count);
+}
+}
+
+static void do_test_bin(const struct entry_desc *a, size_t n_a,
+const struct entry_desc *b, size_t n_b)
+{
+struct qdist qda;
+struct qdist qdb;
+
+qdist_init(&qda);
+
+entries_insert(&qda, a, n_a);
+qdist_inc(&qda, a[0].x);
+qdist_add(&qda, a[0].x, -1);
+
+g_assert_cmpuint(qdist_unique_entries(&qda), ==, n_a);
+g_assert_cmpfloat(qdist_xmin(&qda), ==, a[0].x);
+g_assert_cmpfloat(qdist_xmax(&qda), ==, a[n_a - 1].x);
+histogram_check(&qda, a, n_a, 0);
+histogram_check(&qda, a, n_a, n_a);
+
+qdist_bin__internal(&qdb, &qda, n_b);
+g_assert_cmpuint(qdb.n, ==, n_

[Qemu-devel] [PATCH v7 07/15] tb hash: hash phys_pc, pc, and flags with xxhash

2016-06-08 Thread Emilio G. Cota
For some workloads such as arm bootup, tb_phys_hash is performance-critical.
The is due to the high frequency of accesses to the hash table, originated
by (frequent) TLB flushes that wipe out the cpu-private tb_jmp_cache's.
More info:
  https://lists.nongnu.org/archive/html/qemu-devel/2016-03/msg05098.html

To dig further into this I modified an arm image booting debian jessie to
immediately shut down after boot. Analysis revealed that quite a bit of time
is unnecessarily spent in tb_phys_hash: the cause is poor hashing that
results in very uneven loading of chains in the hash table's buckets;
the longest observed chain had ~550 elements.

The appended addresses this with two changes:

1) Use xxhash as the hash table's hash function. xxhash is a fast,
   high-quality hashing function.

2) Feed the hashing function with not just tb_phys, but also pc and flags.

This improves performance over using just tb_phys for hashing, since that
resulted in some hash buckets having many TB's, while others getting very few;
with these changes, the longest observed chain on a single hash bucket is
brought down from ~550 to ~40.

Tests show that the other element checked for in tb_find_physical,
cs_base, is always a match when tb_phys+pc+flags are a match,
so hashing cs_base is wasteful. It could be that this is an ARM-only
thing, though. UPDATE:
On Tue, Apr 05, 2016 at 08:41:43 -0700, Richard Henderson wrote:
> The cs_base field is only used by i386 (in 16-bit modes), and sparc (for a TB
> consisting of only a delay slot).
> It may well still turn out to be reasonable to ignore cs_base for hashing.

BTW, after this change the hash table should not be called "tb_hash_phys"
anymore; this is addressed later in this series.

This change gives consistent bootup time improvements. I tested two
host machines:
- Intel Xeon E5-2690: 11.6% less time
- Intel i7-4790K: 19.2% less time

Increasing the number of hash buckets yields further improvements. However,
using a larger, fixed number of buckets can degrade performance for other
workloads that do not translate as many blocks (600K+ for debian-jessie arm
bootup). This is dealt with later in this series.

Reviewed-by: Sergey Fedorov 
Reviewed-by: Richard Henderson 
Reviewed-by: Alex Bennée 
Signed-off-by: Emilio G. Cota 
---
 cpu-exec.c |  4 ++--
 include/exec/tb-hash.h |  8 ++--
 translate-all.c| 10 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index f7c642f..b9e294c 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -232,13 +232,13 @@ static TranslationBlock *tb_find_physical(CPUState *cpu,
 {
 CPUArchState *env = (CPUArchState *)cpu->env_ptr;
 TranslationBlock *tb, **tb_hash_head, **ptb1;
-unsigned int h;
+uint32_t h;
 tb_page_addr_t phys_pc, phys_page1;
 
 /* find translated block using physical mappings */
 phys_pc = get_page_addr_code(env, pc);
 phys_page1 = phys_pc & TARGET_PAGE_MASK;
-h = tb_phys_hash_func(phys_pc);
+h = tb_hash_func(phys_pc, pc, flags);
 
 /* Start at head of the hash entry */
 ptb1 = tb_hash_head = &tcg_ctx.tb_ctx.tb_phys_hash[h];
diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h
index 0f4e8a0..88ccfd1 100644
--- a/include/exec/tb-hash.h
+++ b/include/exec/tb-hash.h
@@ -20,6 +20,9 @@
 #ifndef EXEC_TB_HASH
 #define EXEC_TB_HASH
 
+#include "exec/exec-all.h"
+#include "exec/tb-hash-xx.h"
+
 /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
addresses on the same page.  The top bits are the same.  This allows
TLB invalidation to quickly clear a subset of the hash table.  */
@@ -43,9 +46,10 @@ static inline unsigned int 
tb_jmp_cache_hash_func(target_ulong pc)
| (tmp & TB_JMP_ADDR_MASK));
 }
 
-static inline unsigned int tb_phys_hash_func(tb_page_addr_t pc)
+static inline
+uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint32_t flags)
 {
-return (pc >> 2) & (CODE_GEN_PHYS_HASH_SIZE - 1);
+return tb_hash_func5(phys_pc, pc, flags) & (CODE_GEN_PHYS_HASH_SIZE - 1);
 }
 
 #endif
diff --git a/translate-all.c b/translate-all.c
index c599dc4..0adc67c 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -992,12 +992,12 @@ void tb_phys_invalidate(TranslationBlock *tb, 
tb_page_addr_t page_addr)
 {
 CPUState *cpu;
 PageDesc *p;
-unsigned int h;
+uint32_t h;
 tb_page_addr_t phys_pc;
 
 /* remove the TB from the hash list */
 phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK);
-h = tb_phys_hash_func(phys_pc);
+h = tb_hash_func(phys_pc, tb->pc, tb->flags);
 tb_hash_remove(&tcg_ctx.tb_ctx.tb_phys_hash[h], tb);
 
 /* remove the TB from the page list */
@@ -1127,11 +1127,11 @@ static inline void tb_alloc_page(TranslationBlock *tb,
 static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
  tb_page_addr_t phys_page2)
 {
-unsigned int h;
+uint32_t h;
 TranslationBlock **ptb;
 
-/*

[Qemu-devel] [PATCH v7 13/15] qht: add test-qht-par to invoke qht-bench from 'check' target

2016-06-08 Thread Emilio G. Cota
Signed-off-by: Emilio G. Cota 
---
 tests/.gitignore |  1 +
 tests/Makefile   |  5 -
 tests/test-qht-par.c | 56 
 3 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-qht-par.c

diff --git a/tests/.gitignore b/tests/.gitignore
index d19023e..840ea39 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -52,6 +52,7 @@ test-qemu-opts
 test-qdist
 test-qga
 test-qht
+test-qht-par
 test-qmp-commands
 test-qmp-commands.h
 test-qmp-event
diff --git a/tests/Makefile b/tests/Makefile
index 7b00301..7d63d16 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -74,6 +74,8 @@ check-unit-y += tests/test-qdist$(EXESUF)
 gcov-files-test-qdist-y = util/qdist.c
 check-unit-y += tests/test-qht$(EXESUF)
 gcov-files-test-qht-y = util/qht.c
+check-unit-y += tests/test-qht-par$(EXESUF)
+gcov-files-test-qht-par-y = util/qht.c
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-$(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) += 
tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
@@ -400,7 +402,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-opts-visitor.o tests/test-qmp-event.o \
tests/rcutorture.o tests/test-rcu-list.o \
tests/test-qdist.o \
-   tests/test-qht.o tests/qht-bench.o
+   tests/test-qht.o tests/qht-bench.o tests/test-qht-par.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -441,6 +443,7 @@ tests/rcutorture$(EXESUF): tests/rcutorture.o 
$(test-util-obj-y)
 tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y)
 tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y)
 tests/test-qht$(EXESUF): tests/test-qht.o $(test-util-obj-y)
+tests/test-qht-par$(EXESUF): tests/test-qht-par.o tests/qht-bench$(EXESUF) 
$(test-util-obj-y)
 tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y)
 
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
diff --git a/tests/test-qht-par.c b/tests/test-qht-par.c
new file mode 100644
index 000..f09e004
--- /dev/null
+++ b/tests/test-qht-par.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include 
+
+#define TEST_QHT_STRING "tests/qht-bench 1>/dev/null 2>&1 -R -S0.1 -D1 -N1 
"
+
+static void test_qht(int n_threads, int update_rate, int duration)
+{
+char *str;
+int rc;
+
+str = g_strdup_printf(TEST_QHT_STRING "-n %d -u %d -d %d",
+  n_threads, update_rate, duration);
+rc = system(str);
+g_free(str);
+g_assert_cmpint(rc, ==, 0);
+}
+
+static void test_2th0u1s(void)
+{
+test_qht(2, 0, 1);
+}
+
+static void test_2th20u1s(void)
+{
+test_qht(2, 20, 1);
+}
+
+static void test_2th0u5s(void)
+{
+test_qht(2, 0, 5);
+}
+
+static void test_2th20u5s(void)
+{
+test_qht(2, 20, 5);
+}
+
+int main(int argc, char *argv[])
+{
+g_test_init(&argc, &argv, NULL);
+
+if (g_test_quick()) {
+g_test_add_func("/qht/parallel/2threads-0%updates-1s", test_2th0u1s);
+g_test_add_func("/qht/parallel/2threads-20%updates-1s", test_2th20u1s);
+} else {
+g_test_add_func("/qht/parallel/2threads-0%updates-5s", test_2th0u5s);
+g_test_add_func("/qht/parallel/2threads-20%updates-5s", test_2th20u5s);
+}
+return g_test_run();
+}
-- 
2.5.0




[Qemu-devel] [PATCH v7 01/15] compiler.h: add QEMU_ALIGNED() to enforce struct alignment

2016-06-08 Thread Emilio G. Cota
Reviewed-by: Sergey Fedorov 
Reviewed-by: Richard Henderson 
Reviewed-by: Alex Bennée 
Signed-off-by: Emilio G. Cota 
---
 include/qemu/compiler.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 8f1cc7b..b64f899 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -41,6 +41,8 @@
 # define QEMU_PACKED __attribute__((packed))
 #endif
 
+#define QEMU_ALIGNED(X) __attribute__((aligned(X)))
+
 #ifndef glue
 #define xglue(x, y) x ## y
 #define glue(x, y) xglue(x, y)
-- 
2.5.0




Re: [Qemu-devel] [RFC PATCH] configure: Enable -Werror for MinGW builds, too

2016-06-08 Thread Peter Maydell
On 8 June 2016 at 15:09, Stefan Hajnoczi  wrote:
> On Wed, Jun 08, 2016 at 10:13:26AM +0200, Thomas Huth wrote:
>> MinGW seems to compile currently without warnings, so it should
>> be safe to enable -Werror now for this environment, too.
>>
>> Signed-off-by: Thomas Huth 
>> ---
>>  ... at least it compiles without errors for me here. I hope that's
>>  also true for different versions of MinGW ... would be great if
>>  everybody who has such a compiler installed could give it a try!
>>
>>  configure | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> mingw 5.2.0-1.fc23 does not produce any warnings anymore.
>
> Tested-by: Stefan Hajnoczi 

My w32/w64 builds need -Wno-unused-local-typedefs to build
with -Werror, but that's the fault of the glib headers I build
against and I already configure like that in order to use -Werror.

We should check whether we can enable -Werror for OSX too.

thanks
-- PMM



[Qemu-devel] [PATCH v7 06/15] exec: add tb_hash_func5, derived from xxhash

2016-06-08 Thread Emilio G. Cota
This will be used by upcoming changes for hashing the tb hash.

Add this into a separate file to include the copyright notice from
xxhash.

Reviewed-by: Sergey Fedorov 
Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 include/exec/tb-hash-xx.h | 94 +++
 1 file changed, 94 insertions(+)
 create mode 100644 include/exec/tb-hash-xx.h

diff --git a/include/exec/tb-hash-xx.h b/include/exec/tb-hash-xx.h
new file mode 100644
index 000..9f3fc05
--- /dev/null
+++ b/include/exec/tb-hash-xx.h
@@ -0,0 +1,94 @@
+/*
+ * xxHash - Fast Hash algorithm
+ * Copyright (C) 2012-2016, Yann Collet
+ *
+ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * + Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * + Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * You can contact the author at :
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
+ */
+#ifndef EXEC_TB_HASH_XX
+#define EXEC_TB_HASH_XX
+
+#include 
+
+#define PRIME32_1   2654435761U
+#define PRIME32_2   2246822519U
+#define PRIME32_3   3266489917U
+#define PRIME32_4668265263U
+#define PRIME32_5374761393U
+
+#define TB_HASH_XX_SEED 1
+
+/*
+ * xxhash32, customized for input variables that are not guaranteed to be
+ * contiguous in memory.
+ */
+static inline
+uint32_t tb_hash_func5(uint64_t a0, uint64_t b0, uint32_t e)
+{
+uint32_t v1 = TB_HASH_XX_SEED + PRIME32_1 + PRIME32_2;
+uint32_t v2 = TB_HASH_XX_SEED + PRIME32_2;
+uint32_t v3 = TB_HASH_XX_SEED + 0;
+uint32_t v4 = TB_HASH_XX_SEED - PRIME32_1;
+uint32_t a = a0 >> 32;
+uint32_t b = a0;
+uint32_t c = b0 >> 32;
+uint32_t d = b0;
+uint32_t h32;
+
+v1 += a * PRIME32_2;
+v1 = rol32(v1, 13);
+v1 *= PRIME32_1;
+
+v2 += b * PRIME32_2;
+v2 = rol32(v2, 13);
+v2 *= PRIME32_1;
+
+v3 += c * PRIME32_2;
+v3 = rol32(v3, 13);
+v3 *= PRIME32_1;
+
+v4 += d * PRIME32_2;
+v4 = rol32(v4, 13);
+v4 *= PRIME32_1;
+
+h32 = rol32(v1, 1) + rol32(v2, 7) + rol32(v3, 12) + rol32(v4, 18);
+h32 += 20;
+
+h32 += e * PRIME32_3;
+h32  = rol32(h32, 17) * PRIME32_4;
+
+h32 ^= h32 >> 15;
+h32 *= PRIME32_2;
+h32 ^= h32 >> 13;
+h32 *= PRIME32_3;
+h32 ^= h32 >> 16;
+
+return h32;
+}
+
+#endif /* EXEC_TB_HASH_XX */
-- 
2.5.0




[Qemu-devel] [PATCH v7 11/15] qht: add test program

2016-06-08 Thread Emilio G. Cota
Acked-by: Sergey Fedorov 
Reviewed-by: Alex Bennée 
Reviewed-by: Richard Henderson 
Signed-off-by: Emilio G. Cota 
---
 tests/.gitignore |   1 +
 tests/Makefile   |   6 ++-
 tests/test-qht.c | 159 +++
 3 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-qht.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 7c0d156..ffde5d2 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -50,6 +50,7 @@ test-qdev-global-props
 test-qemu-opts
 test-qdist
 test-qga
+test-qht
 test-qmp-commands
 test-qmp-commands.h
 test-qmp-event
diff --git a/tests/Makefile b/tests/Makefile
index 2948945..429d384 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -72,6 +72,8 @@ check-unit-y += tests/test-rcu-list$(EXESUF)
 gcov-files-test-rcu-list-y = util/rcu.c
 check-unit-y += tests/test-qdist$(EXESUF)
 gcov-files-test-qdist-y = util/qdist.c
+check-unit-y += tests/test-qht$(EXESUF)
+gcov-files-test-qht-y = util/qht.c
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-$(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) += 
tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
@@ -397,7 +399,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
tests/test-opts-visitor.o tests/test-qmp-event.o \
tests/rcutorture.o tests/test-rcu-list.o \
-   tests/test-qdist.o
+   tests/test-qdist.o \
+   tests/test-qht.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -437,6 +440,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
 tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y)
 tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y)
 tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y)
+tests/test-qht$(EXESUF): tests/test-qht.o $(test-util-obj-y)
 
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\
diff --git a/tests/test-qht.c b/tests/test-qht.c
new file mode 100644
index 000..c8eb930
--- /dev/null
+++ b/tests/test-qht.c
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2016, Emilio G. Cota 
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include 
+#include "qemu/qht.h"
+
+#define N 5000
+
+static struct qht ht;
+static int32_t arr[N * 2];
+
+static bool is_equal(const void *obj, const void *userp)
+{
+const int32_t *a = obj;
+const int32_t *b = userp;
+
+return *a == *b;
+}
+
+static void insert(int a, int b)
+{
+int i;
+
+for (i = a; i < b; i++) {
+uint32_t hash;
+
+arr[i] = i;
+hash = i;
+
+qht_insert(&ht, &arr[i], hash);
+}
+}
+
+static void rm(int init, int end)
+{
+int i;
+
+for (i = init; i < end; i++) {
+uint32_t hash;
+
+hash = arr[i];
+g_assert_true(qht_remove(&ht, &arr[i], hash));
+}
+}
+
+static void check(int a, int b, bool expected)
+{
+struct qht_stats stats;
+int i;
+
+for (i = a; i < b; i++) {
+void *p;
+uint32_t hash;
+int32_t val;
+
+val = i;
+hash = i;
+p = qht_lookup(&ht, is_equal, &val, hash);
+g_assert_true(!!p == expected);
+}
+qht_statistics_init(&ht, &stats);
+if (stats.used_head_buckets) {
+g_assert_cmpfloat(qdist_avg(&stats.chain), >=, 1.0);
+}
+g_assert_cmpuint(stats.head_buckets, >, 0);
+qht_statistics_destroy(&stats);
+}
+
+static void count_func(struct qht *ht, void *p, uint32_t hash, void *userp)
+{
+unsigned int *curr = userp;
+
+(*curr)++;
+}
+
+static void check_n(size_t expected)
+{
+struct qht_stats stats;
+
+qht_statistics_init(&ht, &stats);
+g_assert_cmpuint(stats.entries, ==, expected);
+qht_statistics_destroy(&stats);
+}
+
+static void iter_check(unsigned int count)
+{
+unsigned int curr = 0;
+
+qht_iter(&ht, count_func, &curr);
+g_assert_cmpuint(curr, ==, count);
+}
+
+static void qht_do_test(unsigned int mode, size_t init_entries)
+{
+qht_init(&ht, 0, mode);
+
+insert(0, N);
+check(0, N, true);
+check_n(N);
+check(-N, -1, false);
+iter_check(N);
+
+rm(101, 102);
+check_n(N - 1);
+insert(N, N * 2);
+check_n(N + N - 1);
+rm(N, N * 2);
+check_n(N - 1);
+insert(101, 102);
+check_n(N);
+
+rm(10, 200);
+check_n(N - 190);
+insert(150, 200);
+check_n(N - 190 + 50);
+insert(10, 150);
+check_n(N);
+
+rm(1, 2);
+check_n(N - 1);
+qht_reset_size(&ht, 0);
+check_n(0);
+check(0, N, false);
+
+qht_destroy(&ht);
+}
+
+static void qht_test(unsigned int mode)
+{
+qht_do_test(mode, 0);
+qht_do_test(mode, 1);
+qht_do_test(mode, 2);
+qht_do_test(mode, 8);
+qht_do_test(mode, 16);
+qht_do_test(mode,

Re: [Qemu-devel] [PULL 00/44] linux-user update

2016-06-08 Thread Peter Maydell
On 8 June 2016 at 14:29,   wrote:
> From: Riku Voipio 
>
> The following changes since commit 76462405809d29bab65a3699686998ba124ab942:
>
>   Merge remote-tracking branch 
> 'remotes/pmaydell/tags/pull-target-arm-20160606-1' into staging (2016-06-06 
> 17:02:42 +0100)
>
> are available in the git repository at:
>
>   git://git.linaro.org/people/riku.voipio/qemu.git 
> tags/pull-linux-user-20160608
>
> for you to fetch changes up to 014628a705bdaf31c09915c29e61f4088956564d:
>
>   linux-user: In fork_end(), remove correct CPUs from CPU list (2016-06-08 
> 12:06:57 +0300)
>
> 
> linux-user pull request for June 2016
>
> 

Applied, thanks.

-- PMM



[Qemu-devel] [PATCH 2/5] hw/arm/virt: set is_default

2016-06-08 Thread Andrew Jones
Make the latest machine type (currently only one) the
default.

Signed-off-by: Andrew Jones 
---
 hw/arm/virt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index a0d35d0826590..09afbafde025d 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1432,6 +1432,7 @@ static void virt_2_6_class_init(ObjectClass *oc, void 
*data)
 
 mc->desc = "QEMU 2.6 ARM Virtual Machine";
 mc->alias = "virt";
+mc->is_default = 1;
 }
 
 static const TypeInfo machvirt_2_6_info = {
-- 
2.4.11




[Qemu-devel] [PATCH 3/5] hw/arm/virt: introduce DEFINE_VIRT_MACHINE

2016-06-08 Thread Andrew Jones
Use DEFINE_VIRT_MACHINE to generate versioned machine type info.

Signed-off-by: Andrew Jones 
---
 hw/arm/virt.c | 40 +++-
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 09afbafde025d..9a3289d2c422c 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -98,6 +98,27 @@ typedef struct {
 #define VIRT_MACHINE_CLASS(klass) \
 OBJECT_CLASS_CHECK(VirtMachineClass, klass, TYPE_VIRT_MACHINE)
 
+
+#define DEFINE_VIRT_MACHINE(major, minor) \
+static void virt_##major##_##minor##_class_init(ObjectClass *oc, void 
*data) \
+{ \
+MachineClass *mc = MACHINE_CLASS(oc); \
+virt_machine_##major##_##minor##_options(mc); \
+mc->desc = "QEMU " # major "." # minor " ARM Virtual Machine"; \
+} \
+static const TypeInfo machvirt_##major##_##minor##_info = { \
+.name = MACHINE_TYPE_NAME("virt-" # major "." # minor), \
+.parent = TYPE_VIRT_MACHINE, \
+.instance_init = virt_##major##_##minor##_instance_init, \
+.class_init = virt_##major##_##minor##_class_init, \
+}; \
+static void machvirt_machine_##major##_##minor##_init(void) \
+{ \
+type_register_static(&machvirt_##major##_##minor##_info); \
+} \
+type_init(machvirt_machine_##major##_##minor##_init);
+
+
 /* RAM limit in GB. Since VIRT_MEM starts at the 1GB mark, this means
  * RAM can go up to the 256GB mark, leaving 256GB of the physical
  * address space unallocated and free for future use between 256G and 512G.
@@ -1426,24 +1447,9 @@ static void virt_2_6_instance_init(Object *obj)
 "Valid values are 2, 3 and host", NULL);
 }
 
-static void virt_2_6_class_init(ObjectClass *oc, void *data)
+static void virt_machine_2_6_options(MachineClass *mc)
 {
-MachineClass *mc = MACHINE_CLASS(oc);
-
-mc->desc = "QEMU 2.6 ARM Virtual Machine";
 mc->alias = "virt";
 mc->is_default = 1;
 }
-
-static const TypeInfo machvirt_2_6_info = {
-.name = MACHINE_TYPE_NAME("virt-2.6"),
-.parent = TYPE_VIRT_MACHINE,
-.instance_init = virt_2_6_instance_init,
-.class_init = virt_2_6_class_init,
-};
-
-static void machvirt_machine_2_6_init(void)
-{
-type_register_static(&machvirt_2_6_info);
-}
-type_init(machvirt_machine_2_6_init);
+DEFINE_VIRT_MACHINE(2, 6)
-- 
2.4.11




[Qemu-devel] [PATCH 4/5] hw/arm/virt: introduce DEFINE_VIRT_MACHINE_AS_LATEST

2016-06-08 Thread Andrew Jones
Create two variants of DEFINE_VIRT_MACHINE. One, just called
DEFINE_VIRT_MACHINE, that does not set properties that only
the latest machine type should have, and another that does.
This will hopefully reduce potential for errors when adding
new versions.

Signed-off-by: Andrew Jones 
---
 hw/arm/virt.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 9a3289d2c422c..017c244a46f41 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -99,12 +99,16 @@ typedef struct {
 OBJECT_CLASS_CHECK(VirtMachineClass, klass, TYPE_VIRT_MACHINE)
 
 
-#define DEFINE_VIRT_MACHINE(major, minor) \
+#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
 static void virt_##major##_##minor##_class_init(ObjectClass *oc, void 
*data) \
 { \
 MachineClass *mc = MACHINE_CLASS(oc); \
 virt_machine_##major##_##minor##_options(mc); \
 mc->desc = "QEMU " # major "." # minor " ARM Virtual Machine"; \
+if (latest) { \
+mc->alias = "virt"; \
+mc->is_default = 1; \
+} \
 } \
 static const TypeInfo machvirt_##major##_##minor##_info = { \
 .name = MACHINE_TYPE_NAME("virt-" # major "." # minor), \
@@ -118,6 +122,11 @@ typedef struct {
 } \
 type_init(machvirt_machine_##major##_##minor##_init);
 
+#define DEFINE_VIRT_MACHINE_AS_LATEST(major, minor) \
+DEFINE_VIRT_MACHINE_LATEST(major, minor, true)
+#define DEFINE_VIRT_MACHINE(major, minor) \
+DEFINE_VIRT_MACHINE_LATEST(major, minor, false)
+
 
 /* RAM limit in GB. Since VIRT_MEM starts at the 1GB mark, this means
  * RAM can go up to the 256GB mark, leaving 256GB of the physical
@@ -1449,7 +1458,5 @@ static void virt_2_6_instance_init(Object *obj)
 
 static void virt_machine_2_6_options(MachineClass *mc)
 {
-mc->alias = "virt";
-mc->is_default = 1;
 }
-DEFINE_VIRT_MACHINE(2, 6)
+DEFINE_VIRT_MACHINE_AS_LATEST(2, 6)
-- 
2.4.11




[Qemu-devel] [PATCH 1/5] hw/arm/virt: separate versioned type-init code

2016-06-08 Thread Andrew Jones
Rename machvirt_info (which is specifically for 2.6 TypeInfo)
to machvirt_2_6_info, and separate the type registration of the
abstract machine type from the versioned type.

Signed-off-by: Andrew Jones 
---
 hw/arm/virt.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 8e46137e9be71..a0d35d0826590 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1387,6 +1387,12 @@ static const TypeInfo virt_machine_info = {
 .class_init= virt_machine_class_init,
 };
 
+static void machvirt_machine_init(void)
+{
+type_register_static(&virt_machine_info);
+}
+type_init(machvirt_machine_init);
+
 static void virt_2_6_instance_init(Object *obj)
 {
 VirtMachineState *vms = VIRT_MACHINE(obj);
@@ -1428,17 +1434,15 @@ static void virt_2_6_class_init(ObjectClass *oc, void 
*data)
 mc->alias = "virt";
 }
 
-static const TypeInfo machvirt_info = {
+static const TypeInfo machvirt_2_6_info = {
 .name = MACHINE_TYPE_NAME("virt-2.6"),
 .parent = TYPE_VIRT_MACHINE,
 .instance_init = virt_2_6_instance_init,
 .class_init = virt_2_6_class_init,
 };
 
-static void machvirt_machine_init(void)
+static void machvirt_machine_2_6_init(void)
 {
-type_register_static(&virt_machine_info);
-type_register_static(&machvirt_info);
+type_register_static(&machvirt_2_6_info);
 }
-
-type_init(machvirt_machine_init);
+type_init(machvirt_machine_2_6_init);
-- 
2.4.11




[Qemu-devel] [PATCH 0/5] create the mach-virt 2.7 machine type

2016-06-08 Thread Andrew Jones
This is the first new machine type mach-virt has received
(2.6 being the first versioned machine type), so we need to
do a bit more than the average "new machine type" patch.
The first four patches prepare for easy-adding of machine
types. The last patch adds the 2.7 type.


Andrew Jones (5):
  hw/arm/virt: separate versioned type-init code
  hw/arm/virt: set is_default
  hw/arm/virt: introduce DEFINE_VIRT_MACHINE
  hw/arm/virt: introduce DEFINE_VIRT_MACHINE_AS_LATEST
  hw/arm/virt: create the 2.7 machine type

 hw/arm/virt.c | 66 ---
 1 file changed, 50 insertions(+), 16 deletions(-)

-- 
2.4.11




[Qemu-devel] [PATCH 5/5] hw/arm/virt: create the 2.7 machine type

2016-06-08 Thread Andrew Jones
Signed-off-by: Andrew Jones 
---
 hw/arm/virt.c | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 017c244a46f41..323ffd4689641 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -42,6 +42,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
 #include "hw/boards.h"
+#include "hw/compat.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
 #include "qemu/bitops.h"
@@ -1423,7 +1424,7 @@ static void machvirt_machine_init(void)
 }
 type_init(machvirt_machine_init);
 
-static void virt_2_6_instance_init(Object *obj)
+static void virt_2_7_instance_init(Object *obj)
 {
 VirtMachineState *vms = VIRT_MACHINE(obj);
 
@@ -1456,7 +1457,22 @@ static void virt_2_6_instance_init(Object *obj)
 "Valid values are 2, 3 and host", NULL);
 }
 
+static void virt_machine_2_7_options(MachineClass *mc)
+{
+}
+DEFINE_VIRT_MACHINE_AS_LATEST(2, 7)
+
+#define VIRT_COMPAT_2_6 \
+HW_COMPAT_2_6
+
+static void virt_2_6_instance_init(Object *obj)
+{
+virt_2_7_instance_init(obj);
+}
+
 static void virt_machine_2_6_options(MachineClass *mc)
 {
+virt_machine_2_7_options(mc);
+SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_6);
 }
-DEFINE_VIRT_MACHINE_AS_LATEST(2, 6)
+DEFINE_VIRT_MACHINE(2, 6)
-- 
2.4.11




Re: [Qemu-devel] [PATCH v6 08/15] qdist: add module to represent frequency distributions of data

2016-06-08 Thread Sergey Fedorov
On 08/06/16 21:06, Emilio G. Cota wrote:
> On Wed, Jun 08, 2016 at 17:10:03 +0300, Sergey Fedorov wrote:
>> On 08/06/16 03:02, Emilio G. Cota wrote:
>>> -dist->entries = g_realloc(dist->entries,
>>> -  sizeof(*dist->entries) * (dist->n + 1));
>>> +if (unlikely(dist->n == dist->size)) {
>>> +dist->size = dist->size ? dist->size * 2 : 1;
>> We could initialize 'dist->size' to 1 and allocate a 1-entry
>> 'dist->entries' array in qdist_init() to avoid this ternary operation ;-)
> Done. This resulted in quite a few modifications, since dist->entries == NULL
> had been used as an equivalent to dist->n == 0.
>
>> (snip)
 So our scale is not linear. I think some users might get confused by this.
>>> That's correct. I think special-casing 0 makes sense though, since
>>> it increases the signal-to-noise ratio of the histogram. For example:
>>>
>>> 1) 0 as ' ':
>>> TB hash occupancy   31.84% avg chain occ. Histogram: [0,10)%|▆ █  
>>> ▅▁▃▁▁|[90,100]%
>>> TB hash avg chain   1.015 buckets. Histogram: 1|█▁▁|3
>>>
>>> 2) 0 as '1/8':
>>> TB hash occupancy   32.07% avg chain occ. Histogram: 
>>> [0,10)%|▆▁█▁▁▅▁▃▁▁|[90,100]%
>>> TB hash avg chain   1.015 buckets. Histogram: 1|▇▁▁|3
>>>
>>> I think in these examples most users would be less confused by 1) than by 
>>> 2).
>> I was meaning to represent all bars whose value < 1/8 as a space, not
>> only whose value is pure zero. Otherwise we can see 1/8 bar where the
>> actual value is negligibly differ from zero as in the second example.
> I see. That would be (3):
>
> TB hash occupancy   32.79% avg chain occ. Histogram: [0,10)%|▅ █  ▅ ▂  
> |[90,100]%
> TB hash avg chain   1.017 buckets. Histogram: 1|█  |3
>
> I still think (1) is the representation that gives the most information.
> IMO it's valuable that "close to zero" and "zero" are represented differently,
> in the same way that max and "close to max" are represented differently
> as well (only max gets 8/8).

Anyhow, these histograms are only for rough estimation and to see some
nice unicode output :)

>
> BTW, while looking into this I fixed a bug; sometimes we'd print 7/8 instead
> of 8/8 for the max value, due to the ordering of FP computations
> [see 1-3 in (2) above; it's 7/8 instead of 8/8]. Fixed with:
>
> diff --git a/util/qdist.c b/util/qdist.c
> index cfe09e6..7842d34 100644
> --- a/util/qdist.c
> +++ b/util/qdist.c
> @@ -103,7 +103,7 @@ static const gunichar qdist_blocks[] = {
>   */
>  static char *qdist_pr_internal(const struct qdist *dist)
>  {
> -double min, max, step;
> +double min, max;
>  GString *s = g_string_new("");
>  size_t i;
>  
> @@ -131,16 +131,14 @@ static char *qdist_pr_internal(const struct qdist *dist)
>  }
>  }
>  
> -/* floor((count - min) * step) will give us the block index */
> -step = (QDIST_NR_BLOCK_CODES - 1) / (max - min);
> -
>  for (i = 0; i < dist->n; i++) {
>  struct qdist_entry *e = &dist->entries[i];
>  int index;
>  
>  /* make an exception with 0; instead of using block[0], print a 
> space */
>  if (e->count) {
> -index = (int)((e->count - min) * step);
> +/* divide first to avoid loss of precision when e->count == max 
> */
> +index = (e->count - min) / (max - min) * (QDIST_NR_BLOCK_CODES - 
> 1);
>  g_string_append_unichar(s, qdist_blocks[index]);
>  } else {
>  g_string_append_c(s, ' ');
>
> I also added a test to test-qdist (called "test_bin_precision") that
> checks for this.
>
>>> The behaviour isn't the same though. With this we have
>>> that the two outer bins (leftmost and rightmost) are unnecessarily
>>> large (since they're out of the range of the input data).
>>>
>>> For example, assume the data is between 0 and 100 and n=5 (i.e. step=25),
>>> it makes no sense to report the first bin as [-12.5,12.5). If we
>>> then truncate the unnecessary edges, we'd have [0,12.5), but
>>> then the second bin is [12.5,37.5). Bins of unequal size are
>>> possible (although a bit unusual) in histograms, but given
>>> our Unicode-based representation, we're limited to same-width bars.
>> That is why I noted that I'm not sure what is the most correct from
>> mathematical point of view. Maybe consider the second option? I.e.
>> rounding to the middle of each bin with:
>>
>> x = left + step / 2;
>>
>> which would give the picture like this:
>>
>>
>> xmin [*---*---*---*---*] xmax   -- from
>>   |   |   |   |   |
>>\ / \ / \ / \ /
>> |   |   |   |
>> V   V   V   V
>>[*   *   *   *]  -- to
> This binning is equivalent to what we do right now.
>
> The only difference is where the value is set (either at the left
> of the bin, or at the center as above); this, however, isn't too
> important, since this value is only used when printing
> the labels, i.e. we could print [left, left+step) or
> [center-step/2, center+step/2) and

[Qemu-devel] [Qemu-devel [RFC] [WIP] v1] Adding feature to reconnect with -r option to migrate command

2016-06-08 Thread Md Haris Iqbal
---
 hmp-commands.hx   | 10 +---
 hmp.c |  4 ++-
 include/migration/migration.h |  1 +
 migration/migration.c | 60 +--
 qapi-schema.json  |  2 +-
 qmp-commands.hx   |  3 ++-
 6 files changed, 60 insertions(+), 20 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4f4f60a..2e7aed3 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -893,10 +893,11 @@ ETEXI
 
 {
 .name   = "migrate",
-.args_type  = "detach:-d,blk:-b,inc:-i,uri:s",
-.params = "[-d] [-b] [-i] uri",
+.args_type  = "detach:-d,recover:-r,blk:-b,inc:-i,uri:s",
+.params = "[-d] [-r] [-b] [-i] uri",
 .help   = "migrate to URI (using -d to not wait for completion)"
- "\n\t\t\t -b for migration without shared storage with"
+ "\n\t\t\t -r to recover from a broken migration\n\t\t\t"
+  " -b for migration without shared storage with"
  " full copy of disk\n\t\t\t -i for migration without "
  "shared storage with incremental copy of disk "
  "(base image shared between src and destination)",
@@ -905,9 +906,10 @@ ETEXI
 
 
 STEXI
-@item migrate [-d] [-b] [-i] @var{uri}
+@item migrate [-d] [-r] [-b] [-i] @var{uri}
 @findex migrate
 Migrate to @var{uri} (using -d to not wait for completion).
+-r to recover from a broken migration
-b for migration with full copy of disk
-i for migration with incremental copy of disk (base image is shared)
 ETEXI
diff --git a/hmp.c b/hmp.c
index d510236..ec8fab4 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1544,12 +1544,14 @@ static void hmp_migrate_status_cb(void *opaque)
 void hmp_migrate(Monitor *mon, const QDict *qdict)
 {
 bool detach = qdict_get_try_bool(qdict, "detach", false);
+bool recover = qdict_get_try_bool(qdict, "recover", false);
 bool blk = qdict_get_try_bool(qdict, "blk", false);
 bool inc = qdict_get_try_bool(qdict, "inc", false);
 const char *uri = qdict_get_str(qdict, "uri");
 Error *err = NULL;
 
-qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
+qmp_migrate(uri, !!recover, recover, !!blk, blk, !!inc, inc, false, false,
+&err);
 if (err) {
 error_report_err(err);
 return;
diff --git a/include/migration/migration.h b/include/migration/migration.h
index ac2c12c..4a3201b 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -139,6 +139,7 @@ struct MigrationState
 
 int state;
 MigrationParams params;
+bool in_recovery;
 
 /* State related to return path */
 struct {
diff --git a/migration/migration.c b/migration/migration.c
index 991313a..a77f62e 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -933,6 +933,7 @@ MigrationState *migrate_init(const MigrationParams *params)
 s->xfer_limit = 0;
 s->cleanup_bh = 0;
 s->to_dst_file = NULL;
+s->in_recovery = false;
 s->state = MIGRATION_STATUS_NONE;
 s->params = *params;
 s->rp_state.from_dst_file = NULL;
@@ -992,13 +993,14 @@ void qmp_migrate_incoming(const char *uri, Error **errp)
 once = false;
 }
 
-void qmp_migrate(const char *uri, bool has_blk, bool blk,
- bool has_inc, bool inc, bool has_detach, bool detach,
+void qmp_migrate(const char *uri, bool in_recover, bool recover, bool has_blk,
+ bool blk, bool has_inc, bool inc, bool has_detach, bool 
detach,
  Error **errp)
 {
 Error *local_err = NULL;
 MigrationState *s = migrate_get_current();
 MigrationParams params;
+bool recovery = in_recover && recover;
 const char *p;
 
 params.blk = has_blk && blk;
@@ -1023,7 +1025,31 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 return;
 }
 
-s = migrate_init(¶ms);
+if (recovery ^ atomic_mb_read(&s->in_recovery)) {
+if (recovery) {
+/* No VM is waiting for recovery and
+ * recovery option was set
+ */
+
+error_setg(errp, QERR_UNDEFINED_ERROR);
+return;
+} else {
+/* A VM is waiting for recovery and
+ * no recovery option is set
+ */
+
+error_setg(errp, QERR_UNDEFINED_ERROR);
+return;
+}
+} else {
+if (!recovery) {
+/* No VM is waiting for recovery and
+ * no recovery option is set
+ */
+fprintf(stderr, "hello1\n");
+s = migrate_init(¶ms);
+}
+}
 
 if (strstart(uri, "tcp:", &p)) {
 tcp_start_outgoing_migration(s, p, &local_err);
@@ -1767,16 +1793,6 @@ static void *migration_thread(void *opaque)
 
 void migrate_fd_connect(MigrationState *s)
 {
-/* This is a best 1st approximation. ns to ms */
-s->expected_downtime = max_downtime/100;

[Qemu-devel] [Qemu-devel [RFC] [WIP] v2] Keeping the Source side alive incase of network failure (Migration recovery from network failure)

2016-06-08 Thread Md Haris Iqbal
---
 include/migration/migration.h |  1 +
 migration/migration.c | 76 ---
 qapi-schema.json  | 11 +--
 vl.c  |  4 +++
 4 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 4a3201b..59e26e6 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -326,6 +326,7 @@ void global_state_store_running(void);
 void flush_page_queue(MigrationState *ms);
 int ram_save_queue_pages(MigrationState *ms, const char *rbname,
  ram_addr_t start, ram_addr_t len);
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState *ms);
 
 PostcopyState postcopy_state_get(void);
 /* Set the state and return the old state */
diff --git a/migration/migration.c b/migration/migration.c
index a77f62e..41c28e1 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -676,6 +676,33 @@ MigrationInfo *qmp_query_migrate(Error **errp)
 case MIGRATION_STATUS_CANCELLED:
 info->has_status = true;
 break;
+case MIGRATION_STATUS_POSTCOPY_RECOVERY:
+info->has_status = true;
+info->has_total_time = true;
+info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+
+info->has_ram = true;
+info->ram = g_malloc0(sizeof(*info->ram));
+info->ram->transferred = ram_bytes_transferred();
+info->ram->remaining = ram_bytes_remaining();
+info->ram->total = ram_bytes_total();
+info->ram->duplicate = dup_mig_pages_transferred();
+info->ram->skipped = skipped_mig_pages_transferred();
+info->ram->normal = norm_mig_pages_transferred();
+info->ram->normal_bytes = norm_mig_bytes_transferred();
+info->ram->dirty_pages_rate = s->dirty_pages_rate;
+info->ram->mbps = s->mbps;
+info->ram->dirty_sync_count = s->dirty_sync_count;
+
+if (blk_mig_active()) {
+info->has_disk = true;
+info->disk = g_malloc0(sizeof(*info->disk));
+info->disk->transferred = blk_mig_bytes_transferred();
+info->disk->remaining = blk_mig_bytes_remaining();
+info->disk->total = blk_mig_bytes_total();
+}
+
+get_xbzrle_cache_stats(info);
 }
 info->status = s->state;
 
@@ -1660,6 +1687,8 @@ static void *migration_thread(void *opaque)
 /* The active state we expect to be in; ACTIVE or POSTCOPY_ACTIVE */
 enum MigrationStatus current_active_state = MIGRATION_STATUS_ACTIVE;
 
+int ret;
+
 rcu_register_thread();
 
 qemu_savevm_state_header(s->to_dst_file);
@@ -1726,11 +1755,32 @@ static void *migration_thread(void *opaque)
 }
 }
 
-if (qemu_file_get_error(s->to_dst_file)) {
-migrate_set_state(&s->state, current_active_state,
-  MIGRATION_STATUS_FAILED);
-trace_migration_thread_file_err();
-break;
+if ((ret = qemu_file_get_error(s->to_dst_file))) {
+fprintf(stderr, "1 : Error %s %d\n", strerror(-ret), -ret);
+
+/*  This check is based on how the error is set during the network
+ *  recv(). When recv() returns 0 (i.e. no data to read), the error
+ *  is set to -EIO. For all other network errors, it is set
+ *  according to the return value received.
+ */
+if (ret != -EIO && s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
+/* Network Failure during postcopy */
+
+current_active_state = MIGRATION_STATUS_POSTCOPY_RECOVERY;
+runstate_set(RUN_STATE_POSTMIGRATE_RECOVERY);
+fprintf(stderr, "1.1 : Error %s %d\n", strerror(-ret), -ret);
+ret = qemu_migrate_postcopy_outgoing_recovery(s);
+if(ret < 0) {
+break;
+}
+
+} else {
+migrate_set_state(&s->state, current_active_state,
+ MIGRATION_STATUS_FAILED);
+fprintf(stderr, "1.2 : Error %s %d\n", strerror(-ret), -ret);
+trace_migration_thread_file_err();
+break;
+}
 }
 current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
 if (current_time >= initial_time + BUFFER_DELAY) {
@@ -1831,6 +1881,22 @@ void migrate_fd_connect(MigrationState *s)
 s->migration_thread_running = true;
 }
 
+int qemu_migrate_postcopy_outgoing_recovery(MigrationState* ms)
+{
+migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE,
+  MIGRATION_STATUS_POSTCOPY_RECOVERY);
+
+ms->in_recovery = true;
+/* Code for network recovery to be added here */
+while(atomic_mb_read(&ms->in_recovery) == true) {
+fprintf(stderr, "Not letting it fail %p\n", ms->to_dst_file);
+sleep(5);
+}
+
+return -1;

Re: [Qemu-devel] [PATCH v6 08/15] qdist: add module to represent frequency distributions of data

2016-06-08 Thread Emilio G. Cota
On Wed, Jun 08, 2016 at 17:10:03 +0300, Sergey Fedorov wrote:
> On 08/06/16 03:02, Emilio G. Cota wrote:
> > -dist->entries = g_realloc(dist->entries,
> > -  sizeof(*dist->entries) * (dist->n + 1));
> > +if (unlikely(dist->n == dist->size)) {
> > +dist->size = dist->size ? dist->size * 2 : 1;
> 
> We could initialize 'dist->size' to 1 and allocate a 1-entry
> 'dist->entries' array in qdist_init() to avoid this ternary operation ;-)

Done. This resulted in quite a few modifications, since dist->entries == NULL
had been used as an equivalent to dist->n == 0.

>  (snip)
> >> So our scale is not linear. I think some users might get confused by this.
> > That's correct. I think special-casing 0 makes sense though, since
> > it increases the signal-to-noise ratio of the histogram. For example:
> >
> > 1) 0 as ' ':
> > TB hash occupancy   31.84% avg chain occ. Histogram: [0,10)%|▆ █  
> > ▅▁▃▁▁|[90,100]%
> > TB hash avg chain   1.015 buckets. Histogram: 1|█▁▁|3
> >
> > 2) 0 as '1/8':
> > TB hash occupancy   32.07% avg chain occ. Histogram: 
> > [0,10)%|▆▁█▁▁▅▁▃▁▁|[90,100]%
> > TB hash avg chain   1.015 buckets. Histogram: 1|▇▁▁|3
> >
> > I think in these examples most users would be less confused by 1) than by 
> > 2).
> 
> I was meaning to represent all bars whose value < 1/8 as a space, not
> only whose value is pure zero. Otherwise we can see 1/8 bar where the
> actual value is negligibly differ from zero as in the second example.

I see. That would be (3):

TB hash occupancy   32.79% avg chain occ. Histogram: [0,10)%|▅ █  ▅ ▂  
|[90,100]%
TB hash avg chain   1.017 buckets. Histogram: 1|█  |3

I still think (1) is the representation that gives the most information.
IMO it's valuable that "close to zero" and "zero" are represented differently,
in the same way that max and "close to max" are represented differently
as well (only max gets 8/8).

BTW, while looking into this I fixed a bug; sometimes we'd print 7/8 instead
of 8/8 for the max value, due to the ordering of FP computations
[see 1-3 in (2) above; it's 7/8 instead of 8/8]. Fixed with:

diff --git a/util/qdist.c b/util/qdist.c
index cfe09e6..7842d34 100644
--- a/util/qdist.c
+++ b/util/qdist.c
@@ -103,7 +103,7 @@ static const gunichar qdist_blocks[] = {
  */
 static char *qdist_pr_internal(const struct qdist *dist)
 {
-double min, max, step;
+double min, max;
 GString *s = g_string_new("");
 size_t i;
 
@@ -131,16 +131,14 @@ static char *qdist_pr_internal(const struct qdist *dist)
 }
 }
 
-/* floor((count - min) * step) will give us the block index */
-step = (QDIST_NR_BLOCK_CODES - 1) / (max - min);
-
 for (i = 0; i < dist->n; i++) {
 struct qdist_entry *e = &dist->entries[i];
 int index;
 
 /* make an exception with 0; instead of using block[0], print a space 
*/
 if (e->count) {
-index = (int)((e->count - min) * step);
+/* divide first to avoid loss of precision when e->count == max */
+index = (e->count - min) / (max - min) * (QDIST_NR_BLOCK_CODES - 
1);
 g_string_append_unichar(s, qdist_blocks[index]);
 } else {
 g_string_append_c(s, ' ');

I also added a test to test-qdist (called "test_bin_precision") that
checks for this.

> > The behaviour isn't the same though. With this we have
> > that the two outer bins (leftmost and rightmost) are unnecessarily
> > large (since they're out of the range of the input data).
> >
> > For example, assume the data is between 0 and 100 and n=5 (i.e. step=25),
> > it makes no sense to report the first bin as [-12.5,12.5). If we
> > then truncate the unnecessary edges, we'd have [0,12.5), but
> > then the second bin is [12.5,37.5). Bins of unequal size are
> > possible (although a bit unusual) in histograms, but given
> > our Unicode-based representation, we're limited to same-width bars.
> 
> That is why I noted that I'm not sure what is the most correct from
> mathematical point of view. Maybe consider the second option? I.e.
> rounding to the middle of each bin with:
> 
> x = left + step / 2;
> 
> which would give the picture like this:
> 
> 
> xmin [*---*---*---*---*] xmax   -- from
>   |   |   |   |   |
>\ / \ / \ / \ /
> |   |   |   |
> V   V   V   V
>[*   *   *   *]  -- to

This binning is equivalent to what we do right now.

The only difference is where the value is set (either at the left
of the bin, or at the center as above); this, however, isn't too
important, since this value is only used when printing
the labels, i.e. we could print [left, left+step) or
[center-step/2, center+step/2) and still get the same results.

> Anyway, you may consider if you like whether it's possible to apply some
> simplifications from my code to the final version.

OK. This is how it looks like:

diff --git a/util/qdist.c b/util/qdist.c
index 7842d34..3ca2227 100644
---

[Qemu-devel] [PATCH v2] blockdev: clarify error on attempt to open locked tray

2016-06-08 Thread Colin Lord
When opening a device with a locked tray, gives an error explaining the
device tray is locked and that the user should wait and try again. This
is less confusing than the previous error, which simply stated that the
tray was locked.

Signed-off-by: Colin Lord 
---
Reworded commit message to hopefully explain things a little better.
As before this is based off my previously submitted patch v3.
 blockdev.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 7dd14b9..8a045d9 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2544,6 +2544,7 @@ void qmp_blockdev_change_medium(const char *device, const 
char *filename,
 BlockBackend *blk;
 BlockDriverState *medium_bs = NULL;
 int bdrv_flags;
+int rc;
 QDict *options = NULL;
 Error *err = NULL;
 
@@ -2598,11 +2599,13 @@ void qmp_blockdev_change_medium(const char *device, 
const char *filename,
 goto fail;
 }
 
-qmp_blockdev_open_tray(device, false, false, &err);
-if (err) {
+rc = do_open_tray(device, false, &err);
+if (rc && rc != -ENOSYS) {
 error_propagate(errp, err);
 goto fail;
 }
+error_free(err);
+err = NULL;
 
 qmp_x_blockdev_remove_medium(device, &err);
 if (err) {
-- 
2.5.5




Re: [Qemu-devel] [PULL 00/31] Block layer patches

2016-06-08 Thread Peter Maydell
On 8 June 2016 at 10:16, Kevin Wolf  wrote:
> The following changes since commit 6ed5546fa7bf12c5b87ef76bafb86e1d77ed6e85:
>
>   Merge remote-tracking branch 
> 'remotes/mjt/tags/pull-trivial-patches-2016-06-07' into staging (2016-06-07 
> 16:34:45 +0100)
>
> are available in the git repository at:
>
>
>   git://repo.or.cz/qemu/kevin.git tags/for-upstream
>
> for you to fetch changes up to 55d539c8f75abab70301a43d8c94b976f6ddc358:
>
>   qemu-img bench: Add --flush-interval (2016-06-08 10:21:09 +0200)
>
> 
> Block layer patches
>

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH 09/10] arm: virt: parse cpu_model only once

2016-06-08 Thread Peter Maydell
On 8 June 2016 at 17:55, Eduardo Habkost  wrote:
> On Mon, Jun 06, 2016 at 05:16:51PM +0200, Igor Mammedov wrote:
>> considering that features are converted to
>> global properties and global properties are
>> automatically applied to every new instance
>> of created CPU (at object_new() time), there
>> is no point in parsing cpu_model string every
>> time a CPU created.
>> So move parsing outside CPU creation loop and
>> do it only once.
>> Parsing also should be done before any CPU is
>> created so that features would affect the first
>> CPU a well.
>>
>> Signed-off-by: Igor Mammedov 
>
> Peter, do you prefer to get this included through my tree with
> the rest of the series, or wait to included it in your tree after
> the other patches get merged to master?

Seems easiest for you to take it.

Reviewed-by: Peter Maydell 

thanks
-- PMM



Re: [Qemu-devel] [PATCH v2 2/3] block/mirror: Fix target backing BDS

2016-06-08 Thread Nir Soffer
On Wed, Jun 8, 2016 at 12:32 PM, Kevin Wolf  wrote:
> Am 06.06.2016 um 16:42 hat Max Reitz geschrieben:
>> Currently, we are trying to move the backing BDS from the source to the
>> target in bdrv_replace_in_backing_chain() which is called from
>> mirror_exit(). However, mirror_complete() already tries to open the
>> target's backing chain with a call to bdrv_open_backing_file().
>>
>> First, we should only set the target's backing BDS once. Second, the
>> mirroring block job has a better idea of what to set it to than the
>> generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
>> conditions on when to move the backing BDS from source to target are not
>> really correct).
>>
>> Therefore, remove that code from bdrv_replace_in_backing_chain() and
>> leave it to mirror_complete().
>>
>> However, mirror_complete() in turn pursues a questionable strategy by
>> employing bdrv_open_backing_file(): On the one hand, because this may
>> open the wrong backing file with drive-mirror in "existing" mode, or
>> because it will not override a possibly wrong backing file in the
>> blockdev-mirror case.
>>
>> On the other hand, we want to reuse the existing backing chain of the
>> source instead of opening everything anew, because the latter results in
>> having multiple BDSs for a single physical file and thus potentially
>> concurrent access which we should try to avoid.
>
> Careful, this "wrong" backing file might actually be intended!
>
> Consider a case where you want to move an image with its whole backing
> chain to different storage. In that case, you would copy all of the
> backing files (cp is good enough, they are read-only), create the
> destination image which already points at the copied backing chain, and
> then mirror in "existing" mode.
>
> The intention is obviously that after the job completion the new backing
> chain is used and not the old one.
>
> I know that such cases were discussed when mirroring was introduced, I'm
> not sure whether it's actually used. We need some input there:
>
> Eric, can you tell us whether libvirt makes use of such a setup?
>
> Nir, I'm not sure who is the right person in oVirt these days, but do
> you either know yourself whether oVirt requires this to work, or do you
> know who else would know?

I'm the right person, thanks for keeping me in the loop.

What you describe is how we migrate a disk from one storage to another:

1. Create a vm snapshot
2. Create a volume on the destination storage for the snapshot
3. Start mirroring from the source snapshot to the destination snapshot
using libvirt virDomainBlockCopy:
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockCopy
4. Copy the reset of the chain from source to destination using qemu-img convert
5. Pivot to the new chain using libvirt virDomainBlockJobAbort
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockJobAbort
6. Remove the old chain

source and target can be files or block device, and we plan to support also
rbd and gluster volumes as target, maybe also as source.

Nir

>
>> Thus, instead of invoking bdrv_open_backing_file(), just set the correct
>> backing BDS directly via bdrv_set_backing_hd(). Also, do so only when
>> mirror_complete() is certain to succeed.
>>
>> In contrast to what bdrv_replace_in_backing_chain() did so far, we do
>> not need to drop the source's backing file.
>>
>> Signed-off-by: Max Reitz 
>
> Leaving the actual code review for later when we have decided what
> semantics we even want.
>
> Kevin



Re: [Qemu-devel] [PATCH] vl: Eliminate usb_enabled()

2016-06-08 Thread Eduardo Habkost
On Wed, Jun 08, 2016 at 02:34:16PM +0100, Peter Maydell wrote:
> On 8 June 2016 at 12:48, Paolo Bonzini  wrote:
> > - Original Message -
> >> From: "Marcel Apfelbaum" 
> >> To: "Eduardo Habkost" , qemu-devel@nongnu.org
> >> Cc: "Paolo Bonzini" , "Andrzej Zaborowski" 
> >> , "Peter Maydell"
> >> , "Michael S. Tsirkin" , 
> >> "Alexander Graf" 
> >> Sent: Wednesday, June 8, 2016 1:25:41 PM
> >> Subject: Re: [PATCH] vl: Eliminate usb_enabled()
> >>
> >> On 06/07/2016 07:56 PM, Eduardo Habkost wrote:
> >> > @@ -2062,6 +2063,7 @@ PXA2xxState *pxa270_init(MemoryRegion 
> >> > *address_space,
> >> >   int i;
> >> >   DriveInfo *dinfo;
> >> >   s = g_new0(PXA2xxState, 1);
> >> > +MachineState *machine = MACHINE(qdev_get_machine());
> >> >
> >>
> >> All the callers of pxa270_init have a reference to the machine,
> >> you can pass it as parameter IMO.
> >
> > Another possibility is to pass a "bool usb_enabled" argument.
> 
> Or we could just create the USB controller always -- this
> is a part of the SoC, not a removable pluggable device,
> so it doesn't make much sense for the user to be able
> to create a system where it's not present.

If you think this is better, I will do it and send v2. It will
make things simpler.

BTW, I am working on a series to refactor all the *_enabled/no_*
code. I will take this into account and add something that will
warn the user if they try to enable something that is never
present in the machine, or disable something that is always
present.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 10/10] pc: parse cpu features only once

2016-06-08 Thread Eduardo Habkost
On Mon, Jun 06, 2016 at 05:16:52PM +0200, Igor Mammedov wrote:
> considering that features are converted to
> global properties and global properties are
> automatically applied to every new instance
> of created CPU (at object_new() time), there
> is no point in parsing cpu_model string every
> time a CPU created.
> So move parsing outside CPU creation loop and
> do it only once.
> Parsing also should be done before any CPU is
> created so that features would affect the first
> CPU a well.
> 
> Signed-off-by: Igor Mammedov 
> ---
>  hw/i386/pc.c  | 37 -
>  target-i386/cpu.c | 44 
>  target-i386/cpu.h |  1 -
>  3 files changed, 28 insertions(+), 54 deletions(-)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index c48322b..0331e6d 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1041,21 +1041,17 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int 
> level)
>  }
>  }
>  
> -static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id,
> +static X86CPU *pc_new_cpu(const char *typename, int64_t apic_id,
>Error **errp)
>  {
>  X86CPU *cpu = NULL;
>  Error *local_err = NULL;
>  
> -cpu = cpu_x86_create(cpu_model, &local_err);
> -if (local_err != NULL) {
> -goto out;
> -}
> +cpu = X86_CPU(object_new(typename));

Nice. :)

>  
>  object_property_set_int(OBJECT(cpu), apic_id, "apic-id", &local_err);
>  object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
>  
> -out:
>  if (local_err) {
>  error_propagate(errp, local_err);
>  object_unref(OBJECT(cpu));
> @@ -1067,7 +1063,8 @@ out:
>  void pc_hot_add_cpu(const int64_t id, Error **errp)
>  {
>  X86CPU *cpu;
> -MachineState *machine = MACHINE(qdev_get_machine());
> +ObjectClass *oc;
> +PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
>  int64_t apic_id = x86_cpu_apic_id_from_index(id);
>  Error *local_err = NULL;
>  
> @@ -1095,7 +1092,9 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
>  return;
>  }
>  
> -cpu = pc_new_cpu(machine->cpu_model, apic_id, &local_err);
> +assert(pcms->possible_cpus->cpus[0].cpu); /* BSP is always present */
> +oc = OBJECT_CLASS(CPU_GET_CLASS(pcms->possible_cpus->cpus[0].cpu));

The same pattern will probably repeat in other machines. I
wouldn't mind adding a new MachineState::cpu_type field, as we
already have MachineState::cpu_model.

MachineState::cpu_model could eventually go away if we move all
parse_features() calls to generic code.

> +cpu = pc_new_cpu(object_class_get_name(oc), apic_id, &local_err);
>  if (local_err) {
>  error_propagate(errp, local_err);
>  return;
> @@ -1106,6 +1105,10 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
>  void pc_cpus_init(PCMachineState *pcms)
>  {
>  int i, j;
> +CPUClass *cc;
> +ObjectClass *oc;
> +const char *typename;
> +gchar **model_pieces;
>  X86CPU *cpu = NULL;
>  MachineState *machine = MACHINE(pcms);
>  
> @@ -1118,6 +1121,22 @@ void pc_cpus_init(PCMachineState *pcms)
>  #endif
>  }
>  
> +model_pieces = g_strsplit(machine->cpu_model, ",", 2);
> +if (!model_pieces[0]) {
> +error_report("Invalid/empty CPU model name");
> +exit(1);
> +}
> +
> +oc = cpu_class_by_name(TYPE_X86_CPU, model_pieces[0]);
> +if (oc == NULL) {
> +error_report("Unable to find CPU definition: %s", model_pieces[0]);
> +exit(1);
> +}
> +typename = object_class_get_name(oc);
> +cc = CPU_CLASS(oc);
> +cc->parse_features(typename, model_pieces[1], &error_fatal);
> +g_strfreev(model_pieces);

Can we move this to a generic function to be reused by other
machines?

> +
>  /* Calculates the limit to CPU APIC ID values
>   *
>   * Limit for the APIC ID value, so that all
> @@ -1148,7 +1167,7 @@ void pc_cpus_init(PCMachineState *pcms)
>  }
>  
>  if (i < smp_cpus) {
> -cpu = pc_new_cpu(machine->cpu_model, 
> x86_cpu_apic_id_from_index(i),
> +cpu = pc_new_cpu(typename, x86_cpu_apic_id_from_index(i),
>   &error_fatal);
>  pcms->possible_cpus->cpus[i].cpu = CPU(cpu);
>  object_unref(OBJECT(cpu));
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 43b22e6..c633579 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2211,50 +2211,6 @@ static void x86_cpu_load_def(X86CPU *cpu, 
> X86CPUDefinition *def, Error **errp)
>  
>  }
>  
> -X86CPU *cpu_x86_create(const char *cpu_model, Error **errp)
> -{
> -X86CPU *cpu = NULL;
> -ObjectClass *oc;
> -CPUClass *cc;
> -gchar **model_pieces;
> -char *name, *features;
> -Error *error = NULL;
> -const char *typename;
> -
> -model_pieces = g_strsplit(cpu_model, ",", 2);
> -if (!model_pieces[0]) {
> -error_setg(&error, "Invalid/empty CPU 

Re: [Qemu-devel] [PATCH 09/10] arm: virt: parse cpu_model only once

2016-06-08 Thread Eduardo Habkost
On Mon, Jun 06, 2016 at 05:16:51PM +0200, Igor Mammedov wrote:
> considering that features are converted to
> global properties and global properties are
> automatically applied to every new instance
> of created CPU (at object_new() time), there
> is no point in parsing cpu_model string every
> time a CPU created.
> So move parsing outside CPU creation loop and
> do it only once.
> Parsing also should be done before any CPU is
> created so that features would affect the first
> CPU a well.
> 
> Signed-off-by: Igor Mammedov 

Peter, do you prefer to get this included through my tree with
the rest of the series, or wait to included it in your tree after
the other patches get merged to master?

> ---
>  hw/arm/virt.c | 42 +-
>  1 file changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 473e439..0dbee47 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -1112,6 +1112,10 @@ static void machvirt_init(MachineState *machine)
>  VirtGuestInfoState *guest_info_state = g_malloc0(sizeof 
> *guest_info_state);
>  VirtGuestInfo *guest_info = &guest_info_state->info;
>  char **cpustr;
> +ObjectClass *oc;
> +const char *typename;
> +CPUClass *cc;
> +Error *err = NULL;
>  bool firmware_loaded = bios_name || drive_get(IF_PFLASH, 0, 0);
>  
>  if (!cpu_model) {
> @@ -1191,27 +1195,24 @@ static void machvirt_init(MachineState *machine)
>  
>  create_fdt(vbi);
>  
> -for (n = 0; n < smp_cpus; n++) {
> -ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpustr[0]);
> -const char *typename = object_class_get_name(oc);
> -CPUClass *cc = CPU_CLASS(oc);
> -Object *cpuobj;
> -Error *err = NULL;
> -char *cpuopts = g_strdup(cpustr[1]);
> -
> -if (!oc) {
> -error_report("Unable to find CPU definition");
> -exit(1);
> -}
> -/* convert -smp CPU options specified by the user into global props 
> */
> -cc->parse_features(typename, cpuopts, &err);
> -cpuobj = object_new(typename);
> +oc = cpu_class_by_name(TYPE_ARM_CPU, cpustr[0]);
> +if (!oc) {
> +error_report("Unable to find CPU definition");
> +exit(1);
> +}
> +typename = object_class_get_name(oc);
>  
> -g_free(cpuopts);
> -if (err) {
> -error_report_err(err);
> -exit(1);
> -}
> +/* convert -smp CPU options specified by the user into global props */
> +cc = CPU_CLASS(oc);
> +cc->parse_features(typename, cpustr[1], &err);
> +g_strfreev(cpustr);
> +if (err) {
> +error_report_err(err);
> +exit(1);
> +}
> +
> +for (n = 0; n < smp_cpus; n++) {
> +Object *cpuobj = object_new(typename);
>  
>  if (!vms->secure) {
>  object_property_set_bool(cpuobj, false, "has_el3", NULL);
> @@ -1242,7 +1243,6 @@ static void machvirt_init(MachineState *machine)
>  
>  object_property_set_bool(cpuobj, true, "realized", NULL);
>  }
> -g_strfreev(cpustr);
>  fdt_add_timer_nodes(vbi, gic_version);
>  fdt_add_cpu_nodes(vbi);
>  fdt_add_psci_node(vbi);
> -- 
> 1.8.3.1
> 

-- 
Eduardo



[Qemu-devel] [PATCH 3/3] .travis.yml: disable Sparse testing

2016-06-08 Thread Alex Bennée
From: Paolo Bonzini 

On travis-ci.org, all builds fail with
   /usr/include/features.h:324:11: error: unable to open bits/predefs.h

With "make docker-travis@ubuntu", they fail with
   /usr/include/features.h:374:13: error: unable to open sys/cdefs.h

With "make docker-travis@fedora", finally, they fail due to sparse
not being able to parse some #pragmas in glib headers.  Just kill
the thing from the CI builds.

Signed-off-by: Paolo Bonzini 
[AJB: tweak title for my OCD]
Signed-off-by: Alex Bennée 
---
 .travis.yml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index cde7d1a..c13881e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -64,9 +64,6 @@ script:
   - make -j3 && ${TEST_CMD}
 matrix:
   include:
-# Sparse is GCC only
-- env: CONFIG="--enable-sparse"
-  compiler: gcc
 # gprof/gcov are GCC features
 - env: CONFIG="--enable-gprof --enable-gcov --disable-pie"
   compiler: gcc
-- 
2.7.4




Re: [Qemu-devel] [PATCH v2 2/3] block/mirror: Fix target backing BDS

2016-06-08 Thread Max Reitz
On 08.06.2016 16:38, Max Reitz wrote:
> On 08.06.2016 11:32, Kevin Wolf wrote:
>> Am 06.06.2016 um 16:42 hat Max Reitz geschrieben:
>>> Currently, we are trying to move the backing BDS from the source to the
>>> target in bdrv_replace_in_backing_chain() which is called from
>>> mirror_exit(). However, mirror_complete() already tries to open the
>>> target's backing chain with a call to bdrv_open_backing_file().
>>>
>>> First, we should only set the target's backing BDS once. Second, the
>>> mirroring block job has a better idea of what to set it to than the
>>> generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
>>> conditions on when to move the backing BDS from source to target are not
>>> really correct).
>>>
>>> Therefore, remove that code from bdrv_replace_in_backing_chain() and
>>> leave it to mirror_complete().
>>>
>>> However, mirror_complete() in turn pursues a questionable strategy by
>>> employing bdrv_open_backing_file(): On the one hand, because this may
>>> open the wrong backing file with drive-mirror in "existing" mode, or
>>> because it will not override a possibly wrong backing file in the
>>> blockdev-mirror case.
>>>
>>> On the other hand, we want to reuse the existing backing chain of the
>>> source instead of opening everything anew, because the latter results in
>>> having multiple BDSs for a single physical file and thus potentially
>>> concurrent access which we should try to avoid.
>>
>> Careful, this "wrong" backing file might actually be intended!
> 
> True.
> 
> I still consider completely opening the backing chain not correct,
> though, at least in absolute-paths mode, because this will result in
> having at least two BDSs for single physical image files (once for the
> old chain, once for the new one).
> 
> So let's go through everything.
> 
> == drive-mirror with absolute-paths ==
> 
> We already have the backing chain open (around the source BDS), and it's
> definitely the correct one. So I think we can always reuse it for the
> target.
> 
> == drive-mirror with existing ==
> 
> You're right, we should probably keep doing bdrv_open_backing_file()
> because we cannot check whether the existing image has the same backing
> chain as a new absolute-paths image would have had.
> 
> This is prone to give you some issues if you actually do want to have
> the "default" backing chain, though, because of the multiple BDS thing.
> This case is basically guaranteed to break with sync=none and default
> image locking.
> 
> == blockdev-mirror ==
> 
> In theory the simplest one: We just assume the backing chain of the
> target has been opened already, and then we blame the user if they have
> created multiple BDSs per physical file.
> 
> Unluckily in practice, though, we require the target BDS to not have a
> backing file at all. blockdev-mirror is just supposed to open the
> backing chain after completion, which I really don't like (I don't think
> a blockdev- command should do this kind of magic).

Good news: Turns out I was wrong. I was somehow mixing things up with
blockdev-snapshot (don't ask me why, I have no clue).

So I think it'd be fine to rely on the user that the backing chain of
the target is correct.

Max

> Maybe we should allow the target to have a backing file (I really don't
> see why it shouldn't have one) and treat the non-backing case like
> drive-mirror in existing mode.
> 
> 
> Does that sound right?
> 
> Max
> 
> 
>> Consider a case where you want to move an image with its whole backing
>> chain to different storage. In that case, you would copy all of the
>> backing files (cp is good enough, they are read-only), create the
>> destination image which already points at the copied backing chain, and
>> then mirror in "existing" mode.
>>
>> The intention is obviously that after the job completion the new backing
>> chain is used and not the old one.
>>
>> I know that such cases were discussed when mirroring was introduced, I'm
>> not sure whether it's actually used. We need some input there:
>>
>> Eric, can you tell us whether libvirt makes use of such a setup?
>>
>> Nir, I'm not sure who is the right person in oVirt these days, but do
>> you either know yourself whether oVirt requires this to work, or do you
>> know who else would know?
>>
>>> Thus, instead of invoking bdrv_open_backing_file(), just set the correct
>>> backing BDS directly via bdrv_set_backing_hd(). Also, do so only when
>>> mirror_complete() is certain to succeed.
>>>
>>> In contrast to what bdrv_replace_in_backing_chain() did so far, we do
>>> not need to drop the source's backing file.
>>>
>>> Signed-off-by: Max Reitz 
>>
>> Leaving the actual code review for later when we have decided what
>> semantics we even want.
>>
>> Kevin
>>
> 
> 




signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 1/3] .travis.yml: add libnfs-dev for NFS block driver

2016-06-08 Thread Alex Bennée
From: Stefan Hajnoczi 

Let's ensure that block/nfs.o is built in Travis.

This patch depends on the following build fixes:
1. block/nfs: add missing #include "qapi/error.h"
2. block/nfs: add missing #include "qemu/cutils.h"

This patch also depends on Travis adding libnfs-dev to the list of
approved packages.  This patch can be safely committed but will not do
anything until the Travis maintainers allow libnfs-dev to be installed.
Please see the GitHub Issue I raised here:
https://github.com/travis-ci/apt-package-whitelist/issues/2788

Signed-off-by: Stefan Hajnoczi 
Signed-off-by: Alex Bennée 
---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 50ac17f..beb98d3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,6 +17,7 @@ addons:
   - libgtk-3-dev
   - libiscsi-dev
   - liblttng-ust-dev
+  - libnfs-dev
   - libncurses5-dev
   - libnss3-dev
   - libpixman-1-dev
-- 
2.7.4




[Qemu-devel] [PATCH 0/3] Current travis queue

2016-06-08 Thread Alex Bennée
Hi,

I have contributions from other developers which is an exciting first
as a "maintainer" ;-). I've dropped all the controversial stuff that
involved tweaking the configure script to allow short-cutting for
classes of targets. Assuming there is no shouting over the next few
days this will be the pull request I submit.

Alex Bennée (1):
  .travis.yml: add trusty GCE target

Paolo Bonzini (1):
  .travis.yml: disable Sparse testing

Stefan Hajnoczi (1):
  .travis.yml: add libnfs-dev for NFS block driver

 .travis.yml | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

-- 
2.7.4




[Qemu-devel] [PATCH 2/3] .travis.yml: add trusty GCE target

2016-06-08 Thread Alex Bennée
If we want to run our docker based tests we'll need to do them on a
normal VM with docker support. Lets just enable the build on trusty for
now to check against a newer Ubuntu.

Signed-off-by: Alex Bennée 
---
 .travis.yml | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index beb98d3..cde7d1a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -89,3 +89,13 @@ matrix:
 - env: CONFIG=""
   os: osx
   compiler: clang
+- env: CONFIG=""
+  sudo: required
+  addons:
+  dist: trusty
+  compiler: gcc
+  before_install:
+- sudo apt-get update -qq
+- sudo apt-get build-dep -qq qemu
+- wget -O - 
http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ
+- git submodule update --init --recursive
-- 
2.7.4




Re: [Qemu-devel] [PATCH 08/10] cpu: use CPUClass->parse_features() as convertor to global properties

2016-06-08 Thread Eduardo Habkost
On Mon, Jun 06, 2016 at 05:16:50PM +0200, Igor Mammedov wrote:
> Currently CPUClass->parse_features() is used to parse
> -cpu features string and set properties on created CPU
> instances.
> 
> But considering that features specified by -cpu apply to
> every created CPU instance, it doesn't make sence to
> parse the same features string for every CPU created.
> It also makes every target that cares about parsing
> features string explicitly call CPUClass->parse_features()
> parser, which gets in a way if we consider using
> generic device_add for CPU hotplug as device_add
> has not a clue about CPU specific hooks.
> 
> Turns out we can use global properties mechanism to set
> properties on every created CPU instance for a given
> type. That way it's possible to convert CPU features
> into a set of global properties for CPU type specified
> by -cpu cpu_model and common Device.device_post_init()
> will apply them to CPU of given type automatically
> regardless whether it's manually created CPU or CPU
> created with help of device_add.
> 
> Signed-off-by: Igor Mammedov 
> ---
> This patch only make CPUClass->parse_features()
> a global properties convertor and follow up patches
> will switch individual users to new behaviour

Considering that we won't fix all callers to not call it multiple
times in the same series, can we add TODO notes to the
->parse_features() callers that are still need to be fixed?

Additional comments (and TODO notes suggestions) below:

> ---
>  hw/arm/virt.c |  7 ---
>  include/qom/cpu.h |  2 +-
>  qom/cpu.c | 29 +
>  target-i386/cpu.c | 30 --
>  4 files changed, 42 insertions(+), 26 deletions(-)
> 
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index e77ed88..473e439 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -1193,6 +1193,7 @@ static void machvirt_init(MachineState *machine)
>  
>  for (n = 0; n < smp_cpus; n++) {
>  ObjectClass *oc = cpu_class_by_name(TYPE_ARM_CPU, cpustr[0]);
> +const char *typename = object_class_get_name(oc);
>  CPUClass *cc = CPU_CLASS(oc);
>  Object *cpuobj;
>  Error *err = NULL;
> @@ -1202,10 +1203,10 @@ static void machvirt_init(MachineState *machine)
>  error_report("Unable to find CPU definition");
>  exit(1);
>  }
> -cpuobj = object_new(object_class_get_name(oc));
> +/* convert -smp CPU options specified by the user into global props 
> */
> +cc->parse_features(typename, cpuopts, &err);

/*TODO: call cc->parse_features() only once */

> +cpuobj = object_new(typename);
>  
> -/* Handle any CPU options specified by the user */
> -cc->parse_features(CPU(cpuobj), cpuopts, &err);
>  g_free(cpuopts);
>  if (err) {
>  error_report_err(err);
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 32f3af3..cacb100 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -134,7 +134,7 @@ typedef struct CPUClass {
>  /*< public >*/
>  
>  ObjectClass *(*class_by_name)(const char *cpu_model);
> -void (*parse_features)(CPUState *cpu, char *str, Error **errp);
> +void (*parse_features)(const char *typename, char *str, Error **errp);
>  
>  void (*reset)(CPUState *cpu);
>  int reset_dump_flags;
> diff --git a/qom/cpu.c b/qom/cpu.c
> index 751e992..f3e3c02 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -28,6 +28,7 @@
>  #include "exec/log.h"
>  #include "qemu/error-report.h"
>  #include "sysemu/sysemu.h"
> +#include "hw/qdev-properties.h"
>  
>  bool cpu_exists(int64_t id)
>  {
> @@ -46,7 +47,7 @@ bool cpu_exists(int64_t id)
>  CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
>  {
>  char *str, *name, *featurestr;
> -CPUState *cpu;
> +CPUState *cpu = NULL;
>  ObjectClass *oc;
>  CPUClass *cc;
>  Error *err = NULL;
> @@ -60,16 +61,15 @@ CPUState *cpu_generic_init(const char *typename, const 
> char *cpu_model)
>  return NULL;
>  }
>  
> -cpu = CPU(object_new(object_class_get_name(oc)));
> -cc = CPU_GET_CLASS(cpu);
> -
> +cc = CPU_CLASS(oc);
>  featurestr = strtok(NULL, ",");
> -cc->parse_features(cpu, featurestr, &err);
> +cc->parse_features(object_class_get_name(oc), featurestr, &err);

/*TODO: all callers of cpu_generic_init() need to be converted to
 * call parse_features() only once, before calling cpu_generic_init().
 */

>  g_free(str);
>  if (err != NULL) {
>  goto out;
>  }
>  
> +cpu = CPU(object_new(object_class_get_name(oc)));
>  object_property_set_bool(OBJECT(cpu), true, "realized", &err);
>  
>  out:
> @@ -282,25 +282,29 @@ static ObjectClass *cpu_common_class_by_name(const char 
> *cpu_model)
>  return NULL;
>  }
>  
> -static void cpu_common_parse_features(CPUState *cpu, char *features,
> +static void cpu_common_parse_features(const char *typename, char *features,
> 

Re: [Qemu-devel] [PATCH v6 00/15] tb hash improvements

2016-06-08 Thread Alex Bennée

Sergey Fedorov  writes:

> On 08/06/16 18:35, Richard Henderson wrote:
>> On 06/07/2016 11:25 PM, Alex Bennée wrote:
>>> Richard,
>>>
>>> How happy are you with this series so far? Are you planning to take in
>>> via your tree when ready?
>> I'm happy with it.  I was all set to merge v6 before Sergey started 
>> commenting.
>
> I think v7 would be fine for merge yet :)

Cool, we await v7 with baited breath then ;-)

--
Alex Bennée



[Qemu-devel] [PATCH v2 0/3] Support building qemu-user powered docker test images

2016-06-08 Thread Alex Bennée
Hi,

This is a re-spin of the previous series built on top of
fam/docker.next. I've made the changes suggested in the last review
and split the first patch apart to separate (and fix) the build
directory changes first.

Now it no longer messes with the docker file you can actually
cross-build tests. First ensure you build the debian-bootstrap image:

DEB_ARCH=armhf DEB_TYPE=testing \
  ./tests/docker/docker.py build qemu:debian-bootstrap \
  ./tests/docker/dockerfiles/debian-bootstrap.docker \
  --include-executable=./arm-linux-user/qemu-arm

And then run the test quick target:

make docker-test-quick@debian-bootstrap J=9 V=1

I'll leave it up to you how we cleanly integrate multi-arch builds
into the Make system ;-)

Alex Bennée (3):
  tests/docker/docker.py: docker_dir outside build
  tests/docker/docker.py: support --include-executable
  add debian-bootstrap.docker target (and pre script)

 tests/docker/docker.py   | 68 +---
 tests/docker/dockerfiles/debian-bootstrap.docker | 21 
 tests/docker/dockerfiles/debian-bootstrap.pre|  5 ++
 3 files changed, 86 insertions(+), 8 deletions(-)
 create mode 100644 tests/docker/dockerfiles/debian-bootstrap.docker
 create mode 100755 tests/docker/dockerfiles/debian-bootstrap.pre

-- 
2.7.4




[Qemu-devel] [PATCH v2 2/3] tests/docker/docker.py: support --include-executable

2016-06-08 Thread Alex Bennée
When passed the path to a binary we copy it and any linked libraries
into the docker build context. These can then be included by a
dockerfile with the line:

  # Copy all of context into container
  ADD . /

This is mainly intended for setting up foreign architecture docker
images which use qemu-$arch to do cross-architecture linux-user
execution. It also relies on the host and guest file-system following
reasonable multi-arch layouts so the copied libraries don't clash with
the guest ones.

Signed-off-by: Alex Bennée 

---
v2
  - change name of option
  - require full path to executable
  - clean-up the copy code
---
 tests/docker/docker.py | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index ae40bb3..ed6fa45 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -20,6 +20,7 @@ import atexit
 import uuid
 import argparse
 import tempfile
+import re
 from shutil import copy, rmtree
 
 def _text_checksum(text):
@@ -38,6 +39,38 @@ def _guess_docker_command():
 raise Exception("Cannot find working docker command. Tried:\n%s" % \
 commands_txt)
 
+def _copy_with_mkdir(src, root_dir, sub_path):
+"""Copy src into root_dir, creating sub_path as needed."""
+dest_dir = os.path.normpath("%s/%s" % (root_dir, sub_path))
+try:
+os.makedirs(dest_dir)
+except OSError:
+print "%s already created" % (dest_dir)
+
+dest_file = "%s/%s" % (dest_dir, os.path.basename(src))
+copy(src, dest_file)
+
+
+def _copy_binary_with_libs(src, dest_dir):
+"""Copy a binary executable and all its dependant libraries.
+
+This does rely on the host file-system being fairly multi-arch
+aware so the file don't clash with the guests layout."""
+
+_copy_with_mkdir(src, dest_dir, "/usr/bin")
+
+# do ldd bit here
+ldd_re = re.compile(r"(/.*/)(\S*)")
+ldd_output = subprocess.check_output(["ldd", src])
+for line in ldd_output.split("\n"):
+search = ldd_re.search(line)
+if search and len(search.groups()) == 2:
+so_path = search.groups()[0]
+so_lib = search.groups()[1]
+_copy_with_mkdir("%s/%s" % (so_path, so_lib),
+ dest_dir, so_path)
+
+
 class Docker(object):
 """ Running Docker commands """
 def __init__(self):
@@ -151,6 +184,10 @@ class BuildCommand(SubCommand):
 """ Build docker image out of a dockerfile. Arguments:  
"""
 name = "build"
 def args(self, parser):
+parser.add_argument("--include-executable", "-e",
+help="""Specify a binary that will be copied to the
+container together with all its dependent
+libraries""")
 parser.add_argument("tag",
 help="Image Tag")
 parser.add_argument("dockerfile",
@@ -168,6 +205,11 @@ class BuildCommand(SubCommand):
 # Create a docker context directory for the build
 docker_dir = tempfile.mkdtemp(prefix="docker_build")
 
+# Do we include a extra binary?
+if args.include_executable:
+_copy_binary_with_libs(args.include_executable,
+   docker_dir)
+
 dkr.build_image(tag, docker_dir, dockerfile,
 quiet=args.quiet, argv=argv)
 
-- 
2.7.4




  1   2   3   4   >