[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC 09/10] hw/mos6522: Avoid using discrepant QEMU clock values
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [RFC 09/10] hw/mos6522: Avoid using discrepant QEMU clock values |
Date: |
Tue, 24 Aug 2021 12:28:31 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
On 8/24/21 12:09 PM, Finn Thain wrote:
> mos6522_read() and mos6522_write() may call various functions to determine
> timer irq state, timer counter value and QEMUTimer deadline. All called
> functions must use the same value for the present time.
>
> Signed-off-by: Finn Thain <fthain@linux-m68k.org>
> ---
> hw/misc/mos6522.c | 51 +++++++++++++++++++++++++----------------------
> 1 file changed, 27 insertions(+), 24 deletions(-)
> @@ -123,20 +123,19 @@ static int64_t get_next_irq_time(MOS6522State *s,
> MOS6522Timer *ti,
> trace_mos6522_get_next_irq_time(ti->latch, d, next_time - d);
> next_time = muldiv64(next_time, NANOSECONDS_PER_SECOND, ti->frequency) +
> ti->load_time;
> -
> - if (next_time <= current_time) {
> - next_time = current_time + 1;
> - }
Maybe extract as an helper? Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> return next_time;
> }
>
> static void mos6522_timer1_update(MOS6522State *s, MOS6522Timer *ti,
> - int64_t current_time)
> + int64_t now)
> {
> if (!ti->timer) {
> return;
> }
> - ti->next_irq_time = get_next_irq_time(s, ti, current_time);
> + ti->next_irq_time = get_next_irq_time(s, ti, now);
> + if (ti->next_irq_time <= now) {
> + ti->next_irq_time = now + 1;
> + }
> if ((s->ier & T1_INT) == 0 ||
> ((s->acr & T1MODE) == T1MODE_ONESHOT && ti->oneshot_fired)) {
> timer_del(ti->timer);
> @@ -146,12 +145,15 @@ static void mos6522_timer1_update(MOS6522State *s,
> MOS6522Timer *ti,
> }
>
> static void mos6522_timer2_update(MOS6522State *s, MOS6522Timer *ti,
> - int64_t current_time)
> + int64_t now)
> {
> if (!ti->timer) {
> return;
> }
> - ti->next_irq_time = get_next_irq_time(s, ti, current_time);
> + ti->next_irq_time = get_next_irq_time(s, ti, now);
> + if (ti->next_irq_time <= now) {
> + ti->next_irq_time = now + 1;
> + }
- Re: [RFC 03/10] hw/mos6522: Remove redundant mos6522_timer1_update() calls, (continued)
- [RFC 10/10] hw/mos6522: Synchronize timer interrupt and timer counter, Finn Thain, 2021/08/24
- [RFC 02/10] hw/mos6522: Remove get_counter_value() methods and functions, Finn Thain, 2021/08/24
- [RFC 06/10] hw/mos6522: Implement oneshot mode, Finn Thain, 2021/08/24
- [RFC 09/10] hw/mos6522: Avoid using discrepant QEMU clock values, Finn Thain, 2021/08/24
- Re: [RFC 00/10] hw/mos6522: VIA timer emulation fixes and improvements, David Gibson, 2021/08/25
- Re: [RFC 00/10] hw/mos6522: VIA timer emulation fixes and improvements, Mark Cave-Ayland, 2021/08/25