Skip to contentSkip to conversation

convert system_powerdown command to notifiers

PATCH Superseded Igor Mammedov 3 participants 11 messages Aug 29, 2012 – Aug 30, 2012

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover convert system_powerdown command to notifiers

global variable qemu_system_powerdown in sysemu.h is the only dep for qemu_irq and qemu_rise_irq is not a generic way to signal guest that it should shutdown.

So replace it by notifiers and allow each implementation to have it's own way to notify guest.

git repo for testing:
last 5 commits
https://github.com/imammedo/qemu/tree/cpu_as_device.WIP

compile tested:
target-list=x86_64-linux-user,x86_64-softmmu,sparc-softmmu,arm-softmmu
runtime tested:
x86_64-softmmu + win7 guest

ps:
reposting because I forgot to add qemu-devel address.

Igor Mammedov (5):
introduce powerdown_notifiers
acpi: use notifier for signaling guest system_powerdown command
target-arm: use notifier for signaling guest system_powerdown command
target-sparc: use notifier for signaling guest system_powerdown
command
cleanup unused qemu_system_powerdown

 hw/acpi_piix4.c |  8 +++++---
 hw/nseries.c    | 14 +++++++++++++-
 hw/sun4m.c      | 14 +++++++++++++-
 sysemu.h        |  3 +--
 vl.c            | 18 ++++++++++++++----
 5 files changed, 46 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.11.4
#7 lore raw

PATCH v2 2/5 acpi: use notifier for signaling guest system_powerdown command

In addition, there is no need to allocate an extra irq just for rising SCI in irq handler. Just rise SCI right from notifier handler instead.

---
 hw/acpi_piix4.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/acpi_piix4.c +5 -3
index 72d6e5c..4b9d0e8 100644
@@ -67,6 +67,7 @@ typedef struct PIIX4PMState {
     qemu_irq smi_irq;
     int kvm_enabled;
     Notifier machine_ready;
+    Notifier powerdown_notifier;
 
     /* for pci hotplug */
     struct pci_status pci0_status;
@@ -359,9 +360,9 @@ static void piix4_reset(void *opaque)
     piix4_update_hotplug(s);
 }
 
-static void piix4_powerdown(void *opaque, int irq, int power_failing)
+static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
 {
-    PIIX4PMState *s = opaque;
+    PIIX4PMState *s = container_of(n, PIIX4PMState, powerdown_notifier);
 
     assert(s != NULL);
     acpi_pm1_evt_power_down(&s->ar);
@@ -415,7 +416,8 @@ static int piix4_pm_initfn(PCIDevice *dev)
     acpi_pm_tmr_init(&s->ar, pm_tmr_timer);
     acpi_gpe_init(&s->ar, GPE_LEN);
 
-    qemu_system_powerdown = *qemu_allocate_irqs(piix4_powerdown, s, 1);
+    s->powerdown_notifier.notify = piix4_pm_powerdown_req;
+    qemu_register_powerdown_notifier(&s->powerdown_notifier);
 
     pm_smbus_init(&s->dev.qdev, &s->smb);
     s->machine_ready.notify = piix4_pm_machine_ready;
Signature · 1 line
1.7.11.4
#8 lore raw

PATCH v2 3/5 target-arm: use notifier for signaling guest system_powerdown command

In reply to Igor Mammedov
---
 hw/nseries.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/nseries.c +13 -1
index 4df2670..6df71eb 100644
@@ -189,6 +189,17 @@ static void n8x0_nand_setup(struct n800_s *s)
     /* XXX: in theory should also update the OOB for both pages */
 }
 
+static qemu_irq n8x0_system_powerdown;
+
+static void n8x0_powerdown_req(Notifier *n, void *opaque)
+{
+    qemu_irq_raise(n8x0_system_powerdown);
+}
+
+static Notifier n8x0_system_powerdown_notifier = {
+    .notify = n8x0_powerdown_req
+};
+
 static void n8x0_i2c_setup(struct n800_s *s)
 {
     DeviceState *dev;
@@ -201,7 +212,8 @@ static void n8x0_i2c_setup(struct n800_s *s)
                           qdev_get_gpio_in(s->mpu->ih[0],
                                            OMAP_INT_24XX_SYS_NIRQ));
 
-    qemu_system_powerdown = qdev_get_gpio_in(dev, 3);
+    n8x0_system_powerdown = qdev_get_gpio_in(dev, 3);
+    qemu_register_powerdown_notifier(&n8x0_system_powerdown_notifier);
 
     /* Attach a TMP105 PM chip (A0 wired to ground) */
     dev = i2c_create_slave(i2c, "tmp105", N8X0_TMP105_ADDR);
Signature · 1 line
1.7.11.4
#9 lore raw

