Re: [Qemu-devel] [PATCH v4 00/10] cpu: add device_add foo-x86_64-cpu support

2015-02-23 Thread Gu Zheng
Hi Igor, Andreas,

The issues you commented in the previous version have been fixed in this one.
Could you please help to review it?

Regards,
Gu
On 02/13/2015 06:25 PM, Zhu Guihua wrote:

 This series is based on the previous patchset from Chen Fan:
 https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html
 
 We try to make cpu hotplug with device_add, and make
 -device foo-x86_64-cpu available, also we can set apic-id
 property with command line, if without setting apic-id property,
 we offer the first unoccupied apic id as the default new apic id.
 When hotplug cpu with device_add, additional check of APIC ID will be
 done after cpu object initialization which was different from
 'cpu_add' command that check 'ids' at the beginning.
 
 The is the first half of the previous series:
 [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove 
 support
 https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html
 
 ---
 Changelog since v3:
  -fix cross version migration issue
  -drop ICC bus impl
  -do a generic for apic to send gpe event
  -do not use migration code for CONFIG_USER_ONLY target
 
 Changelog since v2:
  -rebase on latest upstream.
  -add cpu instance finalize.
 
 Changelog since v1:
  -rebased on latest upstream.
  -introduce a help function to hide the access to icc_bus.
  -use a macro ACPI_ID_NOT_SET to replace the magic number(0x).
 
 Changelog since RFC:
  -split out APIC vmstate/QMP-monitor changes into separate patches.
  -add the handle of the startup cpus(-device foo).
  -remove duplicated checking about env-cpuid_apic_id.
  -do actual APIC ID allocation at realize time if it is not set before.
  -remove the unneeded x86_cpu_cpudef_instance_init().
  -split off device_del support out here.
 ---
 
 Chen Fan (4):
   cpu/apic: drop icc bus/bridge/
   icc_bus: remove icc related files
   cpu: introduce CpuTopoInfo structure for argument simplification
   cpu: add device_add foo-x86_64-cpu support
 
 Gu Zheng (4):
   qom/cpu: move register_vmstate to common CPUClass.realizefn
   qom/cpu: move apic vmstate register into x86_cpu_apic_realize
   monitor: use cc-get_arch_id as the cpu index
   i386/cpu: add instance finalize callback
 
 Zhu Guihua (2):
   cpu: introduce get_compat_arch_id() method and override it for X86CPU
   acpi: introduce acpi_send_gpe_event()
 
  MAINTAINERS|   6 --
  cpus.c |   4 +-
  default-configs/i386-softmmu.mak   |   1 -
  default-configs/x86_64-softmmu.mak |   1 -
  exec.c |  25 +---
  hw/acpi/core.c |   7 +++
  hw/acpi/cpu_hotplug.c  |   6 +-
  hw/cpu/Makefile.objs   |   2 -
  hw/cpu/icc_bus.c   | 118 
 -
  hw/i386/kvm/apic.c |  10 +++-
  hw/i386/pc.c   |  27 ++---
  hw/i386/pc_piix.c  |   9 +--
  hw/i386/pc_q35.c   |   9 +--
  hw/intc/apic.c |  16 +++--
  hw/intc/apic_common.c  |  17 +++---
  include/hw/acpi/acpi.h |   3 +
  include/hw/cpu/icc_bus.h   |  82 --
  include/hw/i386/apic_internal.h|   9 +--
  include/hw/i386/pc.h   |   3 +-
  include/qom/cpu.h  |   6 ++
  monitor.c  |   4 +-
  qom/cpu.c  |  10 
  target-i386/cpu.c  |  95 ++---
  target-i386/cpu.h  |   3 +-
  target-i386/topology.h |  66 -
  25 files changed, 223 insertions(+), 316 deletions(-)
  delete mode 100644 hw/cpu/icc_bus.c
  delete mode 100644 include/hw/cpu/icc_bus.h
 





Re: [Qemu-devel] [PATCH v3 0/7] cpu: add i386 cpu hot remove support

2015-02-23 Thread Gu Zheng
Hi Igor, Andreas,

Could you please help to review this version?

Thanks,
Gu
On 02/13/2015 06:40 PM, Zhu Guihua wrote:

 This series is based on chen fan's previous i386 cpu hot remove patchset:
 https://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg04266.html
 
 Via implementing ACPI standard methods _EJ0 in ACPI table, after Guest
 OS remove one vCPU online, the fireware will store removed bitmap to
 QEMU, then QEMU could know to notify the assigned vCPU of exiting.
 Meanwhile, intruduce the QOM command 'device_del' to remove vCPU from
 QEMU itself.
 
 The whole work is based on the new hot plug/unplug framework, ,the unplug 
 request
 callback does the pre-check and send the request, unplug callback does the
 removal handling.
 
 This series depends on tangchen's common hot plug/unplug enhance patchset.
 [PATCH v2 0/5] Common unplug and unplug request cb for memory and CPU 
 hot-unplug
 https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg03929.html
 
 The is the second half of the previous series:
   
 [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove 
 support
 https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html
  
 
 If you want to test the series, you need to apply the 'device_add 
 foo-x86_64-cpu'
 patchset first:
 [PATCH v4 00/10] cpu: add device_add foo-x86_64-cpu support
 https://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg02584.html
 
 ---
 Changelog since v2:
  -drop ICC bus impl
  -fix delete cpu exceed 32 issue
  -fix bug about deleting the last cpu
 
 Changelog since v1:
  -rebase on the latest version.
  -delete patch i386/cpu: add instance finalize callback, and put it into 
 patchset
   [PATCH v3 0/6] cpu: add device_add foo-x86_64-cpu support.
 
 Changelog since RFC:
  -splited the i386 cpu hot remove into single thread.
  -replaced apic_no with apic_id, so does the related stuff to make it
   work with arbitrary CPU hotadd.
  -add the icc_device_unrealize callback to handle apic unrealize.
  -rework on the new hot plug/unplug platform.
 ---
 
 Chen Fan (2):
   x86: add x86_cpu_unrealizefn() for cpu apic remove
   cpu hotplug: implement function cpu_status_write() for vcpu ejection
 
 Gu Zheng (3):
   acpi/cpu: add cpu hot unplug request callback function
   acpi, pc: add cpu hot unplug callback support
   cpus: reclaim allocated vCPU objects
 
 Zhu Guihua (2):
   acpi, pc: add cpu hot unplug request callback support
   acpi/cpu: add cpu hot unplug callback function
 
  cpus.c| 44 
  hw/acpi/cpu_hotplug.c | 87 
 ---
  hw/acpi/ich9.c| 17 ++--
  hw/acpi/piix4.c   | 12 +-
  hw/core/qdev.c|  2 +-
  hw/i386/acpi-dsdt-cpu-hotplug.dsl | 16 ++-
  hw/i386/kvm/apic.c|  5 +++
  hw/i386/pc.c  | 68 --
  hw/intc/apic.c|  9 
  hw/intc/apic_common.c | 21 ++
  include/hw/acpi/cpu_hotplug.h |  8 
  include/hw/i386/apic_internal.h   |  1 +
  include/hw/qdev-core.h|  1 +
  include/qom/cpu.h |  9 
  include/sysemu/kvm.h  |  1 +
  kvm-all.c | 57 -
  target-i386/cpu.c | 46 +
  17 files changed, 377 insertions(+), 27 deletions(-)
 





Re: [Qemu-devel] [PATCH 00/12] cpu: add i386 cpu hot remove support

2014-12-18 Thread Gu Zheng
ping...
On 12/12/2014 04:43 PM, Gu Zheng wrote:

 This series is based on chen fan's previous i386 cpu hot remove patchset:
 https://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg04266.html
 
 Via implementing ACPI standard methods _EJ0 in ACPI table, after Guest
 OS remove one vCPU online, the fireware will store removed bitmap to
 QEMU, then QEMU could know to notify the assigned vCPU of exiting.
 Meanwhile, intruduce the QOM command 'device_del' to remove vCPU from
 QEMU itself.
 
 The whole work is based on the new hot plug/unplug framework, ,the unplug 
 request
 callback does the pre-check and send the request, unplug callback does the
 removal handling.
 
 This series depends on tangchen's common hot plug/unplug enhance patchset.
 [PATCH] Common unplug and unplug request cb for memory and CPU hot-unplug.
 https://lists.nongnu.org/archive/html/qemu-devel/2014-12/msg01462.html
 
 The is the second half of the previous series:
   
 [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove 
 support
 https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html
  
 
 If you want to test the series, you need to apply the 'device_add 
 foo-x86_64-cpu'
 patchset first:
 [PATCH V2 0/6] cpu: add device_add foo-x86_64-cpu support
 https://lists.nongnu.org/archive/html/qemu-devel/2014-12/msg01812.html
 
 ---
 Changelog since RFC:
  -splited the i386 cpu hot remove into single thread.
  -replaced apic_no with apic_id, so does the related stuff to make it
   work with arbitrary CPU hotadd.
  -add the icc_device_unrealize callback to handle apic unrealize.
  -rework on the new hot plug/unplug platform.
 ---
 
 Chen Fan (2):
   x86: add x86_cpu_unrealizefn() for cpu apic remove
   cpu hotplug: implement function cpu_status_write() for vcpu ejection
 
 Gu Zheng (6):
   i386/cpu: add instance finalize callback
   acpi/cpu: add cpu hot unplug request callback function
   acpi/piix4: add cpu hot unplug callback support
   acpi/ich9: add cpu hot unplug support
   pc: add cpu hot unplug callback support
   cpus: reclaim allocated vCPU objects
 
 Zhu Guihua (4):
   acpi/piix4: add cpu hot unplug request callback support
   acpi/ich9: add cpu hot unplug request callback support
   pc: add cpu hot unplug request callback support
   acpi/cpu: add cpu hot unplug callback function
 
  cpus.c|   44 ++
  hw/acpi/cpu_hotplug.c |   88 
 ++---
  hw/acpi/ich9.c|   17 +--
  hw/acpi/piix4.c   |   12 -
  hw/core/qdev.c|2 +-
  hw/cpu/icc_bus.c  |   11 +
  hw/i386/acpi-dsdt-cpu-hotplug.dsl |6 ++-
  hw/i386/kvm/apic.c|8 +++
  hw/i386/pc.c  |   62 --
  hw/intc/apic.c|   10 
  hw/intc/apic_common.c |   21 +---
  include/hw/acpi/cpu_hotplug.h |8 +++
  include/hw/cpu/icc_bus.h  |1 +
  include/hw/i386/apic_internal.h   |1 +
  include/hw/qdev-core.h|1 +
  include/qom/cpu.h |   10 
  include/sysemu/kvm.h  |1 +
  kvm-all.c |   57 +++-
  target-i386/cpu.c |   54 ++
  19 files changed, 387 insertions(+), 27 deletions(-)
 





Re: [Qemu-devel] [PATCH V2 0/6] cpu: add device_add foo-x86_64-cpu support

2014-12-18 Thread Gu Zheng
ping...

On 12/12/2014 03:43 PM, Gu Zheng wrote:

 This series is based on the previous patchset from Chen Fan:
 https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html
 
 We try to make cpu hotplug with device_add, and make
 -device foo-x86_64-cpu available,also we can set apic-id
 property with command line, if without setting apic-id property,
 we offer the first unoccupied apic id as the default new apic id.
 When hotplug cpu with device_add, additional check of APIC ID will be
 done after cpu object initialization which was different from
 'cpu_add' command that check 'ids' at the beginning.
 
 The is the first half of the previous series:
 [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove 
 support
 https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html
 
 ---
 Changelog since v1:
  -rebased on latest upstream.
  -introduce a help function to hide the access to icc_bus.
  -use a macro ACPI_ID_NOT_SET to replace the magic number(0x).
 
 Changelog since RFC:
  -split out APIC vmstate/QMP-monitor changes into separate patches.
  -add the handle of the startup cpus(-device foo).
  -remove duplicated checking about env-cpuid_apic_id.
  -do actual APIC ID allocation at realize time if it is not set before.
  -remove the unneeded x86_cpu_cpudef_instance_init().
  -split off device_del support out here.
 ---
 
 Chen Fan (2):
   cpu: introduce CpuTopoInfo structure for argument simplification
   cpu: add device_add foo-x86_64-cpu support
 
 Gu Zheng (4):
   qom/cpu: move register_vmstate to common CPUClass.realizefn
   qom/cpu: move apic vmstate register into x86_cpu_apic_realize
   monitor: use cc-get_arch_id as the cpu index
   acpi:cpu hotplug: set pcmachine as icc bus' hotplug handler
 
  cpus.c  |4 ++-
  exec.c  |   32 +-
  hw/acpi/cpu_hotplug.c   |7 +++-
  hw/cpu/icc_bus.c|5 +++
  hw/i386/pc.c|6 
  hw/i386/pc_piix.c   |5 +++
  hw/i386/pc_q35.c|5 +++
  hw/intc/apic_common.c   |3 +-
  include/hw/cpu/icc_bus.h|2 +
  include/hw/i386/apic_internal.h |3 ++
  include/qom/cpu.h   |2 +
  monitor.c   |4 ++-
  qom/cpu.c   |2 +
  target-i386/cpu.c   |   55 
 ---
  target-i386/topology.h  |   51 ---
  15 files changed, 141 insertions(+), 45 deletions(-)
 





[Qemu-devel] [PATCH V2 3/6] qom/cpu: move apic vmstate register into x86_cpu_apic_realize

2014-12-12 Thread Gu Zheng
move apic vmstate register into x86_cpu_apic_realize, and use
cc-get_arch_id as the instance id to avoid using the auto-id which will
break the migration if we add device not in order.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/intc/apic_common.c   |3 +--
 include/hw/i386/apic_internal.h |3 +++
 target-i386/cpu.c   |8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 4e62f25..62843dc 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -375,7 +375,7 @@ static const VMStateDescription vmstate_apic_common_sipi = {
 }
 };
 
-static const VMStateDescription vmstate_apic_common = {
+const VMStateDescription vmstate_apic_common = {
 .name = apic,
 .version_id = 3,
 .minimum_version_id = 3,
@@ -429,7 +429,6 @@ static void apic_common_class_init(ObjectClass *klass, void 
*data)
 ICCDeviceClass *idc = ICC_DEVICE_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
 dc-props = apic_properties_common;
 idc-realize = apic_common_realize;
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 83e2a42..61fddf6 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -23,6 +23,7 @@
 #include exec/memory.h
 #include hw/cpu/icc_bus.h
 #include qemu/timer.h
+#include migration/vmstate.h
 
 /* APIC Local Vector Table */
 #define APIC_LVT_TIMER  0
@@ -137,6 +138,8 @@ typedef struct VAPICState {
 
 extern bool apic_report_tpr_access;
 
+extern const VMStateDescription vmstate_apic_common;
+
 void apic_report_irq_delivered(int delivered);
 bool apic_next_timer(APICCommonState *s, int64_t current_time);
 void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e9df33e..4b4a595 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2692,10 +2692,16 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error 
**errp)
 
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
 {
-if (cpu-apic_state == NULL) {
+DeviceState *apic_state = cpu-apic_state;
+CPUClass *cc = CPU_GET_CLASS(CPU(cpu));
+
+if (apic_state == NULL) {
 return;
 }
 
+vmstate_register(0, cc-get_arch_id(CPU(cpu)),
+ vmstate_apic_common, apic_state);
+
 if (qdev_init(cpu-apic_state)) {
 error_setg(errp, APIC device '%s' could not be initialized,
object_get_typename(OBJECT(cpu-apic_state)));
-- 
1.7.7




[Qemu-devel] [PATCH V2 1/6] cpu: introduce CpuTopoInfo structure for argument simplification

2014-12-12 Thread Gu Zheng
From: Chen Fan chen.fan.f...@cn.fujitsu.com

Reviewed-by: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 target-i386/topology.h |   33 +
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/target-i386/topology.h b/target-i386/topology.h
index 07a6c5f..e9ff89c 100644
--- a/target-i386/topology.h
+++ b/target-i386/topology.h
@@ -47,6 +47,12 @@
  */
 typedef uint32_t apic_id_t;
 
+typedef struct X86CPUTopoInfo {
+unsigned pkg_id;
+unsigned core_id;
+unsigned smt_id;
+} X86CPUTopoInfo;
+
 /* Return the bit width needed for 'count' IDs
  */
 static unsigned apicid_bitwidth_for_count(unsigned count)
@@ -92,13 +98,11 @@ static inline unsigned apicid_pkg_offset(unsigned nr_cores, 
unsigned nr_threads)
  */
 static inline apic_id_t apicid_from_topo_ids(unsigned nr_cores,
  unsigned nr_threads,
- unsigned pkg_id,
- unsigned core_id,
- unsigned smt_id)
+ const X86CPUTopoInfo *topo)
 {
-return (pkg_id   apicid_pkg_offset(nr_cores, nr_threads)) |
-   (core_id  apicid_core_offset(nr_cores, nr_threads)) |
-   smt_id;
+return (topo-pkg_id   apicid_pkg_offset(nr_cores, nr_threads)) |
+   (topo-core_id  apicid_core_offset(nr_cores, nr_threads)) |
+   topo-smt_id;
 }
 
 /* Calculate thread/core/package IDs for a specific topology,
@@ -107,14 +111,12 @@ static inline apic_id_t apicid_from_topo_ids(unsigned 
nr_cores,
 static inline void x86_topo_ids_from_idx(unsigned nr_cores,
  unsigned nr_threads,
  unsigned cpu_index,
- unsigned *pkg_id,
- unsigned *core_id,
- unsigned *smt_id)
+ X86CPUTopoInfo *topo)
 {
 unsigned core_index = cpu_index / nr_threads;
-*smt_id = cpu_index % nr_threads;
-*core_id = core_index % nr_cores;
-*pkg_id = core_index / nr_cores;
+topo-smt_id = cpu_index % nr_threads;
+topo-core_id = core_index % nr_cores;
+topo-pkg_id = core_index / nr_cores;
 }
 
 /* Make APIC ID for the CPU 'cpu_index'
@@ -125,10 +127,9 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned 
nr_cores,
 unsigned nr_threads,
 unsigned cpu_index)
 {
-unsigned pkg_id, core_id, smt_id;
-x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index,
-  pkg_id, core_id, smt_id);
-return apicid_from_topo_ids(nr_cores, nr_threads, pkg_id, core_id, smt_id);
+X86CPUTopoInfo topo;
+x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index, topo);
+return apicid_from_topo_ids(nr_cores, nr_threads, topo);
 }
 
 #endif /* TARGET_I386_TOPOLOGY_H */
-- 
1.7.7




[Qemu-devel] [PATCH V2 0/6] cpu: add device_add foo-x86_64-cpu support

2014-12-12 Thread Gu Zheng
This series is based on the previous patchset from Chen Fan:
https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html

We try to make cpu hotplug with device_add, and make
-device foo-x86_64-cpu available,also we can set apic-id
property with command line, if without setting apic-id property,
we offer the first unoccupied apic id as the default new apic id.
When hotplug cpu with device_add, additional check of APIC ID will be
done after cpu object initialization which was different from
'cpu_add' command that check 'ids' at the beginning.

The is the first half of the previous series:
[RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove 
support
https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html

---
Changelog since v1:
 -rebased on latest upstream.
 -introduce a help function to hide the access to icc_bus.
 -use a macro ACPI_ID_NOT_SET to replace the magic number(0x).

Changelog since RFC:
 -split out APIC vmstate/QMP-monitor changes into separate patches.
 -add the handle of the startup cpus(-device foo).
 -remove duplicated checking about env-cpuid_apic_id.
 -do actual APIC ID allocation at realize time if it is not set before.
 -remove the unneeded x86_cpu_cpudef_instance_init().
 -split off device_del support out here.
---

Chen Fan (2):
  cpu: introduce CpuTopoInfo structure for argument simplification
  cpu: add device_add foo-x86_64-cpu support

Gu Zheng (4):
  qom/cpu: move register_vmstate to common CPUClass.realizefn
  qom/cpu: move apic vmstate register into x86_cpu_apic_realize
  monitor: use cc-get_arch_id as the cpu index
  acpi:cpu hotplug: set pcmachine as icc bus' hotplug handler

 cpus.c  |4 ++-
 exec.c  |   32 +-
 hw/acpi/cpu_hotplug.c   |7 +++-
 hw/cpu/icc_bus.c|5 +++
 hw/i386/pc.c|6 
 hw/i386/pc_piix.c   |5 +++
 hw/i386/pc_q35.c|5 +++
 hw/intc/apic_common.c   |3 +-
 include/hw/cpu/icc_bus.h|2 +
 include/hw/i386/apic_internal.h |3 ++
 include/qom/cpu.h   |2 +
 monitor.c   |4 ++-
 qom/cpu.c   |2 +
 target-i386/cpu.c   |   55 ---
 target-i386/topology.h  |   51 ---
 15 files changed, 141 insertions(+), 45 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH V2 2/6] qom/cpu: move register_vmstate to common CPUClass.realizefn

2014-12-12 Thread Gu Zheng
Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn,
and use cc-get_arch_id as the instance id that suggested by Igor to
fix the migration issue.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 exec.c|   32 +++-
 include/qom/cpu.h |2 ++
 qom/cpu.c |2 ++
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/exec.c b/exec.c
index 71ac104..741f151 100644
--- a/exec.c
+++ b/exec.c
@@ -508,10 +508,28 @@ void tcg_cpu_address_space_init(CPUState *cpu, 
AddressSpace *as)
 }
 #endif
 
+void cpu_vmstate_register(CPUState *cpu)
+{
+CPUClass *cc = CPU_GET_CLASS(cpu);
+int cpu_index = cc-get_arch_id(cpu);
+
+if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+vmstate_register(NULL, cpu_index, vmstate_cpu_common, cpu);
+}
+#if defined(CPU_SAVE_VERSION)  !defined(CONFIG_USER_ONLY)
+register_savevm(NULL, cpu, cpu_index, CPU_SAVE_VERSION,
+cpu_save, cpu_load, cpu-env_ptr);
+assert(cc-vmsd == NULL);
+assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
+#endif
+if (cc-vmsd != NULL) {
+vmstate_register(NULL, cpu_index, cc-vmsd, cpu);
+}
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
 CPUState *cpu = ENV_GET_CPU(env);
-CPUClass *cc = CPU_GET_CLASS(cpu);
 CPUState *some_cpu;
 int cpu_index;
 
@@ -534,18 +552,6 @@ void cpu_exec_init(CPUArchState *env)
 #if defined(CONFIG_USER_ONLY)
 cpu_list_unlock();
 #endif
-if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-vmstate_register(NULL, cpu_index, vmstate_cpu_common, cpu);
-}
-#if defined(CPU_SAVE_VERSION)  !defined(CONFIG_USER_ONLY)
-register_savevm(NULL, cpu, cpu_index, CPU_SAVE_VERSION,
-cpu_save, cpu_load, env);
-assert(cc-vmsd == NULL);
-assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
-#endif
-if (cc-vmsd != NULL) {
-vmstate_register(NULL, cpu_index, cc-vmsd, cpu);
-}
 }
 
 #if defined(TARGET_HAS_ICE)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 2098f1c..936afcd 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -562,6 +562,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
 
 #endif /* USER_ONLY */
 
+void cpu_vmstate_register(CPUState *cpu);
+
 #ifdef CONFIG_SOFTMMU
 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
  bool is_write, bool is_exec,
diff --git a/qom/cpu.c b/qom/cpu.c
index 79d2228..00c1007 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -301,6 +301,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
 {
 CPUState *cpu = CPU(dev);
 
+cpu_vmstate_register(cpu);
+
 if (dev-hotplugged) {
 cpu_synchronize_post_init(cpu);
 cpu_resume(cpu);
-- 
1.7.7




[Qemu-devel] [PATCH V2 5/6] acpi:cpu hotplug: set pcmachine as icc bus' hotplug handler

2014-12-12 Thread Gu Zheng
As the pre-check in the qdev_device_add():
if (qdev_hotplug  bus  !qbus_is_hotpluggable(bus)) {
qerror_report(QERR_BUS_NO_HOTPLUG, bus-name);
return NULL;
}
if device has parent bus, the bus must have valid hotplug_handler,
otherwise can not hot plug.
Currently cpu hotplug is based on the PCMachine's hotplug handler,
so when hot add cpu, the hotpluggable check of icc bus will be
rejected.
So we set pcmachine as icc bus' hotplug handler to avoid the rejetion.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com

---
v2: introduce a help function to hide the access to icc_bus.

 hw/cpu/icc_bus.c |5 +
 hw/i386/pc_piix.c|5 +
 hw/i386/pc_q35.c |5 +
 include/hw/cpu/icc_bus.h |2 ++
 4 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/hw/cpu/icc_bus.c b/hw/cpu/icc_bus.c
index 6646ea2..a933813 100644
--- a/hw/cpu/icc_bus.c
+++ b/hw/cpu/icc_bus.c
@@ -92,6 +92,11 @@ static void icc_bridge_init(Object *obj)
 s-icc_bus.apic_address_space = s-apic_container;
 }
 
+ICCBus *get_icc_bus(DeviceState *dev)
+{
+return ICC_BRIDGE(dev)-icc_bus;
+}
+
 static void icc_bridge_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 85ed3c8..1825d30 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -281,6 +281,7 @@ static void pc_init1(MachineState *machine,
 if (pci_enabled  acpi_enabled) {
 DeviceState *piix4_pm;
 I2CBus *smbus;
+ICCBus *iccbus;
 
 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
 /* TODO: Populate SPD eeprom data.  */
@@ -296,6 +297,10 @@ static void pc_init1(MachineState *machine,
  OBJ_PROP_LINK_UNREF_ON_RELEASE, error_abort);
 object_property_set_link(OBJECT(machine), OBJECT(piix4_pm),
  PC_MACHINE_ACPI_DEVICE_PROP, error_abort);
+
+iccbus = get_icc_bus(icc_bridge);
+object_property_set_link(OBJECT(iccbus), OBJECT(pc_machine),
+ QDEV_HOTPLUG_HANDLER_PROPERTY, error_abort);
 }
 
 if (pci_enabled) {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 0262b5e..1053271 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -88,6 +88,7 @@ static void pc_q35_init(MachineState *machine)
 PcGuestInfo *guest_info;
 ram_addr_t lowmem;
 DriveInfo *hd[MAX_SATA_PORTS];
+ICCBus *iccbus;
 
 /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
  * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
@@ -212,6 +213,10 @@ static void pc_q35_init(MachineState *machine)
 object_property_set_link(OBJECT(machine), OBJECT(lpc),
  PC_MACHINE_ACPI_DEVICE_PROP, error_abort);
 
+iccbus = get_icc_bus(icc_bridge);
+object_property_set_link(OBJECT(iccbus), OBJECT(pc_machine),
+ QDEV_HOTPLUG_HANDLER_PROPERTY, error_abort);
+
 ich9_lpc = ICH9_LPC_DEVICE(lpc);
 ich9_lpc-pic = gsi;
 ich9_lpc-ioapic = gsi_state-ioapic_irq;
diff --git a/include/hw/cpu/icc_bus.h b/include/hw/cpu/icc_bus.h
index 98a979f..7e53afb 100644
--- a/include/hw/cpu/icc_bus.h
+++ b/include/hw/cpu/icc_bus.h
@@ -44,6 +44,8 @@ typedef struct ICCBus {
 
 #define ICC_BUS(obj) OBJECT_CHECK(ICCBus, (obj), TYPE_ICC_BUS)
 
+ICCBus *get_icc_bus(DeviceState *dev);
+
 /**
  * ICCDevice:
  *
-- 
1.7.7




[Qemu-devel] [PATCH V2 4/6] monitor: use cc-get_arch_id as the cpu index

2014-12-12 Thread Gu Zheng
Use cc-get_arch_id as the cpu index to avoid the cpu index duplicated
issue in the QMP/HMP command output.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 cpus.c|4 +++-
 monitor.c |4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0c33458..849d1bf 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1411,6 +1411,7 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 
 CPU_FOREACH(cpu) {
 CpuInfoList *info;
+CPUClass *cc;
 #if defined(TARGET_I386)
 X86CPU *x86_cpu = X86_CPU(cpu);
 CPUX86State *env = x86_cpu-env;
@@ -1428,11 +1429,12 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 CPUTriCoreState *env = tricore_cpu-env;
 #endif
 
+cc = CPU_GET_CLASS(cpu);
 cpu_synchronize_state(cpu);
 
 info = g_malloc0(sizeof(*info));
 info-value = g_malloc0(sizeof(*info-value));
-info-value-CPU = cpu-cpu_index;
+info-value-CPU = cc-get_arch_id(cpu);
 info-value-current = (cpu == first_cpu);
 info-value-halted = cpu-halted;
 info-value-thread_id = cpu-thread_id;
diff --git a/monitor.c b/monitor.c
index f1031a1..d672743 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1024,7 +1024,9 @@ static CPUArchState *mon_get_cpu(void)
 int monitor_get_cpu_index(void)
 {
 CPUState *cpu = ENV_GET_CPU(mon_get_cpu());
-return cpu-cpu_index;
+CPUClass *cc = CPU_GET_CLASS(cpu);
+
+return cc-get_arch_id(cpu);
 }
 
 static void do_info_registers(Monitor *mon, const QDict *qdict)
-- 
1.7.7




[Qemu-devel] [PATCH V2 6/6] cpu: add device_add foo-x86_64-cpu support

2014-12-12 Thread Gu Zheng
From: Chen Fan chen.fan.f...@cn.fujitsu.com

Add support to device_add foo-x86_64-cpu, and additional checks of
apic id are added into x86_cpuid_set_apic_id() to avoid duplicate.
Besides, in order to support device/device_add foo-x86_64-cpu
which without specified apic id, we assign cpuid_apic_id with a
default broadcast value (0x) in initfn, and a new function
get_free_apic_id() to provide a free apid id to cpuid_apic_id if
it still has the default at realize time (e.g. hot add foo-cpu without
a specified apic id) to avoid apic id duplicates.

Thanks very much for Igor's suggestion.

Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com

---
v2: use a macro ACPI_ID_NOT_SET to replace the magic number(0x).

 hw/acpi/cpu_hotplug.c  |7 +--
 hw/i386/pc.c   |6 --
 target-i386/cpu.c  |   47 ---
 target-i386/topology.h |   18 ++
 4 files changed, 67 insertions(+), 11 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index b8ebfad..4047294 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -59,8 +59,11 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
+/* Only trigger sci if cpu is hotplugged */
+if (dev-hotplugged) {
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
 }
 
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f31d55e..38e24ed 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1677,13 +1677,7 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 Error *local_err = NULL;
 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
 
-if (!dev-hotplugged) {
-goto out;
-}
-
 if (!pcms-acpi_dev) {
-error_setg(local_err,
-   cpu hotplug is not enabled: missing acpi device);
 goto out;
 }
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4b4a595..96c6f35 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1647,6 +1647,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor 
*v, void *opaque,
 const int64_t max = UINT32_MAX;
 Error *error = NULL;
 int64_t value;
+X86CPUTopoInfo topo;
 
 if (dev-realized) {
 error_setg(errp, Attempt to set property '%s' on '%s' after 
@@ -1666,6 +1667,19 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor 
*v, void *opaque,
 return;
 }
 
+if (value  x86_cpu_apic_id_from_index(max_cpus - 1)) {
+error_setg(errp, CPU with APIC ID % PRIi64
+is more than MAX APIC ID limits, value);
+return;
+}
+
+x86_topo_ids_from_apic_id(smp_cores, smp_threads, value, topo);
+if (topo.smt_id = smp_threads || topo.core_id = smp_cores) {
+error_setg(errp, CPU with APIC ID % PRIi64  does not match 
+   topology configuration., value);
+return;
+}
+
 if ((value != cpu-env.cpuid_apic_id)  cpu_exists(value)) {
 error_setg(errp, CPU with APIC ID % PRIi64  exists, value);
 return;
@@ -2120,8 +2134,10 @@ static void x86_cpu_cpudef_class_init(ObjectClass *oc, 
void *data)
 {
 X86CPUDefinition *cpudef = data;
 X86CPUClass *xcc = X86_CPU_CLASS(oc);
+DeviceClass *dc = DEVICE_CLASS(oc);
 
 xcc-cpu_def = cpudef;
+dc-cannot_instantiate_with_device_add_yet = false;
 }
 
 static void x86_register_cpudef_type(X86CPUDefinition *def)
@@ -2130,6 +2146,7 @@ static void x86_register_cpudef_type(X86CPUDefinition 
*def)
 TypeInfo ti = {
 .name = typename,
 .parent = TYPE_X86_CPU,
+.instance_size = sizeof(X86CPU),
 .class_init = x86_cpu_cpudef_class_init,
 .class_data = def,
 };
@@ -2663,12 +2680,29 @@ static void mce_init(X86CPU *cpu)
 }
 
 #ifndef CONFIG_USER_ONLY
+static uint32_t get_free_apic_id(void)
+{
+int i;
+
+for (i = 0; i  max_cpus; i++) {
+uint32_t id = x86_cpu_apic_id_from_index(i);
+
+if (!cpu_exists(id)) {
+return id;
+}
+}
+
+return x86_cpu_apic_id_from_index(max_cpus);
+}
+
+#define APIC_ID_NOT_SET (~0U)
+
 static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 {
-CPUX86State *env = cpu-env;
 DeviceState *dev = DEVICE(cpu);
 APICCommonState *apic;
 const char *apic_type = apic;
+uint32_t apic_id;
 
 if (kvm_irqchip_in_kernel()) {
 apic_type = kvm-apic;
@@ -2684,7 +2718,14 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error 
**errp)
 
 object_property_add_child(OBJECT(cpu), apic,
   OBJECT(cpu-apic_state), NULL);
-qdev_prop_set_uint8(cpu-apic_state, id, env-cpuid_apic_id);
+
+apic_id = object_property_get_int(OBJECT(cpu), apic-id, NULL

[Qemu-devel] [PATCH 01/12] x86: add x86_cpu_unrealizefn() for cpu apic remove

2014-12-12 Thread Gu Zheng
From: Chen Fan chen.fan.f...@cn.fujitsu.com

Implement x86_cpu_unrealizefn() for corresponding x86_cpu_realizefn(),
which is mostly used to clean the apic related allocation and vmstates
at here.

Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
Changelog since RFC:
 -replaced apic_no with apic_id, so does the related stuff to make it
  work with arbitrary CPU hotadd.
 -add the icc_device_unrealize callback to handle apic unrealize.

 hw/cpu/icc_bus.c|   11 +
 hw/i386/kvm/apic.c  |8 ++
 hw/intc/apic.c  |   10 
 hw/intc/apic_common.c   |   21 +++--
 include/hw/cpu/icc_bus.h|1 +
 include/hw/i386/apic_internal.h |1 +
 target-i386/cpu.c   |   46 +++
 7 files changed, 90 insertions(+), 8 deletions(-)

diff --git a/hw/cpu/icc_bus.c b/hw/cpu/icc_bus.c
index f455a20..3e7f62f 100644
--- a/hw/cpu/icc_bus.c
+++ b/hw/cpu/icc_bus.c
@@ -44,11 +44,22 @@ static void icc_device_realize(DeviceState *dev, Error 
**errp)
 
 }
 
+static void icc_device_unrealize(DeviceState *dev, Error **errp)
+{
+ICCDeviceClass *idc = ICC_DEVICE_GET_CLASS(dev);
+
+/* convert to QOM */
+if (idc-unrealize) {
+idc-unrealize(dev, errp);
+}
+}
+
 static void icc_device_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
 dc-realize = icc_device_realize;
+dc-unrealize = icc_device_unrealize;
 dc-bus_type = TYPE_ICC_BUS;
 }
 
diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
index 271e97f..ac23504 100644
--- a/hw/i386/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -186,11 +186,19 @@ static void kvm_apic_realize(DeviceState *dev, Error 
**errp)
 }
 }
 
+static void kvm_apic_unrealize(DeviceState *dev, Error **errp)
+{
+APICCommonState *s = APIC_COMMON(dev);
+
+object_unparent(OBJECT(s-io_memory));
+}
+
 static void kvm_apic_class_init(ObjectClass *klass, void *data)
 {
 APICCommonClass *k = APIC_COMMON_CLASS(klass);
 
 k-realize = kvm_apic_realize;
+k-unrealize = kvm_apic_unrealize;
 k-set_base = kvm_apic_set_base;
 k-set_tpr = kvm_apic_set_tpr;
 k-get_tpr = kvm_apic_get_tpr;
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 0f97b47..2f3a7a3 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -889,11 +889,21 @@ static void apic_realize(DeviceState *dev, Error **errp)
 msi_supported = true;
 }
 
+static void apic_unrealize(DeviceState *dev, Error **errp)
+{
+APICCommonState *s = APIC_COMMON(dev);
+
+object_unparent(OBJECT(s-io_memory));
+timer_free(s-timer);
+local_apics[s-idx] = NULL;
+}
+
 static void apic_class_init(ObjectClass *klass, void *data)
 {
 APICCommonClass *k = APIC_COMMON_CLASS(klass);
 
 k-realize = apic_realize;
+k-unrealize = apic_unrealize;
 k-set_base = apic_set_base;
 k-set_tpr = apic_set_tpr;
 k-get_tpr = apic_get_tpr;
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 62843dc..f189fe1 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -294,16 +294,8 @@ static void apic_common_realize(DeviceState *dev, Error 
**errp)
 APICCommonState *s = APIC_COMMON(dev);
 APICCommonClass *info;
 static DeviceState *vapic;
-static int apic_no;
 static bool mmio_registered;
 
-if (apic_no = MAX_APICS) {
-error_setg(errp, %s initialization failed.,
-   object_get_typename(OBJECT(dev)));
-return;
-}
-s-idx = apic_no++;
-
 info = APIC_COMMON_GET_CLASS(s);
 info-realize(dev, errp);
 if (!mmio_registered) {
@@ -324,6 +316,18 @@ static void apic_common_realize(DeviceState *dev, Error 
**errp)
 
 }
 
+static void apic_common_unrealize(DeviceState *dev, Error **errp)
+{
+APICCommonState *s = APIC_COMMON(dev);
+APICCommonClass *info = APIC_COMMON_GET_CLASS(s);
+
+info-unrealize(dev, errp);
+
+if (apic_report_tpr_access  info-enable_tpr_reporting) {
+info-enable_tpr_reporting(s, false);
+}
+}
+
 static int apic_pre_load(void *opaque)
 {
 APICCommonState *s = APIC_COMMON(opaque);
@@ -432,6 +436,7 @@ static void apic_common_class_init(ObjectClass *klass, void 
*data)
 dc-reset = apic_reset_common;
 dc-props = apic_properties_common;
 idc-realize = apic_common_realize;
+idc-unrealize = apic_common_unrealize;
 /*
  * Reason: APIC and CPU need to be wired up by
  * x86_cpu_apic_create()
diff --git a/include/hw/cpu/icc_bus.h b/include/hw/cpu/icc_bus.h
index 7e53afb..0b2ddd5 100644
--- a/include/hw/cpu/icc_bus.h
+++ b/include/hw/cpu/icc_bus.h
@@ -69,6 +69,7 @@ typedef struct ICCDeviceClass {
 /* public */
 
 DeviceRealize realize;
+DeviceUnrealize unrealize;
 } ICCDeviceClass;
 
 #define TYPE_ICC_DEVICE icc-device
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386

[Qemu-devel] [PATCH 06/12] pc: add cpu hot unplug request callback support

2014-12-12 Thread Gu Zheng
From: Zhu Guihua zhugh.f...@cn.fujitsu.com

Add cpu hot unplug request callback support, and a pre-check about the
active cpus is added to avoid removing the last cpu.

Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c |   36 ++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ccf0ef8..ace7dc2 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1693,6 +1693,34 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_unplug_request(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms;
+
+if (smp_cpus == 1) {
+error_setg(local_err,
+   This is the last cpu, should not be removed!);
+goto out;
+}
+
+pcms = PC_MACHINE(hotplug_dev);
+if (!pcms-acpi_dev) {
+if (dev-hotplugged) {
+error_setg(local_err,
+   cpu hot unplug is not enabled: missing acpi device);
+}
+goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-unplug_request(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+out:
+error_propagate(errp, local_err);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
@@ -1706,8 +1734,12 @@ static void pc_machine_device_plug_cb(HotplugHandler 
*hotplug_dev,
 static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug request for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_unplug_request(hotplug_dev, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug request for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
-- 
1.7.7




[Qemu-devel] [PATCH 00/12] cpu: add i386 cpu hot remove support

2014-12-12 Thread Gu Zheng
This series is based on chen fan's previous i386 cpu hot remove patchset:
https://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg04266.html

Via implementing ACPI standard methods _EJ0 in ACPI table, after Guest
OS remove one vCPU online, the fireware will store removed bitmap to
QEMU, then QEMU could know to notify the assigned vCPU of exiting.
Meanwhile, intruduce the QOM command 'device_del' to remove vCPU from
QEMU itself.

The whole work is based on the new hot plug/unplug framework, ,the unplug 
request
callback does the pre-check and send the request, unplug callback does the
removal handling.

This series depends on tangchen's common hot plug/unplug enhance patchset.
[PATCH] Common unplug and unplug request cb for memory and CPU hot-unplug.
https://lists.nongnu.org/archive/html/qemu-devel/2014-12/msg01462.html

The is the second half of the previous series:  

[RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove 
support
https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04779.html  
   

If you want to test the series, you need to apply the 'device_add 
foo-x86_64-cpu'
patchset first:
[PATCH V2 0/6] cpu: add device_add foo-x86_64-cpu support
https://lists.nongnu.org/archive/html/qemu-devel/2014-12/msg01812.html

---
Changelog since RFC:
 -splited the i386 cpu hot remove into single thread.
 -replaced apic_no with apic_id, so does the related stuff to make it
  work with arbitrary CPU hotadd.
 -add the icc_device_unrealize callback to handle apic unrealize.
 -rework on the new hot plug/unplug platform.
---

Chen Fan (2):
  x86: add x86_cpu_unrealizefn() for cpu apic remove
  cpu hotplug: implement function cpu_status_write() for vcpu ejection

Gu Zheng (6):
  i386/cpu: add instance finalize callback
  acpi/cpu: add cpu hot unplug request callback function
  acpi/piix4: add cpu hot unplug callback support
  acpi/ich9: add cpu hot unplug support
  pc: add cpu hot unplug callback support
  cpus: reclaim allocated vCPU objects

Zhu Guihua (4):
  acpi/piix4: add cpu hot unplug request callback support
  acpi/ich9: add cpu hot unplug request callback support
  pc: add cpu hot unplug request callback support
  acpi/cpu: add cpu hot unplug callback function

 cpus.c|   44 ++
 hw/acpi/cpu_hotplug.c |   88 ++---
 hw/acpi/ich9.c|   17 +--
 hw/acpi/piix4.c   |   12 -
 hw/core/qdev.c|2 +-
 hw/cpu/icc_bus.c  |   11 +
 hw/i386/acpi-dsdt-cpu-hotplug.dsl |6 ++-
 hw/i386/kvm/apic.c|8 +++
 hw/i386/pc.c  |   62 --
 hw/intc/apic.c|   10 
 hw/intc/apic_common.c |   21 +---
 include/hw/acpi/cpu_hotplug.h |8 +++
 include/hw/cpu/icc_bus.h  |1 +
 include/hw/i386/apic_internal.h   |1 +
 include/hw/qdev-core.h|1 +
 include/qom/cpu.h |   10 
 include/sysemu/kvm.h  |1 +
 kvm-all.c |   57 +++-
 target-i386/cpu.c |   54 ++
 19 files changed, 387 insertions(+), 27 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH 02/12] i386/cpu: add instance finalize callback

2014-12-12 Thread Gu Zheng
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 include/qom/cpu.h |1 +
 target-i386/cpu.c |8 
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 936afcd..f663199 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -305,6 +305,7 @@ struct CPUState {
 QTAILQ_HEAD(CPUTailQ, CPUState);
 extern struct CPUTailQ cpus;
 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
+#define CPU_REMOVE(cpu) QTAILQ_REMOVE(cpus, cpu, node)
 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, cpus, node)
 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
 QTAILQ_FOREACH_SAFE(cpu, cpus, node, next_cpu)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 9618bc7..718670a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2970,6 +2970,13 @@ static void x86_cpu_initfn(Object *obj)
 }
 }
 
+static void x86_cpu_finalizefn(Object *obj)
+{
+CPUState *cs = CPU(obj);
+
+CPU_REMOVE(cs);
+}
+
 static int64_t x86_cpu_get_arch_id(CPUState *cs)
 {
 X86CPU *cpu = X86_CPU(cs);
@@ -3083,6 +3090,7 @@ static const TypeInfo x86_cpu_type_info = {
 .parent = TYPE_CPU,
 .instance_size = sizeof(X86CPU),
 .instance_init = x86_cpu_initfn,
+.instance_finalize = x86_cpu_finalizefn,
 .abstract = true,
 .class_size = sizeof(X86CPUClass),
 .class_init = x86_cpu_common_class_init,
-- 
1.7.7




[Qemu-devel] [PATCH 03/12] acpi/cpu: add cpu hot unplug request callback function

2014-12-12 Thread Gu Zheng
Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   38 +-
 include/hw/acpi/cpu_hotplug.h |4 
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 4047294..f8a10d2 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -12,6 +12,11 @@
 #include hw/hw.h
 #include hw/acpi/cpu_hotplug.h
 
+typedef enum STS_OPT {
+SET,
+CLEAR,
+} STS_OPT;
+
 static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
 {
 AcpiCpuHotplug *cpus = opaque;
@@ -36,8 +41,8 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
- Error **errp)
+static void acpi_update_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
+STS_OPT opt, Error **errp)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
 int64_t cpu_id;
@@ -48,13 +53,23 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, 
CPUState *cpu,
 return;
 }
 
-g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+switch (opt) {
+case SET:
+g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+break;
+case CLEAR:
+g-sts[cpu_id / 8] = ~(1  (cpu_id % 8));
+break;
+default:
+g_assert(0);
+break;
+}
 }
 
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
 {
-acpi_set_cpu_present_bit(g, CPU(dev), errp);
+acpi_update_cpu_present_bit(g, CPU(dev), SET, errp);
 if (*errp != NULL) {
 return;
 }
@@ -66,13 +81,26 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 }
 }
 
+void acpi_cpu_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+AcpiCpuHotplug *g, DeviceState *dev,
+Error **errp)
+{
+acpi_update_cpu_present_bit(g, CPU(dev), CLEAR, errp);
+if (*errp != NULL) {
+return;
+}
+
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
 CPUState *cpu;
 
 CPU_FOREACH(cpu) {
-acpi_set_cpu_present_bit(gpe_cpu, cpu, error_abort);
+acpi_update_cpu_present_bit(gpe_cpu, cpu, SET, error_abort);
 }
 memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
   gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index f6d358d..8b15a3d 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,10 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
+void acpi_cpu_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+AcpiCpuHotplug *g, DeviceState *dev,
+Error **errp);
+
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH 07/12] acpi/cpu: add cpu hot unplug callback function

2014-12-12 Thread Gu Zheng
From: Zhu Guihua zhugh.f...@cn.fujitsu.com

Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 cpus.c|7 +++
 hw/acpi/cpu_hotplug.c |8 
 include/hw/acpi/cpu_hotplug.h |3 +++
 include/qom/cpu.h |9 +
 4 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index 849d1bf..e3c8b88 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1196,6 +1196,13 @@ void resume_all_vcpus(void)
 }
 }
 
+void cpu_remove(CPUState *cpu)
+{
+cpu-stop = true;
+cpu-exit = true;
+qemu_cpu_kick(cpu);
+}
+
 /* For temporary buffers for forming a name */
 #define VCPU_THREAD_NAME_SIZE 16
 
diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index f8a10d2..36feb6a 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -94,6 +94,14 @@ void acpi_cpu_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
 acpi_update_sci(ar, irq);
 }
 
+void acpi_cpu_unplug_cb(ACPIREGS *ar, qemu_irq irq, AcpiCpuHotplug *g,
+DeviceState *dev, Error **errp)
+{
+CPUState *cpu = CPU(dev);
+
+cpu_remove(cpu);
+}
+
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 8b15a3d..0f84adb 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -27,6 +27,9 @@ void acpi_cpu_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
 AcpiCpuHotplug *g, DeviceState *dev,
 Error **errp);
 
+void acpi_cpu_unplug_cb(ACPIREGS *ar, qemu_irq irq,
+AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
+
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index f663199..0592b4d 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -249,6 +249,7 @@ struct CPUState {
 bool created;
 bool stop;
 bool stopped;
+bool exit;
 volatile sig_atomic_t exit_request;
 uint32_t interrupt_request;
 int singlestep_enabled;
@@ -613,6 +614,14 @@ void cpu_exit(CPUState *cpu);
 void cpu_resume(CPUState *cpu);
 
 /**
+ * cpu_remove:
+ * @cpu: The vCPU to remove.
+ *
+ * Requests the CPU @cpu to be removed.
+ */
+void cpu_remove(CPUState *cpu);
+
+/**
  * qemu_init_vcpu:
  * @cpu: The vCPU to initialize.
  *
-- 
1.7.7




[Qemu-devel] [PATCH 04/12] acpi/piix4: add cpu hot unplug request callback support

2014-12-12 Thread Gu Zheng
From: Zhu Guihua zhugh.f...@cn.fujitsu.com

Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/piix4.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 4407388..9b75780 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -364,6 +364,8 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
 acpi_pcihp_device_unplug_cb(s-ar, s-irq, s-acpi_pci_hotplug, dev,
 errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_unplug_request_cb(s-ar, s-irq, s-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device unplug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
-- 
1.7.7




[Qemu-devel] [PATCH 10/12] pc: add cpu hot unplug callback support

2014-12-12 Thread Gu Zheng
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/i386/pc.c |   26 --
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ace7dc2..a8e34db 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1721,6 +1721,24 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_unplug(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-unplug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+if (local_err) {
+error_propagate(errp, local_err);
+return;
+}
+
+/* decrement the number of CPUs */
+rtc_set_memory(pcms-rtc, 0x5f, rtc_get_memory(pcms-rtc, 0x5f) - 1);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
@@ -1745,8 +1763,12 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_unplug(hotplug_dev, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
-- 
1.7.7




[Qemu-devel] [PATCH 11/12] cpu hotplug: implement function cpu_status_write() for vcpu ejection

2014-12-12 Thread Gu Zheng
From: Chen Fan chen.fan.f...@cn.fujitsu.com

When OS ejected a vcpu (like: echo 1  /sys/bus/acpi/devices/LNXCPUXX/eject),
it would call acpi EJ0 method, the firmware need to write the new cpumap, QEMU
would know which vcpu need to be ejected.

Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   42 -
 hw/core/qdev.c|2 +-
 hw/i386/acpi-dsdt-cpu-hotplug.dsl |6 -
 include/hw/acpi/cpu_hotplug.h |1 +
 include/hw/qdev-core.h|1 +
 5 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 36feb6a..2a56df0 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -17,6 +17,26 @@ typedef enum STS_OPT {
 CLEAR,
 } STS_OPT;
 
+static void acpi_eject_vcpu(AcpiCpuHotplug *cpus_status, int64_t cpu_id)
+{
+CPUState *cpu;
+
+CPU_FOREACH(cpu) {
+CPUClass *cc = CPU_GET_CLASS(cpu);
+int64_t id = cc-get_arch_id(cpu);
+HotplugHandler *hotplug_ctrl;
+
+if (cpu_id == id) {
+cpus_status-old_sts[cpu_id / 8] = ~(1  (cpu_id % 8));
+cpus_status-sts[cpu_id / 8] = ~(1  (cpu_id % 8));
+
+hotplug_ctrl = qdev_get_hotplug_handler(DEVICE(cpu));
+hotplug_handler_unplug(hotplug_ctrl, DEVICE(cpu), NULL);
+break;
+}
+}
+}
+
 static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
 {
 AcpiCpuHotplug *cpus = opaque;
@@ -28,7 +48,26 @@ static uint64_t cpu_status_read(void *opaque, hwaddr addr, 
unsigned int size)
 static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
  unsigned int size)
 {
-/* TODO: implement VCPU removal on guest signal that CPU can be removed */
+AcpiCpuHotplug *cpus = opaque;
+uint8_t val;
+int i;
+int64_t cpu_id = -1;
+
+val = cpus-old_sts[addr] ^ data;
+
+if (val == 0) {
+return;
+}
+
+for (i = 0; i  8; i++) {
+if (val  1  i) {
+cpu_id = 8 * addr + i;
+}
+}
+
+if (cpu_id != -1) {
+acpi_eject_vcpu(cpus, cpu_id);
+}
 }
 
 static const MemoryRegionOps AcpiCpuHotplug_ops = {
@@ -56,6 +95,7 @@ static void acpi_update_cpu_present_bit(AcpiCpuHotplug *g, 
CPUState *cpu,
 switch (opt) {
 case SET:
 g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+g-old_sts[cpu_id / 8] |= (1  (cpu_id % 8));
 break;
 case CLEAR:
 g-sts[cpu_id / 8] = ~(1  (cpu_id % 8));
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 901f289..9f08fe6 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -223,7 +223,7 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
 dev-alias_required_for_version = required_for_version;
 }
 
-static HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
+HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
 {
 HotplugHandler *hotplug_ctrl = NULL;
 
diff --git a/hw/i386/acpi-dsdt-cpu-hotplug.dsl 
b/hw/i386/acpi-dsdt-cpu-hotplug.dsl
index 34aab5a..9485f12 100644
--- a/hw/i386/acpi-dsdt-cpu-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-cpu-hotplug.dsl
@@ -50,7 +50,11 @@ Scope(\_SB) {
 }
 Method(CPEJ, 2, NotSerialized) {
 // _EJ0 method - eject callback
-Sleep(200)
+Store(Zero, Index(CPON, ToInteger(Arg0)))
+Store(One, Local0)
+ShiftLeft(Local0, Arg0, Local0)
+Not(Local0, Local0)
+And(PRS, Local0, PRS)
 }
 
 #define CPU_STATUS_LEN ACPI_GPE_PROC_LEN
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 0f84adb..abbb29e 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -18,6 +18,7 @@
 typedef struct AcpiCpuHotplug {
 MemoryRegion io;
 uint8_t sts[ACPI_GPE_PROC_LEN];
+uint8_t old_sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
 
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 589bbe7..5b28a4f 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -263,6 +263,7 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
 void qdev_unplug(DeviceState *dev, Error **errp);
 void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp);
+HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev);
 void qdev_machine_creation_done(void);
 bool qdev_machine_modified(void);
 
-- 
1.7.7




[Qemu-devel] [PATCH 05/12] acpi/ich9: add cpu hot unplug request callback support

2014-12-12 Thread Gu Zheng
From: Zhu Guihua zhugh.f...@cn.fujitsu.com

Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/ich9.c |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index c48d176..b795f8f 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -304,8 +304,13 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
   Error **errp)
 {
-error_setg(errp, acpi: device unplug request for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_unplug_request_cb(pm-acpi_regs, pm-irq,
+   pm-gpe_cpu, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug request for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
-- 
1.7.7




[Qemu-devel] [PATCH 08/12] acpi/piix4: add cpu hot unplug callback support

2014-12-12 Thread Gu Zheng
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/acpi/piix4.c |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 9b75780..2a923fc 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -375,8 +375,14 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_unplug_cb(s-ar, s-irq, s-gpe_cpu, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
-- 
1.7.7




[Qemu-devel] [PATCH 09/12] acpi/ich9: add cpu hot unplug support

2014-12-12 Thread Gu Zheng
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/acpi/ich9.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index b795f8f..a892e5d 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -316,8 +316,12 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
   Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_unplug_cb(pm-acpi_regs, pm-irq, pm-gpe_cpu, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
-- 
1.7.7




[Qemu-devel] [PATCH 12/12] cpus: reclaim allocated vCPU objects

2014-12-12 Thread Gu Zheng
After ACPI get a signal to eject a vCPU, the vCPU must be
removed from CPU list,before the vCPU really removed,  then
release the all related vCPU objects.

In order to deal well with the kvm vcpus (which can not be removed without any
protection), we do not close KVM vcpu fd, just record and mark it as stopped
into a list, so that we can reuse it for the appending cpu hot-add request if
possible. It is also the approach that kvm guys suggested:
https://www.mail-archive.com/kvm@vger.kernel.org/msg102839.html

Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 cpus.c   |   37 
 include/sysemu/kvm.h |1 +
 kvm-all.c|   57 +-
 3 files changed, 94 insertions(+), 1 deletions(-)

diff --git a/cpus.c b/cpus.c
index e3c8b88..be3dfb6 100644
--- a/cpus.c
+++ b/cpus.c
@@ -865,6 +865,24 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void 
*data), void *data)
 qemu_cpu_kick(cpu);
 }
 
+static void qemu_kvm_destroy_vcpu(CPUState *cpu)
+{
+CPU_REMOVE(cpu);
+
+if (kvm_destroy_vcpu(cpu)  0) {
+error_report(kvm_destroy_vcpu failed.\n);
+exit(EXIT_FAILURE);
+}
+
+object_unparent(OBJECT(cpu));
+}
+
+static void qemu_tcg_destroy_vcpu(CPUState *cpu)
+{
+CPU_REMOVE(cpu);
+object_unparent(OBJECT(cpu));
+}
+
 static void flush_queued_work(CPUState *cpu)
 {
 struct qemu_work_item *wi;
@@ -956,6 +974,11 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
 }
 }
 qemu_kvm_wait_io_event(cpu);
+if (cpu-exit  !cpu_can_run(cpu)) {
+qemu_kvm_destroy_vcpu(cpu);
+qemu_mutex_unlock(qemu_global_mutex);
+return NULL;
+}
 }
 
 return NULL;
@@ -1008,6 +1031,7 @@ static void tcg_exec_all(void);
 static void *qemu_tcg_cpu_thread_fn(void *arg)
 {
 CPUState *cpu = arg;
+CPUState *remove_cpu = NULL;
 
 qemu_tcg_init_cpu_signals();
 qemu_thread_get_self(cpu-thread);
@@ -1040,6 +1064,16 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 }
 }
 qemu_tcg_wait_io_event();
+CPU_FOREACH(cpu) {
+if (cpu-exit  !cpu_can_run(cpu)) {
+remove_cpu = cpu;
+break;
+}
+}
+if (remove_cpu) {
+qemu_tcg_destroy_vcpu(remove_cpu);
+remove_cpu = NULL;
+}
 }
 
 return NULL;
@@ -1397,6 +1431,9 @@ static void tcg_exec_all(void)
 break;
 }
 } else if (cpu-stop || cpu-stopped) {
+if (cpu-exit) {
+next_cpu = CPU_NEXT(cpu);
+}
 break;
 }
 }
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 22e42ef..a72ae40 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -177,6 +177,7 @@ int kvm_has_intx_set_mask(void);
 
 int kvm_init_vcpu(CPUState *cpu);
 int kvm_cpu_exec(CPUState *cpu);
+int kvm_destroy_vcpu(CPUState *cpu);
 
 #ifdef NEED_CPU_H
 
diff --git a/kvm-all.c b/kvm-all.c
index 937bc9d..c33cc1a 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -71,6 +71,12 @@ typedef struct KVMSlot
 
 typedef struct kvm_dirty_log KVMDirtyLog;
 
+struct KVMParkedVcpu {
+unsigned long vcpu_id;
+int kvm_fd;
+QLIST_ENTRY(KVMParkedVcpu) node;
+};
+
 struct KVMState
 {
 AccelState parent_obj;
@@ -107,6 +113,7 @@ struct KVMState
 QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
 bool direct_msi;
 #endif
+QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus;
 };
 
 #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME(kvm)
@@ -246,6 +253,53 @@ static int kvm_set_user_memory_region(KVMState *s, KVMSlot 
*slot)
 return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
 }
 
+int kvm_destroy_vcpu(CPUState *cpu)
+{
+KVMState *s = kvm_state;
+long mmap_size;
+struct KVMParkedVcpu *vcpu = NULL;
+int ret = 0;
+
+DPRINTF(kvm_destroy_vcpu\n);
+
+mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
+if (mmap_size  0) {
+ret = mmap_size;
+DPRINTF(KVM_GET_VCPU_MMAP_SIZE failed\n);
+goto err;
+}
+
+ret = munmap(cpu-kvm_run, mmap_size);
+if (ret  0) {
+goto err;
+}
+
+vcpu = g_malloc0(sizeof(*vcpu));
+vcpu-vcpu_id = kvm_arch_vcpu_id(cpu);
+vcpu-kvm_fd = cpu-kvm_fd;
+QLIST_INSERT_HEAD(kvm_state-kvm_parked_vcpus, vcpu, node);
+err:
+return ret;
+}
+
+static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
+{
+struct KVMParkedVcpu *cpu;
+
+QLIST_FOREACH(cpu, s-kvm_parked_vcpus, node) {
+if (cpu-vcpu_id == vcpu_id) {
+int kvm_fd;
+
+QLIST_REMOVE(cpu, node);
+kvm_fd = cpu-kvm_fd;
+g_free(cpu);
+return kvm_fd;
+}
+}
+
+return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id

Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-12-08 Thread Gu Zheng
Hi Bharata,
On 12/08/2014 05:16 PM, Bharata B Rao wrote:

 On Thu, Aug 28, 2014 at 9:06 AM, Gu Zheng guz.f...@cn.fujitsu.com wrote:
 After ACPI get a signal to eject a vCPU, the vCPU must be
 removed from CPU list,before the vCPU really removed,  then
 release the all related vCPU objects.
 But we do not close KVM vcpu fd, just record it into a list, in
 order to reuse it.
 
 Hi Gu Zheng,
 
 So this approach of parking the vcpu fd in QEMU and reusing it next
 time during CPU hotplug will only work if all architectures supported
 by KVM driver are ok with reuse of vcpu object in the kernel. I am
 using relevant bits of this patch of yours with PowerPC architecture
 to support cpu unplug and I realize that there is at least one case
 where reuse of vcpu object in the kernel causes problems. Before I
 attempt to fix that in ppc KVM, I wanted to check if there is
 consensus on this approach (parking and reusing kvm vcpu fd) in QEMU.

Not yet, also no objection.
But it's the best way that I can find to handle the vcpu object without
touching the CPU array in kernel.

 
 Also is there a latest version of this patchset that I can try ?

A new version is on the respinning, and will be sent out once the 2.2 released.

Thanks,
Gu

 
 Regards,
 Bharata.
 .
 





Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-12-08 Thread Gu Zheng
Hi Peter,
On 12/08/2014 05:26 PM, Peter Maydell wrote:

 On 8 December 2014 at 09:16, Bharata B Rao bharata@gmail.com wrote:
 So this approach of parking the vcpu fd in QEMU and reusing it next
 time during CPU hotplug will only work if all architectures supported
 by KVM driver are ok with reuse of vcpu object in the kernel. I am
 using relevant bits of this patch of yours with PowerPC architecture
 to support cpu unplug and I realize that there is at least one case
 where reuse of vcpu object in the kernel causes problems. Before I
 attempt to fix that in ppc KVM, I wanted to check if there is
 consensus on this approach (parking and reusing kvm vcpu fd) in QEMU.
 
 For ARM we've just clarified the kernel-to-userspace ABI, and
 among other things it says you can't reuse the VCPU unless it's
 for exactly the same CPU type and feature configuration. So

Yes, it's a limitation now, but it is not the final implementation.
As to the QEMU side, the vcpu object in kernel is stateless, and a
reset operation will be done when we hot add a vcpu, so I think we
can kill the limitation, just choose a parked vcpu and reconfigure
it before we use it.

Thanks,
Gu 

 I'm not sure this park-and-reuse approach will work...

 

 -- PMM
 .
 





Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-12-08 Thread Gu Zheng
+cc Gleb, KVM guys,

On 12/09/2014 12:38 AM, Peter Maydell wrote:

 On 8 December 2014 at 15:38, Igor Mammedov imamm...@redhat.com wrote:
 On Mon, 8 Dec 2014 10:50:21 +
 Peter Maydell peter.mayd...@linaro.org wrote:
 Why can't the kernel handle our just destroying the vcpu and
 later recreating it if necessary? That seems the more logical
 approach than trying to keep fds hanging around in userspace
 for reuse.

 It's somewhat complex approach and it was suggested on KVM list to go
 parking route. for more details see thread
  https://www.mail-archive.com/kvm@vger.kernel.org/msg102839.html
 
 If the kernel can't cope with userspace creating and destroying
 vCPUs dynamically then that seems like a kernel bug to me.

Yes, it's a flaw.

 It seems better to me to fix that directly rather than make
 non-x86 architectures change things around to help with working
 around that bug...

Agree.
But as we discussed before:
CPU array is accessed locklessly in a lot of places, so it will have to be 
RCUified. There was attempt to do so 2 year or so ago, but it didn't go 
anyware. 
Adding locks is to big a price to pay for ability to free a little bit
of memory by destroying vcpu.
We worry about the regression if we add lock in a lot of places.
I'm not very familiar with non-x86 architectures. So I'm not sure how long we
need to go to help vcpu hot-unplug working with parking route.

Gleb,
Is any guys still working on the RCUing CPUarray access?
Is there any plan for this issue, or just leave it as it is?

Thanks,
Gu

 
 thanks
 -- PMM
 .
 





Re: [Qemu-devel] [PATCH 0/6] cpu: add device_add foo-x86_64-cpu support

2014-11-17 Thread Gu Zheng
ping...

On 11/13/2014 09:10 AM, Gu Zheng wrote:

 This series is based on the previous patchset from Chen Fan:
 https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html
 
 We try to make cpu hotplug with device_add, and make
 -device foo-x86_64-cpu available,also we can set apic-id
 property with command line, if without setting apic-id property,
 we offer the first unoccupied apic id as the default new apic id.
 When hotplug cpu with device_add, additional check of APIC ID will be
 done after cpu object initialization which was different from
 'cpu_add' command that check 'ids' at the beginning.
 
 ---
 Changelog since RFC:
  -split out APIC vmstate/QMP-monitor changes into separate patches.
  -add the handle of the startup cpus(-device foo).
  -remove duplicated checking about env-cpuid_apic_id.
  -do actual APIC ID allocation at realize time if it is not set before.
  -remove the unneeded x86_cpu_cpudef_instance_init().
  -split off device_del support out here.
 ---
 
 Chen Fan (2):
   cpu: introduce CpuTopoInfo structure for argument simplification
   cpu: add device_add foo-x86_64-cpu support
 
 Gu Zheng (4):
   qom/cpu: move register_vmstate to common CPUClass.realizefn
   qom/cpu: move apic vmstate register into x86_cpu_apic_realize
   monitor: use cc-get_arch_id as the cpu index
   acpi:cpu hotplug: set pcmachine as icc bus' hotplug handler
 
  cpus.c  |4 ++-
  exec.c  |   32 +-
  hw/acpi/cpu_hotplug.c   |5 +++-
  hw/cpu/icc_bus.c|   15 ---
  hw/i386/pc.c|6 
  hw/i386/pc_piix.c   |6 +++-
  hw/i386/pc_q35.c|5 +++
  hw/intc/apic_common.c   |3 +-
  include/hw/cpu/icc_bus.h|   14 ++
  include/hw/i386/apic_internal.h |3 ++
  include/qom/cpu.h   |2 +
  monitor.c   |4 ++-
  qom/cpu.c   |2 +
  target-i386/cpu.c   |   54 +++---
  target-i386/topology.h  |   51 +---
  15 files changed, 145 insertions(+), 61 deletions(-)
 





[Qemu-devel] [PATCH 0/6] cpu: add device_add foo-x86_64-cpu support

2014-11-12 Thread Gu Zheng
This series is based on the previous patchset from Chen Fan:
https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html

We try to make cpu hotplug with device_add, and make
-device foo-x86_64-cpu available,also we can set apic-id
property with command line, if without setting apic-id property,
we offer the first unoccupied apic id as the default new apic id.
When hotplug cpu with device_add, additional check of APIC ID will be
done after cpu object initialization which was different from
'cpu_add' command that check 'ids' at the beginning.

---
Changelog since RFC:
 -split out APIC vmstate/QMP-monitor changes into separate patches.
 -add the handle of the startup cpus(-device foo).
 -remove duplicated checking about env-cpuid_apic_id.
 -do actual APIC ID allocation at realize time if it is not set before.
 -remove the unneeded x86_cpu_cpudef_instance_init().
 -split off device_del support out here.
---

Chen Fan (2):
  cpu: introduce CpuTopoInfo structure for argument simplification
  cpu: add device_add foo-x86_64-cpu support

Gu Zheng (4):
  qom/cpu: move register_vmstate to common CPUClass.realizefn
  qom/cpu: move apic vmstate register into x86_cpu_apic_realize
  monitor: use cc-get_arch_id as the cpu index
  acpi:cpu hotplug: set pcmachine as icc bus' hotplug handler

 cpus.c  |4 ++-
 exec.c  |   32 +-
 hw/acpi/cpu_hotplug.c   |5 +++-
 hw/cpu/icc_bus.c|   15 ---
 hw/i386/pc.c|6 
 hw/i386/pc_piix.c   |6 +++-
 hw/i386/pc_q35.c|5 +++
 hw/intc/apic_common.c   |3 +-
 include/hw/cpu/icc_bus.h|   14 ++
 include/hw/i386/apic_internal.h |3 ++
 include/qom/cpu.h   |2 +
 monitor.c   |4 ++-
 qom/cpu.c   |2 +
 target-i386/cpu.c   |   54 +++---
 target-i386/topology.h  |   51 +---
 15 files changed, 145 insertions(+), 61 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH 1/6] cpu: introduce CpuTopoInfo structure for argument simplification

2014-11-12 Thread Gu Zheng
From: Chen Fan chen.fan.f...@cn.fujitsu.com

Reviewed-by: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 target-i386/topology.h |   33 +
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/target-i386/topology.h b/target-i386/topology.h
index 07a6c5f..e9ff89c 100644
--- a/target-i386/topology.h
+++ b/target-i386/topology.h
@@ -47,6 +47,12 @@
  */
 typedef uint32_t apic_id_t;
 
+typedef struct X86CPUTopoInfo {
+unsigned pkg_id;
+unsigned core_id;
+unsigned smt_id;
+} X86CPUTopoInfo;
+
 /* Return the bit width needed for 'count' IDs
  */
 static unsigned apicid_bitwidth_for_count(unsigned count)
@@ -92,13 +98,11 @@ static inline unsigned apicid_pkg_offset(unsigned nr_cores, 
unsigned nr_threads)
  */
 static inline apic_id_t apicid_from_topo_ids(unsigned nr_cores,
  unsigned nr_threads,
- unsigned pkg_id,
- unsigned core_id,
- unsigned smt_id)
+ const X86CPUTopoInfo *topo)
 {
-return (pkg_id   apicid_pkg_offset(nr_cores, nr_threads)) |
-   (core_id  apicid_core_offset(nr_cores, nr_threads)) |
-   smt_id;
+return (topo-pkg_id   apicid_pkg_offset(nr_cores, nr_threads)) |
+   (topo-core_id  apicid_core_offset(nr_cores, nr_threads)) |
+   topo-smt_id;
 }
 
 /* Calculate thread/core/package IDs for a specific topology,
@@ -107,14 +111,12 @@ static inline apic_id_t apicid_from_topo_ids(unsigned 
nr_cores,
 static inline void x86_topo_ids_from_idx(unsigned nr_cores,
  unsigned nr_threads,
  unsigned cpu_index,
- unsigned *pkg_id,
- unsigned *core_id,
- unsigned *smt_id)
+ X86CPUTopoInfo *topo)
 {
 unsigned core_index = cpu_index / nr_threads;
-*smt_id = cpu_index % nr_threads;
-*core_id = core_index % nr_cores;
-*pkg_id = core_index / nr_cores;
+topo-smt_id = cpu_index % nr_threads;
+topo-core_id = core_index % nr_cores;
+topo-pkg_id = core_index / nr_cores;
 }
 
 /* Make APIC ID for the CPU 'cpu_index'
@@ -125,10 +127,9 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned 
nr_cores,
 unsigned nr_threads,
 unsigned cpu_index)
 {
-unsigned pkg_id, core_id, smt_id;
-x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index,
-  pkg_id, core_id, smt_id);
-return apicid_from_topo_ids(nr_cores, nr_threads, pkg_id, core_id, smt_id);
+X86CPUTopoInfo topo;
+x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index, topo);
+return apicid_from_topo_ids(nr_cores, nr_threads, topo);
 }
 
 #endif /* TARGET_I386_TOPOLOGY_H */
