ptimer: Rename PTIMER_POLICY_DEFAULT to PTIMER_POLICY_LEGACY
Subsystems (4)
PATCH 1/1 ptimer: Rename PTIMER_POLICY_DEFAULT to PTIMER_POLICY_LEGACY
The traditional ptimer behaviour includes a collection of weird edge case behaviours. In 2016 we improved the ptimer implementation to fix these and generally make the behaviour more flexible, with ptimers opting in to the new behaviour by passing an appropriate set of policy flags to ptimer_init(). For backwards-compatibility, we defined PTIMER_POLICY_DEFAULT (which sets no flags) to give the old weird behaviour.
This turns out to be a poor choice of name, because people writing new devices which use ptimers are misled into thinking that the default is probably a sensible choice of flags, when in fact it is almost always not what you want. Rename PTIMER_POLICY_DEFAULT to PTIMER_POLICY_LEGACY and beef up the comment to more clearly say that new devices should not be using it.
The code-change part of this commit was produced by
sed -i -e 's/PTIMER_POLICY_DEFAULT/PTIMER_POLICY_LEGACY/g' $(git grep -l PTIMER_POLICY_DEFAULT)
--- include/hw/ptimer.h | 16 ++++++++++++---- hw/arm/musicpal.c | 2 +- hw/dma/xilinx_axidma.c | 2 +- hw/dma/xlnx_csu_dma.c | 2 +- hw/m68k/mcf5206.c | 2 +- hw/m68k/mcf5208.c | 2 +- hw/net/can/xlnx-zynqmp-can.c | 2 +- hw/net/fsl_etsec/etsec.c | 2 +- hw/net/lan9118.c | 2 +- hw/rtc/exynos4210_rtc.c | 4 ++-- hw/timer/allwinner-a10-pit.c | 2 +- hw/timer/altera_timer.c | 2 +- hw/timer/arm_timer.c | 2 +- hw/timer/digic-timer.c | 2 +- hw/timer/etraxfs_timer.c | 6 +++--- hw/timer/exynos4210_mct.c | 6 +++--- hw/timer/exynos4210_pwm.c | 2 +- hw/timer/grlib_gptimer.c | 2 +- hw/timer/imx_epit.c | 4 ++-- hw/timer/imx_gpt.c | 2 +- hw/timer/mss-timer.c | 2 +- hw/timer/sh_timer.c | 2 +- hw/timer/slavio_timer.c | 2 +- hw/timer/xilinx_timer.c | 2 +- tests/unit/ptimer-test.c | 4 ++-- 25 files changed, 43 insertions(+), 35 deletions(-)
include/hw/ptimer.h +12 -4
@@ -33,9 +33,17 @@* to stderr when the guest attempts to enable the timer. */ -/* The default ptimer policy retains backward compatibility with the legacy -* timers. Custom policies are adjusting the default one. Consider providing -* a correct policy for your timer. +/* +* The 'legacy' ptimer policy retains backward compatibility with the +* traditional ptimer behaviour from before policy flags were introduced. +* It has several weird behaviours which don't match typical hardware +* timer behaviour. For a new device using ptimers, you should not +* use PTIMER_POLICY_LEGACY, but instead check the actual behaviour +* that you need and specify the right set of policy flags to get that. +* +* If you are overhauling an existing device that uses PTIMER_POLICY_LEGACY +* and are in a position to check or test the real hardware behaviour, +* consider updating it to specify the right policy flags. * * The rough edges of the default policy: * - Starting to run with a period = 0 emits error message and stops the
@@ -54,7 +62,7 @@* since the last period, effectively restarting the timer with a * counter = counter value at the moment of change (.i.e. one less). */ -#define PTIMER_POLICY_DEFAULT 0 +#define PTIMER_POLICY_LEGACY 0/* Periodic timer counter stays with "0" for a one period before wrapping * around. */
hw/arm/musicpal.c +1 -1
@@ -464,7 +464,7 @@ static void mv88w8618_timer_init(SysBusDevice *dev, mv88w8618_timer_state *s,sysbus_init_irq (dev, &s->irq); s->freq = freq; - s->ptimer =ptimer_init (mv88w8618_timer_tick, s,PTIMER_POLICY_DEFAULT ); + s->ptimer =ptimer_init (mv88w8618_timer_tick, s,PTIMER_POLICY_LEGACY ); } static uint64_t mv88w8618_pit_read(void *opaque, hwaddr offset,
hw/dma/xilinx_axidma.c +1 -1
@@ -552,7 +552,7 @@ static void xilinx_axidma_realize(DeviceState *dev, Error **errp) st->dma = s; st->nr = i; - st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_DEFAULT ); + st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (st->ptimer);ptimer_set_freq (st->ptimer, s->freqhz);ptimer_transaction_commit (st->ptimer);
hw/dma/xlnx_csu_dma.c +1 -1
@@ -666,7 +666,7 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)sysbus_init_irq (SYS_BUS_DEVICE (dev), &s->irq); s->src_timer =ptimer_init (xlnx_csu_dma_src_timeout_hit, - s,PTIMER_POLICY_DEFAULT ); + s,PTIMER_POLICY_LEGACY ); s->attr =MEMTXATTRS_UNSPECIFIED ;
hw/m68k/mcf5206.c +1 -1
@@ -152,7 +152,7 @@ static m5206_timer_state *m5206_timer_init(qemu_irq irq)m5206_timer_state *s; s =g_new0 (m5206_timer_state,1 ); - s->timer =ptimer_init (m5206_timer_trigger, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (m5206_timer_trigger, s,PTIMER_POLICY_LEGACY ); s->irq = irq;m5206_timer_reset (s);return s;
hw/m68k/mcf5208.c +1 -1
@@ -197,7 +197,7 @@ static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic)/* Timers. */ for (i =0 ; i <2 ; i++) { s =g_new0 (m5208_timer_state,1 ); - s->timer =ptimer_init (m5208_timer_trigger, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (m5208_timer_trigger, s,PTIMER_POLICY_LEGACY );memory_region_init_io (&s->iomem,NULL , &m5208_timer_ops, s,"m5208-timer" ,0x00004000 ); memory_region_add_subregion(address_space, 0xfc080000 + 0x4000 * i,
hw/net/can/xlnx-zynqmp-can.c +1 -1
@@ -1079,7 +1079,7 @@ static void xlnx_zynqmp_can_realize(DeviceState *dev, Error **errp)/* Allocate a new timer. */ s->can_timer =ptimer_init (xlnx_zynqmp_can_ptimer_cb, s, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->can_timer);
hw/net/fsl_etsec/etsec.c +1 -1
@@ -393,7 +393,7 @@ static void etsec_realize(DeviceState *dev, Error **errp) object_get_typename(OBJECT(dev)), dev->id, etsec);qemu_format_nic_info_str (qemu_get_queue (etsec->nic), etsec->conf.macaddr.a); - etsec->ptimer =ptimer_init (etsec_timer_hit, etsec,PTIMER_POLICY_DEFAULT ); + etsec->ptimer =ptimer_init (etsec_timer_hit, etsec,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (etsec->ptimer);ptimer_set_freq (etsec->ptimer,100 );ptimer_transaction_commit (etsec->ptimer);
hw/net/lan9118.c +1 -1
@@ -1363,7 +1363,7 @@ static void lan9118_realize(DeviceState *dev, Error **errp) s->pmt_ctrl =1 ; s->txp = &s->tx_packet; - s->timer =ptimer_init (lan9118_tick, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (lan9118_tick, s,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->timer);ptimer_set_freq (s->timer,10000 );ptimer_set_limit (s->timer,0xffff ,1 );
hw/rtc/exynos4210_rtc.c +2 -2
@@ -564,14 +564,14 @@ static void exynos4210_rtc_init(Object *obj)Exynos4210RTCState *s =EXYNOS4210_RTC (obj);SysBusDevice *dev =SYS_BUS_DEVICE (obj); - s->ptimer =ptimer_init (exynos4210_rtc_tick, s,PTIMER_POLICY_DEFAULT ); + s->ptimer =ptimer_init (exynos4210_rtc_tick, s,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->ptimer);ptimer_set_freq (s->ptimer,RTC_BASE_FREQ );exynos4210_rtc_update_freq (s,0 );ptimer_transaction_commit (s->ptimer); s->ptimer_1Hz =ptimer_init (exynos4210_rtc_1Hz_tick, - s,PTIMER_POLICY_DEFAULT ); + s,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->ptimer_1Hz);ptimer_set_freq (s->ptimer_1Hz,RTC_BASE_FREQ );ptimer_transaction_commit (s->ptimer_1Hz);
hw/timer/allwinner-a10-pit.c +1 -1
@@ -275,7 +275,7 @@ static void a10_pit_init(Object *obj) tc->container = s; tc->index = i; - s->timer[i] =ptimer_init (a10_pit_timer_cb, tc,PTIMER_POLICY_DEFAULT ); + s->timer[i] =ptimer_init (a10_pit_timer_cb, tc,PTIMER_POLICY_LEGACY ); } }
hw/timer/altera_timer.c +1 -1
@@ -185,7 +185,7 @@ static void altera_timer_realize(DeviceState *dev, Error **errp)return ; } - t->ptimer =ptimer_init (timer_hit, t,PTIMER_POLICY_DEFAULT ); + t->ptimer =ptimer_init (timer_hit, t,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (t->ptimer);ptimer_set_freq (t->ptimer, t->freq_hz);ptimer_transaction_commit (t->ptimer);
hw/timer/arm_timer.c +1 -1
@@ -180,7 +180,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq) s->freq = freq; s->control =TIMER_CTRL_IE ; - s->timer =ptimer_init (arm_timer_tick, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (arm_timer_tick, s,PTIMER_POLICY_LEGACY );vmstate_register (NULL ,VMSTATE_INSTANCE_ID_ANY , &vmstate_arm_timer, s);return s; }
hw/timer/digic-timer.c +1 -1
@@ -139,7 +139,7 @@ static void digic_timer_init(Object *obj) {DigicTimerState *s =DIGIC_TIMER (obj); - s->ptimer =ptimer_init (digic_timer_tick,NULL ,PTIMER_POLICY_DEFAULT ); + s->ptimer =ptimer_init (digic_timer_tick,NULL ,PTIMER_POLICY_LEGACY );/* * FIXME: there is no documentation on Digic timer
hw/timer/etraxfs_timer.c +3 -3
@@ -370,9 +370,9 @@ static void etraxfs_timer_realize(DeviceState *dev, Error **errp)ETRAXTimerState *t =ETRAX_TIMER (dev);SysBusDevice *sbd =SYS_BUS_DEVICE (dev); - t->ptimer_t0 =ptimer_init (timer0_hit, t,PTIMER_POLICY_DEFAULT ); - t->ptimer_t1 =ptimer_init (timer1_hit, t,PTIMER_POLICY_DEFAULT ); - t->ptimer_wd =ptimer_init (watchdog_hit, t,PTIMER_POLICY_DEFAULT ); + t->ptimer_t0 =ptimer_init (timer0_hit, t,PTIMER_POLICY_LEGACY ); + t->ptimer_t1 =ptimer_init (timer1_hit, t,PTIMER_POLICY_LEGACY ); + t->ptimer_wd =ptimer_init (watchdog_hit, t,PTIMER_POLICY_LEGACY );sysbus_init_irq (sbd, &t->irq);sysbus_init_irq (sbd, &t->nmi);
hw/timer/exynos4210_mct.c +3 -3
@@ -1503,17 +1503,17 @@ static void exynos4210_mct_init(Object *obj)/* Global timer */ s->g_timer.ptimer_frc =ptimer_init (exynos4210_gfrc_event, s, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY );memset (&s->g_timer.reg,0 ,sizeof (struct gregs ));/* Local timers */ for (i =0 ; i <2 ; i++) { s->l_timer[i].tick_timer.ptimer_tick =ptimer_init (exynos4210_ltick_event, &s->l_timer[i], -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); s->l_timer[i].ptimer_frc =ptimer_init (exynos4210_lfrc_event, &s->l_timer[i], -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); s->l_timer[i].id = i; }
hw/timer/exynos4210_pwm.c +1 -1
@@ -400,7 +400,7 @@ static void exynos4210_pwm_init(Object *obj)sysbus_init_irq (dev, &s->timer[i].irq); s->timer[i].ptimer =ptimer_init (exynos4210_pwm_tick, &s->timer[i], -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); s->timer[i].id = i; s->timer[i].parent = s; }
hw/timer/grlib_gptimer.c +1 -1
@@ -383,7 +383,7 @@ static void grlib_gptimer_realize(DeviceState *dev, Error **errp) timer->unit = unit; timer->ptimer =ptimer_init (grlib_gptimer_hit, timer, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); timer->id = i;/* One IRQ line for each timer */
hw/timer/imx_epit.c +2 -2
@@ -347,9 +347,9 @@ static void imx_epit_realize(DeviceState *dev, Error **errp) 0x00001000);sysbus_init_mmio (sbd, &s->iomem); - s->timer_reload =ptimer_init (imx_epit_reload, s,PTIMER_POLICY_DEFAULT ); + s->timer_reload =ptimer_init (imx_epit_reload, s,PTIMER_POLICY_LEGACY ); - s->timer_cmp =ptimer_init (imx_epit_cmp, s,PTIMER_POLICY_DEFAULT ); + s->timer_cmp =ptimer_init (imx_epit_cmp, s,PTIMER_POLICY_LEGACY ); }static void imx_epit_class_init (ObjectClass *klass,void *data)
hw/timer/imx_gpt.c +1 -1
@@ -505,7 +505,7 @@ static void imx_gpt_realize(DeviceState *dev, Error **errp) 0x00001000);sysbus_init_mmio (sbd, &s->iomem); - s->timer =ptimer_init (imx_gpt_timeout, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (imx_gpt_timeout, s,PTIMER_POLICY_LEGACY ); }static void imx_gpt_class_init (ObjectClass *klass,void *data)
hw/timer/mss-timer.c +1 -1
@@ -232,7 +232,7 @@ static void mss_timer_init(Object *obj)for (i =0 ; i <NUM_TIMERS ; i++) {struct Msf2Timer *st = &t->timers[i]; - st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_DEFAULT ); + st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (st->ptimer);ptimer_set_freq (st->ptimer, t->freq_hz);ptimer_transaction_commit (st->ptimer);
hw/timer/sh_timer.c +1 -1
@@ -239,7 +239,7 @@ static void *sh_timer_init(uint32_t freq, int feat, qemu_irq irq) s->enabled =0 ; s->irq = irq; - s->timer =ptimer_init (sh_timer_tick, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (sh_timer_tick, s,PTIMER_POLICY_LEGACY );sh_timer_write (s,OFFSET_TCOR >>2 , s->tcor);sh_timer_write (s,OFFSET_TCNT >>2 , s->tcnt);
hw/timer/slavio_timer.c +1 -1
@@ -405,7 +405,7 @@ static void slavio_timer_init(Object *obj) tc->timer_index = i; s->cputimer[i].timer =ptimer_init (slavio_timer_irq, tc, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->cputimer[i].timer);ptimer_set_period (s->cputimer[i].timer,TIMER_PERIOD );ptimer_transaction_commit (s->cputimer[i].timer);
hw/timer/xilinx_timer.c +1 -1
@@ -223,7 +223,7 @@ static void xilinx_timer_realize(DeviceState *dev, Error **errp) xt->parent = t; xt->nr = i; - xt->ptimer =ptimer_init (timer_hit, xt,PTIMER_POLICY_DEFAULT ); + xt->ptimer =ptimer_init (timer_hit, xt,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (xt->ptimer);ptimer_set_freq (xt->ptimer, t->freq_hz);ptimer_transaction_commit (xt->ptimer);
tests/unit/ptimer-test.c +2 -2
@@ -768,7 +768,7 @@ static void add_ptimer_tests(uint8_t policy)char policy_name[256 ] ="" ;char *tmp; -if (policy ==PTIMER_POLICY_DEFAULT ) { +if (policy ==PTIMER_POLICY_LEGACY ) {g_sprintf (policy_name,"default" ); }
@@ -862,7 +862,7 @@ static void add_ptimer_tests(uint8_t policy)static void add_all_ptimer_policies_comb_tests (void ) {int last_policy =PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT ; -int policy =PTIMER_POLICY_DEFAULT ; +int policy =PTIMER_POLICY_LEGACY ;for (; policy < (last_policy <<1 ); policy++) { if ((policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) &&
Signature · 1 line
2.25.1
Quoted 412 lines · Peter Maydell
The traditional ptimer behaviour includes a collection of weird edge case behaviours. In 2016 we improved the ptimer implementation to fix these and generally make the behaviour more flexible, with ptimers opting in to the new behaviour by passing an appropriate set of policy flags to
ptimer_init(). For backwards-compatibility, we definedPTIMER_POLICY_DEFAULT(which sets no flags) to give the old weird behaviour.This turns out to be a poor choice of name, because people writing new devices which use ptimers are misled into thinking that the default is probably a sensible choice of flags, when in fact it is almost always not what you want. Rename
PTIMER_POLICY_DEFAULTtoPTIMER_POLICY_LEGACYand beef up the comment to more clearly say that new devices should not be using it.The code-change part of this commit was produced by
sed -i -e 's/PTIMER_POLICY_DEFAULT/PTIMER_POLICY_LEGACY/g' $(git grep -lPTIMER_POLICY_DEFAULT)Signed-off-by Peter Maydell <[email protected]>--- include/hw/ptimer.h | 16 ++++++++++++---- hw/arm/musicpal.c | 2 +- hw/dma/xilinx_axidma.c | 2 +- hw/dma/xlnx_csu_dma.c | 2 +- hw/m68k/mcf5206.c | 2 +- hw/m68k/mcf5208.c | 2 +- hw/net/can/xlnx-zynqmp-can.c | 2 +- hw/net/fsl_etsec/etsec.c | 2 +- hw/net/lan9118.c | 2 +- hw/rtc/exynos4210_rtc.c | 4 ++-- hw/timer/allwinner-a10-pit.c | 2 +- hw/timer/altera_timer.c | 2 +- hw/timer/arm_timer.c | 2 +- hw/timer/digic-timer.c | 2 +- hw/timer/etraxfs_timer.c | 6 +++--- hw/timer/exynos4210_mct.c | 6 +++--- hw/timer/exynos4210_pwm.c | 2 +- hw/timer/grlib_gptimer.c | 2 +- hw/timer/imx_epit.c | 4 ++-- hw/timer/imx_gpt.c | 2 +- hw/timer/mss-timer.c | 2 +- hw/timer/sh_timer.c | 2 +- hw/timer/slavio_timer.c | 2 +- hw/timer/xilinx_timer.c | 2 +- tests/unit/ptimer-test.c | 4 ++-- 25 files changed, 43 insertions(+), 35 deletions(-)include/hw/ptimer.h +12
-4@@ -33,9 +33,17 @@* to stderr when the guest attempts to enable the timer. */ -/* The default ptimer policy retains backward compatibility with the legacy -* timers. Custom policies are adjusting the default one. Consider providing -* a correct policy for your timer. +/* +* The 'legacy' ptimer policy retains backward compatibility with the +* traditional ptimer behaviour from before policy flags were introduced. +* It has several weird behaviours which don't match typical hardware +* timer behaviour. For a new device using ptimers, you should not +* use PTIMER_POLICY_LEGACY, but instead check the actual behaviour +* that you need and specify the right set of policy flags to get that. +* +* If you are overhauling an existing device that uses PTIMER_POLICY_LEGACY +* and are in a position to check or test the real hardware behaviour, +* consider updating it to specify the right policy flags. * * The rough edges of the default policy: * - Starting to run with a period = 0 emits error message and stops the @@ -54,7 +62,7 @@* since the last period, effectively restarting the timer with a * counter = counter value at the moment of change (.i.e. one less). */ -#define PTIMER_POLICY_DEFAULT 0 +#define PTIMER_POLICY_LEGACY 0/* Periodic timer counter stays with "0" for a one period before wrapping * around. */ hw/arm/musicpal.c +1
-1@@ -464,7 +464,7 @@ static void mv88w8618_timer_init(SysBusDevice *dev, mv88w8618_timer_state *s,sysbus_init_irq (dev, &s->irq); s->freq = freq; - s->ptimer =ptimer_init (mv88w8618_timer_tick, s,PTIMER_POLICY_DEFAULT ); + s->ptimer =ptimer_init (mv88w8618_timer_tick, s,PTIMER_POLICY_LEGACY ); } static uint64_t mv88w8618_pit_read(void *opaque, hwaddr offset,hw/dma/xilinx_axidma.c +1
-1@@ -552,7 +552,7 @@ static void xilinx_axidma_realize(DeviceState *dev, Error **errp) st->dma = s; st->nr = i; - st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_DEFAULT ); + st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (st->ptimer);ptimer_set_freq (st->ptimer, s->freqhz);ptimer_transaction_commit (st->ptimer);hw/dma/xlnx_csu_dma.c +1
-1@@ -666,7 +666,7 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)sysbus_init_irq (SYS_BUS_DEVICE (dev), &s->irq); s->src_timer =ptimer_init (xlnx_csu_dma_src_timeout_hit, - s,PTIMER_POLICY_DEFAULT ); + s,PTIMER_POLICY_LEGACY ); s->attr =MEMTXATTRS_UNSPECIFIED ;hw/m68k/mcf5206.c +1
-1@@ -152,7 +152,7 @@ static m5206_timer_state *m5206_timer_init(qemu_irq irq)m5206_timer_state *s; s =g_new0 (m5206_timer_state,1 ); - s->timer =ptimer_init (m5206_timer_trigger, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (m5206_timer_trigger, s,PTIMER_POLICY_LEGACY ); s->irq = irq;m5206_timer_reset (s);return s;hw/m68k/mcf5208.c +1
-1@@ -197,7 +197,7 @@ static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic)/* Timers. */ for (i =0 ; i <2 ; i++) { s =g_new0 (m5208_timer_state,1 ); - s->timer =ptimer_init (m5208_timer_trigger, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (m5208_timer_trigger, s,PTIMER_POLICY_LEGACY );memory_region_init_io (&s->iomem,NULL , &m5208_timer_ops, s,"m5208-timer" ,0x00004000 ); memory_region_add_subregion(address_space, 0xfc080000 + 0x4000 * i,hw/net/can/xlnx-zynqmp-can.c +1
-1@@ -1079,7 +1079,7 @@ static void xlnx_zynqmp_can_realize(DeviceState *dev, Error **errp)/* Allocate a new timer. */ s->can_timer =ptimer_init (xlnx_zynqmp_can_ptimer_cb, s, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->can_timer);hw/net/fsl_etsec/etsec.c +1
-1@@ -393,7 +393,7 @@ static void etsec_realize(DeviceState *dev, Error **errp) object_get_typename(OBJECT(dev)), dev->id, etsec);qemu_format_nic_info_str (qemu_get_queue (etsec->nic), etsec->conf.macaddr.a); - etsec->ptimer =ptimer_init (etsec_timer_hit, etsec,PTIMER_POLICY_DEFAULT ); + etsec->ptimer =ptimer_init (etsec_timer_hit, etsec,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (etsec->ptimer);ptimer_set_freq (etsec->ptimer,100 );ptimer_transaction_commit (etsec->ptimer);hw/net/lan9118.c +1
-1@@ -1363,7 +1363,7 @@ static void lan9118_realize(DeviceState *dev, Error **errp) s->pmt_ctrl =1 ; s->txp = &s->tx_packet; - s->timer =ptimer_init (lan9118_tick, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (lan9118_tick, s,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->timer);ptimer_set_freq (s->timer,10000 );ptimer_set_limit (s->timer,0xffff ,1 );hw/rtc/exynos4210_rtc.c +2
-2@@ -564,14 +564,14 @@ static void exynos4210_rtc_init(Object *obj)Exynos4210RTCState *s =EXYNOS4210_RTC (obj);SysBusDevice *dev =SYS_BUS_DEVICE (obj); - s->ptimer =ptimer_init (exynos4210_rtc_tick, s,PTIMER_POLICY_DEFAULT ); + s->ptimer =ptimer_init (exynos4210_rtc_tick, s,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->ptimer);ptimer_set_freq (s->ptimer,RTC_BASE_FREQ );exynos4210_rtc_update_freq (s,0 );ptimer_transaction_commit (s->ptimer); s->ptimer_1Hz =ptimer_init (exynos4210_rtc_1Hz_tick, - s,PTIMER_POLICY_DEFAULT ); + s,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->ptimer_1Hz);ptimer_set_freq (s->ptimer_1Hz,RTC_BASE_FREQ );ptimer_transaction_commit (s->ptimer_1Hz);hw/timer/allwinner-a10-pit.c +1
-1@@ -275,7 +275,7 @@ static void a10_pit_init(Object *obj) tc->container = s; tc->index = i; - s->timer[i] =ptimer_init (a10_pit_timer_cb, tc,PTIMER_POLICY_DEFAULT ); + s->timer[i] =ptimer_init (a10_pit_timer_cb, tc,PTIMER_POLICY_LEGACY ); } }hw/timer/altera_timer.c +1
-1@@ -185,7 +185,7 @@ static void altera_timer_realize(DeviceState *dev, Error **errp)return ; } - t->ptimer =ptimer_init (timer_hit, t,PTIMER_POLICY_DEFAULT ); + t->ptimer =ptimer_init (timer_hit, t,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (t->ptimer);ptimer_set_freq (t->ptimer, t->freq_hz);ptimer_transaction_commit (t->ptimer);hw/timer/arm_timer.c +1
-1@@ -180,7 +180,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq) s->freq = freq; s->control =TIMER_CTRL_IE ; - s->timer =ptimer_init (arm_timer_tick, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (arm_timer_tick, s,PTIMER_POLICY_LEGACY );vmstate_register (NULL ,VMSTATE_INSTANCE_ID_ANY , &vmstate_arm_timer, s);return s; }hw/timer/digic-timer.c +1
-1@@ -139,7 +139,7 @@ static void digic_timer_init(Object *obj) {DigicTimerState *s =DIGIC_TIMER (obj); - s->ptimer =ptimer_init (digic_timer_tick,NULL ,PTIMER_POLICY_DEFAULT ); + s->ptimer =ptimer_init (digic_timer_tick,NULL ,PTIMER_POLICY_LEGACY );/* * FIXME: there is no documentation on Digic timer hw/timer/etraxfs_timer.c +3
-3@@ -370,9 +370,9 @@ static void etraxfs_timer_realize(DeviceState *dev, Error **errp)ETRAXTimerState *t =ETRAX_TIMER (dev);SysBusDevice *sbd =SYS_BUS_DEVICE (dev); - t->ptimer_t0 =ptimer_init (timer0_hit, t,PTIMER_POLICY_DEFAULT ); - t->ptimer_t1 =ptimer_init (timer1_hit, t,PTIMER_POLICY_DEFAULT ); - t->ptimer_wd =ptimer_init (watchdog_hit, t,PTIMER_POLICY_DEFAULT ); + t->ptimer_t0 =ptimer_init (timer0_hit, t,PTIMER_POLICY_LEGACY ); + t->ptimer_t1 =ptimer_init (timer1_hit, t,PTIMER_POLICY_LEGACY ); + t->ptimer_wd =ptimer_init (watchdog_hit, t,PTIMER_POLICY_LEGACY );sysbus_init_irq (sbd, &t->irq);sysbus_init_irq (sbd, &t->nmi);hw/timer/exynos4210_mct.c +3
-3@@ -1503,17 +1503,17 @@ static void exynos4210_mct_init(Object *obj)/* Global timer */ s->g_timer.ptimer_frc =ptimer_init (exynos4210_gfrc_event, s, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY );memset (&s->g_timer.reg,0 ,sizeof (struct gregs ));/* Local timers */ for (i =0 ; i <2 ; i++) { s->l_timer[i].tick_timer.ptimer_tick =ptimer_init (exynos4210_ltick_event, &s->l_timer[i], -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); s->l_timer[i].ptimer_frc =ptimer_init (exynos4210_lfrc_event, &s->l_timer[i], -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); s->l_timer[i].id = i; }hw/timer/exynos4210_pwm.c +1
-1@@ -400,7 +400,7 @@ static void exynos4210_pwm_init(Object *obj)sysbus_init_irq (dev, &s->timer[i].irq); s->timer[i].ptimer =ptimer_init (exynos4210_pwm_tick, &s->timer[i], -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); s->timer[i].id = i; s->timer[i].parent = s; }hw/timer/grlib_gptimer.c +1
-1@@ -383,7 +383,7 @@ static void grlib_gptimer_realize(DeviceState *dev, Error **errp) timer->unit = unit; timer->ptimer =ptimer_init (grlib_gptimer_hit, timer, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY ); timer->id = i;/* One IRQ line for each timer */ hw/timer/imx_epit.c +2
-2@@ -347,9 +347,9 @@ static void imx_epit_realize(DeviceState *dev, Error **errp) 0x00001000);sysbus_init_mmio (sbd, &s->iomem); - s->timer_reload =ptimer_init (imx_epit_reload, s,PTIMER_POLICY_DEFAULT ); + s->timer_reload =ptimer_init (imx_epit_reload, s,PTIMER_POLICY_LEGACY ); - s->timer_cmp =ptimer_init (imx_epit_cmp, s,PTIMER_POLICY_DEFAULT ); + s->timer_cmp =ptimer_init (imx_epit_cmp, s,PTIMER_POLICY_LEGACY ); }static void imx_epit_class_init (ObjectClass *klass,void *data)hw/timer/imx_gpt.c +1
-1@@ -505,7 +505,7 @@ static void imx_gpt_realize(DeviceState *dev, Error **errp) 0x00001000);sysbus_init_mmio (sbd, &s->iomem); - s->timer =ptimer_init (imx_gpt_timeout, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (imx_gpt_timeout, s,PTIMER_POLICY_LEGACY ); }static void imx_gpt_class_init (ObjectClass *klass,void *data)hw/timer/mss-timer.c +1
-1@@ -232,7 +232,7 @@ static void mss_timer_init(Object *obj)for (i =0 ; i <NUM_TIMERS ; i++) {struct Msf2Timer *st = &t->timers[i]; - st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_DEFAULT ); + st->ptimer =ptimer_init (timer_hit, st,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (st->ptimer);ptimer_set_freq (st->ptimer, t->freq_hz);ptimer_transaction_commit (st->ptimer);hw/timer/sh_timer.c +1
-1@@ -239,7 +239,7 @@ static void *sh_timer_init(uint32_t freq, int feat, qemu_irq irq) s->enabled =0 ; s->irq = irq; - s->timer =ptimer_init (sh_timer_tick, s,PTIMER_POLICY_DEFAULT ); + s->timer =ptimer_init (sh_timer_tick, s,PTIMER_POLICY_LEGACY );sh_timer_write (s,OFFSET_TCOR >>2 , s->tcor);sh_timer_write (s,OFFSET_TCNT >>2 , s->tcnt);hw/timer/slavio_timer.c +1
-1@@ -405,7 +405,7 @@ static void slavio_timer_init(Object *obj) tc->timer_index = i; s->cputimer[i].timer =ptimer_init (slavio_timer_irq, tc, -PTIMER_POLICY_DEFAULT ); +PTIMER_POLICY_LEGACY );ptimer_transaction_begin (s->cputimer[i].timer);ptimer_set_period (s->cputimer[i].timer,TIMER_PERIOD );ptimer_transaction_commit (s->cputimer[i].timer);hw/timer/xilinx_timer.c +1
-1@@ -223,7 +223,7 @@ static void xilinx_timer_realize(DeviceState *dev, Error **errp) xt->parent = t; xt->nr = i; - xt->ptimer =ptimer_init (timer_hit, xt,PTIMER_POLICY_DEFAULT ); + xt->ptimer =ptimer_init (timer_hit, xt,PTIMER_POLICY_LEGACY );ptimer_transaction_begin (xt->ptimer);ptimer_set_freq (xt->ptimer, t->freq_hz);ptimer_transaction_commit (xt->ptimer);tests/unit/ptimer-test.c +0
-0
tests/unit/ptimer-test.c static void add_ptimer_tests(uint8_t policy) · line 772
Quoted 6 lines
tests/unit/ptimer-test.c +1
-1@@ -768,7 +768,7 @@ static void add_ptimer_tests(uint8_t policy)char policy_name[256 ] ="" ;char *tmp; -if (policy ==PTIMER_POLICY_DEFAULT ) { +if (policy ==PTIMER_POLICY_LEGACY ) {g_sprintf (policy_name,"default" );
Hi Peter,
It might be that above is clearer after this patch with "legacy" but since it will break the automatic code changing sed command, with or without the change:
Best regards,
Francisco Iglesias
Quoted 14 lines
tests/unit/ptimer-test.c +1
-1}@@ -862,7 +862,7 @@ static void add_ptimer_tests(uint8_t policy)static void add_all_ptimer_policies_comb_tests (void ) {int last_policy =PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT ; -int policy =PTIMER_POLICY_DEFAULT ; +int policy =PTIMER_POLICY_LEGACY ;for (; policy < (last_policy <<1 ); policy++) { if ((policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) &&Signature · 1 line
2.25.1
Quoted 29 lines · Francisco Iglesias
Quoted 27 lines · Peter Maydell
The traditional ptimer behaviour includes a collection of weird edge case behaviours. In 2016 we improved the ptimer implementation to fix these and generally make the behaviour more flexible, with ptimers opting in to the new behaviour by passing an appropriate set of policy flags to
ptimer_init(). For backwards-compatibility, we definedPTIMER_POLICY_DEFAULT(which sets no flags) to give the old weird behaviour.This turns out to be a poor choice of name, because people writing new devices which use ptimers are misled into thinking that the default is probably a sensible choice of flags, when in fact it is almost always not what you want. Rename
PTIMER_POLICY_DEFAULTtoPTIMER_POLICY_LEGACYand beef up the comment to more clearly say that new devices should not be using it.The code-change part of this commit was produced by
sed -i -e 's/PTIMER_POLICY_DEFAULT/PTIMER_POLICY_LEGACY/g' $(git grep -lPTIMER_POLICY_DEFAULT)Signed-off-by Peter Maydell <[email protected]>tests/unit/ptimer-test.c +0
-0@@ -768,7 +768,7 @@ static void add_ptimer_tests(uint8_t policy)char policy_name[256 ] ="" ;char *tmp;
Quoted 7 lines
tests/unit/ptimer-test.c static void add_ptimer_tests(uint8_t policy) · line 772
Quoted 3 lines
tests/unit/ptimer-test.c +1
-1-if (policy ==PTIMER_POLICY_DEFAULT ) { +if (policy ==PTIMER_POLICY_LEGACY ) {g_sprintf (policy_name,"default" );Hi Peter,
It might be that above is clearer after this patch with "legacy"
Oops, yes, we should adjust the test name string there too.
thanks
-- PMM
Quoted 15 lines · Peter Maydell
The traditional ptimer behaviour includes a collection of weird edge case behaviours. In 2016 we improved the ptimer implementation to fix these and generally make the behaviour more flexible, with ptimers opting in to the new behaviour by passing an appropriate set of policy flags to
ptimer_init(). For backwards-compatibility, we definedPTIMER_POLICY_DEFAULT(which sets no flags) to give the old weird behaviour.This turns out to be a poor choice of name, because people writing new devices which use ptimers are misled into thinking that the default is probably a sensible choice of flags, when in fact it is almost always not what you want. Rename
PTIMER_POLICY_DEFAULTtoPTIMER_POLICY_LEGACYand beef up the comment to more clearly say that new devices should not be using it.
Quoted 5 lines
The code-change part of this commit was produced by
sed -i -e 's/PTIMER_POLICY_DEFAULT/PTIMER_POLICY_LEGACY/g' $(git grep -lPTIMER_POLICY_DEFAULT)Signed-off-by Peter Maydell<[email protected]>---
with the ptimer-test.c string change already noted.
r~