Skip to contentSkip to conversation

hw/timer: Reduce 'hw/ptimer.h' inclusion

PATCH In review Philippe Mathieu-Daudé 4 participants 11 messages Feb 17, 2023 – Feb 23, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover hw/timer: Reduce 'hw/ptimer.h' inclusion

Yet another "try to reduce build-time" series.

Philippe Mathieu-Daudé (2):
qemu/typedefs: Sort in case-insensitive alphabetical order (again) hw/timer: Reduce 'hw/ptimer.h' inclusion

 hw/display/xlnx_dp.c                     |  1 +
 hw/net/can/xlnx-zynqmp-can.c             |  1 +
 hw/net/fsl_etsec/etsec.h                 |  3 +--
 hw/timer/allwinner-a10-pit.c             |  1 +
 hw/timer/arm_mptimer.c                   |  4 ++--
 hw/timer/armv7m_systick.c                |  1 +
 hw/timer/cmsdk-apb-dualtimer.c           |  1 +
 hw/timer/cmsdk-apb-timer.c               |  1 +
 hw/timer/grlib_gptimer.c                 |  2 +-
 hw/timer/imx_epit.c                      |  1 +
 hw/timer/imx_gpt.c                       |  1 +
 hw/timer/mss-timer.c                     |  1 +
 hw/watchdog/cmsdk-apb-watchdog.c         |  1 +
 hw/watchdog/wdt_imx2.c                   |  1 +
 include/hw/display/xlnx_dp.h             |  1 -
 include/hw/dma/xlnx_csu_dma.h            |  1 -
 include/hw/net/xlnx-zynqmp-can.h         |  1 -
 include/hw/ptimer.h                      |  1 -
 include/hw/timer/allwinner-a10-pit.h     |  1 -
 include/hw/timer/arm_mptimer.h           |  2 +-
 include/hw/timer/armv7m_systick.h        |  1 -
 include/hw/timer/cmsdk-apb-dualtimer.h   |  3 +--
 include/hw/timer/cmsdk-apb-timer.h       |  3 +--
 include/hw/timer/digic-timer.h           |  1 -
 include/hw/timer/imx_epit.h              |  1 -
 include/hw/timer/imx_gpt.h               |  1 -
 include/hw/timer/mss-timer.h             |  1 -
 include/hw/watchdog/cmsdk-apb-watchdog.h |  3 +--
 include/hw/watchdog/wdt_imx2.h           |  5 ++---
 include/qemu/typedefs.h                  | 11 ++++++-----
 30 files changed, 27 insertions(+), 30 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/2 qemu/typedefs: Sort in case-insensitive alphabetical order (again)

Following the recommendation added in commit a98c370c46 ("typedefs: (Re-)sort entries alphabetically"), and similarly to commit 64baadc272 ("Sort include/qemu/typedefs.h"), sort again the type definitions (in case-insensitive alphabetical order, using 'sort --ignore-case').

---
 include/qemu/typedefs.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
include/qemu/typedefs.h +5 -5
index c7c8a85315..df4b55ac65 100644
@@ -49,6 +49,7 @@ typedef struct DeviceState DeviceState;
 typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot;
 typedef struct DisplayChangeListener DisplayChangeListener;
 typedef struct DriveInfo DriveInfo;
+typedef struct DumpState DumpState;
 typedef struct Error Error;
 typedef struct EventNotifier EventNotifier;
 typedef struct FlatView FlatView;
@@ -56,6 +57,7 @@ typedef struct FWCfgEntry FWCfgEntry;
 typedef struct FWCfgIoState FWCfgIoState;
 typedef struct FWCfgMemState FWCfgMemState;
 typedef struct FWCfgState FWCfgState;
+typedef struct GraphicHwOps GraphicHwOps;
 typedef struct HostMemoryBackend HostMemoryBackend;
 typedef struct I2CBus I2CBus;
 typedef struct I2SCodec I2SCodec;
@@ -90,10 +92,10 @@ typedef struct PCIDevice PCIDevice;
 typedef struct PCIEAERErr PCIEAERErr;
 typedef struct PCIEAERLog PCIEAERLog;
 typedef struct PCIEAERMsg PCIEAERMsg;
-typedef struct PCIESriovPF PCIESriovPF;
-typedef struct PCIESriovVF PCIESriovVF;
 typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
+typedef struct PCIESriovPF PCIESriovPF;
+typedef struct PCIESriovVF PCIESriovVF;
 typedef struct PCIExpressDevice PCIExpressDevice;
 typedef struct PCIExpressHost PCIExpressHost;
 typedef struct PCIHostDeviceAddress PCIHostDeviceAddress;
@@ -106,6 +108,7 @@ typedef struct QBool QBool;
 typedef struct QDict QDict;
 typedef struct QEMUBH QEMUBH;
 typedef struct QemuConsole QemuConsole;
+typedef struct QEMUCursor QEMUCursor;
 typedef struct QEMUFile QEMUFile;
 typedef struct QemuLockable QemuLockable;
 typedef struct QemuMutex QemuMutex;
@@ -132,9 +135,6 @@ typedef struct VirtIODevice VirtIODevice;
 typedef struct Visitor Visitor;
 typedef struct VMChangeStateEntry VMChangeStateEntry;
 typedef struct VMStateDescription VMStateDescription;