-- 
1.7.7




[Qemu-devel] [PATCH 2/6] qom/cpu: move register_vmstate to common CPUClass.realizefn

2014-11-12 Thread Gu Zheng
Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn,
and use cc-get_arch_id as the instance id that suggested by Igor to
fix the migration issue.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 exec.c|   32 +++-
 include/qom/cpu.h |2 ++
 qom/cpu.c |2 ++
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/exec.c b/exec.c
index 759055d..6823f36 100644
--- a/exec.c
+++ b/exec.c
@@ -508,10 +508,28 @@ void tcg_cpu_address_space_init(CPUState *cpu, 
AddressSpace *as)
 }
 #endif
 
+void cpu_vmstate_register(CPUState *cpu)
+{
+CPUClass *cc = CPU_GET_CLASS(cpu);
+int cpu_index = cc-get_arch_id(cpu);
+
+if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+vmstate_register(NULL, cpu_index, vmstate_cpu_common, cpu);
+}
+#if defined(CPU_SAVE_VERSION)  !defined(CONFIG_USER_ONLY)
+register_savevm(NULL, cpu, cpu_index, CPU_SAVE_VERSION,
+cpu_save, cpu_load, cpu-env_ptr);
+assert(cc-vmsd == NULL);
+assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
+#endif
+if (cc-vmsd != NULL) {
+vmstate_register(NULL, cpu_index, cc-vmsd, cpu);
+}
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
 CPUState *cpu = ENV_GET_CPU(env);
