Skip to contentSkip to conversation

hw/rtc/mc146818rtc: Make this rtc device target independent

PATCH In review Thomas Huth 2 participants 6 messages Dec 29, 2022 – Jan 2, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 hw/rtc/mc146818rtc: Make this rtc device target independent

The only reason for this code being target dependent is the apic-related code in rtc_policy_slew_deliver_irq(). Since these apic functions are rather simple, we can easily move them into a new, separate file (apic_irqcount.c) which will always be compiled and linked if either APIC or the mc146818 device are required. This way we can get rid of the #ifdef TARGET_I386 switches in mc146818rtc.c and declare it in the softmmu_ss instead of specific_ss, so that the code only gets compiled once for all targets.

---
v4: Check for QEMU_ARCH_I386 instead of looking for an APIC

 include/hw/i386/apic.h          |  1 +
 include/hw/i386/apic_internal.h |  1 -
 include/hw/rtc/mc146818rtc.h    |  1 +
 hw/intc/apic_common.c           | 27 -----------------
 hw/intc/apic_irqcount.c         | 53 +++++++++++++++++++++++++++++++++
 hw/rtc/mc146818rtc.c            | 26 +++++-----------
 hw/intc/meson.build             |  6 +++-
 hw/rtc/meson.build              |  3 +-
 8 files changed, 69 insertions(+), 49 deletions(-)
 create mode 100644 hw/intc/apic_irqcount.c
include/hw/i386/apic.h +1 -0
index da1d2fe155..96b9939425 100644
@@ -9,6 +9,7 @@ int apic_accept_pic_intr(DeviceState *s);
 void apic_deliver_pic_intr(DeviceState *s, int level);
 void apic_deliver_nmi(DeviceState *d);
 int apic_get_interrupt(DeviceState *s);
+void apic_report_irq_delivered(int delivered);
 void apic_reset_irq_delivered(void);
 int apic_get_irq_delivered(void);
 void cpu_set_apic_base(DeviceState *s, uint64_t val);
include/hw/i386/apic_internal.h +0 -1
index c175e7e718..e61ad04769 100644
@@ -199,7 +199,6 @@ typedef struct VAPICState {
 
 extern bool apic_report_tpr_access;
 
-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);
 void apic_enable_vapic(DeviceState *d, hwaddr paddr);
include/hw/rtc/mc146818rtc.h +1 -0
index 1db0fcee92..45bcd6f040 100644
@@ -55,5 +55,6 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year,
                              qemu_irq intercept_irq);
 void rtc_set_memory(ISADevice *dev, int addr, int val);
 int rtc_get_memory(ISADevice *dev, int addr);
+void qmp_rtc_reset_reinjection(Error **errp);
 
 #endif /* HW_RTC_MC146818RTC_H */
hw/intc/apic_common.c +0 -27
index 2a20982066..b0f85f9384 100644
@@ -33,7 +33,6 @@
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 
-static int apic_irq_delivered;
 bool apic_report_tpr_access;
 
 void cpu_set_apic_base(DeviceState *dev, uint64_t val)
@@ -122,32 +121,6 @@ void apic_handle_tpr_access_report(DeviceState *dev, target_ulong ip,
     vapic_report_tpr_access(s->vapic, CPU(s->cpu), ip, access);
 }
 