-typedef struct DumpState DumpState;
-typedef struct GraphicHwOps GraphicHwOps;
-typedef struct QEMUCursor QEMUCursor;
 
 /*
  * Pointer types
Signature · 1 line
2.38.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] qemu/typedefs: Sort in case-insensitive alphabetical order (again)

Quoted 10 lines · Philippe Mathieu-Daudé

Following the recommendation added in commit a98c370c46 ("typedefs: (Re-)sort entries alphabetically"), and similarly to commit 64baadc272 ("Sort include/qemu/typedefs.h"), sort again the type definitions (in case-insensitive alphabetical order, using 'sort --ignore-case').

---
  include/qemu/typedefs.h | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

r~

#3 lore raw

Re: [PATCH 1/2] qemu/typedefs: Sort in case-insensitive alphabetical order (again)

In reply to Philippe Mathieu-Daudé

Am 17. Februar 2023 14:18:31 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 5 lines

Following the recommendation added in commit a98c370c46 ("typedefs: (Re-)sort entries alphabetically"), and similarly to commit 64baadc272 ("Sort include/qemu/typedefs.h"), sort again the type definitions (in case-insensitive alphabetical order, using 'sort --ignore-case').

Since it can be done mechanically: Maybe add a checkpach check?

Quoted 57 lines

---
include/qemu/typedefs.h | 10 +++++-----

1 file changed, 5 insertions(+), 5 deletions(-)
include/qemu/typedefs.h +5 -5
index c7c8a85315..df4b55ac65 100644
@@ -49,6 +49,7 @@ typedef struct DeviceState DeviceState;
 typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot;
 typedef struct DisplayChangeListener DisplayChangeListener;
 typedef struct DriveInfo DriveInfo;
+typedef struct DumpState DumpState;
 typedef struct Error Error;
 typedef struct EventNotifier EventNotifier;
 typedef struct FlatView FlatView;
@@ -56,6 +57,7 @@ typedef struct FWCfgEntry FWCfgEntry;
 typedef struct FWCfgIoState FWCfgIoState;
 typedef struct FWCfgMemState FWCfgMemState;
 typedef struct FWCfgState FWCfgState;
+typedef struct GraphicHwOps GraphicHwOps;
 typedef struct HostMemoryBackend HostMemoryBackend;
 typedef struct I2CBus I2CBus;
 typedef struct I2SCodec I2SCodec;
@@ -90,10 +92,10 @@ typedef struct PCIDevice PCIDevice;
 typedef struct PCIEAERErr PCIEAERErr;
 typedef struct PCIEAERLog PCIEAERLog;
 typedef struct PCIEAERMsg PCIEAERMsg;
-typedef struct PCIESriovPF PCIESriovPF;
-typedef struct PCIESriovVF PCIESriovVF;
 typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
+typedef struct PCIESriovPF PCIESriovPF;
+typedef struct PCIESriovVF PCIESriovVF;
 typedef struct PCIExpressDevice PCIExpressDevice;
 typedef struct PCIExpressHost PCIExpressHost;
 typedef struct PCIHostDeviceAddress PCIHostDeviceAddress;
@@ -106,6 +108,7 @@ typedef struct QBool QBool;
 typedef struct QDict QDict;
 typedef struct QEMUBH QEMUBH;
 typedef struct QemuConsole QemuConsole;
+typedef struct QEMUCursor QEMUCursor;
 typedef struct QEMUFile QEMUFile;
 typedef struct QemuLockable QemuLockable;
 typedef struct QemuMutex QemuMutex;
@@ -132,9 +135,6 @@ typedef struct VirtIODevice VirtIODevice;
 typedef struct Visitor Visitor;
 typedef struct VMChangeStateEntry VMChangeStateEntry;
 typedef struct VMStateDescription VMStateDescription;
-typedef struct DumpState DumpState;
-typedef struct GraphicHwOps GraphicHwOps;
-typedef struct QEMUCursor QEMUCursor;
 
 /*
 * Pointer types
#4 lore raw

Re: [PATCH 1/2] qemu/typedefs: Sort in case-insensitive alphabetical order (again)

Quoted 10 lines · Bernhard Beschow

Am 17. Februar 2023 14:18:31 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 5 lines

Following the recommendation added in commit a98c370c46 ("typedefs: (Re-)sort entries alphabetically"), and similarly to commit 64baadc272 ("Sort include/qemu/typedefs.h"), sort again the type definitions (in case-insensitive alphabetical order, using 'sort --ignore-case').

Since it can be done mechanically: Maybe add a checkpach check?

There are 2 different sections in this file, each sorted alphabetically :/

#5 lore raw

PATCH 2/2 hw/timer: Reduce 'hw/ptimer.h' inclusion

In reply to Philippe Mathieu-Daudé

"hw/ptimer.h" API is mostly used by timer / watchdog device models. Since the SoC / machines only access the ptimer via reference, they don't need its definition: the declartion is enough.

On order to reduce the inclusion on the source files, forward-declare 'ptimer_state' in "qemu/typedefs.h". Use the typedef in few place instead of the structure.

---
"30 files changed"... but since this is trivial, there is no point in splitting per subsystem IMO.

---
 hw/display/xlnx_dp.c                     | 1 +
 hw/net/can/xlnx-zynqmp-can.c             | 1 +
 hw/net/fsl_etsec/etsec.h                 | 3 +--
 hw/timer/allwinner-a10-pit.c             | 1 +
 hw/timer/arm_mptimer.c                   | 4 ++--
 hw/timer/armv7m_systick.c                | 1 +
 hw/timer/cmsdk-apb-dualtimer.c           | 1 +
 hw/timer/cmsdk-apb-timer.c               | 1 +
 hw/timer/grlib_gptimer.c                 | 2 +-
 hw/timer/imx_epit.c                      | 1 +
 hw/timer/imx_gpt.c                       | 1 +
 hw/timer/mss-timer.c                     | 1 +
 hw/watchdog/cmsdk-apb-watchdog.c         | 1 +
 hw/watchdog/wdt_imx2.c                   | 1 +
 include/hw/display/xlnx_dp.h             | 1 -
 include/hw/dma/xlnx_csu_dma.h            | 1 -
 include/hw/net/xlnx-zynqmp-can.h         | 1 -
 include/hw/ptimer.h                      | 1 -
 include/hw/timer/allwinner-a10-pit.h     | 1 -
 include/hw/timer/arm_mptimer.h           | 2 +-
 include/hw/timer/armv7m_systick.h        | 1 -
 include/hw/timer/cmsdk-apb-dualtimer.h   | 3 +--
 include/hw/timer/cmsdk-apb-timer.h       | 3 +--
 include/hw/timer/digic-timer.h           | 1 -
 include/hw/timer/imx_epit.h              | 1 -
 include/hw/timer/imx_gpt.h               | 1 -
 include/hw/timer/mss-timer.h             | 1 -
 include/hw/watchdog/cmsdk-apb-watchdog.h | 3 +--
 include/hw/watchdog/wdt_imx2.h           | 5 ++---
 include/qemu/typedefs.h                  | 1 +
 30 files changed, 22 insertions(+), 25 deletions(-)
hw/display/xlnx_dp.c +1 -0
index b0828d65aa..d3e7696134 100644
@@ -29,6 +29,7 @@
 #include "qemu/module.h"
 #include "hw/display/xlnx_dp.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "migration/vmstate.h"
 
 #ifndef DEBUG_DP
hw/net/can/xlnx-zynqmp-can.c +1 -0
index e93e6c5e19..28b9db78d4 100644
@@ -33,6 +33,7 @@
 #include "hw/sysbus.h"
 #include "hw/register.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "qapi/error.h"
 #include "qemu/bitops.h"
 #include "qemu/log.h"
hw/net/fsl_etsec/etsec.h +1 -2
index 3c625c955c..9321a2f9a0 100644
@@ -27,7 +27,6 @@
 
 #include "hw/sysbus.h"
 #include "net/net.h"
-#include "hw/ptimer.h"
 #include "qom/object.h"
 
 /* Buffer Descriptors */
@@ -142,7 +141,7 @@ struct eTSEC {
     uint16_t phy_control;
 
     /* Polling */
-    struct ptimer_state *ptimer;
+    ptimer_state *ptimer;
 
     /* Whether we should flush the rx queue when buffer becomes available. */
     bool need_flush;
hw/timer/allwinner-a10-pit.c +1 -0
index 971f78462a..7cce098508 100644
@@ -17,6 +17,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/qdev-properties.h"
 #include "hw/sysbus.h"
 #include "hw/timer/allwinner-a10-pit.h"
hw/timer/arm_mptimer.c +2 -2
index cdfca3000b..104c3d8af8 100644
@@ -65,7 +65,7 @@ static inline uint32_t timerblock_scale(uint32_t control)
 }
 
 /* Must be called within a ptimer transaction block */