-CPUClass *cc = CPU_GET_CLASS(cpu);
 CPUState *some_cpu;
 int cpu_index;
 
@@ -534,18 +552,6 @@ void cpu_exec_init(CPUArchState *env)
 #if defined(CONFIG_USER_ONLY)
 cpu_list_unlock();
 #endif
-if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
-vmstate_register(NULL, cpu_index, vmstate_cpu_common, cpu);
-}
-#if defined(CPU_SAVE_VERSION)  !defined(CONFIG_USER_ONLY)
-register_savevm(NULL, cpu, cpu_index, CPU_SAVE_VERSION,
-cpu_save, cpu_load, env);
-assert(cc-vmsd == NULL);
-assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
-#endif
-if (cc-vmsd != NULL) {
-vmstate_register(NULL, cpu_index, cc-vmsd, cpu);
-}
 }
 
 #if defined(TARGET_HAS_ICE)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 2098f1c..936afcd 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -562,6 +562,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
 
 #endif /* USER_ONLY */
 
+void cpu_vmstate_register(CPUState *cpu);
+
 #ifdef CONFIG_SOFTMMU
 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
  bool is_write, bool is_exec,
diff --git a/qom/cpu.c b/qom/cpu.c
index 79d2228..00c1007 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -301,6 +301,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
 {
 CPUState *cpu = CPU(dev);
 
+cpu_vmstate_register(cpu);
+
 if (dev-hotplugged) {
 cpu_synchronize_post_init(cpu);
 cpu_resume(cpu);
-- 
1.7.7




[Qemu-devel] [PATCH 3/6] qom/cpu: move apic vmstate register into x86_cpu_apic_realize

2014-11-12 Thread Gu Zheng
move apic vmstate register into x86_cpu_apic_realize, and use
cc-get_arch_id as the instance id to avoid using the auto-id which will
break the migration if we add device not in order.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/intc/apic_common.c   |3 +--
 include/hw/i386/apic_internal.h |3 +++
 target-i386/cpu.c   |8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ce3d903..029f67d 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -345,7 +345,7 @@ static int apic_dispatch_post_load(void *opaque, int 
version_id)
 return 0;
 }
 
-static const VMStateDescription vmstate_apic_common = {
+const VMStateDescription vmstate_apic_common = {
 .name = apic,
 .version_id = 3,
 .minimum_version_id = 3,
@@ -391,7 +391,6 @@ static void apic_common_class_init(ObjectClass *klass, void 
*data)
 ICCDeviceClass *idc = ICC_DEVICE_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
 dc-props = apic_properties_common;
 idc-realize = apic_common_realize;
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 83e2a42..61fddf6 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -23,6 +23,7 @@
 #include exec/memory.h
 #include hw/cpu/icc_bus.h
 #include qemu/timer.h
+#include migration/vmstate.h
 
 /* APIC Local Vector Table */
 #define APIC_LVT_TIMER  0
@@ -137,6 +138,8 @@ typedef struct VAPICState {
 
 extern bool apic_report_tpr_access;
 
+extern const VMStateDescription vmstate_apic_common;
+
 void apic_report_irq_delivered(int delivered);
 bool apic_next_timer(APICCommonState *s, int64_t current_time);
 void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e4ccee1..0f23ba3 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2678,10 +2678,16 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error 
**errp)
 
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
 {
-if (cpu-apic_state == NULL) {
+DeviceState *apic_state = cpu-apic_state;
+CPUClass *cc = CPU_GET_CLASS(CPU(cpu));
+
+if (apic_state == NULL) {
 return;
 }
 
+vmstate_register(0, cc-get_arch_id(CPU(cpu)),
+vmstate_apic_common, apic_state);
+
 if (qdev_init(cpu-apic_state)) {
 error_setg(errp, APIC device '%s' could not be initialized,
object_get_typename(OBJECT(cpu-apic_state)));
-- 
1.7.7




[Qemu-devel] [PATCH 4/6] monitor: use cc-get_arch_id as the cpu index

2014-11-12 Thread Gu Zheng
Use cc-get_arch_id as the cpu index to avoid the cpu index duplicated
issue in the QMP/HMP command output.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 cpus.c|4 +++-
 monitor.c |4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0c33458..849d1bf 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1411,6 +1411,7 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 
 CPU_FOREACH(cpu) {
 CpuInfoList *info;
+CPUClass *cc;
 #if defined(TARGET_I386)
 X86CPU *x86_cpu = X86_CPU(cpu);
 CPUX86State *env = x86_cpu-env;
@@ -1428,11 +1429,12 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 CPUTriCoreState *env = tricore_cpu-env;
 #endif
 
+cc = CPU_GET_CLASS(cpu);
 cpu_synchronize_state(cpu);
 
 info = g_malloc0(sizeof(*info));
 info-value = g_malloc0(sizeof(*info-value));
-info-value-CPU = cpu-cpu_index;
+info-value-CPU = cc-get_arch_id(cpu);
 info-value-current = (cpu == first_cpu);
 info-value-halted = cpu-halted;
 info-value-thread_id = cpu-thread_id;
diff --git a/monitor.c b/monitor.c
index 1fc201a..fdd51fa 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1024,7 +1024,9 @@ static CPUArchState *mon_get_cpu(void)
 int monitor_get_cpu_index(void)
 {
 CPUState *cpu = ENV_GET_CPU(mon_get_cpu());
-return cpu-cpu_index;
+CPUClass *cc = CPU_GET_CLASS(cpu);
+
+return cc-get_arch_id(cpu);
 }
 
 static void do_info_registers(Monitor *mon, const QDict *qdict)
-- 
1.7.7




[Qemu-devel] [PATCH 5/6] acpi:cpu hotplug: set pcmachine as icc bus' hotplug handler

2014-11-12 Thread Gu Zheng
As the pre-check in the qdev_device_add():
if (qdev_hotplug  bus  !qbus_is_hotpluggable(bus)) {
qerror_report(QERR_BUS_NO_HOTPLUG, bus-name);
return NULL;
}
if device has parent bus, the bus must have valid hotplug_handler,
otherwise can not hot plug.
Currently cpu hotplug is based on the PCMachine's hotplug handler,
so when hot add cpu, the hotpluggable check of icc bus will be
rejected.
So we set pcmachine as icc bus' hotplug handler to avoid the rejetion.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com
---
 hw/cpu/icc_bus.c |   15 ---
 hw/i386/pc_piix.c|6 +-
 hw/i386/pc_q35.c |5 +
 include/hw/cpu/icc_bus.h |   14 ++
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/hw/cpu/icc_bus.c b/hw/cpu/icc_bus.c
index 9575fd6..1c55a07 100644
--- a/hw/cpu/icc_bus.c
+++ b/hw/cpu/icc_bus.c
@@ -20,7 +20,6 @@
  * License along with this library; if not, see http://www.gnu.org/licenses/
  */
 #include hw/cpu/icc_bus.h
-#include hw/sysbus.h
 
 /* icc-bridge implementation */
 
@@ -61,20 +60,6 @@ static const TypeInfo icc_device_info = {
 .class_init = icc_device_class_init,
 };
 
-
-/*  icc-bridge implementation */
-
-typedef struct ICCBridgeState {
-/* private */
-SysBusDevice parent_obj;
-/* public */
-
-ICCBus icc_bus;
-MemoryRegion apic_container;
-} ICCBridgeState;
-
-#define ICC_BRIGDE(obj) OBJECT_CHECK(ICCBridgeState, (obj), TYPE_ICC_BRIDGE)
-
 static void icc_bridge_init(Object *obj)
 {
 ICCBridgeState *s = ICC_BRIGDE(obj);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 537bcf2..6bb9ccc 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -276,7 +276,7 @@ static void pc_init1(MachineState *machine,
 if (pci_enabled  acpi_enabled) {
 DeviceState *piix4_pm;
 I2CBus *smbus;
-
+ICCBus *iccbus;
 smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
 /* TODO: Populate SPD eeprom data.  */
 smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
@@ -291,6 +291,10 @@ static void pc_init1(MachineState *machine,
  OBJ_PROP_LINK_UNREF_ON_RELEASE, error_abort);
 object_property_set_link(OBJECT(machine), OBJECT(piix4_pm),
  PC_MACHINE_ACPI_DEVICE_PROP, error_abort);
+
+iccbus = ICC_BRIGDE(icc_bridge)-icc_bus;
+object_property_set_link(OBJECT(iccbus), OBJECT(pc_machine),
+ QDEV_HOTPLUG_HANDLER_PROPERTY, error_abort);
 }
 
 if (pci_enabled) {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 296bdec..443603d 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -88,6 +88,7 @@ static void pc_q35_init(MachineState *machine)
 PcGuestInfo *guest_info;
 ram_addr_t lowmem;
 DriveInfo *hd[MAX_SATA_PORTS];
+ICCBus *iccbus;
 
 /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
  * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
@@ -212,6 +213,10 @@ static void pc_q35_init(MachineState *machine)
 object_property_set_link(OBJECT(machine), OBJECT(lpc),
  PC_MACHINE_ACPI_DEVICE_PROP, error_abort);
 
+iccbus = ICC_BRIGDE(icc_bridge)-icc_bus;
+object_property_set_link(OBJECT(iccbus), OBJECT(pc_machine),
+ QDEV_HOTPLUG_HANDLER_PROPERTY, error_abort);
+
 ich9_lpc = ICH9_LPC_DEVICE(lpc);
 ich9_lpc-pic = gsi;
 ich9_lpc-ioapic = gsi_state-ioapic_irq;
diff --git a/include/hw/cpu/icc_bus.h b/include/hw/cpu/icc_bus.h
index 98a979f..8354c96 100644
--- a/include/hw/cpu/icc_bus.h
+++ b/include/hw/cpu/icc_bus.h
@@ -24,6 +24,7 @@
 
 #include exec/memory.h
 #include hw/qdev-core.h
+#include hw/sysbus.h
 
 #define TYPE_ICC_BUS icc-bus
 
@@ -44,6 +45,19 @@ typedef struct ICCBus {
 
 #define ICC_BUS(obj) OBJECT_CHECK(ICCBus, (obj), TYPE_ICC_BUS)
 
+/*  icc-bridge implementation */
+
+typedef struct ICCBridgeState {
+/* private */
+SysBusDevice parent_obj;
+/* public */
+
+ICCBus icc_bus;
+MemoryRegion apic_container;
+} ICCBridgeState;
+
+#define ICC_BRIGDE(obj) OBJECT_CHECK(ICCBridgeState, (obj), TYPE_ICC_BRIDGE)
+
 /**
  * ICCDevice:
  *
-- 
1.7.7




Re: [Qemu-devel] [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support

2014-11-11 Thread Gu Zheng
Hi Igor,
As your hot-plug rework has been merged in upstream, and we need to respin
the i386 cpu hot remove a lot based on the latest tree.
So I want to split the series into two parts:
Part 1/2: add device_add foo-x86_64-cpu support.
Part 2/2: i386 cpu hot remove support.
, which will be easy to review.
The Part 1/2 will come soon, and Part 2/2 will be sent out once the rework
is done.
What's your opinion?

Thanks,
Gu 

On 08/28/2014 11:36 AM, Gu Zheng wrote:

 This series is based on the previous patchset from Chen Fan:
 https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html
 https://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg04266.html
 
 Patch 1~3: add device_add foo-x86_64-cpu support
 These three patches try to make cpu hotplug with device_add, and make
 -device foo-x86_64-cpu available,also we can set apic-id
 property with command line, if without setting apic-id property,
 we offer the first unoccupied apic id as the default new apic id.
 When hotplug cpu with device_add, additional check of APIC ID will be
 done after cpu object initialization which was different from
 'cpu_add' command that check 'ids' at the beginning.
 
 Patch 4~10: add i386 cpu hot remove support
 Via implementing ACPI standard methods _EJ0 in ACPI table, after Guest
 OS remove one vCPU online, the fireware will store removed bitmap to
 QEMU, then QEMU could know to notify the assigned vCPU of exiting.
 Meanwhile, intruduce the QOM command 'device_del' to remove vCPU from
 QEMU itself.
 
 v2:
  -fix the cpu index duplicated issue in the QMP/HMP command output.
 
 Chen Fan (6):
   cpu: introduce CpuTopoInfo structure for argument simplification
   cpu: add device_add foo-x86_64-cpu support
   x86: add x86_cpu_unrealizefn() for cpu apic remove
   qom cpu: rename variable 'cpu_added_notifier' to
 'cpu_hotplug_notifier'
   i386: implement pc interface cpu_common_unrealizefn() in qom/cpu.c
   cpu hotplug: implement function cpu_status_write() for vcpu ejection
 
 Gu Zheng (4):
   qom/cpu: move register_vmstate to common CPUClass.realizefn
   i386: add cpu device_del support
   qom cpu: add UNPLUG cpu notify support
   cpus: reclaim allocated vCPU objects
 
  cpus.c|   48 +-
  exec.c|   32 +
  hw/acpi/cpu_hotplug.c |   55 +--
  hw/acpi/ich9.c|   13 ++--
  hw/acpi/piix4.c   |   21 +++---
  hw/i386/acpi-dsdt-cpu-hotplug.dsl |6 ++-
  hw/i386/kvm/apic.c|8 ++
  hw/i386/pc.c  |2 +-
  hw/intc/apic.c|   10 +++
  hw/intc/apic_common.c |   26 ++-
  include/hw/acpi/cpu_hotplug.h |   14 -
  include/hw/acpi/ich9.h|2 +-
  include/hw/cpu/icc_bus.h  |1 +
  include/hw/i386/apic_internal.h   |3 +
  include/qom/cpu.h |   12 +++
  include/sysemu/kvm.h  |1 +
  include/sysemu/sysemu.h   |2 +-
  kvm-all.c |   57 +++-
  monitor.c |4 +-
  qdev-monitor.c|1 +
  qom/cpu.c |   29 +++--
  target-i386/cpu-qom.h |1 +
  target-i386/cpu.c |  138 
 -
  target-i386/topology.h|   51 +
  24 files changed, 470 insertions(+), 67 deletions(-)
 





Re: [Qemu-devel] [RFC V2 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support

2014-11-11 Thread Gu Zheng
Hi Igor,
As your hot-plug rework has been merged in upstream, and we need to respin
the i386 cpu hot remove a lot based on the latest tree.
So I want to split the series into two parts:
Part 1/2: add device_add foo-x86_64-cpu support.
Part 2/2: i386 cpu hot remove support.
, which will be easy to review.
The Part 1/2 will come soon, and Part 2/2 will be sent out once the rework
is done.
What's your opinion?

Thanks,
Gu 

On 08/28/2014 11:36 AM, Gu Zheng wrote:

 This series is based on the previous patchset from Chen Fan:
 https://lists.nongnu.org/archive/html/qemu-devel/2014-05/msg02360.html
 https://lists.nongnu.org/archive/html/qemu-devel/2013-12/msg04266.html
 
 Patch 1~3: add device_add foo-x86_64-cpu support
 These three patches try to make cpu hotplug with device_add, and make
 -device foo-x86_64-cpu available,also we can set apic-id
 property with command line, if without setting apic-id property,
 we offer the first unoccupied apic id as the default new apic id.
 When hotplug cpu with device_add, additional check of APIC ID will be
 done after cpu object initialization which was different from
 'cpu_add' command that check 'ids' at the beginning.
 
 Patch 4~10: add i386 cpu hot remove support
 Via implementing ACPI standard methods _EJ0 in ACPI table, after Guest
 OS remove one vCPU online, the fireware will store removed bitmap to
 QEMU, then QEMU could know to notify the assigned vCPU of exiting.
 Meanwhile, intruduce the QOM command 'device_del' to remove vCPU from
 QEMU itself.
 
 v2:
  -fix the cpu index duplicated issue in the QMP/HMP command output.
 
 Chen Fan (6):
   cpu: introduce CpuTopoInfo structure for argument simplification
   cpu: add device_add foo-x86_64-cpu support
   x86: add x86_cpu_unrealizefn() for cpu apic remove
   qom cpu: rename variable 'cpu_added_notifier' to
 'cpu_hotplug_notifier'
   i386: implement pc interface cpu_common_unrealizefn() in qom/cpu.c
   cpu hotplug: implement function cpu_status_write() for vcpu ejection
 
 Gu Zheng (4):
   qom/cpu: move register_vmstate to common CPUClass.realizefn
   i386: add cpu device_del support
   qom cpu: add UNPLUG cpu notify support
   cpus: reclaim allocated vCPU objects
 
  cpus.c|   48 +-
  exec.c|   32 +
  hw/acpi/cpu_hotplug.c |   55 +--
  hw/acpi/ich9.c|   13 ++--
  hw/acpi/piix4.c   |   21 +++---
  hw/i386/acpi-dsdt-cpu-hotplug.dsl |6 ++-
  hw/i386/kvm/apic.c|8 ++
  hw/i386/pc.c  |2 +-
  hw/intc/apic.c|   10 +++
  hw/intc/apic_common.c |   26 ++-
  include/hw/acpi/cpu_hotplug.h |   14 -
  include/hw/acpi/ich9.h|2 +-
  include/hw/cpu/icc_bus.h  |1 +
  include/hw/i386/apic_internal.h   |3 +
  include/qom/cpu.h |   12 +++
  include/sysemu/kvm.h  |1 +
  include/sysemu/sysemu.h   |2 +-
  kvm-all.c |   57 +++-
  monitor.c |4 +-
  qdev-monitor.c|1 +
  qom/cpu.c |   29 +++--
  target-i386/cpu-qom.h |1 +
  target-i386/cpu.c |  138 
 -
  target-i386/topology.h|   51 +
  24 files changed, 470 insertions(+), 67 deletions(-)
 





Re: [Qemu-devel] [PATCH V6 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-11-02 Thread Gu Zheng
Hi Michael,
Could you please have a look at this series?

Thanks,
Gu
On 10/22/2014 11:24 AM, Gu Zheng wrote:

 Previously we use cpu_added_notifiers to register cpu hotplug notifier 
 callback
 which is not able to pass/handle errors, so we switch it to unified hotplug
 handler API which allows to pass errors and would allow to cancel device_add
 in case of error.
 Thanks very much for Igor's review and suggestion.
 
 ---
 v6:
  Patch 8/8:
  -using error_abort instead of local_err, so that we can gain the error report
   before abort (suggested by Igor).
 
 v5:
  -rebase on the latest upstream and fix some comments.
  Patch 4/8:
  -split the check out of acpi_dev block.
  Patch 5/8:
  -move CPU hot-plug notifier cleanup hunk into Patch 6/8.
  Patch 6/8:
  -delete the caller of notifier_list_notify() in this patch.
  Patch 8/8:
  -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better 
 readability.
 
 v4:
  -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
  Patch 1/7:
  -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
   and do cast to CPU inside.
  Patch 5/7:
  -Make rtc_state as a link property in PCMachine rather than the global
   variables.
  -Split out the removal of unused notifier into separate patch.
  -Check the result of plug callback before update rtc_state.
 
 v3:
  -deal with start-up cpus in pc_cpu_plug as Igor suggested.
 
 v2:
  -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
   1/5--1/7
   2/5--2/7
   3/5--3/7
   4/5--4/7
  Patch 1/7:
  -add errp argument to catch error.
  -return error instead of aborting if cpu id is invalid.
  -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
  Patch 3/7:
  -remove unused AcpiCpuHotplug_add directly.
  Patch 5/7:
  -switch the last user of cpu hotplug notifier to hotplug handler API, and
   remove the unused cpu hotplug notify.
  Patch 6/7:
  -split the function rename (just cleanup) into single patch.
  Patch 7/7:
  -introduce help function acpi_set_local_sts to keep the bit setting in
   one place.
 ---
 
 Gu Zheng (8):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug to hotplug_handler API
   acpi:piix4: convert cpu hotplug to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   pc: Update rtc_cmos in pc_cpu_plug
   qom/cpu: remove the unused CPU hot-plug notifier
   cpu-hotplug: rename function for better readability
   acpi/cpu-hotplug: introduce helper function to keep bit setting in
 one place
 
  hw/acpi/cpu_hotplug.c |   34 ++---
  hw/acpi/ich9.c|   17 ++
  hw/acpi/piix4.c   |   18 ++-
  hw/i386/pc.c  |   65 
 +++--
  hw/i386/pc_piix.c |2 +-
  hw/i386/pc_q35.c  |2 +-
  include/hw/acpi/cpu_hotplug.h |7 ++--
  include/hw/acpi/ich9.h|1 -
  include/hw/i386/pc.h  |3 +-
  include/sysemu/sysemu.h   |3 --
  qom/cpu.c |   10 --
  11 files changed, 82 insertions(+), 80 deletions(-)
 





Re: [Qemu-devel] [PATCH V6 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-10-23 Thread Gu Zheng
Hi,
This series has been reviewed by Igor, could you please apply it?

Thanks,
Gu
On 10/22/2014 11:24 AM, Gu Zheng wrote:

 Previously we use cpu_added_notifiers to register cpu hotplug notifier 
 callback
 which is not able to pass/handle errors, so we switch it to unified hotplug
 handler API which allows to pass errors and would allow to cancel device_add
 in case of error.
 Thanks very much for Igor's review and suggestion.
 
 ---
 v6:
  Patch 8/8:
  -using error_abort instead of local_err, so that we can gain the error report
   before abort (suggested by Igor).
 
 v5:
  -rebase on the latest upstream and fix some comments.
  Patch 4/8:
  -split the check out of acpi_dev block.
  Patch 5/8:
  -move CPU hot-plug notifier cleanup hunk into Patch 6/8.
  Patch 6/8:
  -delete the caller of notifier_list_notify() in this patch.
  Patch 8/8:
  -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better 
 readability.
 
 v4:
  -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
  Patch 1/7:
  -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
   and do cast to CPU inside.
  Patch 5/7:
  -Make rtc_state as a link property in PCMachine rather than the global
   variables.
  -Split out the removal of unused notifier into separate patch.
  -Check the result of plug callback before update rtc_state.
 
 v3:
  -deal with start-up cpus in pc_cpu_plug as Igor suggested.
 
 v2:
  -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
   1/5--1/7
   2/5--2/7
   3/5--3/7
   4/5--4/7
  Patch 1/7:
  -add errp argument to catch error.
  -return error instead of aborting if cpu id is invalid.
  -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
  Patch 3/7:
  -remove unused AcpiCpuHotplug_add directly.
  Patch 5/7:
  -switch the last user of cpu hotplug notifier to hotplug handler API, and
   remove the unused cpu hotplug notify.
  Patch 6/7:
  -split the function rename (just cleanup) into single patch.
  Patch 7/7:
  -introduce help function acpi_set_local_sts to keep the bit setting in
   one place.
 ---
 
 Gu Zheng (8):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug to hotplug_handler API
   acpi:piix4: convert cpu hotplug to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   pc: Update rtc_cmos in pc_cpu_plug
   qom/cpu: remove the unused CPU hot-plug notifier
   cpu-hotplug: rename function for better readability
   acpi/cpu-hotplug: introduce helper function to keep bit setting in
 one place
 
  hw/acpi/cpu_hotplug.c |   34 ++---
  hw/acpi/ich9.c|   17 ++
  hw/acpi/piix4.c   |   18 ++-
  hw/i386/pc.c  |   65 
 +++--
  hw/i386/pc_piix.c |2 +-
  hw/i386/pc_q35.c  |2 +-
  include/hw/acpi/cpu_hotplug.h |7 ++--
  include/hw/acpi/ich9.h|1 -
  include/hw/i386/pc.h  |3 +-
  include/sysemu/sysemu.h   |3 --
  qom/cpu.c |   10 --
  11 files changed, 82 insertions(+), 80 deletions(-)
 





[Qemu-devel] [PATCH V6 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-10-21 Thread Gu Zheng
Previously we use cpu_added_notifiers to register cpu hotplug notifier callback
which is not able to pass/handle errors, so we switch it to unified hotplug
handler API which allows to pass errors and would allow to cancel device_add
in case of error.
Thanks very much for Igor's review and suggestion.

---
v6:
 Patch 8/8:
 -using error_abort instead of local_err, so that we can gain the error report
  before abort (suggested by Igor).

v5:
 -rebase on the latest upstream and fix some comments.
 Patch 4/8:
 -split the check out of acpi_dev block.
 Patch 5/8:
 -move CPU hot-plug notifier cleanup hunk into Patch 6/8.
 Patch 6/8:
 -delete the caller of notifier_list_notify() in this patch.
 Patch 8/8:
 -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better readability.

v4:
 -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
 Patch 1/7:
 -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
  and do cast to CPU inside.
 Patch 5/7:
 -Make rtc_state as a link property in PCMachine rather than the global
  variables.
 -Split out the removal of unused notifier into separate patch.
 -Check the result of plug callback before update rtc_state.

v3:
 -deal with start-up cpus in pc_cpu_plug as Igor suggested.

v2:
 -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
  1/5--1/7
  2/5--2/7
  3/5--3/7
  4/5--4/7
 Patch 1/7:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
 Patch 3/7:
 -remove unused AcpiCpuHotplug_add directly.
 Patch 5/7:
 -switch the last user of cpu hotplug notifier to hotplug handler API, and
  remove the unused cpu hotplug notify.
 Patch 6/7:
 -split the function rename (just cleanup) into single patch.
 Patch 7/7:
 -introduce help function acpi_set_local_sts to keep the bit setting in
  one place.
---

Gu Zheng (8):
  acpi/cpu: add cpu hotplug callback function to match hotplug_handler
API
  acpi:ich9: convert cpu hotplug to hotplug_handler API
  acpi:piix4: convert cpu hotplug to hotplug_handler API
  pc: add cpu hotplug handler to PC_MACHINE
  pc: Update rtc_cmos in pc_cpu_plug
  qom/cpu: remove the unused CPU hot-plug notifier
  cpu-hotplug: rename function for better readability
  acpi/cpu-hotplug: introduce helper function to keep bit setting in
one place

 hw/acpi/cpu_hotplug.c |   34 ++---
 hw/acpi/ich9.c|   17 ++
 hw/acpi/piix4.c   |   18 ++-
 hw/i386/pc.c  |   65 +++--
 hw/i386/pc_piix.c |2 +-
 hw/i386/pc_q35.c  |2 +-
 include/hw/acpi/cpu_hotplug.h |7 ++--
 include/hw/acpi/ich9.h|1 -
 include/hw/i386/pc.h  |3 +-
 include/sysemu/sysemu.h   |3 --
 qom/cpu.c |   10 --
 11 files changed, 82 insertions(+), 80 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH V6 1/8] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-10-21 Thread Gu Zheng
Add cpu hotplug callback function (acpi_cpu_plug_cb) to match hotplug_handler 
API.

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v4:
 -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
  and do cast to CPU inside.
v2:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.

 hw/acpi/cpu_hotplug.c |   18 ++
 include/hw/acpi/cpu_hotplug.h |3 +++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2ad83a0..06e9c61 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,6 +36,24 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+CPUState *cpu = CPU(dev);
+CPUClass *k = CPU_GET_CLASS(cpu);
+int64_t cpu_id;
+
+cpu_id = k-get_arch_id(cpu);
+if ((cpu_id / 8) = ACPI_GPE_PROC_LEN) {
+error_setg(errp, acpi: invalid cpu id: % PRIi64, cpu_id);
+return;
+}
+
+AcpiCpuHotplug_add(ar-gpe, g, cpu);
+
+acpi_update_sci(ar, irq);
+}
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 9e5d30c..5dca8d7 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
 uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
 
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
-- 
1.7.7




[Qemu-devel] [PATCH V6 2/8] acpi:ich9: convert cpu hotplug to hotplug_handler API

2014-10-21 Thread Gu Zheng
Convert notifier based hotplug to hotplug_handler API.

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -drop 'handle' from the comment and subject.

 hw/acpi/ich9.c |   13 ++---
 include/hw/acpi/ich9.h |1 -
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..7585364 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -209,15 +209,6 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 acpi_pm1_evt_power_down(pm-acpi_regs);
 }
 
-static void ich9_cpu_added_req(Notifier *n, void *opaque)
-{
-ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_added_notifier);
-
-assert(pm != NULL);
-AcpiCpuHotplug_add(pm-acpi_regs.gpe, pm-gpe_cpu, CPU(opaque));
-acpi_update_sci(pm-acpi_regs, pm-irq);
-}
-
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
   qemu_irq sci_irq)
 {
@@ -246,8 +237,6 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 
 AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
 pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
-pm-cpu_added_notifier.notify = ich9_cpu_added_req;
-qemu_register_cpu_added_notifier(pm-cpu_added_notifier);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
@@ -304,6 +293,8 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 acpi_memory_plug_cb(pm-acpi_regs, pm-irq, pm-acpi_memory_hotplug,
 dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(pm-acpi_regs, pm-irq, pm-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..fe975e6 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -47,7 +47,6 @@ typedef struct ICH9LPCPMRegs {
 Notifier powerdown_notifier;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
-- 
1.7.7




[Qemu-devel] [PATCH V6 3/8] acpi:piix4: convert cpu hotplug to hotplug_handler API

2014-10-21 Thread Gu Zheng
Convert notifier based hotplug to hotplug_handler API,
and remove the unused AcpiCpuHotplug_add().

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -drop 'handle' from the comment and subject.
v2:
 -remove the unused AcpiCpuHotplug_add().

 hw/acpi/cpu_hotplug.c |   14 ++
 hw/acpi/piix4.c   |   14 ++
 include/hw/acpi/cpu_hotplug.h |2 --
 3 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 06e9c61..b69b16c 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -49,22 +49,12 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-AcpiCpuHotplug_add(ar-gpe, g, cpu);
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
-{
-CPUClass *k = CPU_GET_CLASS(cpu);
-int64_t cpu_id;
-
-*gpe-sts = *gpe-sts | ACPI_CPU_HOTPLUG_STATUS;
-cpu_id = k-get_arch_id(CPU(cpu));
-g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
-g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
-}
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b72b34e..8320b18 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -83,7 +83,6 @@ typedef struct PIIX4PMState {
 uint8_t s4_val;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
@@ -348,6 +347,8 @@ static void piix4_device_plug_cb(HotplugHandler 
*hotplug_dev,
 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
 acpi_pcihp_device_plug_cb(s-ar, s-irq, s-acpi_pci_hotplug, dev,
   errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(s-ar, s-irq, s-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
@@ -544,15 +545,6 @@ static const MemoryRegionOps piix4_gpe_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void piix4_cpu_added_req(Notifier *n, void *opaque)
-{
-PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
-
-assert(s != NULL);
-AcpiCpuHotplug_add(s-ar.gpe, s-gpe_cpu, CPU(opaque));
-acpi_update_sci(s-ar, s-irq);
-}
-
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s)
 {
@@ -565,8 +557,6 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 
 AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
 PIIX4_CPU_HOTPLUG_IO_BASE);
-s-cpu_added_notifier.notify = piix4_cpu_added_req;
-qemu_register_cpu_added_notifier(s-cpu_added_notifier);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 5dca8d7..4657e71 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,8 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V6 4/8] pc: add cpu hotplug handler to PC_MACHINE

2014-10-21 Thread Gu Zheng
Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
cpu hotplug callback via hotplug_handler API.

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -split the check out of acpi_dev block.
v3:
 -deal with start up cpus in a more neat way as Igor suggested.
v2:
 -just rebase.

 hw/i386/pc.c |   28 +++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d045e8b..eff19ef 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1617,11 +1617,36 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_plug(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!dev-hotplugged) {
+goto out;
+}
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   cpu hotplug is not enabled: missing acpi device);
+goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+out:
+error_propagate(errp, local_err);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 pc_dimm_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_plug(hotplug_dev, dev, errp);
 }
 }
 
@@ -1630,7 +1655,8 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState 
*machine,
 {
 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 return HOTPLUG_HANDLER(machine);
 }
 
-- 
1.7.7




[Qemu-devel] [PATCH V6 5/8] pc: Update rtc_cmos in pc_cpu_plug

2014-10-21 Thread Gu Zheng
Update rtc_cmos in pc_cpu_plug() directly, instead of the notifier.

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -move CPU hot-plug notifier cleanup hunk into Patch 6/8.

v4:
 -Make linkrtc property in PCMachine rather than the global
  variables.
 -Split out the removal of unused notifier into separate patch.

 hw/i386/pc.c |   37 -
 hw/i386/pc_piix.c|2 +-
 hw/i386/pc_q35.c |2 +-
 include/hw/i386/pc.h |3 ++-
 4 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index eff19ef..0f10ec8 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -355,30 +355,15 @@ static void pc_cmos_init_late(void *opaque)
 qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
-typedef struct RTCCPUHotplugArg {
-Notifier cpu_added_notifier;
-ISADevice *rtc_state;
-} RTCCPUHotplugArg;
-
-static void rtc_notify_cpu_added(Notifier *notifier, void *data)
-{
-RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
- cpu_added_notifier);
-ISADevice *s = arg-rtc_state;
-
-/* increment the number of CPUs */
-rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
-}
-
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
-  const char *boot_device,
+  const char *boot_device, MachineState *machine,
   ISADevice *floppy, BusState *idebus0, BusState *idebus1,
   ISADevice *s)
 {
 int val, nb, i;
 FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
 static pc_cmos_init_late_arg arg;
-static RTCCPUHotplugArg cpu_hotplug_cb;
+PCMachineState *pc_machine = PC_MACHINE(machine);
 
 /* various important CMOS locations needed by PC/Bochs bios */
 
@@ -417,10 +402,14 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 
 /* set the number of CPU */
 rtc_set_memory(s, 0x5f, smp_cpus - 1);
-/* init CPU hotplug notifier */
-cpu_hotplug_cb.rtc_state = s;
-cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
-qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
+
+object_property_add_link(OBJECT(machine), rtc_state,
+ TYPE_ISA_DEVICE,
+ (Object **)pc_machine-rtc,
+ object_property_allow_set_link,
+ OBJ_PROP_LINK_UNREF_ON_RELEASE, error_abort);
+object_property_set_link(OBJECT(machine), OBJECT(s),
+ rtc_state, error_abort);
 
 if (set_boot_dev(s, boot_device)) {
 exit(1);
@@ -1636,6 +1625,12 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
 hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+if (local_err) {
+goto out;
+}
+
+/* increment the number of CPUs */
+rtc_set_memory(pcms-rtc, 0x5f, rtc_get_memory(pcms-rtc, 0x5f) + 1);
 out:
 error_propagate(errp, local_err);
 }
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 4384633..2ff7e84 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -266,7 +266,7 @@ static void pc_init1(MachineState *machine,
 }
 
 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
- floppy, idebus[0], idebus[1], rtc_state);
+ machine, floppy, idebus[0], idebus[1], rtc_state);
 
 if (pci_enabled  usb_enabled(false)) {
 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 bb0dc8e..7cab8e4 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -270,7 +270,7 @@ static void pc_q35_init(MachineState *machine)
   8, NULL, 0);
 
 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
- floppy, idebus[0], idebus[1], rtc_state);
+ machine, floppy, idebus[0], idebus[1], rtc_state);
 
 /* the rest devices to which pci devfn is automatically assigned */
 pc_vga_init(isa_bus, host_bus);
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 77316d5..7a4bff4 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -33,6 +33,7 @@ struct PCMachineState {
 MemoryRegion hotplug_memory;
 
 HotplugHandler *acpi_dev;
+ISADevice *rtc;
 
 uint64_t max_ram_below_4g;
 };
@@ -210,7 +211,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
   uint32 hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
-  const char *boot_device,
+  const char *boot_device, MachineState *machine,
   ISADevice *floppy, BusState *ide0, BusState *ide1,
   ISADevice *s);
 void

[Qemu-devel] [PATCH V6 6/8] qom/cpu: remove the unused CPU hot-plug notifier

2014-10-21 Thread Gu Zheng
Remove the unused CPU hot-plug notifier.

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -delete the caller of notifier_list_notify() in this patch.

 include/sysemu/sysemu.h |3 ---
 qom/cpu.c   |   10 --
 2 files changed, 0 insertions(+), 13 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..acfe494 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -183,9 +183,6 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict 
*qdict);
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
-/* CPU hotplug */
-void qemu_register_cpu_added_notifier(Notifier *notifier);
-
 /* pcie aer error injection */
 void pcie_aer_inject_error_print(Monitor *mon, const QObject *data);
 int do_pcie_aer_inject_error(Monitor *mon,
diff --git a/qom/cpu.c b/qom/cpu.c
index 0ec3337..79d2228 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -107,15 +107,6 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
 error_setg(errp, Obtaining memory mappings is unsupported on this CPU.);
 }
 
-/* CPU hot-plug notifiers */
-static NotifierList cpu_added_notifiers =
-NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
-
-void qemu_register_cpu_added_notifier(Notifier *notifier)
-{
-notifier_list_add(cpu_added_notifiers, notifier);
-}
-
 void cpu_reset_interrupt(CPUState *cpu, int mask)
 {
 cpu-interrupt_request = ~mask;
@@ -312,7 +303,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
 
 if (dev-hotplugged) {
 cpu_synchronize_post_init(cpu);
-notifier_list_notify(cpu_added_notifiers, dev);
 cpu_resume(cpu);
 }
 }
-- 
1.7.7




[Qemu-devel] [PATCH V6 7/8] cpu-hotplug: rename function for better readability

2014-10-21 Thread Gu Zheng
Rename:
AcpiCpuHotplug_init -- acpi_cpu_hotplug_init
AcpiCpuHotplug_ops -- acpi_cpu_hotplug_ops
for better readability, just cleanup.

Reviewed-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |4 ++--
 hw/acpi/ich9.c|4 ++--
 hw/acpi/piix4.c   |4 ++--
 include/hw/acpi/cpu_hotplug.h |4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index b69b16c..ae48b63 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -55,8 +55,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base)
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
 CPUState *cpu;
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7585364..ea991a3 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -235,8 +235,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 pm-powerdown_notifier.notify = pm_powerdown_req;
 qemu_register_powerdown_notifier(pm-powerdown_notifier);
 
-AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
-pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+  pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 8320b18..8fde808 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -555,8 +555,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 acpi_pcihp_init(s-acpi_pci_hotplug, bus, parent,
 s-use_acpi_pci_hotplug);
 
-AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
-PIIX4_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(parent, OBJECT(s), s-gpe_cpu,
+  PIIX4_CPU_HOTPLUG_IO_BASE);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 4657e71..f6d358d 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base);
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V6 8/8] acpi/cpu-hotplug: introduce helper function to keep bit setting in one place

2014-10-21 Thread Gu Zheng
Introduce helper function acpi_set_cpu_present_bit() to simplify 
acpi_cpu_plug_cb
and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v6:
 -using error_abort instead of local_err, so that we can gain the error report
  before abort (suggested by Igor).
v5:
 -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better readability.

 hw/acpi/cpu_hotplug.c |   22 +-
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index ae48b63..b8ebfad 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,10 +36,9 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
+ Error **errp)
 {
-CPUState *cpu = CPU(dev);
 CPUClass *k = CPU_GET_CLASS(cpu);
 int64_t cpu_id;
 
@@ -49,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+}
+
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+acpi_set_cpu_present_bit(g, CPU(dev), errp);
+if (*errp != NULL) {
+return;
+}
 
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 acpi_update_sci(ar, irq);
 }
 