PATCH v2 4/5 target-sparc: use notifier for signaling guest system_powerdown command

In reply to Igor Mammedov
---
 hw/sun4m.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/sun4m.c +13 -1
index 0f909b5..c98cd5e 100644
@@ -472,6 +472,17 @@ static void slavio_timer_init_all(target_phys_addr_t addr, qemu_irq master_irq,
     }
 }
 
+static qemu_irq  slavio_system_powerdown;
+
+static void slavio_powerdown_req(Notifier *n, void *opaque)
+{
+    qemu_irq_raise(slavio_system_powerdown);
+}
+
+static Notifier slavio_system_powerdown_notifier = {
+    .notify = slavio_powerdown_req
+};
+
 #define MISC_LEDS 0x01600000
 #define MISC_CFG  0x01800000
 #define MISC_DIAG 0x01a00000
@@ -514,7 +525,8 @@ static void slavio_misc_init(target_phys_addr_t base,
     }
     sysbus_connect_irq(s, 0, irq);
     sysbus_connect_irq(s, 1, fdc_tc);
-    qemu_system_powerdown = qdev_get_gpio_in(dev, 0);
+    slavio_system_powerdown = qdev_get_gpio_in(dev, 0);
+    qemu_register_powerdown_notifier(&slavio_system_powerdown_notifier);
 }
 
 static void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)
Signature · 1 line
1.7.11.4
#10 lore raw

PATCH v2 5/5 cleanup unused qemu_system_powerdown

In reply to Igor Mammedov

all deps that used qemu_system_powerdown are converted to notifiers, so remove it for have no use anymore

---
 sysemu.h | 2 --
 vl.c     | 3 ---
 2 files changed, 5 deletions(-)
sysemu.h +0 -2
index eb9a750..1093046 100644
@@ -9,7 +9,6 @@
 #include "qapi-types.h"
 #include "notify.h"
 #include "main-loop.h"
-#include "hw/irq.h"
 
 /* vl.c */
 
@@ -63,7 +62,6 @@ int qemu_reset_requested(void);
 int qemu_powerdown_requested(void);
 void qemu_system_killed(int signal, pid_t pid);
 void qemu_kill_report(void);
-extern qemu_irq qemu_system_powerdown;
 void qemu_devices_reset(void);
 void qemu_system_reset(bool report);
 
vl.c +0 -3
index 8dc4b4f..e0d1295 100644
@@ -1594,8 +1594,6 @@ void qemu_system_vmstop_request(RunState state)
     qemu_notify_event();
 }
 
-qemu_irq qemu_system_powerdown;
-
 static bool main_loop_should_exit(void)
 {
     RunState r;
@@ -1633,7 +1631,6 @@ static bool main_loop_should_exit(void)
     }
     if (qemu_powerdown_requested()) {
         qemu_system_powerdown();
-        qemu_irq_raise(qemu_system_powerdown);
     }
     if (qemu_vmstop_requested(&r)) {
         vm_stop(r);
Signature · 1 line
1.7.11.4
#1 lore raw

PATCH v2 1/5 introduce powerdown_notifiers

In reply to Igor Mammedov

notifier will be used for signaling powerdown request to guest in more general way and intended to replace very specific qemu_irq_rise(qemu_system_powerdown) and will allow to remove global variable qemu_system_powerdown.

v2:
do not make qemu_system_powerdown static,

---
 sysemu.h |  1 +
 vl.c     | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
sysemu.h +1 -0
index f765821..eb9a750 100644
@@ -53,6 +53,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
+void qemu_register_powerdown_notifier(Notifier *notifier);
 void qemu_system_debug_request(void);
 void qemu_system_vmstop_request(RunState reason);
 int qemu_shutdown_requested_get(void);
vl.c +14 -1
index 7c577fa..8dc4b4f 100644
@@ -1355,6 +1355,8 @@ static int powerdown_requested;
 static int debug_requested;
 static int suspend_requested;
 static int wakeup_requested;
+static NotifierList powerdown_notifiers =
+    NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
 static NotifierList suspend_notifiers =
     NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
 static NotifierList wakeup_notifiers =
@@ -1563,12 +1565,23 @@ void qemu_system_shutdown_request(void)
     qemu_notify_event();
 }
 
+static void qemu_system_powerdown(void)
+{
+    monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+    notifier_list_notify(&powerdown_notifiers, NULL);
+}
+
 void qemu_system_powerdown_request(void)
 {
     powerdown_requested = 1;
     qemu_notify_event();
 }
 
