Skip to contentSkip to conversation

pc: Implement -no-hpet as sugar for -machine hpet=off

PATCH Superseded Eduardo Habkost 2 participants 5 messages Oct 20, 2020 – Oct 21, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: Implement -no-hpet as sugar for -machine hpet=off

Get rid of yet another global variable.

---
 include/hw/i386/pc.h  |  1 +
 include/hw/i386/x86.h |  3 ---
 hw/i386/pc.c          | 21 ++++++++++++++++++++-
 hw/i386/pc_piix.c     |  2 +-
 softmmu/vl.c          |  4 ++--
 5 files changed, 24 insertions(+), 7 deletions(-)
include/hw/i386/pc.h +1 -0
index 84639d0ebc..911e460097 100644
@@ -43,6 +43,7 @@ typedef struct PCMachineState {
     bool smbus_enabled;
     bool sata_enabled;
     bool pit_enabled;
+    bool hpet_enabled;
 
     /* NUMA information: */
     uint64_t numa_nodes;
include/hw/i386/x86.h +0 -3
index d5dcf7a07f..4e66a15ff5 100644
@@ -124,7 +124,4 @@ qemu_irq x86_allocate_cpu_irq(void);
 void gsi_handler(void *opaque, int n, int level);
 void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name);
 
-/* hpet.c */
-extern int no_hpet;
-
 #endif
hw/i386/pc.c +20 -1
index 4e323755d0..ff863231e4 100644
@@ -1142,7 +1142,8 @@ void pc_basic_device_init(struct PCMachineState *pcms,
      * Without KVM_CAP_PIT_STATE2, we cannot switch off the in-kernel PIT
      * when the HPET wants to take over. Thus we have to disable the latter.
      */
-    if (!no_hpet && (!kvm_irqchip_in_kernel() || kvm_has_pit_state2())) {
+    if (pcms->hpet_enabled && (!kvm_irqchip_in_kernel() ||
+                                kvm_has_pit_state2())) {
         hpet = qdev_try_new(TYPE_HPET);
         if (hpet) {
             /* For pc-piix-*, hpet's intcap is always IRQ2. For pc-q35-1.7
@@ -1535,6 +1536,20 @@ static void pc_machine_set_pit(Object *obj, bool value, Error **errp)
     pcms->pit_enabled = value;
 }
 
+static bool pc_machine_get_hpet(Object *obj, Error **errp)
+{
+    PCMachineState *pcms = PC_MACHINE(obj);
+
+    return pcms->hpet_enabled;
+}
+
+static void pc_machine_set_hpet(Object *obj, bool value, Error **errp)
+{
+    PCMachineState *pcms = PC_MACHINE(obj);
+
+    pcms->hpet_enabled = value;
+}
+
 static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v,
                                             const char *name, void *opaque,
                                             Error **errp)
@@ -1585,6 +1600,7 @@ static void pc_machine_initfn(Object *obj)
     pcms->smbus_enabled = true;
     pcms->sata_enabled = true;
     pcms->pit_enabled = true;
+    pcms->hpet_enabled = true;
 
     pc_system_flash_create(pcms);
     pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
@@ -1705,6 +1721,9 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
 
     object_class_property_add_bool(oc, PC_MACHINE_PIT,
         pc_machine_get_pit, pc_machine_set_pit);
+
+    object_class_property_add_bool(oc, "hpet",
+        pc_machine_get_hpet, pc_machine_set_hpet);
 }
 
 static const TypeInfo pc_machine_info = {
hw/i386/pc_piix.c +1 -1
index 0cf22a57ad..13d1628f13 100644
@@ -216,7 +216,7 @@ static void pc_init1(MachineState *machine,
         i440fx_state = NULL;
         isa_bus = isa_bus_new(NULL, get_system_memory(), system_io,
                               &error_abort);
-        no_hpet = 1;
+        pcms->hpet_enabled = false;
     }
     isa_bus_irqs(isa_bus, x86ms->gsi);
 
softmmu/vl.c +2 -2
index cb476aa70b..c2281f45a8 100644
@@ -146,7 +146,6 @@ static Chardev **serial_hds;
 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 int win2k_install_hack = 0;
 int singlestep = 0;
-int no_hpet = 0;
 int fd_bootchk = 1;
 static int no_reboot;
 int no_shutdown = 0;
@@ -3562,7 +3561,8 @@ void qemu_init(int argc, char **argv, char **envp)
                 qemu_opts_parse_noisily(olist, "acpi=off", false);
                 break;
             case QEMU_OPTION_no_hpet:
-                no_hpet = 1;
+                olist = qemu_find_opts("machine");
+                qemu_opts_parse_noisily(olist, "hpet=off", false);
                 break;
             case QEMU_OPTION_no_reboot:
                 no_reboot = 1;
Signature · 1 line
2.28.0
#2 lore raw
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Eduardo Habkost

+ pcms->hpet_enabled = true;

Should this be within #ifdef CONFIG_HPET? [...]

Oops, I wasn't aware of CONFIG_HPET, and hadn't noticed that pc_basic_device_init() uses qdev_try_new(). I agree that not failing if hpet=on is explicitly set and CONFIG_HPET=n is wrong.

Supporting a "require hpet to be on" use case would be a new feature and out of scope of this work, though. I will just rename the property to "allow-hpet". We can still implement a OnOfAuto "hpet" property in the future, if we think it's useful.

Quoted 3 lines
                                    [...]  Otherwise

Thanks!

Signature · 1 line
Eduardo
#3 lore raw
Quoted 2 lines · Eduardo Habkost
Quoted 1 line

Should this be within #ifdef CONFIG_HPET? [...]

Oops, I wasn't aware of CONFIG_HPET

That's just a config-devices.h (aka CONFIG_DEVICES) definition.

Quoted 8 lines

, and hadn't noticed that
pc_basic_device_init() uses qdev_try_new(). I agree that not failing if hpet=on is explicitly set and CONFIG_HPET=n is wrong.

Supporting a "require hpet to be on" use case would be a new feature and out of scope of this work, though. I will just rename the property to "allow-hpet". We can still implement a OnOfAuto "hpet" property in the future, if we think it's useful.

You don't need OnOffAuto; you can just change the qdev_try_new() to qdev_new() if you default it to true only if CONFIG_HPET is defined. It should work properly, defaulting to on/off depending on CONFIG_HPET and failing if hpet=on is explicitly set with CONFIG_HPET=n.

Paolo

#4 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 2 lines · Eduardo Habkost
Quoted 1 line

Should this be within #ifdef CONFIG_HPET? [...]

Oops, I wasn't aware of CONFIG_HPET

That's just a config-devices.h (aka CONFIG_DEVICES) definition.

Quoted 8 lines

, and hadn't noticed that
pc_basic_device_init() uses qdev_try_new(). I agree that not failing if hpet=on is explicitly set and CONFIG_HPET=n is wrong.

Supporting a "require hpet to be on" use case would be a new feature and out of scope of this work, though. I will just rename the property to "allow-hpet". We can still implement a OnOfAuto "hpet" property in the future, if we think it's useful.

Quoted 4 lines

You don't need OnOffAuto; you can just change the qdev_try_new() to qdev_new() if you default it to true only if CONFIG_HPET is defined. It should work properly, defaulting to on/off depending on CONFIG_HPET and failing if hpet=on is explicitly set with CONFIG_HPET=n.

Makes sense, except for the fact that qdev_new(TYPE_HPET) will abort if CONFIG_HPET=n. But we can just use qdev_try_new() and error out if it fails.

Signature · 1 line
Eduardo