@@ -61,11 +69,7 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
*owner,
 CPUState *cpu;
 
 CPU_FOREACH(cpu) {
-CPUClass *cc = CPU_GET_CLASS(cpu);
-int64_t id = cc-get_arch_id(cpu);
-
-g_assert((id / 8)  ACPI_GPE_PROC_LEN);
-gpe_cpu-sts[id / 8] |= (1  (id % 8));
+acpi_set_cpu_present_bit(gpe_cpu, cpu, error_abort);
 }
 memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
   gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
-- 
1.7.7




Re: [Qemu-devel] [PATCH V5 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-10-20 Thread Gu Zheng
Hi Igor,
How about this version?

Regards,
Gu
On 10/10/2014 10:15 AM, Gu Zheng wrote:

 Previously we use cpu_added_notifiers to register cpu hotplug notifier 
 callback
 which is not able to pass/handle errors, so we switch it to unified hotplug
 handler API which allows to pass errors and would allow to cancel device_add
 in case of error.
 Thanks very much for Igor's review and suggestion.
 
 ---
 v5:
  -rebase on the latest upstream and fix some comments.
  Patch 4/8:
  -split the check out of acpi_dev block.
  Patch 5/8:
  -move CPU hot-plug notifier cleanup hunk into Patch 6/8.
  Patch 6/8:
  -delete the caller of notifier_list_notify() in this patch.
  Patch 8/8:
  -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better 
 readability.
 
 v4:
  -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
  Patch 1/7:
  -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
   and do cast to CPU inside.
  Patch 5/7:
  -Make rtc_state as a link property in PCMachine rather than the global
   variables.
  -Split out the removal of unused notifier into separate patch.
  -Check the result of plug callback before update rtc_state.
 
 v3:
  -deal with start-up cpus in pc_cpu_plug as Igor suggested.
 
 v2:
  -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
   1/5--1/7
   2/5--2/7
   3/5--3/7
   4/5--4/7
  Patch 1/7:
  -add errp argument to catch error.
  -return error instead of aborting if cpu id is invalid.
  -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
  Patch 3/7:
  -remove unused AcpiCpuHotplug_add directly.
  Patch 5/7:
  -switch the last user of cpu hotplug notifier to hotplug handler API, and
   remove the unused cpu hotplug notify.
  Patch 6/7:
  -split the function rename (just cleanup) into single patch.
  Patch 7/7:
  -introduce help function acpi_set_local_sts to keep the bit setting in
   one place.
 ---
 
 Gu Zheng (8):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug to hotplug_handler API
   acpi:piix4: convert cpu hotplug to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   pc: Update rtc_cmos in pc_cpu_plug
   qom/cpu: remove the unused CPU hot-plug notifier
   cpu-hotplug: rename function for better readability
   acpi/cpu-hotplug: introduce help function to keep bit setting in one
 place
 
  hw/acpi/cpu_hotplug.c |   35 --
  hw/acpi/ich9.c|   17 ++
  hw/acpi/piix4.c   |   18 ++-
  hw/i386/pc.c  |   65 
 +++--
  hw/i386/pc_piix.c |2 +-
  hw/i386/pc_q35.c  |2 +-
  include/hw/acpi/cpu_hotplug.h |7 ++--
  include/hw/acpi/ich9.h|1 -
  include/hw/i386/pc.h  |3 +-
  include/sysemu/sysemu.h   |3 --
  qom/cpu.c |   10 --
  11 files changed, 84 insertions(+), 79 deletions(-)
 





Re: [Qemu-devel] [PATCH V5 8/8] acpi/cpu-hotplug: introduce helper function to keep bit setting in one place

2014-10-20 Thread Gu Zheng
Hi Igor,
On 10/20/2014 11:09 PM, Igor Mammedov wrote:

 On Fri, 10 Oct 2014 10:16:07 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Introduce helper function acpi_set_cpu_present_bit() to simplify 
 acpi_cpu_plug_cb
 and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
 v5:
  -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better 
 readability.

  hw/acpi/cpu_hotplug.c |   23 +++
  1 files changed, 15 insertions(+), 8 deletions(-)

 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
 index ae48b63..8b8d15a 100644
 --- a/hw/acpi/cpu_hotplug.c
 +++ b/hw/acpi/cpu_hotplug.c
 @@ -36,10 +36,9 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
  },
  };
  
 -void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 -  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
 +static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
 + Error **errp)
  {
 -CPUState *cpu = CPU(dev);
  CPUClass *k = CPU_GET_CLASS(cpu);
  int64_t cpu_id;
  
 @@ -49,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
  return;
  }
  
 -ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
  g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 +}
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
 +{
 +acpi_set_cpu_present_bit(g, CPU(dev), errp);
 +if (*errp != NULL) {
 +return;
 +}
 +
 +ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
  acpi_update_sci(ar, irq);
  }
  
 @@ -61,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
 *owner,
  CPUState *cpu;
  
  CPU_FOREACH(cpu) {
 -CPUClass *cc = CPU_GET_CLASS(cpu);
 -int64_t id = cc-get_arch_id(cpu);
 +Error *local_err = NULL;
  
 -g_assert((id / 8)  ACPI_GPE_PROC_LEN);
 -gpe_cpu-sts[id / 8] |= (1  (id % 8));
 +acpi_set_cpu_present_bit(gpe_cpu, cpu, local_err);
 +g_assert(local_err == NULL);
 it would be nice to report error before dying,
 using error_abort instead of local_err will do that for you.

It would be nice. I'll fix it.
Thanks very for your review.

Best regards,
Gu

 
  }
  memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
 
 .
 