-static inline void timerblock_set_count(struct ptimer_state *timer,
+static inline void timerblock_set_count(ptimer_state *timer,
                                         uint32_t control, uint64_t *count)
 {
     /* PTimer would trigger interrupt for periodic timer when counter set
@@ -78,7 +78,7 @@ static inline void timerblock_set_count(struct ptimer_state *timer,
 }
 
 /* Must be called within a ptimer transaction block */
-static inline void timerblock_run(struct ptimer_state *timer,
+static inline void timerblock_run(ptimer_state *timer,
                                   uint32_t control, uint32_t load)
 {
     if ((control & 1) && ((control & 0xff00) || load != 0)) {
hw/timer/armv7m_systick.c +1 -0
index 5dfe39afe3..36fba84f15 100644
@@ -13,6 +13,7 @@
 #include "hw/timer/armv7m_systick.h"
 #include "migration/vmstate.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/sysbus.h"
 #include "hw/qdev-clock.h"
 #include "qemu/timer.h"
hw/timer/cmsdk-apb-dualtimer.c +1 -0
index d4a509c798..c967988035 100644
@@ -23,6 +23,7 @@
 #include "qemu/module.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/qdev-properties.h"
 #include "hw/registerfields.h"
 #include "hw/qdev-clock.h"
hw/timer/cmsdk-apb-timer.c +1 -0
index 68aa1a7636..cce9135eb1 100644
@@ -34,6 +34,7 @@
 #include "trace.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/registerfields.h"
 #include "hw/qdev-clock.h"
 #include "hw/timer/cmsdk-apb-timer.h"
hw/timer/grlib_gptimer.c +1 -1
index 5c4923c1e0..8347e3047f 100644
@@ -61,7 +61,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(GPTimerUnit, GRLIB_GPTIMER)
 typedef struct GPTimer     GPTimer;
 
 struct GPTimer {
-    struct ptimer_state *ptimer;
+    ptimer_state *ptimer;
 
     qemu_irq     irq;
     int          id;
hw/timer/imx_epit.c +1 -0
index 3a869782bc..6fab1be5cf 100644
@@ -17,6 +17,7 @@
 #include "hw/timer/imx_epit.h"
 #include "migration/vmstate.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/misc/imx_ccm.h"
 #include "qemu/module.h"
 #include "qemu/log.h"
hw/timer/imx_gpt.c +1 -0
index 7222b1b387..ab2e13d3a0 100644
@@ -14,6 +14,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/timer/imx_gpt.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
hw/timer/mss-timer.c +1 -0
index ee7438f168..18174d0b8d 100644
@@ -27,6 +27,7 @@
 #include "qemu/module.h"
 #include "qemu/log.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/qdev-properties.h"
 #include "hw/timer/mss-timer.h"
 #include "migration/vmstate.h"
hw/watchdog/cmsdk-apb-watchdog.c +1 -0
index 5a2cd46eb7..e30da55101 100644
@@ -28,6 +28,7 @@
 #include "sysemu/watchdog.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
+#include "hw/ptimer.h"
 #include "hw/qdev-properties.h"
 #include "hw/registerfields.h"
 #include "hw/qdev-clock.h"
hw/watchdog/wdt_imx2.c +1 -0
index e776a2fbd4..316a959beb 100644
@@ -15,6 +15,7 @@
 #include "sysemu/watchdog.h"
 #include "migration/vmstate.h"
 #include "hw/qdev-properties.h"
+#include "hw/ptimer.h"
 
 #include "hw/watchdog/wdt_imx2.h"
 
include/hw/display/xlnx_dp.h +0 -1
index e86a87f235..f859da66f9 100644
@@ -35,7 +35,6 @@
 #include "hw/dma/xlnx_dpdma.h"
 #include "audio/audio.h"
 #include "qom/object.h"
-#include "hw/ptimer.h"
 
 #define AUD_CHBUF_MAX_DEPTH                 (32 * KiB)
 #define MAX_QEMU_BUFFER_SIZE                (4 * KiB)
include/hw/dma/xlnx_csu_dma.h +0 -1
index 922ab80eb6..2b3a52c58b 100644
@@ -23,7 +23,6 @@
 
 #include "hw/sysbus.h"
 #include "hw/register.h"
-#include "hw/ptimer.h"
 #include "hw/stream.h"
 
 #define TYPE_XLNX_CSU_DMA "xlnx.csu_dma"
include/hw/net/xlnx-zynqmp-can.h +0 -1
index fd2aa77760..2cacaf6181 100644
@@ -35,7 +35,6 @@
 #include "net/can_emu.h"
 #include "net/can_host.h"
 #include "qemu/fifo32.h"
-#include "hw/ptimer.h"
 #include "hw/qdev-clock.h"
 
 #define TYPE_XLNX_ZYNQMP_CAN "xlnx.zynqmp-can"
include/hw/ptimer.h +0 -1
index 4dc02b0de4..30b7eac7ad 100644
@@ -94,7 +94,6 @@
 #define PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT (1 << 5)
 
 /* ptimer.c */
-typedef struct ptimer_state ptimer_state;
 typedef void (*ptimer_cb)(void *opaque);
 
 /**
include/hw/timer/allwinner-a10-pit.h +0 -1
index 8435758ad6..31054b231c 100644
@@ -1,7 +1,6 @@
 #ifndef ALLWINNER_A10_PIT_H
 #define ALLWINNER_A10_PIT_H
 
-#include "hw/ptimer.h"
 #include "hw/sysbus.h"
 #include "qom/object.h"
 
include/hw/timer/arm_mptimer.h +1 -1
index 65a96e2a0d..339cb9fe4b 100644
@@ -30,7 +30,7 @@
 typedef struct {
     uint32_t control;
     uint32_t status;
-    struct ptimer_state *timer;
+    ptimer_state *timer;
     qemu_irq irq;
     MemoryRegion iomem;
 } TimerBlock;
include/hw/timer/armv7m_systick.h +0 -1
index ee09b13881..deb1d66a51 100644
@@ -14,7 +14,6 @@
 
 #include "hw/sysbus.h"
 #include "qom/object.h"
-#include "hw/ptimer.h"
 #include "hw/clock.h"
 
 #define TYPE_SYSTICK "armv7m_systick"
include/hw/timer/cmsdk-apb-dualtimer.h +1 -2
index f3ec86c00b..5d8450eda1 100644
@@ -27,7 +27,6 @@
 #define CMSDK_APB_DUALTIMER_H
 
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "hw/clock.h"
 #include "qom/object.h"
 
@@ -38,7 +37,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBDualTimer, CMSDK_APB_DUALTIMER)
 /* One of the two identical timer modules in the dual-timer module */
 typedef struct CMSDKAPBDualTimerModule {
     CMSDKAPBDualTimer *parent;
-    struct ptimer_state *timer;
+    ptimer_state *timer;
     qemu_irq timerint;
     /*
      * We must track the guest LOAD and VALUE register state by hand
include/hw/timer/cmsdk-apb-timer.h +1 -2
index c4c7eae849..b61e254d4d 100644
@@ -14,7 +14,6 @@
 
 #include "hw/qdev-properties.h"
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "hw/clock.h"
 #include "qom/object.h"
 
@@ -34,7 +33,7 @@ struct CMSDKAPBTimer {
     /*< public >*/
     MemoryRegion iomem;
     qemu_irq timerint;
-    struct ptimer_state *timer;
+    ptimer_state *timer;
     Clock *pclk;
 
     uint32_t ctrl;
include/hw/timer/digic-timer.h +0 -1
index da82fb4663..6c422a8451 100644
@@ -19,7 +19,6 @@
 #define HW_TIMER_DIGIC_TIMER_H
 
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "qom/object.h"
 
 #define TYPE_DIGIC_TIMER "digic-timer"
include/hw/timer/imx_epit.h +0 -1
index 79aff0cec2..55f2611f79 100644
@@ -30,7 +30,6 @@
 #define IMX_EPIT_H
 
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "hw/misc/imx_ccm.h"
 #include "qom/object.h"
 
include/hw/timer/imx_gpt.h +0 -1
index 5a1230da35..d5743778e0 100644
@@ -30,7 +30,6 @@
 #define IMX_GPT_H
 
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "hw/misc/imx_ccm.h"
 #include "qom/object.h"
 
include/hw/timer/mss-timer.h +0 -1
index da38512904..783cec30e3 100644
@@ -26,7 +26,6 @@
 #define HW_MSS_TIMER_H
 
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "qom/object.h"
 
 #define TYPE_MSS_TIMER     "mss-timer"
include/hw/watchdog/cmsdk-apb-watchdog.h +1 -2
index c6b3e78731..d02bfd0dd7 100644
@@ -32,7 +32,6 @@
 #define CMSDK_APB_WATCHDOG_H
 
 #include "hw/sysbus.h"
-#include "hw/ptimer.h"
 #include "hw/clock.h"
 #include "qom/object.h"
 
@@ -53,7 +52,7 @@ struct CMSDKAPBWatchdog {
     MemoryRegion iomem;
     qemu_irq wdogint;
     bool is_luminary;
-    struct ptimer_state *timer;
+    ptimer_state *timer;
     Clock *wdogclk;
 
     uint32_t control;
include/hw/watchdog/wdt_imx2.h +2 -3
index 600a552d2e..d4cddac352 100644
@@ -15,7 +15,6 @@
 #include "qemu/bitops.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
-#include "hw/ptimer.h"
 #include "qom/object.h"
 
 #define TYPE_IMX2_WDT "imx2.wdt"
@@ -71,8 +70,8 @@ struct IMX2WdtState {
     MemoryRegion mmio;
     qemu_irq irq;
 
-    struct ptimer_state *timer;
-    struct ptimer_state *itimer;
+    ptimer_state *timer;
+    ptimer_state *itimer;
 
     bool pretimeout_support;
     bool wicr_locked;
include/qemu/typedefs.h +1 -0
index df4b55ac65..effcba4bca 100644
@@ -104,6 +104,7 @@ typedef struct PICCommonState PICCommonState;
 typedef struct PostcopyDiscardState PostcopyDiscardState;
 typedef struct Property Property;
 typedef struct PropertyInfo PropertyInfo;
+typedef struct ptimer_state ptimer_state;
 typedef struct QBool QBool;
 typedef struct QDict QDict;
 typedef struct QEMUBH QEMUBH;
Signature · 1 line
2.38.1
Reviewed-by on v1 2/2
#6 lore raw
Quoted 9 lines · Philippe Mathieu-Daudé

"hw/ptimer.h" API is mostly used by timer / watchdog device models. Since the SoC / machines only access the ptimer via reference, they don't need its definition: the declartion is enough.

On order to reduce the inclusion on the source files, forward-declare 'ptimer_state' in "qemu/typedefs.h". Use the typedef in few place instead of the structure.

Quoted 5 lines

---
"30 files changed"... but since this is trivial, there is no point in splitting per subsystem IMO.
---

r~

#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

"hw/ptimer.h" API is mostly used by timer / watchdog device models. Since the SoC / machines only access the ptimer via reference, they don't need its definition: the declartion is enough.

On order to reduce the inclusion on the source files, forward-declare 'ptimer_state' in "qemu/typedefs.h". Use the typedef in few place instead of the structure.

---
"30 files changed"... but since this is trivial, there is no point in splitting per subsystem IMO.
---

...

include/qemu/typedefs.h typedef struct PICCommonState PICCommonState; · line 107

Quoted 9 lines
include/qemu/typedefs.h +1 -0
index df4b55ac65..effcba4bca 100644
@@ -104,6 +104,7 @@ typedef struct PICCommonState PICCommonState;
  typedef struct PostcopyDiscardState PostcopyDiscardState;
  typedef struct Property Property;
  typedef struct PropertyInfo PropertyInfo;
+typedef struct ptimer_state ptimer_state;

Would it make sense to properly CamelCase the type while you're at it anyway?

Thomas

#8 lore raw
Quoted 16 lines · Thomas Huth
Quoted 14 lines · Philippe Mathieu-Daudé

"hw/ptimer.h" API is mostly used by timer / watchdog device models. Since the SoC / machines only access the ptimer via reference, they don't need its definition: the declartion is enough.

On order to reduce the inclusion on the source files, forward-declare 'ptimer_state' in "qemu/typedefs.h". Use the typedef in few place instead of the structure.

---
"30 files changed"... but since this is trivial, there is no point in splitting per subsystem IMO.
---

...

Quoted 11 lines

include/qemu/typedefs.h typedef struct PICCommonState PICCommonState; · line 107

Quoted 9 lines
include/qemu/typedefs.h +1 -0
index df4b55ac65..effcba4bca 100644
@@ -104,6 +104,7 @@ typedef struct PICCommonState PICCommonState;
   typedef struct PostcopyDiscardState PostcopyDiscardState;
   typedef struct Property Property;
   typedef struct PropertyInfo PropertyInfo;
+typedef struct ptimer_state ptimer_state;

Would it make sense to properly CamelCase the type while you're at it anyway?

PeriodicTimer, PTimerState, PTimer?

This API is documented as 'ptimer API' although, and renaming all the API methods doesn't seem to bring much, so maybe stick to PTimer.

More generically for QOM objects, we can agree for no 'State' trailing for instance state, and 'Class' trailing for class one, similar to Object / ObjectClass. I.e:

PeriodicTimer // instance
PeriodicTimerClass // class

Maybe 'Device' is too generic? Here the API uses 'qdev_' prefix, so QDev / QDevClass could work...

#9 lore raw

[PATCH 3/2] hw/timer: Rename ptimer_state -> PTimer

In reply to Philippe Mathieu-Daudé

Remove a pointless cast in ptimer_tick() and rename 'ptimer_state' as 'PTimer' to follow the Structure naming convention.

See docs/devel/style.rst:

Variables are lower_case_with_underscores; easy to type and read. Structured type names are in CamelCase; harder to type but standing out. Enum type names and function type names should also be in CamelCase. Scalar type names are lower_case_with_underscores_ending_with_a_t, like the POSIX uint64_t and family.

Mechanical change doing:

  $ sed -i -e s/ptimer_state/PTimer/g \
      $(git grep -l ptimer_state)
---
 hw/arm/musicpal.c                        |  2 +-
 hw/core/ptimer.c                         | 56 ++++++++++++------------
 hw/dma/xilinx_axidma.c                   |  2 +-
 hw/m68k/mcf5206.c                        |  2 +-
 hw/m68k/mcf5208.c                        |  2 +-
 hw/net/fsl_etsec/etsec.h                 |  2 +-
 hw/net/lan9118.c                         |  2 +-
 hw/rtc/exynos4210_rtc.c                  |  4 +-
 hw/timer/altera_timer.c                  |  2 +-
 hw/timer/arm_mptimer.c                   |  4 +-
 hw/timer/arm_timer.c                     |  2 +-
 hw/timer/etraxfs_timer.c                 |  8 ++--
 hw/timer/exynos4210_mct.c                |  8 ++--
 hw/timer/exynos4210_pwm.c                |  2 +-
 hw/timer/grlib_gptimer.c                 |  2 +-
 hw/timer/sh_timer.c                      |  2 +-
 hw/timer/slavio_timer.c                  |  2 +-
 hw/timer/xilinx_timer.c                  |  2 +-
 include/hw/display/xlnx_dp.h             |  2 +-
 include/hw/dma/xlnx_csu_dma.h            |  2 +-
 include/hw/net/xlnx-zynqmp-can.h         |  2 +-
 include/hw/ptimer.h                      | 34 +++++++-------
 include/hw/timer/allwinner-a10-pit.h     |  2 +-
 include/hw/timer/arm_mptimer.h           |  2 +-
 include/hw/timer/armv7m_systick.h        |  2 +-
 include/hw/timer/cmsdk-apb-dualtimer.h   |  2 +-
 include/hw/timer/cmsdk-apb-timer.h       |  2 +-
 include/hw/timer/digic-timer.h           |  2 +-
 include/hw/timer/imx_epit.h              |  4 +-
 include/hw/timer/imx_gpt.h               |  2 +-
 include/hw/timer/mss-timer.h             |  2 +-
 include/hw/watchdog/cmsdk-apb-watchdog.h |  2 +-
 include/hw/watchdog/wdt_imx2.h           |  4 +-
 include/qemu/typedefs.h                  |  2 +-
 tests/unit/ptimer-test.c                 | 22 +++++-----
 35 files changed, 98 insertions(+), 98 deletions(-)
hw/arm/musicpal.c +1 -1
index 89b66606c3..63e0bbda95 100644
@@ -435,7 +435,7 @@ static const TypeInfo mv88w8618_pic_info = {
 #define MP_BOARD_RESET_MAGIC    0x10000
 
 typedef struct mv88w8618_timer_state {
-    ptimer_state *ptimer;
+    PTimer *ptimer;
     uint32_t limit;
     int freq;
     qemu_irq irq;
hw/core/ptimer.c +28 -28

170 lines not on this page · raw message

hw/dma/xilinx_axidma.c +1 -1
index 6030c76435..5710192da3 100644
@@ -102,7 +102,7 @@ enum {
 
 struct Stream {
     struct XilinxAXIDMA *dma;
-    ptimer_state *ptimer;
+    PTimer *ptimer;
     qemu_irq irq;
 
     int nr;
hw/m68k/mcf5206.c +1 -1
index 2ab1b4f059..61ed70f2b1 100644
@@ -24,7 +24,7 @@ typedef struct {
     uint16_t trr;
     uint16_t tcr;
     uint16_t ter;
-    ptimer_state *timer;
+    PTimer *timer;
     qemu_irq irq;
     int irq_state;
 } m5206_timer_state;
hw/m68k/mcf5208.c +1 -1
index be1033f84f..006a1ee5c5 100644
@@ -43,7 +43,7 @@
 typedef struct {
     MemoryRegion iomem;
     qemu_irq irq;
-    ptimer_state *timer;
+    PTimer *timer;
     uint16_t pcsr;
     uint16_t pmr;
     uint16_t pcntr;
hw/net/fsl_etsec/etsec.h +1 -1
index 9321a2f9a0..947dd063d8 100644
@@ -141,7 +141,7 @@ struct eTSEC {
     uint16_t phy_control;
 
     /* Polling */
-    ptimer_state *ptimer;
+    PTimer *ptimer;
 
     /* Whether we should flush the rx queue when buffer becomes available. */
     bool need_flush;
hw/net/lan9118.c +1 -1
index f1cba55967..6356ab49d5 100644
@@ -201,7 +201,7 @@ struct lan9118_state {
     NICConf conf;
     qemu_irq irq;
     MemoryRegion mmio;
-    ptimer_state *timer;
+    PTimer *timer;
 
     uint32_t irq_cfg;
     uint32_t int_sts;
hw/rtc/exynos4210_rtc.c +2 -2
index 2b8a38a296..95a44be7a8 100644
@@ -105,8 +105,8 @@ struct Exynos4210RTCState {
     uint32_t    reg_almyear;
     uint32_t    reg_curticcnt;
 
-    ptimer_state    *ptimer;        /* tick timer */
-    ptimer_state    *ptimer_1Hz;    /* clock timer */
+    PTimer      *ptimer;        /* tick timer */
+    PTimer      *ptimer_1Hz;    /* clock timer */
     uint32_t        freq;
 
     qemu_irq        tick_irq;   /* Time Tick Generator irq */
hw/timer/altera_timer.c +1 -1
index 0f1f54206a..5f2e411358 100644
@@ -52,7 +52,7 @@ struct AlteraTimer {
     MemoryRegion  mmio;
     qemu_irq      irq;
     uint32_t      freq_hz;
-    ptimer_state *ptimer;
+    PTimer       *ptimer;
     uint32_t      regs[R_MAX];
 };
 
hw/timer/arm_mptimer.c +2 -2
index 104c3d8af8..124eb43215 100644
@@ -65,7 +65,7 @@ static inline uint32_t timerblock_scale(uint32_t control)
 }
 
 /* Must be called within a ptimer transaction block */
-static inline void timerblock_set_count(ptimer_state *timer,
+static inline void timerblock_set_count(PTimer *timer,
                                         uint32_t control, uint64_t *count)
 {
     /* PTimer would trigger interrupt for periodic timer when counter set
@@ -78,7 +78,7 @@ static inline void timerblock_set_count(ptimer_state *timer,
 }
 
 /* Must be called within a ptimer transaction block */
-static inline void timerblock_run(ptimer_state *timer,
+static inline void timerblock_run(PTimer *timer,
                                   uint32_t control, uint32_t load)
 {
     if ((control & 1) && ((control & 0xff00) || load != 0)) {
hw/timer/arm_timer.c +1 -1
index 69c8863472..06063a8fb1 100644
@@ -30,7 +30,7 @@
 #define TIMER_CTRL_ENABLE       (1 << 7)
 
 typedef struct {
-    ptimer_state *timer;
+    PTimer *timer;
     uint32_t control;
     uint32_t limit;
     int freq;
hw/timer/etraxfs_timer.c +4 -4
index 2d6d92ef93..e3c8eb51d6 100644
@@ -61,9 +61,9 @@ struct ETRAXTimerState {
     qemu_irq irq;
     qemu_irq nmi;
 
-    ptimer_state *ptimer_t0;
-    ptimer_state *ptimer_t1;
-    ptimer_state *ptimer_wd;
+    PTimer *ptimer_t0;
+    PTimer *ptimer_t1;
+    PTimer *ptimer_wd;
 
     uint32_t wd_hits;
 
@@ -151,7 +151,7 @@ static void update_ctrl(ETRAXTimerState *t, int tnum)
     unsigned int div;
     uint32_t ctrl;
 
-    ptimer_state *timer;
+    PTimer *timer;
 
     if (tnum == 0) {
         ctrl = t->rw_tmr0_ctrl;
hw/timer/exynos4210_mct.c +4 -4
index c17b247da3..53206d697f 100644
@@ -201,7 +201,7 @@ typedef struct {
     uint64_t count;            /* Value FRC was armed with */
     int32_t curr_comp;             /* Current comparator FRC is running to */
 
-    ptimer_state *ptimer_frc;                   /* FRC timer */
+    PTimer *ptimer_frc;        /* FRC timer */
 
 } Exynos4210MCTGT;
 
@@ -224,12 +224,12 @@ typedef struct {
         uint64_t    progress;       /* progress when counting by steps */
         uint64_t    count;          /* count to arm timer with */
 
-        ptimer_state *ptimer_tick;  /* timer for tick counter */
+        PTimer *ptimer_tick;        /* timer for tick counter */
     } tick_timer;
 
     /* use ptimer.c to represent count down timer */
 
-    ptimer_state *ptimer_frc;   /* timer for free running counter */
+    PTimer *ptimer_frc;             /* timer for free running counter */
 
     /* registers */
     struct lregs {
@@ -981,7 +981,7 @@ static void exynos4210_ltick_event(void *opaque)
     exynos4210_ltick_int_start(&s->tick_timer);
 }
 
-static void tx_ptimer_set_freq(ptimer_state *s, uint32_t freq)
+static void tx_ptimer_set_freq(PTimer *s, uint32_t freq)
 {
     /*
      * callers of exynos4210_mct_update_freq() never do anything
hw/timer/exynos4210_pwm.c +1 -1
index 3528d0f33a..4895a7770f 100644
@@ -92,7 +92,7 @@ typedef struct {
     uint32_t    freq;           /* timer frequency */
 
     /* use ptimer.c to represent count down timer */
-    ptimer_state *ptimer;       /* timer  */
+    PTimer     *ptimer;         /* timer  */
 
     /* registers */
     uint32_t    reg_tcntb;      /* counter register buffer */
hw/timer/grlib_gptimer.c +1 -1
index 8347e3047f..50963def2e 100644
@@ -61,7 +61,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(GPTimerUnit, GRLIB_GPTIMER)
 typedef struct GPTimer     GPTimer;
 
 struct GPTimer {
-    ptimer_state *ptimer;
+    PTimer *ptimer;
 
     qemu_irq     irq;
     int          id;
hw/timer/sh_timer.c +1 -1
index 7788939766..713151b9a0 100644
@@ -34,7 +34,7 @@
 #define OFFSET_TCPR   3
 
 typedef struct {
-    ptimer_state *timer;
+    PTimer *timer;
     uint32_t tcnt;
     uint32_t tcor;
     uint32_t tcr;
hw/timer/slavio_timer.c +1 -1
index 8c4f6eb06b..569d590e4e 100644
@@ -52,7 +52,7 @@
 
 typedef struct CPUTimerState {
     qemu_irq irq;
-    ptimer_state *timer;
+    PTimer *timer;
     uint32_t count, counthigh, reached;
     /* processor only */
     uint32_t run;
hw/timer/xilinx_timer.c +1 -1
index 32a9df69e0..359c1fad6e 100644
@@ -52,7 +52,7 @@
 
 struct xlx_timer
 {
-    ptimer_state *ptimer;
+    PTimer *ptimer;
     void *parent;
     int nr; /* for debug.  */
 
include/hw/display/xlnx_dp.h +1 -1
index f859da66f9..e50c955700 100644
@@ -108,7 +108,7 @@ struct XlnxDPState {
     DPCDState *dpcd;
     I2CDDCState *edid;
 
-    ptimer_state *vblank;
+    PTimer *vblank;
 };
 
 #define TYPE_XLNX_DP "xlnx.v-dp"
include/hw/dma/xlnx_csu_dma.h +1 -1
index 2b3a52c58b..84a7aac892 100644
@@ -37,7 +37,7 @@ typedef struct XlnxCSUDMA {
     AddressSpace dma_as;
     qemu_irq irq;
     StreamSink *tx_dev; /* Used as generic StreamSink */
-    ptimer_state *src_timer;
+    PTimer *src_timer;
 
     uint16_t width;
     bool is_dst;
include/hw/net/xlnx-zynqmp-can.h +1 -1
index 2cacaf6181..88eb849d8d 100644
@@ -72,7 +72,7 @@ typedef struct XlnxZynqMPCANState {
     Fifo32              tx_fifo;
     Fifo32              txhpb_fifo;
 
-    ptimer_state        *can_timer;
+    PTimer              *can_timer;
 } XlnxZynqMPCANState;
 
 #endif
include/hw/ptimer.h +17 -17
index 30b7eac7ad..baa38aa987 100644
@@ -124,9 +124,9 @@ typedef void (*ptimer_cb)(void *opaque);
  * the ptimer state such that another ptimer expiry is triggered, then
  * the callback will be called a second time after the first call returns.
  */
-ptimer_state *ptimer_init(ptimer_cb callback,
-                          void *callback_opaque,
-                          uint8_t policy_mask);
+PTimer *ptimer_init(ptimer_cb callback,
+                    void *callback_opaque,
+                    uint8_t policy_mask);
 
 /**
  * ptimer_free - Free a ptimer
@@ -134,7 +134,7 @@ ptimer_state *ptimer_init(ptimer_cb callback,
  *
  * Free a ptimer created using ptimer_init().
  */
-void ptimer_free(ptimer_state *s);
+void ptimer_free(PTimer *s);
 
 /**
  * ptimer_transaction_begin() - Start a ptimer modification transaction
@@ -146,7 +146,7 @@ void ptimer_free(ptimer_state *s);
  * It is an error to call this function for a BH-based ptimer;
  * attempting to do this will trigger an assert.
  */
-void ptimer_transaction_begin(ptimer_state *s);
+void ptimer_transaction_begin(PTimer *s);
 
 /**
  * ptimer_transaction_commit() - Commit a ptimer modification transaction
@@ -156,7 +156,7 @@ void ptimer_transaction_begin(ptimer_state *s);
  * ptimer state now means that we should trigger the timer expiry
  * callback, it will be called directly.
  */
-void ptimer_transaction_commit(ptimer_state *s);
+void ptimer_transaction_commit(PTimer *s);
 
 /**
  * ptimer_set_period - Set counter increment interval in nanoseconds
@@ -170,7 +170,7 @@ void ptimer_transaction_commit(ptimer_state *s);
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_set_period(ptimer_state *s, int64_t period);
+void ptimer_set_period(PTimer *s, int64_t period);
 
 /**
  * ptimer_set_period_from_clock - Set counter increment from a Clock
@@ -191,7 +191,7 @@ void ptimer_set_period(ptimer_state *s, int64_t period);
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_set_period_from_clock(ptimer_state *s, const Clock *clock,
+void ptimer_set_period_from_clock(PTimer *s, const Clock *clock,
                                   unsigned int divisor);
 
 /**
@@ -208,7 +208,7 @@ void ptimer_set_period_from_clock(ptimer_state *s, const Clock *clock,
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_set_freq(ptimer_state *s, uint32_t freq);
+void ptimer_set_freq(PTimer *s, uint32_t freq);
 
 /**
  * ptimer_get_limit - Get the configured limit of the ptimer
@@ -223,7 +223,7 @@ void ptimer_set_freq(ptimer_state *s, uint32_t freq);
  * and set limit functions rather than needing to also track it
  * in their own state structure.
  */
-uint64_t ptimer_get_limit(ptimer_state *s);
+uint64_t ptimer_get_limit(PTimer *s);
 
 /**
  * ptimer_set_limit - Set the limit of the ptimer
@@ -238,7 +238,7 @@ uint64_t ptimer_get_limit(ptimer_state *s);
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload);
+void ptimer_set_limit(PTimer *s, uint64_t limit, int reload);
 
 /**
  * ptimer_get_count - Get the current value of the ptimer
@@ -248,7 +248,7 @@ void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload);
  * return the correct value whether the counter is enabled or
  * disabled.
  */
-uint64_t ptimer_get_count(ptimer_state *s);
+uint64_t ptimer_get_count(PTimer *s);
 
 /**
  * ptimer_set_count - Set the current value of the ptimer
@@ -262,7 +262,7 @@ uint64_t ptimer_get_count(ptimer_state *s);
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_set_count(ptimer_state *s, uint64_t count);
+void ptimer_set_count(PTimer *s, uint64_t count);
 
 /**
  * ptimer_run - Start a ptimer counting
@@ -279,7 +279,7 @@ void ptimer_set_count(ptimer_state *s, uint64_t count);
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_run(ptimer_state *s, int oneshot);
+void ptimer_run(PTimer *s, int oneshot);
 
 /**
  * ptimer_stop - Stop a ptimer counting
@@ -294,15 +294,15 @@ void ptimer_run(ptimer_state *s, int oneshot);
  * This function will assert if it is called outside a
  * ptimer_transaction_begin/commit block.
  */
-void ptimer_stop(ptimer_state *s);
+void ptimer_stop(PTimer *s);
 
 extern const VMStateDescription vmstate_ptimer;
 
 #define VMSTATE_PTIMER(_field, _state) \
-    VMSTATE_STRUCT_POINTER_V(_field, _state, 1, vmstate_ptimer, ptimer_state)
+    VMSTATE_STRUCT_POINTER_V(_field, _state, 1, vmstate_ptimer, PTimer)
 
 #define VMSTATE_PTIMER_ARRAY(_f, _s, _n)                                \
     VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, 0,                   \
-                                       vmstate_ptimer, ptimer_state)
+                                       vmstate_ptimer, PTimer)
 
 #endif
include/hw/timer/allwinner-a10-pit.h +1 -1
index 31054b231c..939fb103c8 100644
@@ -47,7 +47,7 @@ struct AwA10PITState {
     SysBusDevice parent_obj;
     /*< public >*/
     qemu_irq irq[AW_A10_PIT_TIMER_NR];
-    ptimer_state * timer[AW_A10_PIT_TIMER_NR];
+    PTimer *timer[AW_A10_PIT_TIMER_NR];
     AwA10TimerContext timer_context[AW_A10_PIT_TIMER_NR];
     MemoryRegion iomem;
     uint32_t clk_freq[4];
include/hw/timer/arm_mptimer.h +1 -1
index 339cb9fe4b..174fbe6c88 100644
@@ -30,7 +30,7 @@
 typedef struct {
     uint32_t control;
     uint32_t status;
-    ptimer_state *timer;
+    PTimer *timer;
     qemu_irq irq;
     MemoryRegion iomem;
 } TimerBlock;
include/hw/timer/armv7m_systick.h +1 -1
index deb1d66a51..074efb5fb2 100644
@@ -39,7 +39,7 @@ struct SysTickState {
     uint32_t control;
     uint32_t reload;
     int64_t tick;
-    ptimer_state *ptimer;
+    PTimer *ptimer;
     MemoryRegion iomem;
     qemu_irq irq;
     Clock *refclk;
include/hw/timer/cmsdk-apb-dualtimer.h +1 -1
index 5d8450eda1..1bab7e7961 100644
@@ -37,7 +37,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBDualTimer, CMSDK_APB_DUALTIMER)
 /* One of the two identical timer modules in the dual-timer module */
 typedef struct CMSDKAPBDualTimerModule {
     CMSDKAPBDualTimer *parent;
-    ptimer_state *timer;
+    PTimer *timer;
     qemu_irq timerint;
     /*
      * We must track the guest LOAD and VALUE register state by hand
include/hw/timer/cmsdk-apb-timer.h +1 -1
index b61e254d4d..c3d68f1154 100644
@@ -33,7 +33,7 @@ struct CMSDKAPBTimer {
     /*< public >*/
     MemoryRegion iomem;
     qemu_irq timerint;
-    ptimer_state *timer;
+    PTimer *timer;
     Clock *pclk;
 
     uint32_t ctrl;
include/hw/timer/digic-timer.h +1 -1
index 6c422a8451..38e363faf4 100644
@@ -36,7 +36,7 @@ struct DigicTimerState {
     /*< public >*/
 
     MemoryRegion iomem;
-    ptimer_state *ptimer;
+    PTimer *ptimer;
 
     uint32_t control;
     uint32_t relvalue;
include/hw/timer/imx_epit.h +2 -2
index 55f2611f79..351af8dbdb 100644
@@ -64,8 +64,8 @@ struct IMXEPITState {
     SysBusDevice parent_obj;
 
     /*< public >*/
-    ptimer_state *timer_reload;
-    ptimer_state *timer_cmp;
+    PTimer *timer_reload;
+    PTimer *timer_cmp;
     MemoryRegion  iomem;
     IMXCCMState  *ccm;
 
include/hw/timer/imx_gpt.h +1 -1
index d5743778e0..377ce42611 100644
@@ -91,7 +91,7 @@ struct IMXGPTState {
     SysBusDevice parent_obj;
 
     /*< public >*/
-    ptimer_state *timer;
+    PTimer *timer;
     MemoryRegion  iomem;
     IMXCCMState  *ccm;
 
include/hw/timer/mss-timer.h +1 -1
index 783cec30e3..48098e336c 100644
@@ -45,7 +45,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(MSSTimerState, MSS_TIMER)
 #define R_TIM1_MAX        6
 
 struct Msf2Timer {
-    ptimer_state *ptimer;
+    PTimer *ptimer;
 
     uint32_t regs[R_TIM1_MAX];
     qemu_irq irq;
include/hw/watchdog/cmsdk-apb-watchdog.h +1 -1
index d02bfd0dd7..74bea181dd 100644
@@ -52,7 +52,7 @@ struct CMSDKAPBWatchdog {
     MemoryRegion iomem;
     qemu_irq wdogint;
     bool is_luminary;
-    ptimer_state *timer;
+    PTimer *timer;
     Clock *wdogclk;
 
     uint32_t control;
include/hw/watchdog/wdt_imx2.h +2 -2
index d4cddac352..de1b73c752 100644
@@ -70,8 +70,8 @@ struct IMX2WdtState {
     MemoryRegion mmio;
     qemu_irq irq;
 
-    ptimer_state *timer;
-    ptimer_state *itimer;
+    PTimer *timer;
+    PTimer *itimer;
 
     bool pretimeout_support;
     bool wicr_locked;
include/qemu/typedefs.h +1 -1
index effcba4bca..e687ffe5fc 100644
@@ -104,7 +104,7 @@ typedef struct PICCommonState PICCommonState;
 typedef struct PostcopyDiscardState PostcopyDiscardState;
 typedef struct Property Property;
 typedef struct PropertyInfo PropertyInfo;
-typedef struct ptimer_state ptimer_state;
+typedef struct PTimer PTimer;
 typedef struct QBool QBool;
 typedef struct QDict QDict;
 typedef struct QEMUBH QEMUBH;
tests/unit/ptimer-test.c +11 -11
index 04b5f4e3d0..907fe75996 100644
@@ -66,7 +66,7 @@ static void qemu_clock_step(uint64_t ns)
 static void check_set_count(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
 
     triggered = false;
 
@@ -81,7 +81,7 @@ static void check_set_count(gconstpointer arg)
 static void check_set_limit(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
 
     triggered = false;
 
@@ -104,7 +104,7 @@ static void check_set_limit(gconstpointer arg)
 static void check_oneshot(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
 
     triggered = false;
@@ -222,7 +222,7 @@ static void check_oneshot(gconstpointer arg)
 static void check_periodic(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
     bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
     bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
@@ -408,7 +408,7 @@ static void check_periodic(gconstpointer arg)
 static void check_on_the_fly_mode_change(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
     bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
 
@@ -460,7 +460,7 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
 static void check_on_the_fly_period_change(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
 
     triggered = false;
@@ -496,7 +496,7 @@ static void check_on_the_fly_period_change(gconstpointer arg)
 static void check_on_the_fly_freq_change(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
 
     triggered = false;
@@ -532,7 +532,7 @@ static void check_on_the_fly_freq_change(gconstpointer arg)
 static void check_run_with_period_0(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
 
     triggered = false;
 
@@ -551,7 +551,7 @@ static void check_run_with_period_0(gconstpointer arg)
 static void check_run_with_delta_0(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
     bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
     bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
@@ -664,7 +664,7 @@ static void check_run_with_delta_0(gconstpointer arg)
 static void check_periodic_with_load_0(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
     bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
     bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
@@ -729,7 +729,7 @@ static void check_periodic_with_load_0(gconstpointer arg)
 static void check_oneshot_with_load_0(gconstpointer arg)
 {
     const uint8_t *policy = arg;
-    ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
+    PTimer *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
     bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
     bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
 
Signature · 1 line
2.38.1
Reviewed-by
#10 lore raw

Re: [PATCH 3/2] hw/timer: Rename ptimer_state -> PTimer

Quoted 20 lines · Philippe Mathieu-Daudé

Remove a pointless cast in ptimer_tick() and rename 'ptimer_state' as 'PTimer' to follow the Structure naming convention.

See docs/devel/style.rst:

Variables are lower_case_with_underscores; easy to type and read. Structured type names are in CamelCase; harder to type but standing out. Enum type names and function type names should also be in CamelCase. Scalar type names are lower_case_with_underscores_ending_with_a_t, like the POSIX uint64_t and family.

Mechanical change doing:

   $ sed -i -e s/ptimer_state/PTimer/g \
       $(git grep -l ptimer_state)

---

...

hw/core/ptimer.c static void ptimer_reload(ptimer_state *s, int delta_adjust) · line 157

Quoted 6 lines
hw/core/ptimer.c +1 -1
@@ -154,7 +154,7 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
 
  static void ptimer_tick(void *opaque)
  {
-    ptimer_state *s = (ptimer_state *)opaque;
+    PTimer *s = opaque;

I like that you also removed the useless cast here.

Quoted 115 lines
hw/core/ptimer.c +16 -19
      bool trigger = true;
 
      /*
@@ -198,7 +198,7 @@ static void ptimer_tick(void *opaque)
      ptimer_transaction_commit(s);
  }
 
-uint64_t ptimer_get_count(ptimer_state *s)
+uint64_t ptimer_get_count(PTimer *s)
  {
      uint64_t counter;
 
@@ -294,7 +294,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
      return counter;
  }
 
-void ptimer_set_count(ptimer_state *s, uint64_t count)
+void ptimer_set_count(PTimer *s, uint64_t count)
  {
      assert(s->in_transaction);
      s->delta = count;
@@ -303,7 +303,7 @@ void ptimer_set_count(ptimer_state *s, uint64_t count)
      }
  }
 
-void ptimer_run(ptimer_state *s, int oneshot)
+void ptimer_run(PTimer *s, int oneshot)
  {
      bool was_disabled = !s->enabled;
 
@@ -323,7 +323,7 @@ void ptimer_run(ptimer_state *s, int oneshot)
 
  /* Pause a timer.  Note that this may cause it to "lose" time, even if it
     is immediately restarted.  */
-void ptimer_stop(ptimer_state *s)
+void ptimer_stop(PTimer *s)
  {
      assert(s->in_transaction);
 
@@ -337,7 +337,7 @@ void ptimer_stop(ptimer_state *s)
  }
 
  /* Set counter increment interval in nanoseconds.  */
-void ptimer_set_period(ptimer_state *s, int64_t period)
+void ptimer_set_period(PTimer *s, int64_t period)
  {
      assert(s->in_transaction);
      s->delta = ptimer_get_count(s);
@@ -349,7 +349,7 @@ void ptimer_set_period(ptimer_state *s, int64_t period)
  }
 
  /* Set counter increment interval from a Clock */
-void ptimer_set_period_from_clock(ptimer_state *s, const Clock *clk,
+void ptimer_set_period_from_clock(PTimer *s, const Clock *clk,
                                    unsigned int divisor)
  {
      /*
@@ -382,7 +382,7 @@ void ptimer_set_period_from_clock(ptimer_state *s, const Clock *clk,
  }
 
  /* Set counter frequency in Hz.  */
-void ptimer_set_freq(ptimer_state *s, uint32_t freq)
+void ptimer_set_freq(PTimer *s, uint32_t freq)
  {
      assert(s->in_transaction);
      s->delta = ptimer_get_count(s);
@@ -395,7 +395,7 @@ void ptimer_set_freq(ptimer_state *s, uint32_t freq)
 
  /* Set the initial countdown value.  If reload is nonzero then also set
     count = limit.  */
-void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload)
+void ptimer_set_limit(PTimer *s, uint64_t limit, int reload)
  {
      assert(s->in_transaction);
      s->limit = limit;
@@ -406,19 +406,19 @@ void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload)
      }
  }
 
-uint64_t ptimer_get_limit(ptimer_state *s)
+uint64_t ptimer_get_limit(PTimer *s)
  {
      return s->limit;
  }
 
-void ptimer_transaction_begin(ptimer_state *s)
+void ptimer_transaction_begin(PTimer *s)
  {
      assert(!s->in_transaction);
      s->in_transaction = true;
      s->need_reload = false;
  }
 
-void ptimer_transaction_commit(ptimer_state *s)
+void ptimer_transaction_commit(PTimer *s)
  {
      assert(s->in_transaction);
      /*
@@ -442,27 +442,27 @@ const VMStateDescription vmstate_ptimer = {
      .version_id = 1,
      .minimum_version_id = 1,
      .fields = (VMStateField[]) {
-        VMSTATE_UINT8(enabled, ptimer_state),
-        VMSTATE_UINT64(limit, ptimer_state),
-        VMSTATE_UINT64(delta, ptimer_state),
-        VMSTATE_UINT32(period_frac, ptimer_state),
-        VMSTATE_INT64(period, ptimer_state),
-        VMSTATE_INT64(last_event, ptimer_state),
-        VMSTATE_INT64(next_event, ptimer_state),
-        VMSTATE_TIMER_PTR(timer, ptimer_state),
+        VMSTATE_UINT8(enabled, PTimer),
+        VMSTATE_UINT64(limit, PTimer),
+        VMSTATE_UINT64(delta, PTimer),
+        VMSTATE_UINT32(period_frac, PTimer),
+        VMSTATE_INT64(period, PTimer),

hw/core/ptimer.c const VMStateDescription vmstate_ptimer = { · line 458

Quoted 10 lines
hw/core/ptimer.c +4 -1
+        VMSTATE_INT64(last_event, PTimer),
+        VMSTATE_INT64(next_event, PTimer),
+        VMSTATE_TIMER_PTR(timer, PTimer),
          VMSTATE_END_OF_LIST()
      }
  };
 
-ptimer_state *ptimer_init(ptimer_cb callback, void *callback_opaque,
+PTimer *ptimer_init(ptimer_cb callback, void *callback_opaque,
                            uint8_t policy_mask)

Just a nit: In case you respin, please adjust the indentation here.