+void qemu_register_powerdown_notifier(Notifier *notifier)
+{
+    notifier_list_add(&powerdown_notifiers, notifier);
+}
+
 void qemu_system_debug_request(void)
 {
     debug_requested = 1;
@@ -1619,7 +1632,7 @@ static bool main_loop_should_exit(void)
         monitor_protocol_event(QEVENT_WAKEUP, NULL);
     }
     if (qemu_powerdown_requested()) {
-        monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+        qemu_system_powerdown();
         qemu_irq_raise(qemu_system_powerdown);
     }
     if (qemu_vmstop_requested(&r)) {
Signature · 1 line
1.7.11.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] introduce powerdown_notifiers

Am 29.08.2012 19:02, schrieb Igor Mammedov:

Quoted 8 lines

notifier will be used for signaling powerdown request to guest in more general way and intended to replace very specific qemu_irq_rise(qemu_system_powerdown) and will allow to remove global variable qemu_system_powerdown.

v2:
do not make qemu_system_powerdown static,

Is the "not" a typo or did you send the wrong patch? It seems to be static below.

Andreas

Quoted 66 lines
---
 sysemu.h |  1 +
 vl.c     | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
sysemu.h +1 -0
index f765821..eb9a750 100644
@@ -53,6 +53,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
+void qemu_register_powerdown_notifier(Notifier *notifier);
 void qemu_system_debug_request(void);
 void qemu_system_vmstop_request(RunState reason);
 int qemu_shutdown_requested_get(void);
vl.c +14 -1
index 7c577fa..8dc4b4f 100644
@@ -1355,6 +1355,8 @@ static int powerdown_requested;
 static int debug_requested;
 static int suspend_requested;
 static int wakeup_requested;
+static NotifierList powerdown_notifiers =
+    NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
 static NotifierList suspend_notifiers =
     NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
 static NotifierList wakeup_notifiers =
@@ -1563,12 +1565,23 @@ void qemu_system_shutdown_request(void)
     qemu_notify_event();
 }
 
+static void qemu_system_powerdown(void)
+{
+    monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+    notifier_list_notify(&powerdown_notifiers, NULL);
+}
+
 void qemu_system_powerdown_request(void)
 {
     powerdown_requested = 1;
     qemu_notify_event();
 }
 
+void qemu_register_powerdown_notifier(Notifier *notifier)
+{
+    notifier_list_add(&powerdown_notifiers, notifier);
+}
+
 void qemu_system_debug_request(void)
 {
     debug_requested = 1;
@@ -1619,7 +1632,7 @@ static bool main_loop_should_exit(void)
         monitor_protocol_event(QEVENT_WAKEUP, NULL);
     }
     if (qemu_powerdown_requested()) {
-        monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+        qemu_system_powerdown();
         qemu_irq_raise(qemu_system_powerdown);
     }
     if (qemu_vmstop_requested(&r)) {
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] introduce powerdown_notifiers

Quoted 6 lines · On Wed, 29 Aug 2012 19:06:45 +0200 Andreas Färber <[email protected]> wrote:

Am 29.08.2012 19:02, schrieb Igor Mammedov:

Quoted 5 lines

notifier will be used for signaling powerdown request to guest in more general way and intended to replace very specific qemu_irq_rise(qemu_system_powerdown) and will allow to remove global variable qemu_system_powerdown.

Quoted 6 lines
Quoted 3 lines

v2:
do not make qemu_system_powerdown static,

Is the "not" a typo or did you send the wrong patch? It seems to be static below.

Nope, it's not typo. There is global var qemu_system_powerdown, and in the first version I've changed it to static for no good reason and that killed bisectability of series. So I've reverted it to original state.

Quoted 75 lines

Andreas

Quoted 66 lines
---
 sysemu.h |  1 +
 vl.c     | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
sysemu.h +1 -0
index f765821..eb9a750 100644
@@ -53,6 +53,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
+void qemu_register_powerdown_notifier(Notifier *notifier);
 void qemu_system_debug_request(void);
 void qemu_system_vmstop_request(RunState reason);
 int qemu_shutdown_requested_get(void);
vl.c +14 -1
index 7c577fa..8dc4b4f 100644
@@ -1355,6 +1355,8 @@ static int powerdown_requested;
 static int debug_requested;
 static int suspend_requested;
 static int wakeup_requested;
+static NotifierList powerdown_notifiers =
+    NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
 static NotifierList suspend_notifiers =
     NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
 static NotifierList wakeup_notifiers =
@@ -1563,12 +1565,23 @@ void qemu_system_shutdown_request(void)
     qemu_notify_event();
 }
 
+static void qemu_system_powerdown(void)
+{
+    monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+    notifier_list_notify(&powerdown_notifiers, NULL);
+}
+
 void qemu_system_powerdown_request(void)
 {
     powerdown_requested = 1;
     qemu_notify_event();
 }
 