Re: [Qemu-devel] [PATCH V5 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-10-16 Thread Gu Zheng
ping...

On 10/10/2014 10:15 AM, Gu Zheng wrote:

 Previously we use cpu_added_notifiers to register cpu hotplug notifier 
 callback
 which is not able to pass/handle errors, so we switch it to unified hotplug
 handler API which allows to pass errors and would allow to cancel device_add
 in case of error.
 Thanks very much for Igor's review and suggestion.
 
 ---
 v5:
  -rebase on the latest upstream and fix some comments.
  Patch 4/8:
  -split the check out of acpi_dev block.
  Patch 5/8:
  -move CPU hot-plug notifier cleanup hunk into Patch 6/8.
  Patch 6/8:
  -delete the caller of notifier_list_notify() in this patch.
  Patch 8/8:
  -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better 
 readability.
 
 v4:
  -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
  Patch 1/7:
  -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
   and do cast to CPU inside.
  Patch 5/7:
  -Make rtc_state as a link property in PCMachine rather than the global
   variables.
  -Split out the removal of unused notifier into separate patch.
  -Check the result of plug callback before update rtc_state.
 
 v3:
  -deal with start-up cpus in pc_cpu_plug as Igor suggested.
 
 v2:
  -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
   1/5--1/7
   2/5--2/7
   3/5--3/7
   4/5--4/7
  Patch 1/7:
  -add errp argument to catch error.
  -return error instead of aborting if cpu id is invalid.
  -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
  Patch 3/7:
  -remove unused AcpiCpuHotplug_add directly.
  Patch 5/7:
  -switch the last user of cpu hotplug notifier to hotplug handler API, and
   remove the unused cpu hotplug notify.
  Patch 6/7:
  -split the function rename (just cleanup) into single patch.
  Patch 7/7:
  -introduce help function acpi_set_local_sts to keep the bit setting in
   one place.
 ---
 
 Gu Zheng (8):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug to hotplug_handler API
   acpi:piix4: convert cpu hotplug to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   pc: Update rtc_cmos in pc_cpu_plug
   qom/cpu: remove the unused CPU hot-plug notifier
   cpu-hotplug: rename function for better readability
   acpi/cpu-hotplug: introduce help function to keep bit setting in one
 place
 
  hw/acpi/cpu_hotplug.c |   35 --
  hw/acpi/ich9.c|   17 ++
  hw/acpi/piix4.c   |   18 ++-
  hw/i386/pc.c  |   65 
 +++--
  hw/i386/pc_piix.c |2 +-
  hw/i386/pc_q35.c  |2 +-
  include/hw/acpi/cpu_hotplug.h |7 ++--
  include/hw/acpi/ich9.h|1 -
  include/hw/i386/pc.h  |3 +-
  include/sysemu/sysemu.h   |3 --
  qom/cpu.c |   10 --
  11 files changed, 84 insertions(+), 79 deletions(-)
 





[Qemu-devel] [PATCH V5 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-10-09 Thread Gu Zheng
Previously we use cpu_added_notifiers to register cpu hotplug notifier callback
which is not able to pass/handle errors, so we switch it to unified hotplug
handler API which allows to pass errors and would allow to cancel device_add
in case of error.
Thanks very much for Igor's review and suggestion.

---
v5:
 -rebase on the latest upstream and fix some comments.
 Patch 4/8:
 -split the check out of acpi_dev block.
 Patch 5/8:
 -move CPU hot-plug notifier cleanup hunk into Patch 6/8.
 Patch 6/8:
 -delete the caller of notifier_list_notify() in this patch.
 Patch 8/8:
 -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better readability.

v4:
 -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
 Patch 1/7:
 -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
  and do cast to CPU inside.
 Patch 5/7:
 -Make rtc_state as a link property in PCMachine rather than the global
  variables.
 -Split out the removal of unused notifier into separate patch.
 -Check the result of plug callback before update rtc_state.

v3:
 -deal with start-up cpus in pc_cpu_plug as Igor suggested.

v2:
 -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
  1/5--1/7
  2/5--2/7
  3/5--3/7
  4/5--4/7
 Patch 1/7:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
 Patch 3/7:
 -remove unused AcpiCpuHotplug_add directly.
 Patch 5/7:
 -switch the last user of cpu hotplug notifier to hotplug handler API, and
  remove the unused cpu hotplug notify.
 Patch 6/7:
 -split the function rename (just cleanup) into single patch.
 Patch 7/7:
 -introduce help function acpi_set_local_sts to keep the bit setting in
  one place.
---

Gu Zheng (8):
  acpi/cpu: add cpu hotplug callback function to match hotplug_handler
API
  acpi:ich9: convert cpu hotplug to hotplug_handler API
  acpi:piix4: convert cpu hotplug to hotplug_handler API
  pc: add cpu hotplug handler to PC_MACHINE
  pc: Update rtc_cmos in pc_cpu_plug
  qom/cpu: remove the unused CPU hot-plug notifier
  cpu-hotplug: rename function for better readability
  acpi/cpu-hotplug: introduce help function to keep bit setting in one
place

 hw/acpi/cpu_hotplug.c |   35 --
 hw/acpi/ich9.c|   17 ++
 hw/acpi/piix4.c   |   18 ++-
 hw/i386/pc.c  |   65 +++--
 hw/i386/pc_piix.c |2 +-
 hw/i386/pc_q35.c  |2 +-
 include/hw/acpi/cpu_hotplug.h |7 ++--
 include/hw/acpi/ich9.h|1 -
 include/hw/i386/pc.h  |3 +-
 include/sysemu/sysemu.h   |3 --
 qom/cpu.c |   10 --
 11 files changed, 84 insertions(+), 79 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH V5 1/8] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-10-09 Thread Gu Zheng
Add cpu hotplug callback function (acpi_cpu_plug_cb) to match hotplug_handler 
API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v4:
 -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
  and do cast to CPU inside.
v2:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.

 hw/acpi/cpu_hotplug.c |   18 ++
 include/hw/acpi/cpu_hotplug.h |3 +++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2ad83a0..06e9c61 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,6 +36,24 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+CPUState *cpu = CPU(dev);
+CPUClass *k = CPU_GET_CLASS(cpu);
+int64_t cpu_id;
+
+cpu_id = k-get_arch_id(cpu);
+if ((cpu_id / 8) = ACPI_GPE_PROC_LEN) {
+error_setg(errp, acpi: invalid cpu id: % PRIi64, cpu_id);
+return;
+}
+
+AcpiCpuHotplug_add(ar-gpe, g, cpu);
+
+acpi_update_sci(ar, irq);
+}
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 9e5d30c..5dca8d7 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
 uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
 
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
-- 
1.7.7




[Qemu-devel] [PATCH V5 2/8] acpi:ich9: convert cpu hotplug to hotplug_handler API

2014-10-09 Thread Gu Zheng
Convert notifier based hotplug to hotplug_handler API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -drop 'handle' from the comment and subject.

 hw/acpi/ich9.c |   13 ++---
 include/hw/acpi/ich9.h |1 -
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..7585364 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -209,15 +209,6 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 acpi_pm1_evt_power_down(pm-acpi_regs);
 }
 
-static void ich9_cpu_added_req(Notifier *n, void *opaque)
-{
-ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_added_notifier);
-
-assert(pm != NULL);
-AcpiCpuHotplug_add(pm-acpi_regs.gpe, pm-gpe_cpu, CPU(opaque));
-acpi_update_sci(pm-acpi_regs, pm-irq);
-}
-
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
   qemu_irq sci_irq)
 {
@@ -246,8 +237,6 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 
 AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
 pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
-pm-cpu_added_notifier.notify = ich9_cpu_added_req;
-qemu_register_cpu_added_notifier(pm-cpu_added_notifier);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
@@ -304,6 +293,8 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 acpi_memory_plug_cb(pm-acpi_regs, pm-irq, pm-acpi_memory_hotplug,
 dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(pm-acpi_regs, pm-irq, pm-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..fe975e6 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -47,7 +47,6 @@ typedef struct ICH9LPCPMRegs {
 Notifier powerdown_notifier;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
-- 
1.7.7




[Qemu-devel] [PATCH V5 3/8] acpi:piix4: convert cpu hotplug to hotplug_handler API

2014-10-09 Thread Gu Zheng
Convert notifier based hotplug to hotplug_handler API,
and remove the unused AcpiCpuHotplug_add().

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -drop 'handle' from the comment and subject.
v2:
 -remove the unused AcpiCpuHotplug_add().

 hw/acpi/cpu_hotplug.c |   14 ++
 hw/acpi/piix4.c   |   14 ++
 include/hw/acpi/cpu_hotplug.h |2 --
 3 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 06e9c61..b69b16c 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -49,22 +49,12 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-AcpiCpuHotplug_add(ar-gpe, g, cpu);
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
-{
-CPUClass *k = CPU_GET_CLASS(cpu);
-int64_t cpu_id;
-
-*gpe-sts = *gpe-sts | ACPI_CPU_HOTPLUG_STATUS;
-cpu_id = k-get_arch_id(CPU(cpu));
-g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
-g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
-}
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b72b34e..8320b18 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -83,7 +83,6 @@ typedef struct PIIX4PMState {
 uint8_t s4_val;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
@@ -348,6 +347,8 @@ static void piix4_device_plug_cb(HotplugHandler 
*hotplug_dev,
 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
 acpi_pcihp_device_plug_cb(s-ar, s-irq, s-acpi_pci_hotplug, dev,
   errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(s-ar, s-irq, s-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
@@ -544,15 +545,6 @@ static const MemoryRegionOps piix4_gpe_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void piix4_cpu_added_req(Notifier *n, void *opaque)
-{
-PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
-
-assert(s != NULL);
-AcpiCpuHotplug_add(s-ar.gpe, s-gpe_cpu, CPU(opaque));
-acpi_update_sci(s-ar, s-irq);
-}
-
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s)
 {
@@ -565,8 +557,6 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 
 AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
 PIIX4_CPU_HOTPLUG_IO_BASE);
-s-cpu_added_notifier.notify = piix4_cpu_added_req;
-qemu_register_cpu_added_notifier(s-cpu_added_notifier);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 5dca8d7..4657e71 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,8 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V5 4/8] pc: add cpu hotplug handler to PC_MACHINE

2014-10-09 Thread Gu Zheng
Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
cpu hotplug callback via hotplug_handler API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -split the check out of acpi_dev block.
v3:
 -deal with start up cpus in a more neat way as Igor suggested.
v2:
 -just rebase.

 hw/i386/pc.c |   28 +++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d045e8b..eff19ef 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1617,11 +1617,36 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_plug(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!dev-hotplugged) {
+goto out;
+}
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   cpu hotplug is not enabled: missing acpi device);
+goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+out:
+error_propagate(errp, local_err);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 pc_dimm_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_plug(hotplug_dev, dev, errp);
 }
 }
 
@@ -1630,7 +1655,8 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState 
*machine,
 {
 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 return HOTPLUG_HANDLER(machine);
 }
 
-- 
1.7.7




[Qemu-devel] [PATCH V5 5/8] pc: Update rtc_cmos in pc_cpu_plug

2014-10-09 Thread Gu Zheng
Update rtc_cmos in pc_cpu_plug() directly, instead of the notifier.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -move CPU hot-plug notifier cleanup hunk into Patch 6/8.

v4:
 -Make linkrtc property in PCMachine rather than the global
  variables.
 -Split out the removal of unused notifier into separate patch.

 hw/i386/pc.c |   37 -
 hw/i386/pc_piix.c|2 +-
 hw/i386/pc_q35.c |2 +-
 include/hw/i386/pc.h |3 ++-
 4 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index eff19ef..0f10ec8 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -355,30 +355,15 @@ static void pc_cmos_init_late(void *opaque)
 qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
-typedef struct RTCCPUHotplugArg {
-Notifier cpu_added_notifier;
-ISADevice *rtc_state;
-} RTCCPUHotplugArg;
-
-static void rtc_notify_cpu_added(Notifier *notifier, void *data)
-{
-RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
- cpu_added_notifier);
-ISADevice *s = arg-rtc_state;
-
-/* increment the number of CPUs */
-rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
-}
-
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
-  const char *boot_device,
+  const char *boot_device, MachineState *machine,
   ISADevice *floppy, BusState *idebus0, BusState *idebus1,
   ISADevice *s)
 {
 int val, nb, i;
 FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
 static pc_cmos_init_late_arg arg;
-static RTCCPUHotplugArg cpu_hotplug_cb;
+PCMachineState *pc_machine = PC_MACHINE(machine);
 
 /* various important CMOS locations needed by PC/Bochs bios */
 
@@ -417,10 +402,14 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 
 /* set the number of CPU */
 rtc_set_memory(s, 0x5f, smp_cpus - 1);
-/* init CPU hotplug notifier */
-cpu_hotplug_cb.rtc_state = s;
-cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
-qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
+
+object_property_add_link(OBJECT(machine), rtc_state,
+ TYPE_ISA_DEVICE,
+ (Object **)pc_machine-rtc,
+ object_property_allow_set_link,
+ OBJ_PROP_LINK_UNREF_ON_RELEASE, error_abort);
+object_property_set_link(OBJECT(machine), OBJECT(s),
+ rtc_state, error_abort);
 
 if (set_boot_dev(s, boot_device)) {
 exit(1);
@@ -1636,6 +1625,12 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
 hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+if (local_err) {
+goto out;
+}
+
+/* increment the number of CPUs */
+rtc_set_memory(pcms-rtc, 0x5f, rtc_get_memory(pcms-rtc, 0x5f) + 1);
 out:
 error_propagate(errp, local_err);
 }
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 4384633..2ff7e84 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -266,7 +266,7 @@ static void pc_init1(MachineState *machine,
 }
 
 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
- floppy, idebus[0], idebus[1], rtc_state);
+ machine, floppy, idebus[0], idebus[1], rtc_state);
 
 if (pci_enabled  usb_enabled(false)) {
 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 bb0dc8e..7cab8e4 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -270,7 +270,7 @@ static void pc_q35_init(MachineState *machine)
   8, NULL, 0);
 
 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
- floppy, idebus[0], idebus[1], rtc_state);
+ machine, floppy, idebus[0], idebus[1], rtc_state);
 
 /* the rest devices to which pci devfn is automatically assigned */
 pc_vga_init(isa_bus, host_bus);
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 77316d5..7a4bff4 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -33,6 +33,7 @@ struct PCMachineState {
 MemoryRegion hotplug_memory;
 
 HotplugHandler *acpi_dev;
+ISADevice *rtc;
 
 uint64_t max_ram_below_4g;
 };
@@ -210,7 +211,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
   uint32 hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
-  const char *boot_device,
+  const char *boot_device, MachineState *machine,
   ISADevice *floppy, BusState *ide0, BusState *ide1,
   ISADevice *s);
 void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus

[Qemu-devel] [PATCH V5 6/8] qom/cpu: remove the unused CPU hot-plug notifier

2014-10-09 Thread Gu Zheng
Remove the unused CPU hot-plug notifier.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -delete the caller of notifier_list_notify() in this patch.

 include/sysemu/sysemu.h |3 ---
 qom/cpu.c   |   10 --
 2 files changed, 0 insertions(+), 13 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..acfe494 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -183,9 +183,6 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict 
*qdict);
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
-/* CPU hotplug */
-void qemu_register_cpu_added_notifier(Notifier *notifier);
-
 /* pcie aer error injection */
 void pcie_aer_inject_error_print(Monitor *mon, const QObject *data);
 int do_pcie_aer_inject_error(Monitor *mon,
diff --git a/qom/cpu.c b/qom/cpu.c
index 0ec3337..79d2228 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -107,15 +107,6 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
 error_setg(errp, Obtaining memory mappings is unsupported on this CPU.);
 }
 
-/* CPU hot-plug notifiers */
-static NotifierList cpu_added_notifiers =
-NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
-
-void qemu_register_cpu_added_notifier(Notifier *notifier)
-{
-notifier_list_add(cpu_added_notifiers, notifier);
-}
-
 void cpu_reset_interrupt(CPUState *cpu, int mask)
 {
 cpu-interrupt_request = ~mask;
@@ -312,7 +303,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
 
 if (dev-hotplugged) {
 cpu_synchronize_post_init(cpu);
-notifier_list_notify(cpu_added_notifiers, dev);
 cpu_resume(cpu);
 }
 }
-- 
1.7.7




[Qemu-devel] [PATCH V5 7/8] cpu-hotplug: rename function for better readability

2014-10-09 Thread Gu Zheng
Rename:
AcpiCpuHotplug_init -- acpi_cpu_hotplug_init
AcpiCpuHotplug_ops -- acpi_cpu_hotplug_ops
for better readability, just cleanup.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |4 ++--
 hw/acpi/ich9.c|4 ++--
 hw/acpi/piix4.c   |4 ++--
 include/hw/acpi/cpu_hotplug.h |4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index b69b16c..ae48b63 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -55,8 +55,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base)
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
 CPUState *cpu;
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7585364..ea991a3 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -235,8 +235,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 pm-powerdown_notifier.notify = pm_powerdown_req;
 qemu_register_powerdown_notifier(pm-powerdown_notifier);
 
-AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
-pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+  pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 8320b18..8fde808 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -555,8 +555,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 acpi_pcihp_init(s-acpi_pci_hotplug, bus, parent,
 s-use_acpi_pci_hotplug);
 
-AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
-PIIX4_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(parent, OBJECT(s), s-gpe_cpu,
+  PIIX4_CPU_HOTPLUG_IO_BASE);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 4657e71..f6d358d 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base);
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V5 8/8] acpi/cpu-hotplug: introduce helper function to keep bit setting in one place

2014-10-09 Thread Gu Zheng
Introduce helper function acpi_set_cpu_present_bit() to simplify 
acpi_cpu_plug_cb
and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
v5:
 -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better readability.

 hw/acpi/cpu_hotplug.c |   23 +++
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index ae48b63..8b8d15a 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,10 +36,9 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
+ Error **errp)
 {
-CPUState *cpu = CPU(dev);
 CPUClass *k = CPU_GET_CLASS(cpu);
 int64_t cpu_id;
 
@@ -49,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+}
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+acpi_set_cpu_present_bit(g, CPU(dev), errp);
+if (*errp != NULL) {
+return;
+}
+
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 acpi_update_sci(ar, irq);
 }
 
@@ -61,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
*owner,
 CPUState *cpu;
 
 CPU_FOREACH(cpu) {
-CPUClass *cc = CPU_GET_CLASS(cpu);
-int64_t id = cc-get_arch_id(cpu);
+Error *local_err = NULL;
 
-g_assert((id / 8)  ACPI_GPE_PROC_LEN);
-gpe_cpu-sts[id / 8] |= (1  (id % 8));
+acpi_set_cpu_present_bit(gpe_cpu, cpu, local_err);
+g_assert(local_err == NULL);
 }
 memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
   gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
-- 
1.7.7




Re: [Qemu-devel] [PATCH V4 5/8] pc: Update rtc_cmos in pc_cpu_plug

2014-10-08 Thread Gu Zheng
On 10/08/2014 08:25 PM, Igor Mammedov wrote:

 On Wed, 8 Oct 2014 09:12:11 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Hi Igor,

 On 10/07/2014 09:01 PM, Igor Mammedov wrote:

 On Mon, 29 Sep 2014 18:52:34 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:

 Update rtc_cmos in pc_cpu_plug directly instead of the notifier.

 v4:
  -Make linkrtc property in PCMachine rather than the global
   variables.
  -Split out the removal of unused notifier into separate patch.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/i386/pc.c |   37 -
  hw/i386/pc_piix.c|2 +-
  hw/i386/pc_q35.c |2 +-
  include/hw/i386/pc.h |3 ++-
  qom/cpu.c|1 -
  5 files changed, 20 insertions(+), 25 deletions(-)

 diff --git a/hw/i386/pc.c b/hw/i386/pc.c
 index dcb9332..301e704 100644
 --- a/hw/i386/pc.c
 +++ b/hw/i386/pc.c
 @@ -355,30 +355,15 @@ static void pc_cmos_init_late(void *opaque)
  qemu_unregister_reset(pc_cmos_init_late, opaque);
  }
  
 -typedef struct RTCCPUHotplugArg {
 -Notifier cpu_added_notifier;
 -ISADevice *rtc_state;
 -} RTCCPUHotplugArg;
 -
 -static void rtc_notify_cpu_added(Notifier *notifier, void *data)
 -{
 -RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
 - cpu_added_notifier);
 -ISADevice *s = arg-rtc_state;
 -
 -/* increment the number of CPUs */
 -rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
 -}
 -
  void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
 -  const char *boot_device,
 +  const char *boot_device, MachineState *machine,
ISADevice *floppy, BusState *idebus0, BusState *idebus1,
ISADevice *s)
  {
  int val, nb, i;
  FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
  static pc_cmos_init_late_arg arg;
 -static RTCCPUHotplugArg cpu_hotplug_cb;
 +PCMachineState *pc_machine = PC_MACHINE(machine);
  
  /* various important CMOS locations needed by PC/Bochs bios */
  
 @@ -417,10 +402,14 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
 above_4g_mem_size,
  
  /* set the number of CPU */
  rtc_set_memory(s, 0x5f, smp_cpus - 1);
 -/* init CPU hotplug notifier */
 -cpu_hotplug_cb.rtc_state = s;
 -cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
 -qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
 +
 +object_property_add_link(OBJECT(machine), rtc_state,
 + TYPE_ISA_DEVICE,
 + (Object **)pc_machine-rtc,
 + object_property_allow_set_link,
 + OBJ_PROP_LINK_UNREF_ON_RELEASE, 
 error_abort);
 +object_property_set_link(OBJECT(machine), OBJECT(s),
 + rtc_state, error_abort);
  
  if (set_boot_dev(s, boot_device)) {
  exit(1);
 @@ -1633,6 +1622,12 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
  
  hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
  hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
 +if (local_err) {
 +goto out;
 +}
 +
 +/* increment the number of CPUs */
 +rtc_set_memory(pcms-rtc, 0x5f, rtc_get_memory(pcms-rtc, 0x5f) + 1);
  out:
  error_propagate(errp, local_err);
  }
 diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
 index 103d756..2c8d4dc 100644
 --- a/hw/i386/pc_piix.c
 +++ b/hw/i386/pc_piix.c
 @@ -266,7 +266,7 @@ static void pc_init1(MachineState *machine,
  }
  
  pc_cmos_init(below_4g_mem_size, above_4g_mem_size, 
 machine-boot_order,
 - floppy, idebus[0], idebus[1], rtc_state);
 + machine, floppy, idebus[0], idebus[1], rtc_state);
  
  if (pci_enabled  usb_enabled(false)) {
  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 d4a907c..94ba98d 100644
 --- a/hw/i386/pc_q35.c
 +++ b/hw/i386/pc_q35.c
 @@ -266,7 +266,7 @@ static void pc_q35_init(MachineState *machine)
8, NULL, 0);
  
  pc_cmos_init(below_4g_mem_size, above_4g_mem_size, 
 machine-boot_order,
 - floppy, idebus[0], idebus[1], rtc_state);
 + machine, floppy, idebus[0], idebus[1], rtc_state);
  
  /* the rest devices to which pci devfn is automatically assigned */
  pc_vga_init(isa_bus, host_bus);
 diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
 index 77316d5..7a4bff4 100644
 --- a/include/hw/i386/pc.h
 +++ b/include/hw/i386/pc.h
 @@ -33,6 +33,7 @@ struct PCMachineState {
  MemoryRegion hotplug_memory;
  
  HotplugHandler *acpi_dev;
 +ISADevice *rtc;
  
  uint64_t max_ram_below_4g;
  };
 @@ -210,7 +211,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq 
 *gsi,