-void apic_report_irq_delivered(int delivered)
-{
-    apic_irq_delivered += delivered;
-
-    trace_apic_report_irq_delivered(apic_irq_delivered);
-}
-
-void apic_reset_irq_delivered(void)
-{
-    /* Copy this into a local variable to encourage gcc to emit a plain
-     * register for a sys/sdt.h marker.  For details on this workaround, see:
-     * https://sourceware.org/bugzilla/show_bug.cgi?id=13296
-     */
-    volatile int a_i_d = apic_irq_delivered;
-    trace_apic_reset_irq_delivered(a_i_d);
-
-    apic_irq_delivered = 0;
-}
-
-int apic_get_irq_delivered(void)
-{
-    trace_apic_get_irq_delivered(apic_irq_delivered);
-
-    return apic_irq_delivered;
-}
-
 void apic_deliver_nmi(DeviceState *dev)
 {
     APICCommonState *s = APIC_COMMON(dev);
hw/intc/apic_irqcount.c new file +53 -0

53 lines not on this page · raw message

hw/rtc/mc146818rtc.c +8 -18
index 1ebb412479..5477ff6dbb 100644
@@ -31,6 +31,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "qemu/timer.h"
+#include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/replay.h"
 #include "sysemu/reset.h"
@@ -43,11 +44,7 @@
 #include "qapi/qapi-events-misc.h"
 #include "qapi/visitor.h"
 #include "hw/rtc/mc146818rtc_regs.h"
-
-#ifdef TARGET_I386
-#include "qapi/qapi-commands-misc-target.h"
 #include "hw/i386/apic.h"
-#endif
 
 //#define DEBUG_CMOS
 //#define DEBUG_COALESCED
@@ -112,7 +109,6 @@ static void rtc_coalesced_timer_update(RTCState *s)
 static QLIST_HEAD(, RTCState) rtc_devices =
     QLIST_HEAD_INITIALIZER(rtc_devices);
 
-#ifdef TARGET_I386
 void qmp_rtc_reset_reinjection(Error **errp)
 {
     RTCState *s;
@@ -145,13 +141,6 @@ static void rtc_coalesced_timer(void *opaque)
 
     rtc_coalesced_timer_update(s);
 }
-#else
-static bool rtc_policy_slew_deliver_irq(RTCState *s)
-{
-    assert(0);
-    return false;
-}
-#endif
 
 static uint32_t rtc_periodic_clock_ticks(RTCState *s)
 {
@@ -922,14 +911,15 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
     rtc_set_date_from_host(isadev);
 
     switch (s->lost_tick_policy) {
-#ifdef TARGET_I386
-    case LOST_TICK_POLICY_SLEW:
-        s->coalesced_timer =
-            timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
-        break;
-#endif
     case LOST_TICK_POLICY_DISCARD:
         break;
+    case LOST_TICK_POLICY_SLEW:
+        /* Slew tick policy is only available on x86 */
+        if (arch_type == QEMU_ARCH_I386) {
+            s->coalesced_timer = timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
+            break;
+        }
+        /* fallthrough */
     default:
         error_setg(errp, "Invalid lost tick policy.");
         return;
hw/intc/meson.build +5 -1
index bcbf22ff51..036ad1936b 100644
@@ -25,8 +25,12 @@ softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_intc.c'))
 softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-ipi.c'))
 softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP_PMU', if_true: files('xlnx-pmu-iomod-intc.c'))
 
-specific_ss.add(when: 'CONFIG_ALLWINNER_A10_PIC', if_true: files('allwinner-a10-pic.c'))
+if config_all_devices.has_key('CONFIG_APIC') or config_all_devices.has_key('CONFIG_MC146818RTC')
+    softmmu_ss.add(files('apic_irqcount.c'))
+endif
 specific_ss.add(when: 'CONFIG_APIC', if_true: files('apic.c', 'apic_common.c'))
+
+specific_ss.add(when: 'CONFIG_ALLWINNER_A10_PIC', if_true: files('allwinner-a10-pic.c'))
 specific_ss.add(when: 'CONFIG_ARM_GIC', if_true: files('arm_gicv3_cpuif_common.c'))
 specific_ss.add(when: 'CONFIG_ARM_GICV3_TCG', if_true: files('arm_gicv3_cpuif.c'))
 specific_ss.add(when: 'CONFIG_ARM_GIC_KVM', if_true: files('arm_gic_kvm.c'))
hw/rtc/meson.build +1 -2
index dc33973384..34a4d316fa 100644
@@ -13,5 +13,4 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_rtc.c'))
 softmmu_ss.add(when: 'CONFIG_GOLDFISH_RTC', if_true: files('goldfish_rtc.c'))
 softmmu_ss.add(when: 'CONFIG_LS7A_RTC', if_true: files('ls7a_rtc.c'))
 softmmu_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-rtc.c'))
-
-specific_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'))
+softmmu_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'))
Signature · 1 line
2.31.1
#1 lore raw

Am 29. Dezember 2022 10:58:48 UTC schrieb Thomas Huth <[email protected]>:

Quoted 8 lines

The only reason for this code being target dependent is the apic-related code in rtc_policy_slew_deliver_irq(). Since these apic functions are rather simple, we can easily move them into a new, separate file (apic_irqcount.c) which will always be compiled and linked if either APIC or the mc146818 device are required. This way we can get rid of the #ifdef TARGET_I386 switches in mc146818rtc.c and declare it in the softmmu_ss instead of specific_ss, so that the code only gets compiled once for all targets.

Quoted 5 lines

---
v4: Check for QEMU_ARCH_I386 instead of looking for an APIC

Can we find a more appropriate name for the helpers than "apic" then? If the slew tick policy is a workaround for (x86-) KVM I propose to do s/apic/kvm/ while still compiling for every target.

Quoted 202 lines
include/hw/i386/apic.h          |  1 +
include/hw/i386/apic_internal.h |  1 -
include/hw/rtc/mc146818rtc.h    |  1 +
hw/intc/apic_common.c           | 27 -----------------
hw/intc/apic_irqcount.c         | 53 +++++++++++++++++++++++++++++++++
hw/rtc/mc146818rtc.c            | 26 +++++-----------
hw/intc/meson.build             |  6 +++-
hw/rtc/meson.build              |  3 +-
8 files changed, 69 insertions(+), 49 deletions(-)

create mode 100644 hw/intc/apic_irqcount.c

include/hw/i386/apic.h +1 -0
index da1d2fe155..96b9939425 100644
@@ -9,6 +9,7 @@ int apic_accept_pic_intr(DeviceState *s);
 void apic_deliver_pic_intr(DeviceState *s, int level);
 void apic_deliver_nmi(DeviceState *d);
 int apic_get_interrupt(DeviceState *s);
+void apic_report_irq_delivered(int delivered);
 void apic_reset_irq_delivered(void);
 int apic_get_irq_delivered(void);
 void cpu_set_apic_base(DeviceState *s, uint64_t val);
include/hw/i386/apic_internal.h +0 -1
index c175e7e718..e61ad04769 100644
@@ -199,7 +199,6 @@ typedef struct VAPICState {
 
 extern bool apic_report_tpr_access;
 
-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);
 void apic_enable_vapic(DeviceState *d, hwaddr paddr);
include/hw/rtc/mc146818rtc.h +1 -0
index 1db0fcee92..45bcd6f040 100644
@@ -55,5 +55,6 @@ ISADevice *mc146818_rtc_init(ISABus *bus, int base_year,
                             qemu_irq intercept_irq);
 void rtc_set_memory(ISADevice *dev, int addr, int val);
 int rtc_get_memory(ISADevice *dev, int addr);
+void qmp_rtc_reset_reinjection(Error **errp);
 
 #endif /* HW_RTC_MC146818RTC_H */
hw/intc/apic_common.c +0 -27
index 2a20982066..b0f85f9384 100644
@@ -33,7 +33,6 @@
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
 
-static int apic_irq_delivered;
 bool apic_report_tpr_access;
 
 void cpu_set_apic_base(DeviceState *dev, uint64_t val)
@@ -122,32 +121,6 @@ void apic_handle_tpr_access_report(DeviceState *dev, target_ulong ip,
    vapic_report_tpr_access(s->vapic, CPU(s->cpu), ip, access);
 }
 
-void apic_report_irq_delivered(int delivered)
-{
-    apic_irq_delivered += delivered;
-
-    trace_apic_report_irq_delivered(apic_irq_delivered);
-}
-
-void apic_reset_irq_delivered(void)
-{
-    /* Copy this into a local variable to encourage gcc to emit a plain
-     * register for a sys/sdt.h marker.  For details on this workaround, see:
-     * https://sourceware.org/bugzilla/show_bug.cgi?id=13296
-     */
-    volatile int a_i_d = apic_irq_delivered;
-    trace_apic_reset_irq_delivered(a_i_d);
-
-    apic_irq_delivered = 0;
-}
-
-int apic_get_irq_delivered(void)
-{
-    trace_apic_get_irq_delivered(apic_irq_delivered);
-
-    return apic_irq_delivered;
-}
-
 void apic_deliver_nmi(DeviceState *dev)
 {
    APICCommonState *s = APIC_COMMON(dev);
hw/intc/apic_irqcount.c new file +53 -0
new file mode 100644
index 0000000000..0aadef1cb5
@@ -0,0 +1,53 @@
+/*
+ * APIC support - functions for counting the delivered IRQs.
+ * (this code is in a separate file since it is used from the
+ * mc146818rtc code on targets without APIC, too)
+ *
+ *  Copyright (c) 2011      Jan Kiszka, Siemens AG
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#include "qemu/osdep.h"
+#include "hw/i386/apic.h"
+#include "trace.h"
+
+static int apic_irq_delivered;
+
+void apic_report_irq_delivered(int delivered)
+{
+    apic_irq_delivered += delivered;
+
+    trace_apic_report_irq_delivered(apic_irq_delivered);
+}
+
+void apic_reset_irq_delivered(void)
+{
+    /*
+     * Copy this into a local variable to encourage gcc to emit a plain
+     * register for a sys/sdt.h marker.  For details on this workaround, see:
+     * https://sourceware.org/bugzilla/show_bug.cgi?id=13296
+     */
+    volatile int a_i_d = apic_irq_delivered;
+    trace_apic_reset_irq_delivered(a_i_d);
+
+    apic_irq_delivered = 0;
+}
+
+int apic_get_irq_delivered(void)
+{
+    trace_apic_get_irq_delivered(apic_irq_delivered);
+
+    return apic_irq_delivered;
+}
hw/rtc/mc146818rtc.c +1 -4
index 1ebb412479..5477ff6dbb 100644
@@ -31,6 +31,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "qemu/timer.h"
+#include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/replay.h"
 #include "sysemu/reset.h"
@@ -43,11 +44,7 @@
 #include "qapi/qapi-events-misc.h"
 #include "qapi/visitor.h"
 #include "hw/rtc/mc146818rtc_regs.h"
-
-#ifdef TARGET_I386
-#include "qapi/qapi-commands-misc-target.h"
 #include "hw/i386/apic.h"
-#endif
 
 //#define DEBUG_CMOS
 //#define DEBUG_COALESCED
@@ -112,7 +109,6 @@ static void rtc_coalesced_timer_update(RTCState *s)

static QLIST_HEAD(, RTCState) rtc_devices =

    QLIST_HEAD_INITIALIZER(rtc_devices);

-#ifdef TARGET_I386
void qmp_rtc_reset_reinjection(Error **errp)

{
    RTCState *s;
hw/rtc/mc146818rtc.c +0 -8
@@ -145,13 +141,6 @@ static void rtc_coalesced_timer(void *opaque)
 
    rtc_coalesced_timer_update(s);
 }
-#else
-static bool rtc_policy_slew_deliver_irq(RTCState *s)
-{
-    assert(0);
-    return false;
-}
-#endif
 
 static uint32_t rtc_periodic_clock_ticks(RTCState *s)
 {
@@ -922,14 +911,15 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
    rtc_set_date_from_host(isadev);
 
    switch (s->lost_tick_policy) {
-#ifdef TARGET_I386

hw/rtc/mc146818rtc.c static void rtc_realizefn(DeviceState *dev, Error **errp) · line 918

Quoted 10 lines
hw/rtc/mc146818rtc.c +3 -5
-    case LOST_TICK_POLICY_SLEW:
-        s->coalesced_timer =
-            timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
-        break;
-#endif
    case LOST_TICK_POLICY_DISCARD:
        break;
+    case LOST_TICK_POLICY_SLEW:
+        /* Slew tick policy is only available on x86 */
+        if (arch_type == QEMU_ARCH_I386) {

This reflects the intention much better than before, which is nice.

How does arch_type play together with qemu-system-all? IIUC it should be possible to load all arch backends simultaneously while arch_type is an external symbol defined by each arch backend differently. So this seems to conflict.

Can we just add a property such as "slew-tick-policy-available" instead? It should default to false and all x86 machines would need to opt in explicitly. We could even error out in rtc_realize() if an attempt is made to enable the workaround although not available.

I still wonder if the slew tick policy is a workaround specific for x86-KVM. If so, we might only set the property to true if KVM is enabled.

Best regards,
Bernhard

Quoted 36 lines
hw/rtc/mc146818rtc.c +4 -0
+            s->coalesced_timer = timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
+            break;
+        }
+        /* fallthrough */
    default:
        error_setg(errp, "Invalid lost tick policy.");
        return;
hw/intc/meson.build +5 -1
index bcbf22ff51..036ad1936b 100644
@@ -25,8 +25,12 @@ softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_intc.c'))
 softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-ipi.c'))
 softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP_PMU', if_true: files('xlnx-pmu-iomod-intc.c'))
 
-specific_ss.add(when: 'CONFIG_ALLWINNER_A10_PIC', if_true: files('allwinner-a10-pic.c'))
+if config_all_devices.has_key('CONFIG_APIC') or config_all_devices.has_key('CONFIG_MC146818RTC')
+    softmmu_ss.add(files('apic_irqcount.c'))
+endif
 specific_ss.add(when: 'CONFIG_APIC', if_true: files('apic.c', 'apic_common.c'))
+
+specific_ss.add(when: 'CONFIG_ALLWINNER_A10_PIC', if_true: files('allwinner-a10-pic.c'))
 specific_ss.add(when: 'CONFIG_ARM_GIC', if_true: files('arm_gicv3_cpuif_common.c'))
 specific_ss.add(when: 'CONFIG_ARM_GICV3_TCG', if_true: files('arm_gicv3_cpuif.c'))
 specific_ss.add(when: 'CONFIG_ARM_GIC_KVM', if_true: files('arm_gic_kvm.c'))
hw/rtc/meson.build +1 -2
index dc33973384..34a4d316fa 100644
@@ -13,5 +13,4 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_rtc.c'))
 softmmu_ss.add(when: 'CONFIG_GOLDFISH_RTC', if_true: files('goldfish_rtc.c'))
 softmmu_ss.add(when: 'CONFIG_LS7A_RTC', if_true: files('ls7a_rtc.c'))
 softmmu_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-rtc.c'))
-
-specific_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'))
+softmmu_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'))
#2 lore raw
Quoted 11 lines · Bernhard Beschow

Am 29. Dezember 2022 10:58:48 UTC schrieb Thomas Huth <[email protected]>:

Quoted 8 lines

The only reason for this code being target dependent is the apic-related code in rtc_policy_slew_deliver_irq(). Since these apic functions are rather simple, we can easily move them into a new, separate file (apic_irqcount.c) which will always be compiled and linked if either APIC or the mc146818 device are required. This way we can get rid of the #ifdef TARGET_I386 switches in mc146818rtc.c and declare it in the softmmu_ss instead of specific_ss, so that the code only gets compiled once for all targets.

Quoted 7 lines
Quoted 5 lines

---
v4: Check for QEMU_ARCH_I386 instead of looking for an APIC

Can we find a more appropriate name for the helpers than "apic" then? If the slew tick policy is a workaround for (x86-) KVM I propose to do s/apic/kvm/ while still compiling for every target.

Yes, since the IRQ-counting is also used by the old i8259 PIC, it likely makes sense to rename the functions.

Quoted 20 lines
Quoted 7 lines

static uint32_t rtc_periodic_clock_ticks(RTCState *s) {

hw/rtc/mc146818rtc.c +0 -1
@@ -922,14 +911,15 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
     rtc_set_date_from_host(isadev);
 
     switch (s->lost_tick_policy) {
-#ifdef TARGET_I386

hw/rtc/mc146818rtc.c static void rtc_realizefn(DeviceState *dev, Error **errp) · line 918

Quoted 10 lines
hw/rtc/mc146818rtc.c +3 -5
-    case LOST_TICK_POLICY_SLEW:
-        s->coalesced_timer =
-            timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
-        break;
-#endif
     case LOST_TICK_POLICY_DISCARD:
         break;
+    case LOST_TICK_POLICY_SLEW:
+        /* Slew tick policy is only available on x86 */
+        if (arch_type == QEMU_ARCH_I386) {

This reflects the intention much better than before, which is nice.

Quoted 1 line

How does arch_type play together with qemu-system-all? IIUC it should be possible to load all arch backends simultaneously while arch_type is an external symbol defined by each arch backend differently. So this seems to conflict.

I assume that there still will be a main arch_type for the current selected machine? ... not sure how this will exactly work, though ...

Quoted 1 line

Can we just add a property such as "slew-tick-policy-available" instead? It should default to false and all x86 machines would need to opt in explicitly.

Sounds like a good idea, it's certainly better than checking arch_type here ... I'll give it a try, thanks!

Thomas

#3 lore raw
Quoted 3 lines · Thomas Huth
Quoted 2 lines · Bernhard Beschow

Am 29. Dezember 2022 10:58:48 UTC schrieb Thomas Huth <[email protected]>:

[...]

Quoted 21 lines
Quoted 21 lines
Quoted 13 lines

static uint32_t rtc_periodic_clock_ticks(RTCState *s) {

hw/rtc/mc146818rtc.c +0 -6
@@ -922,14 +911,15 @@ static void rtc_realizefn(DeviceState *dev, Error 
 **errp)
      rtc_set_date_from_host(isadev);
 
      switch (s->lost_tick_policy) {
-#ifdef TARGET_I386
-    case LOST_TICK_POLICY_SLEW:
-        s->coalesced_timer =
-            timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
-        break;
-#endif
Quoted 5 lines

     case LOST_TICK_POLICY_DISCARD:
         break;
+    case LOST_TICK_POLICY_SLEW:
+        /* Slew tick policy is only available on x86 */ +        if (arch_type == QEMU_ARCH_I386) {

This reflects the intention much better than before, which is nice.

Quoted 7 lines
Quoted 1 line

How does arch_type play together with qemu-system-all? IIUC it should be possible to load all arch backends simultaneously while arch_type is an external symbol defined by each arch backend differently. So this seems to conflict.

I assume that there still will be a main arch_type for the current selected machine? ... not sure how this will exactly work, though ...

Quoted 1 line

Can we just add a property such as "slew-tick-policy-available" instead? It should default to false and all x86 machines would need to opt in explicitly.

Sounds like a good idea, it's certainly better than checking arch_type here ... I'll give it a try, thanks!

I've now had a look at this, and it's also getting ugly: Since the property has to be set before realize() is done, the setting of the property has to be added to the mc146818_rtc_init() function. Thus this function would need a new parameter - and it then needs to be changed all over the place, i.e. also for all the non-x86 machines, defeating the idea of a default value...

Maybe it makes more sense to check for a TYPE_X86_MACHINE machine type instead?

Thomas

#4 lore raw

Am 2. Januar 2023 16:09:08 UTC schrieb Thomas Huth <[email protected]>:

Quoted 29 lines · Thomas Huth
Quoted 3 lines · Bernhard Beschow
Quoted 2 lines

Am 29. Dezember 2022 10:58:48 UTC schrieb Thomas Huth <[email protected]>:

[...]

Quoted 24 lines
Quoted 20 lines
Quoted 12 lines

static uint32_t rtc_periodic_clock_ticks(RTCState *s) {

hw/rtc/mc146818rtc.c +0 -6
@@ -922,14 +911,15 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
      rtc_set_date_from_host(isadev);
 
      switch (s->lost_tick_policy) {
-#ifdef TARGET_I386
-    case LOST_TICK_POLICY_SLEW:
-        s->coalesced_timer =
-            timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
-        break;
-#endif
Quoted 5 lines

     case LOST_TICK_POLICY_DISCARD:
         break;
+    case LOST_TICK_POLICY_SLEW:
+        /* Slew tick policy is only available on x86 */ +        if (arch_type == QEMU_ARCH_I386) {

This reflects the intention much better than before, which is nice.

Quoted 1 line

How does arch_type play together with qemu-system-all? IIUC it should be possible to load all arch backends simultaneously while arch_type is an external symbol defined by each arch backend differently. So this seems to conflict.

I assume that there still will be a main arch_type for the current selected machine? ... not sure how this will exactly work, though ...

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Can we just add a property such as "slew-tick-policy-available" instead? It should default to false and all x86 machines would need to opt in explicitly.

Sounds like a good idea, it's certainly better than checking arch_type here ... I'll give it a try, thanks!

I've now had a look at this, and it's also getting ugly: Since the property has to be set before realize() is done, the setting of the property has to be added to the mc146818_rtc_init() function. Thus this function would need a new parameter - and it then needs to be changed all over the place, i.e. also for all the non-x86 machines, defeating the idea of a default value...

Maybe it makes more sense to check for a TYPE_X86_MACHINE machine type instead?

Maybe you could base your patch on https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg03795.html ? This patch looks like it should get you covered and is part of my PIIX consolidation series [1] which seems to be ready to be queued into Phil's mips-next tree. My series is currently just blocked by a MIPS-related regression.

Best regards,
Bernhard

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg03788.html

Quoted 3 lines

Thomas

#5 lore raw
Quoted 34 lines · Bernhard Beschow

Am 2. Januar 2023 16:09:08 UTC schrieb Thomas Huth <[email protected]>:

Quoted 31 lines · Thomas Huth
Quoted 3 lines · Bernhard Beschow
Quoted 2 lines

Am 29. Dezember 2022 10:58:48 UTC schrieb Thomas Huth <[email protected]>:

[...]

Quoted 26 lines
Quoted 20 lines
Quoted 7 lines

static uint32_t rtc_periodic_clock_ticks(RTCState *s) {

hw/rtc/mc146818rtc.c +0 -1
@@ -922,14 +911,15 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
      rtc_set_date_from_host(isadev);
 
      switch (s->lost_tick_policy) {
-#ifdef TARGET_I386

hw/rtc/mc146818rtc.c static void rtc_realizefn(DeviceState *dev, Error **errp) · line 918

Quoted 10 lines
hw/rtc/mc146818rtc.c +3 -5
-    case LOST_TICK_POLICY_SLEW:
-        s->coalesced_timer =
-            timer_new_ns(rtc_clock, rtc_coalesced_timer, s);
-        break;
-#endif
      case LOST_TICK_POLICY_DISCARD:
          break;
+    case LOST_TICK_POLICY_SLEW:
+        /* Slew tick policy is only available on x86 */
+        if (arch_type == QEMU_ARCH_I386) {

This reflects the intention much better than before, which is nice.

Quoted 1 line

How does arch_type play together with qemu-system-all? IIUC it should be possible to load all arch backends simultaneously while arch_type is an external symbol defined by each arch backend differently. So this seems to conflict.

I assume that there still will be a main arch_type for the current selected machine? ... not sure how this will exactly work, though ...

Quoted 1 line

Can we just add a property such as "slew-tick-policy-available" instead? It should default to false and all x86 machines would need to opt in explicitly.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Sounds like a good idea, it's certainly better than checking arch_type here ... I'll give it a try, thanks!

I've now had a look at this, and it's also getting ugly: Since the property has to be set before realize() is done, the setting of the property has to be added to the mc146818_rtc_init() function. Thus this function would need a new parameter - and it then needs to be changed all over the place, i.e. also for all the non-x86 machines, defeating the idea of a default value...

Maybe it makes more sense to check for a TYPE_X86_MACHINE machine type instead?

Maybe you could base your patch on https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg03795.html ?

That would help, indeed. ... OK, then let's postpone my clean-up until your series has landed.

Thomas