+void qemu_register_powerdown_notifier(Notifier *notifier)
+{
+    notifier_list_add(&powerdown_notifiers, notifier);
+}
+
 void qemu_system_debug_request(void)
 {
     debug_requested = 1;
@@ -1619,7 +1632,7 @@ static bool main_loop_should_exit(void)
         monitor_protocol_event(QEVENT_WAKEUP, NULL);
     }
     if (qemu_powerdown_requested()) {
-        monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+        qemu_system_powerdown();
         qemu_irq_raise(qemu_system_powerdown);
     }
     if (qemu_vmstop_requested(&r)) {
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 2 lines
Regards,
  Igor
#4 lore raw

Re: [Qemu-devel] [PATCH 1/5] introduce powerdown_notifiers

In reply to Andreas Färber
Quoted 51 lines · On Wed, 29 Aug 2012 19:06:45 +0200 Andreas Färber <[email protected]> wrote:

Am 29.08.2012 19:02, schrieb Igor Mammedov:

Quoted 8 lines

notifier will be used for signaling powerdown request to guest in more general way and intended to replace very specific qemu_irq_rise(qemu_system_powerdown) and will allow to remove global variable qemu_system_powerdown.

v2:
do not make qemu_system_powerdown static,

Is the "not" a typo or did you send the wrong patch? It seems to be static below.

Andreas

Quoted 36 lines
---
 sysemu.h |  1 +
 vl.c     | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
sysemu.h +1 -0
index f765821..eb9a750 100644
@@ -53,6 +53,7 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
+void qemu_register_powerdown_notifier(Notifier *notifier);
 void qemu_system_debug_request(void);
 void qemu_system_vmstop_request(RunState reason);
 int qemu_shutdown_requested_get(void);
vl.c +2 -0
index 7c577fa..8dc4b4f 100644
@@ -1355,6 +1355,8 @@ static int powerdown_requested;
 static int debug_requested;
 static int suspend_requested;
 static int wakeup_requested;
+static NotifierList powerdown_notifiers =
+    NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
 static NotifierList suspend_notifiers =
     NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
 static NotifierList wakeup_notifiers =
@@ -1563,12 +1565,23 @@ void qemu_system_shutdown_request(void)
     qemu_notify_event();
 }
 
Quoted 1 line

vl.c void qemu_system_shutdown_request(void) · line 1568

Quoted 1 line
vl.c +1 -0
+static void qemu_system_powerdown(void)

this is a bad naming that conflicts with global var qemu_system_powerdown, so bisectability of series is still broken.
perhaps qemu_do_system_powerdown() would be better for function name, although it doesn't match common name pattern used for this kind of functions.

Quoted 34 lines
Quoted 29 lines
vl.c +11 -1
+{
+    monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+    notifier_list_notify(&powerdown_notifiers, NULL);
+}
+
 void qemu_system_powerdown_request(void)
 {
     powerdown_requested = 1;
     qemu_notify_event();
 }
 
+void qemu_register_powerdown_notifier(Notifier *notifier)
+{
+    notifier_list_add(&powerdown_notifiers, notifier);
+}
+
 void qemu_system_debug_request(void)
 {
     debug_requested = 1;
@@ -1619,7 +1632,7 @@ static bool main_loop_should_exit(void)
         monitor_protocol_event(QEVENT_WAKEUP, NULL);
     }
     if (qemu_powerdown_requested()) {
-        monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+        qemu_system_powerdown();
         qemu_irq_raise(qemu_system_powerdown);
     }
     if (qemu_vmstop_requested(&r)) {
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 2 lines
Regards,
  Igor
#5 lore raw

Re: [Qemu-devel] [PATCH 1/5] introduce powerdown_notifiers

Il 30/08/2012 08:49, Igor Mammedov ha scritto:

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static void qemu_system_powerdown(void)

this is a bad naming that conflicts with global var qemu_system_powerdown, so bisectability of series is still broken.
perhaps qemu_do_system_powerdown() would be better for function name, although it doesn't match common name pattern used for this kind of functions.

Just inline the function in this patch, and uninline it later.

Paolo

#6 lore raw

Re: [Qemu-devel] [PATCH 1/5] introduce powerdown_notifiers

Quoted 9 lines · On Thu, 30 Aug 2012 09:41:55 +0200 Paolo Bonzini <[email protected]> wrote:

Il 30/08/2012 08:49, Igor Mammedov ha scritto:

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static void qemu_system_powerdown(void)

this is a bad naming that conflicts with global var qemu_system_powerdown, so bisectability of series is still broken.
perhaps qemu_do_system_powerdown() would be better for function name, although it doesn't match common name pattern used for this kind of functions.

Just inline the function in this patch, and uninline it later.

Thanks, fixed in https://github.com/imammedo/qemu/tree/cpu_as_device.WIP

Quoted 3 lines

Paolo

Signature · 2 lines
Regards,
  Igor