uint32 hpet_irqs);
  void pc_init_ne2k_isa(ISABus *bus

Re: [Qemu-devel] [PATCH V4 5/8] pc: Update rtc_cmos in pc_cpu_plug

2014-10-07 Thread Gu Zheng
Hi Igor,

On 10/07/2014 09:01 PM, Igor Mammedov wrote:

 On Mon, 29 Sep 2014 18:52:34 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Update rtc_cmos in pc_cpu_plug directly instead of the notifier.

 v4:
  -Make linkrtc property in PCMachine rather than the global
   variables.
  -Split out the removal of unused notifier into separate patch.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/i386/pc.c |   37 -
  hw/i386/pc_piix.c|2 +-
  hw/i386/pc_q35.c |2 +-
  include/hw/i386/pc.h |3 ++-
  qom/cpu.c|1 -
  5 files changed, 20 insertions(+), 25 deletions(-)

 diff --git a/hw/i386/pc.c b/hw/i386/pc.c
 index dcb9332..301e704 100644
 --- a/hw/i386/pc.c
 +++ b/hw/i386/pc.c
 @@ -355,30 +355,15 @@ static void pc_cmos_init_late(void *opaque)
  qemu_unregister_reset(pc_cmos_init_late, opaque);
  }
  
 -typedef struct RTCCPUHotplugArg {
 -Notifier cpu_added_notifier;
 -ISADevice *rtc_state;
 -} RTCCPUHotplugArg;
 -
 -static void rtc_notify_cpu_added(Notifier *notifier, void *data)
 -{
 -RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
 - cpu_added_notifier);
 -ISADevice *s = arg-rtc_state;
 -
 -/* increment the number of CPUs */
 -rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
 -}
 -
  void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
 -  const char *boot_device,
 +  const char *boot_device, MachineState *machine,
ISADevice *floppy, BusState *idebus0, BusState *idebus1,
ISADevice *s)
  {
  int val, nb, i;
  FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
  static pc_cmos_init_late_arg arg;
 -static RTCCPUHotplugArg cpu_hotplug_cb;
 +PCMachineState *pc_machine = PC_MACHINE(machine);
  
  /* various important CMOS locations needed by PC/Bochs bios */
  
 @@ -417,10 +402,14 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
 above_4g_mem_size,
  
  /* set the number of CPU */
  rtc_set_memory(s, 0x5f, smp_cpus - 1);
 -/* init CPU hotplug notifier */
 -cpu_hotplug_cb.rtc_state = s;
 -cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
 -qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
 +
 +object_property_add_link(OBJECT(machine), rtc_state,
 + TYPE_ISA_DEVICE,
 + (Object **)pc_machine-rtc,
 + object_property_allow_set_link,
 + OBJ_PROP_LINK_UNREF_ON_RELEASE, error_abort);
 +object_property_set_link(OBJECT(machine), OBJECT(s),
 + rtc_state, error_abort);
  
  if (set_boot_dev(s, boot_device)) {
  exit(1);
 @@ -1633,6 +1622,12 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
  
  hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
  hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
 +if (local_err) {
 +goto out;
 +}
 +
 +/* increment the number of CPUs */
 +rtc_set_memory(pcms-rtc, 0x5f, rtc_get_memory(pcms-rtc, 0x5f) + 1);
  out:
  error_propagate(errp, local_err);
  }
 diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
 index 103d756..2c8d4dc 100644
 --- a/hw/i386/pc_piix.c
 +++ b/hw/i386/pc_piix.c
 @@ -266,7 +266,7 @@ static void pc_init1(MachineState *machine,
  }
  
  pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
 - floppy, idebus[0], idebus[1], rtc_state);
 + machine, floppy, idebus[0], idebus[1], rtc_state);
  
  if (pci_enabled  usb_enabled(false)) {
  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 d4a907c..94ba98d 100644
 --- a/hw/i386/pc_q35.c
 +++ b/hw/i386/pc_q35.c
 @@ -266,7 +266,7 @@ static void pc_q35_init(MachineState *machine)
8, NULL, 0);
  
  pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
 - floppy, idebus[0], idebus[1], rtc_state);
 + machine, floppy, idebus[0], idebus[1], rtc_state);
  
  /* the rest devices to which pci devfn is automatically assigned */
  pc_vga_init(isa_bus, host_bus);
 diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
 index 77316d5..7a4bff4 100644
 --- a/include/hw/i386/pc.h
 +++ b/include/hw/i386/pc.h
 @@ -33,6 +33,7 @@ struct PCMachineState {
  MemoryRegion hotplug_memory;
  
  HotplugHandler *acpi_dev;
 +ISADevice *rtc;
  
  uint64_t max_ram_below_4g;
  };
 @@ -210,7 +211,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
uint32 hpet_irqs);
  void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
  void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
 -  const char *boot_device

Re: [Qemu-devel] [PATCH V3 7/7] acpi/cpu-hotplug: introduce help function to keep bit setting in one place

2014-09-29 Thread Gu Zheng
Hi Igor,
On 09/26/2014 09:37 PM, Igor Mammedov wrote:

 On Wed, 17 Sep 2014 09:24:03 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Introduce help function acpi_set_local_sts() to simplify acpi_cpu_plug_cb
 and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/acpi/cpu_hotplug.c |   22 +++---
  1 files changed, 15 insertions(+), 7 deletions(-)

 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
 index 7629686..d42c961 100644
 --- a/hw/acpi/cpu_hotplug.c
 +++ b/hw/acpi/cpu_hotplug.c
 @@ -36,8 +36,8 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
  },
  };
  
 -void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 -  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
 +static void acpi_set_local_sts(AcpiCpuHotplug *g, CPUState *cpu,
 +   Error **errp)
  {
  CPUClass *k = CPU_GET_CLASS(cpu);
  int64_t cpu_id;
 @@ -48,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
  return;
  }
  
 -ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
  g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 +}
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
 +{
 +acpi_set_local_sts(g, cpu, errp);
 +if (*errp != NULL) {
 +return;
 +}
 +
 
 +ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 ^^^ shouldn't be set for coldplugged CPUs along with IRQ below
 
  acpi_update_sci(ar, irq);
  }
  
 @@ -60,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
 *owner,
  CPUState *cpu;
  
  CPU_FOREACH(cpu) {
 -CPUClass *cc = CPU_GET_CLASS(cpu);
 -int64_t id = cc-get_arch_id(cpu);
 +Error *local_err = NULL;
  
 -g_assert((id / 8)  ACPI_GPE_PROC_LEN);
 -gpe_cpu-sts[id / 8] |= (1  (id % 8));
 +acpi_set_local_sts(gpe_cpu, cpu, local_err);
 +g_assert(local_err == NULL);
 Wouldn't acpi_cpu_plug_cb() do everything this FOREACH does?
 I've suggest to drop CPU_FOREACH() altogether.

I got your meaning: Make acpi_cpu_plug_cb serve all CPUs (both startup and 
hotpluged)
, and only triggers sci irq for hotpluged ones, so that we can drop the 
duplicated
operations in acpi_cpu_hotplug_init.
But one problem is that pcms-acpi_dev was registered after startup CPUs set 
realized, so
acpi_cpu_plug_cb can not serve startup CPUs.
I tried to switch the order, but it failed, because there are some internal 
dependences.
Now, I'm trying to split the startup CPUs init into two steps (init and 
realize), and
register pcms-acpi_dev between the two steps.
What's your opinion?

Thanks,
Gu

 
  }
  memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
 
 .
 





Re: [Qemu-devel] [PATCH V3 7/7] acpi/cpu-hotplug: introduce help function to keep bit setting in one place

2014-09-29 Thread Gu Zheng
On 09/29/2014 05:47 PM, Igor Mammedov wrote:

 On Mon, 29 Sep 2014 17:22:08 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Hi Igor,
 On 09/26/2014 09:37 PM, Igor Mammedov wrote:

 On Wed, 17 Sep 2014 09:24:03 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:

 Introduce help function acpi_set_local_sts() to simplify
 acpi_cpu_plug_cb and acpi_cpu_hotplug_init, so that we can keep
 bit setting in one place.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/acpi/cpu_hotplug.c |   22 +++---
  1 files changed, 15 insertions(+), 7 deletions(-)

 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
 index 7629686..d42c961 100644
 --- a/hw/acpi/cpu_hotplug.c
 +++ b/hw/acpi/cpu_hotplug.c
 @@ -36,8 +36,8 @@ static const MemoryRegionOps AcpiCpuHotplug_ops
 = { },
  };
  
 -void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 -  AcpiCpuHotplug *g, CPUState *cpu, Error
 **errp) +static void acpi_set_local_sts(AcpiCpuHotplug *g,
 CPUState *cpu,
 +   Error **errp)
  {
  CPUClass *k = CPU_GET_CLASS(cpu);
  int64_t cpu_id;
 @@ -48,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq
 irq, return;
  }
  
 -ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
  g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 +}
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, CPUState *cpu, Error
 **errp) +{
 +acpi_set_local_sts(g, cpu, errp);
 +if (*errp != NULL) {
 +return;
 +}
 +

 +ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 ^^^ shouldn't be set for coldplugged CPUs along with IRQ below

  acpi_update_sci(ar, irq);
  }
  
 @@ -60,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion
 *parent, Object *owner, CPUState *cpu;
  
  CPU_FOREACH(cpu) {
 -CPUClass *cc = CPU_GET_CLASS(cpu);
 -int64_t id = cc-get_arch_id(cpu);
 +Error *local_err = NULL;
  
 -g_assert((id / 8)  ACPI_GPE_PROC_LEN);
 -gpe_cpu-sts[id / 8] |= (1  (id % 8));
 +acpi_set_local_sts(gpe_cpu, cpu, local_err);
 +g_assert(local_err == NULL);
 Wouldn't acpi_cpu_plug_cb() do everything this FOREACH does?
 I've suggest to drop CPU_FOREACH() altogether.

 I got your meaning: Make acpi_cpu_plug_cb serve all CPUs (both
 startup and hotpluged) , and only triggers sci irq for hotpluged
 ones, so that we can drop the duplicated operations in
 acpi_cpu_hotplug_init. But one problem is that pcms-acpi_dev was
 registered after startup CPUs set realized, so acpi_cpu_plug_cb can
 not serve startup CPUs. I tried to switch the order, but it failed,
 because there are some internal dependences. Now, I'm trying to split
 the startup CPUs init into two steps (init and realize), and register
 pcms-acpi_dev between the two steps. What's your opinion?
 Could you point out what dependecies are there?

E.g.
Allocation smi_irq for PIIX4PMState dependents on the valid *first_cpu*.

smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
/* TODO: Populate SPD eeprom data.  */
smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
  gsi[9], *smi_irq,
  kvm_enabled(), fw_cfg, piix4_pm);

Thanks,
Gu

 

 Thanks,
 Gu


  }
  memory_region_init_io(gpe_cpu-io, owner,
 AcpiCpuHotplug_ops, gpe_cpu, acpi-cpu-hotplug,
 ACPI_GPE_PROC_LEN);

 .



 
 .
 





[Qemu-devel] [PATCH V4 5/8] pc: Update rtc_cmos in pc_cpu_plug

2014-09-29 Thread Gu Zheng
Update rtc_cmos in pc_cpu_plug directly instead of the notifier.

v4:
 -Make linkrtc property in PCMachine rather than the global
  variables.
 -Split out the removal of unused notifier into separate patch.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c |   37 -
 hw/i386/pc_piix.c|2 +-
 hw/i386/pc_q35.c |2 +-
 include/hw/i386/pc.h |3 ++-
 qom/cpu.c|1 -
 5 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index dcb9332..301e704 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -355,30 +355,15 @@ static void pc_cmos_init_late(void *opaque)
 qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
-typedef struct RTCCPUHotplugArg {
-Notifier cpu_added_notifier;
-ISADevice *rtc_state;
-} RTCCPUHotplugArg;
-
-static void rtc_notify_cpu_added(Notifier *notifier, void *data)
-{
-RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
- cpu_added_notifier);
-ISADevice *s = arg-rtc_state;
-
-/* increment the number of CPUs */
-rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
-}
-
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
-  const char *boot_device,
+  const char *boot_device, MachineState *machine,
   ISADevice *floppy, BusState *idebus0, BusState *idebus1,
   ISADevice *s)
 {
 int val, nb, i;
 FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
 static pc_cmos_init_late_arg arg;
-static RTCCPUHotplugArg cpu_hotplug_cb;
+PCMachineState *pc_machine = PC_MACHINE(machine);
 
 /* various important CMOS locations needed by PC/Bochs bios */
 
@@ -417,10 +402,14 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 
 /* set the number of CPU */
 rtc_set_memory(s, 0x5f, smp_cpus - 1);
-/* init CPU hotplug notifier */
-cpu_hotplug_cb.rtc_state = s;
-cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
-qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
+
+object_property_add_link(OBJECT(machine), rtc_state,
+ TYPE_ISA_DEVICE,
+ (Object **)pc_machine-rtc,
+ object_property_allow_set_link,
+ OBJ_PROP_LINK_UNREF_ON_RELEASE, error_abort);
+object_property_set_link(OBJECT(machine), OBJECT(s),
+ rtc_state, error_abort);
 
 if (set_boot_dev(s, boot_device)) {
 exit(1);
@@ -1633,6 +1622,12 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
 hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+if (local_err) {
+goto out;
+}
+
+/* increment the number of CPUs */
+rtc_set_memory(pcms-rtc, 0x5f, rtc_get_memory(pcms-rtc, 0x5f) + 1);
 out:
 error_propagate(errp, local_err);
 }
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 103d756..2c8d4dc 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -266,7 +266,7 @@ static void pc_init1(MachineState *machine,
 }
 
 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
- floppy, idebus[0], idebus[1], rtc_state);
+ machine, floppy, idebus[0], idebus[1], rtc_state);
 
 if (pci_enabled  usb_enabled(false)) {
 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 d4a907c..94ba98d 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -266,7 +266,7 @@ static void pc_q35_init(MachineState *machine)
   8, NULL, 0);
 
 pc_cmos_init(below_4g_mem_size, above_4g_mem_size, machine-boot_order,
- floppy, idebus[0], idebus[1], rtc_state);
+ machine, floppy, idebus[0], idebus[1], rtc_state);
 
 /* the rest devices to which pci devfn is automatically assigned */
 pc_vga_init(isa_bus, host_bus);
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 77316d5..7a4bff4 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -33,6 +33,7 @@ struct PCMachineState {
 MemoryRegion hotplug_memory;
 
 HotplugHandler *acpi_dev;
+ISADevice *rtc;
 
 uint64_t max_ram_below_4g;
 };
@@ -210,7 +211,7 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
   uint32 hpet_irqs);
 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd);
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
-  const char *boot_device,
+  const char *boot_device, MachineState *machine,
   ISADevice *floppy, BusState *ide0, BusState *ide1,
   ISADevice *s);
 void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus);
diff --git a/qom/cpu.c b/qom/cpu.c
index

[Qemu-devel] [PATCH V4 1/8] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-09-29 Thread Gu Zheng
v4:
 -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
  and do cast to CPU inside.

v2:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   18 ++
 include/hw/acpi/cpu_hotplug.h |3 +++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2ad83a0..06e9c61 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,6 +36,24 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+CPUState *cpu = CPU(dev);
+CPUClass *k = CPU_GET_CLASS(cpu);
+int64_t cpu_id;
+
+cpu_id = k-get_arch_id(cpu);
+if ((cpu_id / 8) = ACPI_GPE_PROC_LEN) {
+error_setg(errp, acpi: invalid cpu id: % PRIi64, cpu_id);
+return;
+}
+
+AcpiCpuHotplug_add(ar-gpe, g, cpu);
+
+acpi_update_sci(ar, irq);
+}
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 9e5d30c..5dca8d7 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
 uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
 
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
-- 
1.7.7




[Qemu-devel] [PATCH V4 0/8] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-09-29 Thread Gu Zheng
Previously we use cpu_added_notifiers to register cpu hotplug notifier callback
which is not able to pass/handle errors, so we switch it to unified hotplug
handler API which allows to pass errors and would allow to cancel device_add
in case of error.
Thanks very much for Igor's review and suggestion.

v4:
 -split removal of CPU hotplug notifier into separate patch (Patch 6/8).
 Patch 1/7:
 -convert CPUState *cpu to DeviceState *dev like it's done for other handlers
  and do cast to CPU inside.
 Patch 5/7:
 -Make rtc_state as a link property in PCMachine rather than the global
  variables.
 -Split out the removal of unused notifier into separate patch.
 -Check the result of plug callback before update rtc_state.

v3:
 -deal with start-up cpus in pc_cpu_plug as Igor suggested.

v2:
 -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
  1/5--1/7
  2/5--2/7
  3/5--3/7
  4/5--4/7
 Patch 1/7:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
 Patch 3/7:
 -remove unused AcpiCpuHotplug_add directly.
 Patch 5/7:
 -switch the last user of cpu hotplug notifier to hotplug handler API, and
  remove the unused cpu hotplug notify.
 Patch 6/7:
 -split the function rename (just cleanup) into single patch.
 Patch 7/7:
 -introduce help function acpi_set_local_sts to keep the bit setting in
  one place.

Gu Zheng (8):
  acpi/cpu: add cpu hotplug callback function to match hotplug_handler
API
  acpi:ich9: convert cpu hotplug handle to hotplug_handler API
  acpi:piix4: convert cpu hotplug handle to hotplug_handler API
  pc: add cpu hotplug handler to PC_MACHINE
  pc: Update rtc_cmos in pc_cpu_plug
  qom/cpu: remove the unused CPU hot-plug notifier
  cpu-hotplug: rename function for better readability
  acpi/cpu-hotplug: introduce help function to keep bit setting in one
place

 hw/acpi/cpu_hotplug.c |   35 --
 hw/acpi/ich9.c|   17 ++
 hw/acpi/piix4.c   |   18 ++-
 hw/i386/pc.c  |   63 ++--
 hw/i386/pc_piix.c |2 +-
 hw/i386/pc_q35.c  |2 +-
 include/hw/acpi/cpu_hotplug.h |7 ++--
 include/hw/acpi/ich9.h|1 -
 include/hw/i386/pc.h  |3 +-
 include/sysemu/sysemu.h   |3 --
 qom/cpu.c |   10 --
 11 files changed, 82 insertions(+), 79 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH V4 2/8] acpi:ich9: convert cpu hotplug handle to hotplug_handler API

2014-09-29 Thread Gu Zheng
Convert notifier based hotplug handle to hotplug_handler API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/ich9.c |   13 ++---
 include/hw/acpi/ich9.h |1 -
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..7585364 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -209,15 +209,6 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 acpi_pm1_evt_power_down(pm-acpi_regs);
 }
 
-static void ich9_cpu_added_req(Notifier *n, void *opaque)
-{
-ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_added_notifier);
-
-assert(pm != NULL);
-AcpiCpuHotplug_add(pm-acpi_regs.gpe, pm-gpe_cpu, CPU(opaque));
-acpi_update_sci(pm-acpi_regs, pm-irq);
-}
-
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
   qemu_irq sci_irq)
 {
@@ -246,8 +237,6 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 
 AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
 pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
-pm-cpu_added_notifier.notify = ich9_cpu_added_req;
-qemu_register_cpu_added_notifier(pm-cpu_added_notifier);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
@@ -304,6 +293,8 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 acpi_memory_plug_cb(pm-acpi_regs, pm-irq, pm-acpi_memory_hotplug,
 dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(pm-acpi_regs, pm-irq, pm-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..fe975e6 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -47,7 +47,6 @@ typedef struct ICH9LPCPMRegs {
 Notifier powerdown_notifier;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
-- 
1.7.7




[Qemu-devel] [PATCH V4 3/8] acpi:piix4: convert cpu hotplug handle to hotplug_handler API

2014-09-29 Thread Gu Zheng
Convert notifier based hotplug handle to hotplug_handler API,
and remove the unused AcpiCpuHotplug_add().

v2:
-remove the unused AcpiCpuHotplug_add().

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   14 ++
 hw/acpi/piix4.c   |   14 ++
 include/hw/acpi/cpu_hotplug.h |2 --
 3 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 06e9c61..b69b16c 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -49,22 +49,12 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-AcpiCpuHotplug_add(ar-gpe, g, cpu);
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
-{
-CPUClass *k = CPU_GET_CLASS(cpu);
-int64_t cpu_id;
-
-*gpe-sts = *gpe-sts | ACPI_CPU_HOTPLUG_STATUS;
-cpu_id = k-get_arch_id(CPU(cpu));
-g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
-g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
-}
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b72b34e..8320b18 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -83,7 +83,6 @@ typedef struct PIIX4PMState {
 uint8_t s4_val;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
@@ -348,6 +347,8 @@ static void piix4_device_plug_cb(HotplugHandler 
*hotplug_dev,
 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
 acpi_pcihp_device_plug_cb(s-ar, s-irq, s-acpi_pci_hotplug, dev,
   errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(s-ar, s-irq, s-gpe_cpu, dev, errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
@@ -544,15 +545,6 @@ static const MemoryRegionOps piix4_gpe_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void piix4_cpu_added_req(Notifier *n, void *opaque)
-{
-PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
-
-assert(s != NULL);
-AcpiCpuHotplug_add(s-ar.gpe, s-gpe_cpu, CPU(opaque));
-acpi_update_sci(s-ar, s-irq);
-}
-
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s)
 {
@@ -565,8 +557,6 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 
 AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
 PIIX4_CPU_HOTPLUG_IO_BASE);
-s-cpu_added_notifier.notify = piix4_cpu_added_req;
-qemu_register_cpu_added_notifier(s-cpu_added_notifier);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 5dca8d7..4657e71 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,8 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V4 8/8] acpi/cpu-hotplug: introduce help function to keep bit setting in one place

2014-09-29 Thread Gu Zheng
Introduce help function acpi_set_local_sts() to simplify acpi_cpu_plug_cb
and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   23 +++
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index ae48b63..8ff8c4d 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,10 +36,9 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+static void acpi_set_local_sts(AcpiCpuHotplug *g, CPUState *cpu,
+   Error **errp)
 {
-CPUState *cpu = CPU(dev);
 CPUClass *k = CPU_GET_CLASS(cpu);
 int64_t cpu_id;
 
@@ -49,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+}
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+acpi_set_local_sts(g, CPU(dev), errp);
+if (*errp != NULL) {
+return;
+}
+
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 acpi_update_sci(ar, irq);
 }
 
@@ -61,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
*owner,
 CPUState *cpu;
 
 CPU_FOREACH(cpu) {
-CPUClass *cc = CPU_GET_CLASS(cpu);
-int64_t id = cc-get_arch_id(cpu);
+Error *local_err = NULL;
 
-g_assert((id / 8)  ACPI_GPE_PROC_LEN);
-gpe_cpu-sts[id / 8] |= (1  (id % 8));
+acpi_set_local_sts(gpe_cpu, cpu, local_err);
+g_assert(local_err == NULL);
 }
 memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
   gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
-- 
1.7.7




[Qemu-devel] [PATCH V4 7/8] cpu-hotplug: rename function for better readability

2014-09-29 Thread Gu Zheng
Rename:
AcpiCpuHotplug_init -- acpi_cpu_hotplug_init
AcpiCpuHotplug_ops -- acpi_cpu_hotplug_ops
for better readability, just cleanup.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |4 ++--
 hw/acpi/ich9.c|4 ++--
 hw/acpi/piix4.c   |4 ++--
 include/hw/acpi/cpu_hotplug.h |4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index b69b16c..ae48b63 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -55,8 +55,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base)
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
 CPUState *cpu;
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7585364..ea991a3 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -235,8 +235,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 pm-powerdown_notifier.notify = pm_powerdown_req;
 qemu_register_powerdown_notifier(pm-powerdown_notifier);
 
-AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
-pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+  pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 8320b18..8fde808 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -555,8 +555,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 acpi_pcihp_init(s-acpi_pci_hotplug, bus, parent,
 s-use_acpi_pci_hotplug);
 
-AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
-PIIX4_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(parent, OBJECT(s), s-gpe_cpu,
+  PIIX4_CPU_HOTPLUG_IO_BASE);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 4657e71..f6d358d 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base);
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V4 6/8] qom/cpu: remove the unused CPU hot-plug notifier

2014-09-29 Thread Gu Zheng
Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 include/sysemu/sysemu.h |3 ---
 qom/cpu.c   |9 -
 2 files changed, 0 insertions(+), 12 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..acfe494 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -183,9 +183,6 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict 
*qdict);
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
-/* CPU hotplug */
-void qemu_register_cpu_added_notifier(Notifier *notifier);
-
 /* pcie aer error injection */
 void pcie_aer_inject_error_print(Monitor *mon, const QObject *data);
 int do_pcie_aer_inject_error(Monitor *mon,
diff --git a/qom/cpu.c b/qom/cpu.c
index 09c7e41..83c3559 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -107,15 +107,6 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
 error_setg(errp, Obtaining memory mappings is unsupported on this CPU.);
 }
 
-/* CPU hot-plug notifiers */
-static NotifierList cpu_added_notifiers =
-NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
-
-void qemu_register_cpu_added_notifier(Notifier *notifier)
-{
-notifier_list_add(cpu_added_notifiers, notifier);
-}
-
 void cpu_reset_interrupt(CPUState *cpu, int mask)
 {
 cpu-interrupt_request = ~mask;
-- 
1.7.7




[Qemu-devel] [PATCH V4 4/8] pc: add cpu hotplug handler to PC_MACHINE

2014-09-29 Thread Gu Zheng
Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
cpu hotplug callback via hotplug_handler API.

v3:
 -deal with start up cpus in a more neat way as Igor suggested.
v2:
 -just rebase.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c |   26 +-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 82a7daa..dcb9332 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1616,11 +1616,34 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_plug(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+if (dev-hotplugged) {
+error_setg(local_err,
+   cpu hotplug is not enabled: missing acpi device);
+}
+goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+out:
+error_propagate(errp, local_err);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 pc_dimm_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_plug(hotplug_dev, dev, errp);
 }
 }
 
@@ -1629,7 +1652,8 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState 
*machine,
 {
 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 return HOTPLUG_HANDLER(machine);
 }
 
-- 
1.7.7




Re: [Qemu-devel] [PATCH V3 0/7] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-09-23 Thread Gu Zheng
ping...

On 09/17/2014 09:23 AM, Gu Zheng wrote:

 Previously we use cpu_added_notifiers to register cpu hotplug notifier 
 callback
 which is not able to pass/handle errors, so we switch it to unified hotplug
 handler API which allows to pass errors and would allow to cancel device_add
 in case of error.
 Thanks very much for Igor's review and suggestion.
 
 v3:
  -deal with start-up cpus in pc_cpu_plug as Igor suggested.
 
 v2:
  -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
   1/5--1/7
   2/5--2/7
   3/5--3/7
   4/5--4/7
  Patch 1/7:
  -add errp argument to catch error.
  -return error instead of aborting if cpu id is invalid.
  -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
  Patch 3/7:
  -remove unused AcpiCpuHotplug_add directly.
  Patch 5/7:
  -switch the last user of cpu hotplug notifier to hotplug handler API, and
   remove the unused cpu hotplug notify.
  Patch 6/7:
  -split the function rename (just cleanup) into single patch.
  Patch 7/7:
  -introduce help function acpi_set_local_sts to keep the bit setting in
   one place.
 
 Gu Zheng (7):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug handle to hotplug_handler API
   acpi:piix4: convert cpu hotplug handle to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   pc: Update rtc_cmos in pc_cpu_plug
   cpu-hotplug: rename function for better readability
   acpi/cpu-hotplug: introduce help function to keep bit setting in one
 place
 
  hw/acpi/cpu_hotplug.c |   35 
  hw/acpi/ich9.c|   18 --
  hw/acpi/piix4.c   |   18 +++---
  hw/i386/pc.c  |   51 
 +
  include/hw/acpi/cpu_hotplug.h |7 +++--
  include/hw/acpi/ich9.h|1 -
  include/sysemu/sysemu.h   |3 --
  qom/cpu.c |   10 
  8 files changed, 69 insertions(+), 74 deletions(-)
 





Re: [Qemu-devel] [PATCH V3 0/7] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-09-18 Thread Gu Zheng
Hi Igor,
The issues you mentioned in previous comments are fixed in this version.
Could please help to review it?

Thanks,
Gu

On 09/17/2014 09:23 AM, Gu Zheng wrote:

 Previously we use cpu_added_notifiers to register cpu hotplug notifier 
 callback
 which is not able to pass/handle errors, so we switch it to unified hotplug
 handler API which allows to pass errors and would allow to cancel device_add
 in case of error.
 Thanks very much for Igor's review and suggestion.
 
 v3:
  -deal with start-up cpus in pc_cpu_plug as Igor suggested.
 
 v2:
  -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
   1/5--1/7
   2/5--2/7
   3/5--3/7
   4/5--4/7
  Patch 1/7:
  -add errp argument to catch error.
  -return error instead of aborting if cpu id is invalid.
  -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
  Patch 3/7:
  -remove unused AcpiCpuHotplug_add directly.
  Patch 5/7:
  -switch the last user of cpu hotplug notifier to hotplug handler API, and
   remove the unused cpu hotplug notify.
  Patch 6/7:
  -split the function rename (just cleanup) into single patch.
  Patch 7/7:
  -introduce help function acpi_set_local_sts to keep the bit setting in
   one place.
 
 Gu Zheng (7):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug handle to hotplug_handler API
   acpi:piix4: convert cpu hotplug handle to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   pc: Update rtc_cmos in pc_cpu_plug
   cpu-hotplug: rename function for better readability
   acpi/cpu-hotplug: introduce help function to keep bit setting in one
 place
 
  hw/acpi/cpu_hotplug.c |   35 
  hw/acpi/ich9.c|   18 --
  hw/acpi/piix4.c   |   18 +++---
  hw/i386/pc.c  |   51 
 +
  include/hw/acpi/cpu_hotplug.h |7 +++--
  include/hw/acpi/ich9.h|1 -
  include/sysemu/sysemu.h   |3 --
  qom/cpu.c |   10 
  8 files changed, 69 insertions(+), 74 deletions(-)
 





[Qemu-devel] [PATCH V3 0/7] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-09-16 Thread Gu Zheng
Previously we use cpu_added_notifiers to register cpu hotplug notifier callback
which is not able to pass/handle errors, so we switch it to unified hotplug
handler API which allows to pass errors and would allow to cancel device_add
in case of error.
Thanks very much for Igor's review and suggestion.

v3:
 -deal with start-up cpus in pc_cpu_plug as Igor suggested.

v2:
 -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
  1/5--1/7
  2/5--2/7
  3/5--3/7
  4/5--4/7
 Patch 1/7:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
 Patch 3/7:
 -remove unused AcpiCpuHotplug_add directly.
 Patch 5/7:
 -switch the last user of cpu hotplug notifier to hotplug handler API, and
  remove the unused cpu hotplug notify.
 Patch 6/7:
 -split the function rename (just cleanup) into single patch.
 Patch 7/7:
 -introduce help function acpi_set_local_sts to keep the bit setting in
  one place.

Gu Zheng (7):
  acpi/cpu: add cpu hotplug callback function to match hotplug_handler
API
  acpi:ich9: convert cpu hotplug handle to hotplug_handler API
  acpi:piix4: convert cpu hotplug handle to hotplug_handler API
  pc: add cpu hotplug handler to PC_MACHINE
  pc: Update rtc_cmos in pc_cpu_plug
  cpu-hotplug: rename function for better readability
  acpi/cpu-hotplug: introduce help function to keep bit setting in one
place

 hw/acpi/cpu_hotplug.c |   35 
 hw/acpi/ich9.c|   18 --
 hw/acpi/piix4.c   |   18 +++---
 hw/i386/pc.c  |   51 +
 include/hw/acpi/cpu_hotplug.h |7 +++--
 include/hw/acpi/ich9.h|1 -
 include/sysemu/sysemu.h   |3 --
 qom/cpu.c |   10 
 8 files changed, 69 insertions(+), 74 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH V3 1/7] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-09-16 Thread Gu Zheng
---
v2:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
---

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   17 +
 include/hw/acpi/cpu_hotplug.h |3 +++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2ad83a0..dfd6de5 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,6 +36,23 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
+{
+CPUClass *k = CPU_GET_CLASS(cpu);
+int64_t cpu_id;
+
+cpu_id = k-get_arch_id(cpu);
+if ((cpu_id / 8) = ACPI_GPE_PROC_LEN) {
+error_setg(errp, acpi: invalid cpu id: % PRIi64, cpu_id);
+return;
+}
+
+AcpiCpuHotplug_add(ar-gpe, g, cpu);
+
+acpi_update_sci(ar, irq);
+}
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 9e5d30c..166edb0 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
 uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, CPUState *dev, Error **errp);
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
 
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
-- 
1.7.7




[Qemu-devel] [PATCH V3 2/7] acpi:ich9: convert cpu hotplug handle to hotplug_handler API

2014-09-16 Thread Gu Zheng
Convert notifier based hotplug handle to hotplug_handler API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/ich9.c |   14 +++---
 include/hw/acpi/ich9.h |1 -
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..c53d4ab 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -209,15 +209,6 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 acpi_pm1_evt_power_down(pm-acpi_regs);
 }
 
-static void ich9_cpu_added_req(Notifier *n, void *opaque)
-{
-ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_added_notifier);
-
-assert(pm != NULL);
-AcpiCpuHotplug_add(pm-acpi_regs.gpe, pm-gpe_cpu, CPU(opaque));
-acpi_update_sci(pm-acpi_regs, pm-irq);
-}
-
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
   qemu_irq sci_irq)
 {
@@ -246,8 +237,6 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 
 AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
 pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
-pm-cpu_added_notifier.notify = ich9_cpu_added_req;
-qemu_register_cpu_added_notifier(pm-cpu_added_notifier);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
@@ -304,6 +293,9 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 acpi_memory_plug_cb(pm-acpi_regs, pm-irq, pm-acpi_memory_hotplug,
 dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(pm-acpi_regs, pm-irq, pm-gpe_cpu,
+ CPU(dev), errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..fe975e6 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -47,7 +47,6 @@ typedef struct ICH9LPCPMRegs {
 Notifier powerdown_notifier;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
-- 
1.7.7




[Qemu-devel] [PATCH V3 3/7] acpi:piix4: convert cpu hotplug handle to hotplug_handler API

2014-09-16 Thread Gu Zheng
Convert notifier based hotplug handle to hotplug_handler API,
and remove the unused AcpiCpuHotplug_add().

v2:
-remove the unused AcpiCpuHotplug_add().

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   14 ++
 hw/acpi/piix4.c   |   14 ++
 include/hw/acpi/cpu_hotplug.h |2 --
 3 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index dfd6de5..0b9fa55 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -48,22 +48,12 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-AcpiCpuHotplug_add(ar-gpe, g, cpu);
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
-{
-CPUClass *k = CPU_GET_CLASS(cpu);
-int64_t cpu_id;
-
-*gpe-sts = *gpe-sts | ACPI_CPU_HOTPLUG_STATUS;
-cpu_id = k-get_arch_id(CPU(cpu));
-g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
-g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
-}
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b72b34e..b046cd3 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -83,7 +83,6 @@ typedef struct PIIX4PMState {
 uint8_t s4_val;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
@@ -348,6 +347,8 @@ static void piix4_device_plug_cb(HotplugHandler 
*hotplug_dev,
 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
 acpi_pcihp_device_plug_cb(s-ar, s-irq, s-acpi_pci_hotplug, dev,
   errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(s-ar, s-irq, s-gpe_cpu, CPU(dev), errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
@@ -544,15 +545,6 @@ static const MemoryRegionOps piix4_gpe_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void piix4_cpu_added_req(Notifier *n, void *opaque)
-{
-PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
-
-assert(s != NULL);
-AcpiCpuHotplug_add(s-ar.gpe, s-gpe_cpu, CPU(opaque));
-acpi_update_sci(s-ar, s-irq);
-}
-
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s)
 {
@@ -565,8 +557,6 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 
 AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
 PIIX4_CPU_HOTPLUG_IO_BASE);
-s-cpu_added_notifier.notify = piix4_cpu_added_req;
-qemu_register_cpu_added_notifier(s-cpu_added_notifier);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 166edb0..8188630 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,8 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, CPUState *dev, Error **errp);
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V3 4/7] pc: add cpu hotplug handler to PC_MACHINE

2014-09-16 Thread Gu Zheng
Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
cpu hotplug callback via hotplug_handler API.

v3:
 -deal with start up cpus in a more neat way as Igor suggested.
v2:
 -just rebase.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c |   26 +-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index b6c9b61..e25e71b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1613,11 +1613,34 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_plug(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+if (dev-hotplugged) {
+error_setg(local_err,
+   cpu hotplug is not enabled: missing acpi device);
+}
+goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+out:
+error_propagate(errp, local_err);
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 pc_dimm_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_plug(hotplug_dev, dev, errp);
 }
 }
 
@@ -1626,7 +1649,8 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState 
*machine,
 {
 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 return HOTPLUG_HANDLER(machine);
 }
 
-- 
1.7.7




[Qemu-devel] [PATCH V3 6/7] cpu-hotplug: rename function for better readability

2014-09-16 Thread Gu Zheng
Rename:
AcpiCpuHotplug_init -- acpi_cpu_hotplug_init
AcpiCpuHotplug_ops -- acpi_cpu_hotplug_ops
for better readability, just cleanup.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |4 ++--
 hw/acpi/ich9.c|4 ++--
 hw/acpi/piix4.c   |4 ++--
 include/hw/acpi/cpu_hotplug.h |4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 0b9fa55..7629686 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -54,8 +54,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base)
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
 CPUState *cpu;
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index c53d4ab..42cf8fa 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -235,8 +235,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 pm-powerdown_notifier.notify = pm_powerdown_req;
 qemu_register_powerdown_notifier(pm-powerdown_notifier);
 
-AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
-pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+  pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b046cd3..205ba66 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -555,8 +555,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 acpi_pcihp_init(s-acpi_pci_hotplug, bus, parent,
 s-use_acpi_pci_hotplug);
 
-AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
-PIIX4_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(parent, OBJECT(s), s-gpe_cpu,
+  PIIX4_CPU_HOTPLUG_IO_BASE);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 8188630..d015bef 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, CPUState *dev, Error **errp);
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base);
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V3 5/7] pc: Update rtc_cmos in pc_cpu_plug

2014-09-16 Thread Gu Zheng
Update rtc_cmos in pc_cpu_plug directly instead of the notifier, with
this change, there will no user of CPU hot-plug notifier any more, so
remove it.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c|   25 ++---
 include/sysemu/sysemu.h |3 ---
 qom/cpu.c   |   10 --
 3 files changed, 6 insertions(+), 32 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e25e71b..8b887c7 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -353,20 +353,7 @@ static void pc_cmos_init_late(void *opaque)
 qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
-typedef struct RTCCPUHotplugArg {
-Notifier cpu_added_notifier;
-ISADevice *rtc_state;
-} RTCCPUHotplugArg;
-
-static void rtc_notify_cpu_added(Notifier *notifier, void *data)
-{
-RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
- cpu_added_notifier);
-ISADevice *s = arg-rtc_state;
-
-/* increment the number of CPUs */
-rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
-}
+static ISADevice *rtc_state;
 
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
   const char *boot_device,
@@ -376,7 +363,6 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 int val, nb, i;
 FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
 static pc_cmos_init_late_arg arg;
-static RTCCPUHotplugArg cpu_hotplug_cb;
 
 /* various important CMOS locations needed by PC/Bochs bios */
 
@@ -415,10 +401,8 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 
 /* set the number of CPU */
 rtc_set_memory(s, 0x5f, smp_cpus - 1);
-/* init CPU hotplug notifier */
-cpu_hotplug_cb.rtc_state = s;
-cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
-qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
+
+rtc_state = s;
 
 if (set_boot_dev(s, boot_device)) {
 exit(1);
@@ -1630,6 +1614,9 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
 hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+
+/* increment the number of CPUs */
+rtc_set_memory(rtc_state, 0x5f, rtc_get_memory(rtc_state, 0x5f) + 1);
 out:
 error_propagate(errp, local_err);
 }
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..acfe494 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -183,9 +183,6 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict 
*qdict);
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
-/* CPU hotplug */
-void qemu_register_cpu_added_notifier(Notifier *notifier);
-
 /* pcie aer error injection */
 void pcie_aer_inject_error_print(Monitor *mon, const QObject *data);
 int do_pcie_aer_inject_error(Monitor *mon,
diff --git a/qom/cpu.c b/qom/cpu.c
index b32dd0a..19c5de5 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -107,15 +107,6 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
 error_setg(errp, Obtaining memory mappings is unsupported on this CPU.);
 }
 
-/* CPU hot-plug notifiers */
-static NotifierList cpu_added_notifiers =
-NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
-
-void qemu_register_cpu_added_notifier(Notifier *notifier)
-{
-notifier_list_add(cpu_added_notifiers, notifier);
-}
-
 void cpu_reset_interrupt(CPUState *cpu, int mask)
 {
 cpu-interrupt_request = ~mask;
@@ -303,7 +294,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
 
 if (dev-hotplugged) {
 cpu_synchronize_post_init(cpu);
-notifier_list_notify(cpu_added_notifiers, dev);
 cpu_resume(cpu);
 }
 }
-- 
1.7.7




[Qemu-devel] [PATCH V3 7/7] acpi/cpu-hotplug: introduce help function to keep bit setting in one place

2014-09-16 Thread Gu Zheng
Introduce help function acpi_set_local_sts() to simplify acpi_cpu_plug_cb
and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   22 +++---
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 7629686..d42c961 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,8 +36,8 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
+static void acpi_set_local_sts(AcpiCpuHotplug *g, CPUState *cpu,
+   Error **errp)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
 int64_t cpu_id;
@@ -48,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+}
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
+{
+acpi_set_local_sts(g, cpu, errp);
+if (*errp != NULL) {
+return;
+}
+
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 acpi_update_sci(ar, irq);
 }
 
@@ -60,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
*owner,
 CPUState *cpu;
 
 CPU_FOREACH(cpu) {
-CPUClass *cc = CPU_GET_CLASS(cpu);
-int64_t id = cc-get_arch_id(cpu);
+Error *local_err = NULL;
 
-g_assert((id / 8)  ACPI_GPE_PROC_LEN);
-gpe_cpu-sts[id / 8] |= (1  (id % 8));
+acpi_set_local_sts(gpe_cpu, cpu, local_err);
+g_assert(local_err == NULL);
 }
 memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
   gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
-- 
1.7.7




Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-09-15 Thread Gu Zheng
Hi Bharata,
On 09/12/2014 09:52 PM, Bharata B Rao wrote:

 On Fri, Sep 12, 2014 at 4:23 PM, Anshul Makkar
 anshul.mak...@profitbricks.com wrote:
 During plugging we can see this event: echo 1  cpu8/online.

 But during unplugging , we can't see the event echo 0  cpu8/online.
 
 That's because I didn't do that explicitly, was always trying to
 remove an online cpu from the monitor w/o explicitly offlining it from
 inside the guest. Either ways I still see the removed CPU being listed
 in QEMU monitor.
 
 I don't ever hit any of the below code paths during CPU removal:

It seems that the guest OS did not call the _EJ0 method.
Could you please dump the guest os' acpi dsdt, and check whether the _EJ0
method exists? 

 
 cpus.c: qemu_kvm_destroy_vcpu()
 cpus.c: x86_cpu_finalizefn()
 
 I see CPU_REMOVE() being called from above two routines.
 
 And neither does hw/acpi/cpu_hotplug.c:cpu_status_write() gets called
 here. Does the message ACPI: Device does not support D3cold guest
 kernel throws during hot removal is causing this behaviour here ?
 Guest kernel is 3.11.10, should I be on latest kernel ?

I have tested the fedora 20 guest with the default kernel, it works well,
so the kernel should be fine.
One more question, is the guest kernel config the same as fedora 20's default 
one?

Thanks,
Gu

 
 Regards,
 Bharata.
 .
 





Re: [Qemu-devel] [PATCH 4/5] pc: add cpu hotplug handler to PC_MACHINE

2014-09-14 Thread Gu Zheng
Hi Igor,

On 09/12/2014 10:28 PM, Igor Mammedov wrote:

 On Fri, 12 Sep 2014 11:02:09 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Hi Igor,
 On 09/10/2014 09:55 PM, Igor Mammedov wrote:

 On Wed,  3 Sep 2014 17:06:16 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:

 Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
 cpu hotplug callback via hotplug_handler API.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/i386/pc.c |   26 +-
  qom/cpu.c|1 -
  2 files changed, 25 insertions(+), 2 deletions(-)

 diff --git a/hw/i386/pc.c b/hw/i386/pc.c
 index 8fa8d2f..c2956f9 100644
 --- a/hw/i386/pc.c
 +++ b/hw/i386/pc.c
 @@ -1607,11 +1607,34 @@ out:
  error_propagate(errp, local_err);
  }
  
 +static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 + DeviceState *dev, Error **errp)
 +{
 +HotplugHandlerClass *hhc;
 +Error *local_err = NULL;
 +PCMachineState *pcms = PC_MACHINE(hotplug_dev);
 +
 +if (dev-hotplugged) {
 for startup CPUs we set gpe_cpu status bits in AcpiCpuHotplug_init()
 and for hotpluged in AcpiCpuHotplug_add() which is duplicating
 essentially the same code.

 Could you drop above check and make AcpiCpuHotplug_init() take care
 about startup CPUs as well, keeping bit setting in one place.

 Yeah, with the above change, code will be more neat, but I think it is not
 a serious problem.:)
 And pcms-acpi_dev is set when PC hardware initialisation (e.g. pc_init1),
 for start up cpus, the plug handler is not valid, so the check is needed
 here to avoid trigger error by start cpu.
 
 then check for !pcms-acpi_dev and exit if it not set (i.e. as pc_dimm_plug() 
 does)
 since there isn't acpi hardware to update for startup CPUs either.
 
 may be something along this lines:
 
 if (!pcms-acpi_dev) {
   if (dev-hotplugged) error_setg(local_err, CPU hotplug is not supported 
 without ACPI);
   goto out;
 }

This is more neat, thanks.

 


 +if (!pcms-acpi_dev) {
 +error_setg(local_err,
 +   cpu hotplug is not enabled: missing acpi device);
 +goto out;
 +}
 +
 +hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 +hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
 +out:
 +error_propagate(errp, local_err);
 +}
 +}
 +
  static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
  {
  if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
  pc_dimm_plug(hotplug_dev, dev, errp);
 +} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 +pc_cpu_plug(hotplug_dev, dev, errp);
  }
  }
  
 @@ -1620,7 +1643,8 @@ static HotplugHandler 
 *pc_get_hotpug_handler(MachineState *machine,
  {
  PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
  
 -if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 +if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)
 +|| object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
  return HOTPLUG_HANDLER(machine);
  }
  
 diff --git a/qom/cpu.c b/qom/cpu.c
 index b32dd0a..af8e83f 100644
 --- a/qom/cpu.c
 +++ b/qom/cpu.c
 @@ -304,7 +304,6 @@ static void cpu_common_realizefn(DeviceState *dev, 
 Error **errp)
  if (dev-hotplugged) {
  cpu_synchronize_post_init(cpu);
  notifier_list_notify(cpu_added_notifiers, dev);
 -cpu_resume(cpu);
  }
  }
  

 I don't see what sets PCMachine as hotplug_handler for CPU,
 maybe series is missing a patch?

 Previous memory hotplug has built the frame work, here just adding the case
 to handle CPU.
 You still need to set hotplug handler for CPU device or ICCBus
 grep for qbus_set_hotplug_handler()

Current implementation is the same as bus-less device's (e.g. memory), via the
machine's get_hotplug_handler method to discover a hotplug handler controller,
and it works fine.
Shall we still need to set hotplug handler ICCBus, which seems duplicated?
Or switch to set hotplug handler to ICCBus, and drop current implementation?

Thanks,
Gu

 

  static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
  {
  if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
  pc_dimm_plug(hotplug_dev, dev, errp);
 +} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 +pc_cpu_plug(hotplug_dev, dev, errp);
  }

 Thanks,
 Gu


 .



 
 .
 





Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-09-14 Thread Gu Zheng
Hi Igor,
On 09/12/2014 10:15 PM, Igor Mammedov wrote:

 On Thu, 28 Aug 2014 11:36:42 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 After ACPI get a signal to eject a vCPU, the vCPU must be
 removed from CPU list,before the vCPU really removed,  then
 release the all related vCPU objects.
 But we do not close KVM vcpu fd, just record it into a list, in
 order to reuse it.
 An additional question,
   Have you checked if migration works after CPU unplug?

Yes, migration works fine after CPU unplug.

Thanks,
Gu

 

 Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  cpus.c   |   37 
  include/sysemu/kvm.h |1 +
  kvm-all.c|   57 
 +-
  3 files changed, 94 insertions(+), 1 deletions(-)

 diff --git a/cpus.c b/cpus.c
 index eee693b..0608b41 100644
 --- a/cpus.c
 +++ b/cpus.c
 @@ -851,6 +851,24 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void 
 *data), void *data)
  qemu_cpu_kick(cpu);
  }
  
 +static void qemu_kvm_destroy_vcpu(CPUState *cpu)
 +{
 +CPU_REMOVE(cpu);
 +
 +if (kvm_destroy_vcpu(cpu)  0) {
 +fprintf(stderr, kvm_destroy_vcpu failed.\n);
 +exit(1);
 +}
 +
 +object_unparent(OBJECT(cpu));
 +}
 +
 +static void qemu_tcg_destroy_vcpu(CPUState *cpu)
 +{
 +CPU_REMOVE(cpu);
 +object_unparent(OBJECT(cpu));
 +}
 +
  static void flush_queued_work(CPUState *cpu)
  {
  struct qemu_work_item *wi;
 @@ -942,6 +960,11 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
  }
  }
  qemu_kvm_wait_io_event(cpu);
 +if (cpu-exit  !cpu_can_run(cpu)) {
 +qemu_kvm_destroy_vcpu(cpu);
 +qemu_mutex_unlock(qemu_global_mutex);
 +return NULL;
 +}
  }
  
  return NULL;
 @@ -994,6 +1017,7 @@ static void tcg_exec_all(void);
  static void *qemu_tcg_cpu_thread_fn(void *arg)
  {
  CPUState *cpu = arg;
 +CPUState *remove_cpu = NULL;
  
  qemu_tcg_init_cpu_signals();
  qemu_thread_get_self(cpu-thread);
 @@ -1026,6 +1050,16 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
  }
  }
  qemu_tcg_wait_io_event();
 +CPU_FOREACH(cpu) {
 +if (cpu-exit  !cpu_can_run(cpu)) {
 +remove_cpu = cpu;
 +break;
 +}
 +}
 +if (remove_cpu) {
 +qemu_tcg_destroy_vcpu(remove_cpu);
 +remove_cpu = NULL;
 +}
  }
  
  return NULL;
 @@ -1383,6 +1417,9 @@ static void tcg_exec_all(void)
  break;
  }
  } else if (cpu-stop || cpu-stopped) {
 +if (cpu-exit) {
 +next_cpu = CPU_NEXT(cpu);
 +}
  break;
  }
  }
 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index 174ea36..88e2403 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -178,6 +178,7 @@ int kvm_has_intx_set_mask(void);
  
  int kvm_init_vcpu(CPUState *cpu);
  int kvm_cpu_exec(CPUState *cpu);
 +int kvm_destroy_vcpu(CPUState *cpu);
  
  #ifdef NEED_CPU_H
  
 diff --git a/kvm-all.c b/kvm-all.c
 index 1402f4f..d0caeff 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -74,6 +74,12 @@ typedef struct KVMSlot
  
  typedef struct kvm_dirty_log KVMDirtyLog;
  
 +struct KVMParkedVcpu {
 +unsigned long vcpu_id;
 +int kvm_fd;
 +QLIST_ENTRY(KVMParkedVcpu) node;
 +};
 +
  struct KVMState
  {
  KVMSlot *slots;
 @@ -108,6 +114,7 @@ struct KVMState
  QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
  bool direct_msi;
  #endif
 +QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus;
  };
  
  KVMState *kvm_state;
 @@ -226,6 +233,53 @@ static int kvm_set_user_memory_region(KVMState *s, 
 KVMSlot *slot)
  return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
  }
  
 +int kvm_destroy_vcpu(CPUState *cpu)
 +{
 +KVMState *s = kvm_state;
 +long mmap_size;
 +struct KVMParkedVcpu *vcpu = NULL;
 +int ret = 0;
 +
 +DPRINTF(kvm_destroy_vcpu\n);
 +
 +mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
 +if (mmap_size  0) {
 +ret = mmap_size;
 +DPRINTF(KVM_GET_VCPU_MMAP_SIZE failed\n);
 +goto err;
 +}
 +
 +ret = munmap(cpu-kvm_run, mmap_size);
 +if (ret  0) {
 +goto err;
 +}
 +
 +vcpu = g_malloc0(sizeof(*vcpu));
 +vcpu-vcpu_id = kvm_arch_vcpu_id(cpu);
 +vcpu-kvm_fd = cpu-kvm_fd;
 +QLIST_INSERT_HEAD(kvm_state-kvm_parked_vcpus, vcpu, node);
 +err:
 +return ret;
 +}
 +
 +static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
 +{
 +struct KVMParkedVcpu *cpu;
 +
 +QLIST_FOREACH(cpu, s-kvm_parked_vcpus, node) {
 +if (cpu-vcpu_id == vcpu_id) {
 +int kvm_fd;
 +
 +QLIST_REMOVE(cpu, node);
 +kvm_fd = cpu-kvm_fd;
 +g_free(cpu);
 +return kvm_fd

[Qemu-devel] [PATCH V2 0/7] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-09-12 Thread Gu Zheng
Previously we use cpu_added_notifiers to register cpu hotplug notifier callback
which is not able to pass/handle errors, so we switch it to unified hotplug
handler API which allows to pass errors and would allow to cancel device_add
in case of error.
Thanks very much for Igor's review and suggestion.

v2:
 -Add 3 new patches(5/7,6/7,7/7), delete original patch 5/5.
  1/5--1/7
  2/5--2/7
  3/5--3/7
  4/5--4/7
 Patch 1/7:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
 Patch 3/7:
 -remove unused AcpiCpuHotplug_add here directly.
 Patch 5/7:
 -switch the last user of cpu hotplug notifier to hotplug handler API, and
  remove the unused cpu hotplug notify.
 Patch 6/7:
 -split the function rename (just cleanup) into single patch.
 Patch 7/7:
 -introduce help function acpi_set_local_sts to keep the bit setting in
  one place.

Gu Zheng (7):
  acpi/cpu: add cpu hotplug callback function to match hotplug_handler
API
  acpi:ich9: convert cpu hotplug handle to hotplug_handler API
  acpi:piix4: convert cpu hotplug handle to hotplug_handler API
  pc: add cpu hotplug handler to PC_MACHINE
  pc: Update rtc_cmos in pc_cpu_plug
  cpu-hotplug: rename function for better readability
  acpi/cpu-hotplug: introduce help function to keep bit setting in one
place

 hw/acpi/cpu_hotplug.c |   35 
 hw/acpi/ich9.c|   18 --
 hw/acpi/piix4.c   |   18 +++---
 hw/i386/pc.c  |   51 +
 include/hw/acpi/cpu_hotplug.h |7 +++--
 include/hw/acpi/ich9.h|1 -
 include/sysemu/sysemu.h   |3 --
 qom/cpu.c |   10 
 8 files changed, 69 insertions(+), 74 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH V2 1/7] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-09-12 Thread Gu Zheng
---
v2:
 -add errp argument to catch error.
 -return error instead of aborting if cpu id is invalid.
 -make acpi_cpu_plug_cb as a wrapper around AcpiCpuHotplug_add.
---

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   17 +
 include/hw/acpi/cpu_hotplug.h |3 +++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 2ad83a0..dfd6de5 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,6 +36,23 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
+{
+CPUClass *k = CPU_GET_CLASS(cpu);
+int64_t cpu_id;
+
+cpu_id = k-get_arch_id(cpu);
+if ((cpu_id / 8) = ACPI_GPE_PROC_LEN) {
+error_setg(errp, acpi: invalid cpu id: % PRIi64, cpu_id);
+return;
+}
+
+AcpiCpuHotplug_add(ar-gpe, g, cpu);
+
+acpi_update_sci(ar, irq);
+}
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 9e5d30c..166edb0 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
 uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, CPUState *dev, Error **errp);
+
 void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
 
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
-- 
1.7.7




[Qemu-devel] [PATCH V2 2/7] acpi:ich9: convert cpu hotplug handle to hotplug_handler API

2014-09-12 Thread Gu Zheng
Convert notifier based hotplug handle to hotplug_handler API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/ich9.c |   14 +++---
 include/hw/acpi/ich9.h |1 -
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..c53d4ab 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -209,15 +209,6 @@ static void pm_powerdown_req(Notifier *n, void *opaque)
 acpi_pm1_evt_power_down(pm-acpi_regs);
 }
 
-static void ich9_cpu_added_req(Notifier *n, void *opaque)
-{
-ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_added_notifier);
-
-assert(pm != NULL);
-AcpiCpuHotplug_add(pm-acpi_regs.gpe, pm-gpe_cpu, CPU(opaque));
-acpi_update_sci(pm-acpi_regs, pm-irq);
-}
-
 void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
   qemu_irq sci_irq)
 {
@@ -246,8 +237,6 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 
 AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
 pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
-pm-cpu_added_notifier.notify = ich9_cpu_added_req;
-qemu_register_cpu_added_notifier(pm-cpu_added_notifier);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
@@ -304,6 +293,9 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 acpi_memory_plug_cb(pm-acpi_regs, pm-irq, pm-acpi_memory_hotplug,
 dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(pm-acpi_regs, pm-irq, pm-gpe_cpu,
+ CPU(dev), errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..fe975e6 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -47,7 +47,6 @@ typedef struct ICH9LPCPMRegs {
 Notifier powerdown_notifier;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } ICH9LPCPMRegs;
-- 
1.7.7




[Qemu-devel] [PATCH V2 3/7] acpi:piix4: convert cpu hotplug handle to hotplug_handler API

2014-09-12 Thread Gu Zheng
Convert notifier based hotplug handle to hotplug_handler API,
and remove the unused AcpiCpuHotplug_add().

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   14 ++
 hw/acpi/piix4.c   |   14 ++
 include/hw/acpi/cpu_hotplug.h |2 --
 3 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index dfd6de5..0b9fa55 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -48,22 +48,12 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-AcpiCpuHotplug_add(ar-gpe, g, cpu);
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
-{
-CPUClass *k = CPU_GET_CLASS(cpu);
-int64_t cpu_id;
-
-*gpe-sts = *gpe-sts | ACPI_CPU_HOTPLUG_STATUS;
-cpu_id = k-get_arch_id(CPU(cpu));
-g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
-g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
-}
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b72b34e..b046cd3 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -83,7 +83,6 @@ typedef struct PIIX4PMState {
 uint8_t s4_val;
 
 AcpiCpuHotplug gpe_cpu;
-Notifier cpu_added_notifier;
 
 MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
@@ -348,6 +347,8 @@ static void piix4_device_plug_cb(HotplugHandler 
*hotplug_dev,
 } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
 acpi_pcihp_device_plug_cb(s-ar, s-irq, s-acpi_pci_hotplug, dev,
   errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+acpi_cpu_plug_cb(s-ar, s-irq, s-gpe_cpu, CPU(dev), errp);
 } else {
 error_setg(errp, acpi: device plug request for not supported device
 type: %s, object_get_typename(OBJECT(dev)));
@@ -544,15 +545,6 @@ static const MemoryRegionOps piix4_gpe_ops = {
 .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void piix4_cpu_added_req(Notifier *n, void *opaque)
-{
-PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
-
-assert(s != NULL);
-AcpiCpuHotplug_add(s-ar.gpe, s-gpe_cpu, CPU(opaque));
-acpi_update_sci(s-ar, s-irq);
-}
-
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s)
 {
@@ -565,8 +557,6 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 
 AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
 PIIX4_CPU_HOTPLUG_IO_BASE);
-s-cpu_added_notifier.notify = piix4_cpu_added_req;
-qemu_register_cpu_added_notifier(s-cpu_added_notifier);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 166edb0..8188630 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,8 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, CPUState *dev, Error **errp);
 
-void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
-
 void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
  AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V2 4/7] pc: add cpu hotplug handler to PC_MACHINE

2014-09-12 Thread Gu Zheng
Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
cpu hotplug callback via hotplug_handler API.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c |   26 +-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index b6c9b61..28fc66b 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1613,11 +1613,34 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_cpu_plug(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (dev-hotplugged) {
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   cpu hotplug is not enabled: missing acpi device);
+goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+out:
+error_propagate(errp, local_err);
+}
+}
+
 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 pc_dimm_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_plug(hotplug_dev, dev, errp);
 }
 }
 
@@ -1626,7 +1649,8 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState 
*machine,
 {
 PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 return HOTPLUG_HANDLER(machine);
 }
 
-- 
1.7.7




[Qemu-devel] [PATCH V2 5/7] pc: Update rtc_cmos in pc_cpu_plug

2014-09-12 Thread Gu Zheng
Update rtc_cmos in pc_cpu_plug directly instead of the notifier, with
this change, there will no user of CPU hot-plug notifier any more, so
remove it.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/i386/pc.c|   25 ++---
 include/sysemu/sysemu.h |3 ---
 qom/cpu.c   |   10 --
 3 files changed, 6 insertions(+), 32 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 28fc66b..337d662 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -353,20 +353,7 @@ static void pc_cmos_init_late(void *opaque)
 qemu_unregister_reset(pc_cmos_init_late, opaque);
 }
 
-typedef struct RTCCPUHotplugArg {
-Notifier cpu_added_notifier;
-ISADevice *rtc_state;
-} RTCCPUHotplugArg;
-
-static void rtc_notify_cpu_added(Notifier *notifier, void *data)
-{
-RTCCPUHotplugArg *arg = container_of(notifier, RTCCPUHotplugArg,
- cpu_added_notifier);
-ISADevice *s = arg-rtc_state;
-
-/* increment the number of CPUs */
-rtc_set_memory(s, 0x5f, rtc_get_memory(s, 0x5f) + 1);
-}
+static ISADevice *rtc_state;
 
 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
   const char *boot_device,
@@ -376,7 +363,6 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 int val, nb, i;
 FDriveType fd_type[2] = { FDRIVE_DRV_NONE, FDRIVE_DRV_NONE };
 static pc_cmos_init_late_arg arg;
-static RTCCPUHotplugArg cpu_hotplug_cb;
 
 /* various important CMOS locations needed by PC/Bochs bios */
 
@@ -415,10 +401,8 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t 
above_4g_mem_size,
 
 /* set the number of CPU */
 rtc_set_memory(s, 0x5f, smp_cpus - 1);
-/* init CPU hotplug notifier */
-cpu_hotplug_cb.rtc_state = s;
-cpu_hotplug_cb.cpu_added_notifier.notify = rtc_notify_cpu_added;
-qemu_register_cpu_added_notifier(cpu_hotplug_cb.cpu_added_notifier);
+
+rtc_state = s;
 
 if (set_boot_dev(s, boot_device)) {
 exit(1);
@@ -1629,6 +1613,9 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
 hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+
+/* increment the number of CPUs */
+rtc_set_memory(rtc_state, 0x5f, rtc_get_memory(rtc_state, 0x5f) + 1);
 out:
 error_propagate(errp, local_err);
 }
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..acfe494 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -183,9 +183,6 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict 
*qdict);
 /* generic hotplug */
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 
-/* CPU hotplug */
-void qemu_register_cpu_added_notifier(Notifier *notifier);
-
 /* pcie aer error injection */
 void pcie_aer_inject_error_print(Monitor *mon, const QObject *data);
 int do_pcie_aer_inject_error(Monitor *mon,
diff --git a/qom/cpu.c b/qom/cpu.c
index b32dd0a..19c5de5 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -107,15 +107,6 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
 error_setg(errp, Obtaining memory mappings is unsupported on this CPU.);
 }
 
-/* CPU hot-plug notifiers */
-static NotifierList cpu_added_notifiers =
-NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
-
-void qemu_register_cpu_added_notifier(Notifier *notifier)
-{
-notifier_list_add(cpu_added_notifiers, notifier);
-}
-
 void cpu_reset_interrupt(CPUState *cpu, int mask)
 {
 cpu-interrupt_request = ~mask;
@@ -303,7 +294,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
 
 if (dev-hotplugged) {
 cpu_synchronize_post_init(cpu);
-notifier_list_notify(cpu_added_notifiers, dev);
 cpu_resume(cpu);
 }
 }
-- 
1.7.7




[Qemu-devel] [PATCH V2 6/7] cpu-hotplug: rename function for better readability

2014-09-12 Thread Gu Zheng
Rename:
AcpiCpuHotplug_init -- acpi_cpu_hotplug_init
AcpiCpuHotplug_ops -- acpi_cpu_hotplug_ops
for better readability, just cleanup.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |4 ++--
 hw/acpi/ich9.c|4 ++--
 hw/acpi/piix4.c   |4 ++--
 include/hw/acpi/cpu_hotplug.h |4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 0b9fa55..7629686 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -54,8 +54,8 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 acpi_update_sci(ar, irq);
 }
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base)
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
 CPUState *cpu;
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index c53d4ab..42cf8fa 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -235,8 +235,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,
 pm-powerdown_notifier.notify = pm_powerdown_req;
 qemu_register_powerdown_notifier(pm-powerdown_notifier);
 
-AcpiCpuHotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
-pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
+  pm-gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
 
 if (pm-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), 
OBJECT(lpc_pci),
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b046cd3..205ba66 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -555,8 +555,8 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion 
*parent,
 acpi_pcihp_init(s-acpi_pci_hotplug, bus, parent,
 s-use_acpi_pci_hotplug);
 
-AcpiCpuHotplug_init(parent, OBJECT(s), s-gpe_cpu,
-PIIX4_CPU_HOTPLUG_IO_BASE);
+acpi_cpu_hotplug_init(parent, OBJECT(s), s-gpe_cpu,
+  PIIX4_CPU_HOTPLUG_IO_BASE);
 
 if (s-acpi_memory_hotplug.is_enabled) {
 acpi_memory_hotplug_init(parent, OBJECT(s), s-acpi_memory_hotplug);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 8188630..d015bef 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,6 @@ typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
   AcpiCpuHotplug *g, CPUState *dev, Error **errp);
 
-void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
- AcpiCpuHotplug *gpe_cpu, uint16_t base);
+void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
+   AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH V2 7/7] acpi/cpu-hotplug: introduce help function to keep bit setting in one place

2014-09-12 Thread Gu Zheng
Introduce help function acpi_set_local_sts() to simplify acpi_cpu_plug_cb
and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
---
 hw/acpi/cpu_hotplug.c |   22 +++---
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 7629686..5d62218 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,8 +36,8 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
 },
 };
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
+static void acpi_set_local_sts(AcpiCpuHotplug *g, CPUState *cpu,
+  Error **errp)
 {
 CPUClass *k = CPU_GET_CLASS(cpu);
 int64_t cpu_id;
@@ -48,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 return;
 }
 
-ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
+}
 
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+  AcpiCpuHotplug *g, CPUState *cpu, Error **errp)
+{
+acpi_set_local_sts(g, cpu, errp);
+if (*errp != NULL) {
+return;
+}
+
+ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 acpi_update_sci(ar, irq);
 }
 
@@ -60,11 +69,10 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object 
*owner,
 CPUState *cpu;
 
 CPU_FOREACH(cpu) {
-CPUClass *cc = CPU_GET_CLASS(cpu);
-int64_t id = cc-get_arch_id(cpu);
+Error *local_err = NULL;
 
-g_assert((id / 8)  ACPI_GPE_PROC_LEN);
-gpe_cpu-sts[id / 8] |= (1  (id % 8));
+acpi_set_local_sts(gpe_cpu, cpu, local_err);
+g_assert(local_err == NULL);
 }
 memory_region_init_io(gpe_cpu-io, owner, AcpiCpuHotplug_ops,
   gpe_cpu, acpi-cpu-hotplug, ACPI_GPE_PROC_LEN);
-- 
1.7.7




Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-09-11 Thread Gu Zheng
On 09/11/2014 05:35 PM, Bharata B Rao wrote:

 On Thu, Aug 28, 2014 at 9:06 AM, Gu Zheng guz.f...@cn.fujitsu.com wrote:
 After ACPI get a signal to eject a vCPU, the vCPU must be
 removed from CPU list,before the vCPU really removed,  then
 release the all related vCPU objects.
 But we do not close KVM vcpu fd, just record it into a list, in
 order to reuse it.
 
 After I add and delete a CPU, info cpus from monitor still lists the
 removed CPU. Is this expected ?

No, neither from QEMU (e.g. monitor) nor guest side, you can not see the
removed cpu, but from the kernel side it is still there, just no one uses it
any more.

Thanks,
Gu

 
 Regards,
 Bharata.
 .
 





Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-09-11 Thread Gu Zheng
On 09/11/2014 05:35 PM, Bharata B Rao wrote:

 On Thu, Aug 28, 2014 at 9:06 AM, Gu Zheng guz.f...@cn.fujitsu.com wrote:
 After ACPI get a signal to eject a vCPU, the vCPU must be
 removed from CPU list,before the vCPU really removed,  then
 release the all related vCPU objects.
 But we do not close KVM vcpu fd, just record it into a list, in
 order to reuse it.
 
 After I add and delete a CPU, info cpus from monitor still lists the
 removed CPU. Is this expected ?

No, you can not see the removed cpu from QEMU (e.g. monitor) or guest side,
but from the kernel side it is still there, just no one uses it any more.

Thanks,
Gu

 
 Regards,
 Bharata.
 .
 





Re: [Qemu-devel] [RFC V2 10/10] cpus: reclaim allocated vCPU objects

2014-09-11 Thread Gu Zheng
Hi Bharata,

On 09/11/2014 08:37 PM, Bharata B Rao wrote:

 On Thu, Sep 11, 2014 at 3:23 PM, Gu Zheng guz.f...@cn.fujitsu.com wrote:
 On 09/11/2014 05:35 PM, Bharata B Rao wrote:

 On Thu, Aug 28, 2014 at 9:06 AM, Gu Zheng guz.f...@cn.fujitsu.com wrote:
 After ACPI get a signal to eject a vCPU, the vCPU must be
 removed from CPU list,before the vCPU really removed,  then
 release the all related vCPU objects.
 But we do not close KVM vcpu fd, just record it into a list, in
 order to reuse it.

 After I add and delete a CPU, info cpus from monitor still lists the
 removed CPU. Is this expected ?

 No, you can not see the removed cpu from QEMU (e.g. monitor) or guest side,
 but from the kernel side it is still there, just no one uses it any more.
 
 I am trying your patches, but still see the removed CPU after deletion.
 
 (qemu) info cpus
 * CPU #0: pc=0x8100b82c (halted) thread_id=7812
   CPU #1: pc=0x8100b82c (halted) thread_id=7813
   CPU #2: pc=0x8100b82c (halted) thread_id=7814
   CPU #3: pc=0x8100b82c (halted) thread_id=7815
   CPU #4: pc=0x8100b82c (halted) thread_id=7816
   CPU #5: pc=0x8100b82c (halted) thread_id=7817
   CPU #6: pc=0x8100b82c (halted) thread_id=7818
   CPU #7: pc=0x8100b82c (halted) thread_id=7819
 (qemu) device_add qemu64-x86_64-cpu,id=cpu8
 (qemu) info cpus
 * CPU #0: pc=0x8100b82c (halted) thread_id=7812
   CPU #1: pc=0x8100b82c (halted) thread_id=7813
   CPU #2: pc=0x8100b82c (halted) thread_id=7814
   CPU #3: pc=0x8100b82c (halted) thread_id=7815
   CPU #4: pc=0x8100b82c (halted) thread_id=7816
   CPU #5: pc=0x8100b82c (halted) thread_id=7817
   CPU #6: pc=0x8100b82c (halted) thread_id=7818
   CPU #7: pc=0x8100b82c (halted) thread_id=7819
   CPU #8: pc=0x8100b82c (halted) thread_id=8041
 (qemu) device_del cpu8
 (qemu) info cpus
 * CPU #0: pc=0x8100b82c (halted) thread_id=7812
   CPU #1: pc=0x8100b82c (halted) thread_id=7813
   CPU #2: pc=0x8100b82c (halted) thread_id=7814
   CPU #3: pc=0x8100b82c (halted) thread_id=7815
   CPU #4: pc=0x8100b82c (halted) thread_id=7816
   CPU #5: pc=0x8100b82c (halted) thread_id=7817
   CPU #6: pc=0x8100b82c (halted) thread_id=7818
   CPU #7: pc=0x8100b82c (halted) thread_id=7819
   CPU #8: pc=0x81031722 (halted) thread_id=8041
 
 I applied your patchset on commit 69f87f713069f1f70, may be I should
 try with latest QEMU ?

Is guest os enabled acpi cpu hotplug? What's the guest's cpu info?
Please try latest QEMU, and any feedback is welcome.

Thanks,
Gu

 
 Regards,
 Bharata.
 .
 





Re: [Qemu-devel] [PATCH 1/5] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-09-11 Thread Gu Zheng
Hi Igor,
On 09/11/2014 06:12 PM, Igor Mammedov wrote:

 On Thu, 11 Sep 2014 11:04:10 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Hi Igor,
 On 09/10/2014 09:28 PM, Igor Mammedov wrote:

 On Wed,  3 Sep 2014 17:06:13 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:


 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/acpi/cpu_hotplug.c |   17 +
  include/hw/acpi/cpu_hotplug.h |3 +++
  2 files changed, 20 insertions(+), 0 deletions(-)

 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
 index 2ad83a0..92c189b 100644
 --- a/hw/acpi/cpu_hotplug.c
 +++ b/hw/acpi/cpu_hotplug.c
 @@ -36,6 +36,23 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
  },
  };
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, DeviceState *dev)
 wrong indentation ^^^

 it wouldn't hurt to add errp argument here ...

 +{
 +CPUState *cpu = CPU(dev);
 +CPUClass *k = CPU_GET_CLASS(cpu);
 +int64_t cpu_id;
 +
 +ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 +cpu_id = k-get_arch_id(cpu);
 +g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
 ... and return error from here instead of aborting

 Got it.


 +g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 +
 +acpi_update_sci(ar, irq);
 +
 +cpu_resume(cpu);
 Why are you adding cpu_resume() here?
 check cpu_common_realizefn() which already does it.

 Because hot added callback is called after cpu_common_realizefn(), so I moved
 cpu_resume(cpu) from cpu_common_realizefn() here to ensure the guest has 
 already
 hot added cpu before we resume it.
 cpu.realize() should create a fully working CPU and moving CPU internals to 
 ACPI
 is not correct. CPU hot-add shouyld not depend on whether guest OS supports 
 it or not.
 
 More over there is no need to resume CPU when guest OS hot-added it,
 cpu.realize() creates secondary CPU in RESET state, so it does nothing and 
 waits
 for INIT/SIPI sequence (i.e. when guest OS decides to online CPU).

Seems I had a misreading on this, thanks for your explanation.

Best regards,
Gu

 


 +}
 +
  void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
  {
  CPUClass *k = CPU_GET_CLASS(cpu);
 diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
 index 9e5d30c..d025731 100644
 --- a/include/hw/acpi/cpu_hotplug.h
 +++ b/include/hw/acpi/cpu_hotplug.h
 @@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
  uint8_t sts[ACPI_GPE_PROC_LEN];
  } AcpiCpuHotplug;
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, DeviceState *dev);
 wrong indentation ^^^

 OK, will fix this too.

 Thanks,
 Gu


 +
  void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
  
  void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,


 .



 
 .
 





Re: [Qemu-devel] [PATCH 4/5] pc: add cpu hotplug handler to PC_MACHINE

2014-09-11 Thread Gu Zheng
Hi Igor,
On 09/10/2014 09:55 PM, Igor Mammedov wrote:

 On Wed,  3 Sep 2014 17:06:16 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 
 Add cpu hotplug handler to PC_MACHINE, which will perform the acpi
 cpu hotplug callback via hotplug_handler API.

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/i386/pc.c |   26 +-
  qom/cpu.c|1 -
  2 files changed, 25 insertions(+), 2 deletions(-)

 diff --git a/hw/i386/pc.c b/hw/i386/pc.c
 index 8fa8d2f..c2956f9 100644
 --- a/hw/i386/pc.c
 +++ b/hw/i386/pc.c
 @@ -1607,11 +1607,34 @@ out:
  error_propagate(errp, local_err);
  }
  
 +static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 + DeviceState *dev, Error **errp)
 +{
 +HotplugHandlerClass *hhc;
 +Error *local_err = NULL;
 +PCMachineState *pcms = PC_MACHINE(hotplug_dev);
 +
 +if (dev-hotplugged) {
 for startup CPUs we set gpe_cpu status bits in AcpiCpuHotplug_init()
 and for hotpluged in AcpiCpuHotplug_add() which is duplicating
 essentially the same code.
 
 Could you drop above check and make AcpiCpuHotplug_init() take care
 about startup CPUs as well, keeping bit setting in one place.

Yeah, with the above change, code will be more neat, but I think it is not
a serious problem.:)
And pcms-acpi_dev is set when PC hardware initialisation (e.g. pc_init1),
for start up cpus, the plug handler is not valid, so the check is needed
here to avoid trigger error by start cpu.

 
 +if (!pcms-acpi_dev) {
 +error_setg(local_err,
 +   cpu hotplug is not enabled: missing acpi device);
 +goto out;
 +}
 +
 +hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
 +hhc-plug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
 +out:
 +error_propagate(errp, local_err);
 +}
 +}
 +
  static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
  {
  if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
  pc_dimm_plug(hotplug_dev, dev, errp);
 +} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
 +pc_cpu_plug(hotplug_dev, dev, errp);
  }
  }
  
 @@ -1620,7 +1643,8 @@ static HotplugHandler 
 *pc_get_hotpug_handler(MachineState *machine,
  {
  PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
  
 -if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 +if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)
 +|| object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
  return HOTPLUG_HANDLER(machine);
  }
  
 diff --git a/qom/cpu.c b/qom/cpu.c
 index b32dd0a..af8e83f 100644
 --- a/qom/cpu.c
 +++ b/qom/cpu.c
 @@ -304,7 +304,6 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
 **errp)
  if (dev-hotplugged) {
  cpu_synchronize_post_init(cpu);
  notifier_list_notify(cpu_added_notifiers, dev);
 -cpu_resume(cpu);
  }
  }
  
 
 I don't see what sets PCMachine as hotplug_handler for CPU,
 maybe series is missing a patch?

Previous memory hotplug has built the frame work, here just adding the case
to handle CPU.

 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
   DeviceState *dev, Error **errp)
 {
 if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
 pc_dimm_plug(hotplug_dev, dev, errp);
+} else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+pc_cpu_plug(hotplug_dev, dev, errp);
 }

Thanks,
Gu

 
 .
 





Re: [Qemu-devel] [PATCH 0/5] cpu/acpi: convert cpu hot plug to hotplug_handler API

2014-09-10 Thread Gu Zheng
Hi Igor,
Thanks very much for your review and suggestion.
On 09/10/2014 10:12 PM, Igor Mammedov wrote:

 On Wed,  3 Sep 2014 17:06:12 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 

 Gu Zheng (5):
   acpi/cpu: add cpu hotplug callback function to match hotplug_handler
 API
   acpi:ich9: convert cpu hotplug handle to hotplug_handler API
   acpi:piix4: convert cpu hotplug handle to hotplug_handler API
   pc: add cpu hotplug handler to PC_MACHINE
   cpu/hotplug: remove the left unused cpu hotplug notifier function

  hw/acpi/cpu_hotplug.c |   18 --
  hw/acpi/ich9.c|   15 +++
  hw/acpi/piix4.c   |   16 +++-
  hw/i386/pc.c  |   26 +-
  include/hw/acpi/cpu_hotplug.h |6 --
  include/hw/acpi/ich9.h|1 -
  qom/cpu.c |1 -
  7 files changed, 47 insertions(+), 36 deletions(-)

 
 Looks like right direction that would allow to drop cpu_added_notifiers
 which is not able to pass/handle errors and switch to unified hotplug handler
 API which allows to pass errors and would allow to cancel device_add in case 
 of
 error.

It seems the key value we can gain from above change, I'll follow your 
suggestion. 

 
 PS:
 Gu Zheng,
 
 Please grep for qemu_register_cpu_added_notifier(), you've missed to convert
 rtc usage of CPU notifier.

Thanks for your reminder.

 
 I'd prefer this to go in before you device_add/add cpu series.

OK, I'll work on this series first.

Best regards,
Gu

 .
 





Re: [Qemu-devel] [PATCH 1/5] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API

2014-09-10 Thread Gu Zheng
Hi Igor,
On 09/10/2014 09:28 PM, Igor Mammedov wrote:

 On Wed,  3 Sep 2014 17:06:13 +0800
 Gu Zheng guz.f...@cn.fujitsu.com wrote:
 

 Signed-off-by: Gu Zheng guz.f...@cn.fujitsu.com
 ---
  hw/acpi/cpu_hotplug.c |   17 +
  include/hw/acpi/cpu_hotplug.h |3 +++
  2 files changed, 20 insertions(+), 0 deletions(-)

 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
 index 2ad83a0..92c189b 100644
 --- a/hw/acpi/cpu_hotplug.c
 +++ b/hw/acpi/cpu_hotplug.c
 @@ -36,6 +36,23 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
  },
  };
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, DeviceState *dev)
 wrong indentation ^^^
 
 it wouldn't hurt to add errp argument here ...
 
 +{
 +CPUState *cpu = CPU(dev);
 +CPUClass *k = CPU_GET_CLASS(cpu);
 +int64_t cpu_id;
 +
 +ar-gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
 +cpu_id = k-get_arch_id(cpu);
 +g_assert((cpu_id / 8)  ACPI_GPE_PROC_LEN);
 ... and return error from here instead of aborting

Got it.

 
 +g-sts[cpu_id / 8] |= (1  (cpu_id % 8));
 +
 +acpi_update_sci(ar, irq);
 +
 +cpu_resume(cpu);
 Why are you adding cpu_resume() here?
 check cpu_common_realizefn() which already does it.

Because hot added callback is called after cpu_common_realizefn(), so I moved
cpu_resume(cpu) from cpu_common_realizefn() here to ensure the guest has already
hot added cpu before we resume it.

 
 +}
 +
  void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
  {
  CPUClass *k = CPU_GET_CLASS(cpu);
 diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
 index 9e5d30c..d025731 100644
 --- a/include/hw/acpi/cpu_hotplug.h
 +++ b/include/hw/acpi/cpu_hotplug.h
 @@ -20,6 +20,9 @@ typedef struct AcpiCpuHotplug {
  uint8_t sts[ACPI_GPE_PROC_LEN];
  } AcpiCpuHotplug;
  
 +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
 +  AcpiCpuHotplug *g, DeviceState *dev);
 wrong indentation ^^^

OK, will fix this too.

Thanks,
Gu

 
 +
  void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
  
  void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
 
 
 .
 





  1   2   >