Re: vmd: tweak mc146818 periodic interrupt updating

2019-05-26 Thread Mike Larkin
On Sun, May 26, 2019 at 08:14:43PM +0200, Jasper Lievisse Adriaanse wrote:
> Hi,
> 
> Whilst looking at the mc146818 code in vmd I noticed something that initially 
> struck
> me as a pasto as the same code is present in the rtc_update_regb() function. 
> However
> it led me to look at how other emulators handle the updating of registers. 
> Based on
> that here's a diff to only reschedule the periodic interrupt after updating 
> register A
> if something changed in register A.
> 
> When updating register A we were checking in register B if the
> PIE bit was set in order to decide if rtc_reschedule_per needed
> to be called. if that bit was changed then the timer rate would
> already have been adjusted by rtc_update_regb so the call from
> rtc_update_rega is not needed. This now matches what qemu and
> other emulators are doing too.
> 
> This has been running fine for a few days in a number of VMs.
> 
> OK?
> 

sure, ok mlarkin

> Index: mc146818.c
> ===
> RCS file: /cvs/src/usr.sbin/vmd/mc146818.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 mc146818.c
> --- mc146818.c12 Jul 2018 10:15:44 -  1.18
> +++ mc146818.c26 May 2019 12:13:32 -
> @@ -216,7 +216,7 @@ rtc_update_rega(uint32_t data)
>   __func__);
>  
>   rtc.regs[MC_REGA] = data;
> - if (rtc.regs[MC_REGB] & MC_REGB_PIE)
> + if ((rtc.regs[MC_REGA] ^ data) & 0x0f)
>   rtc_reschedule_per();
>  }
>  
> 
> -- 
> jasper
> 



vmd: tweak mc146818 periodic interrupt updating

2019-05-26 Thread Jasper Lievisse Adriaanse
Hi,

Whilst looking at the mc146818 code in vmd I noticed something that initially 
struck
me as a pasto as the same code is present in the rtc_update_regb() function. 
However
it led me to look at how other emulators handle the updating of registers. 
Based on
that here's a diff to only reschedule the periodic interrupt after updating 
register A
if something changed in register A.

When updating register A we were checking in register B if the
PIE bit was set in order to decide if rtc_reschedule_per needed
to be called. if that bit was changed then the timer rate would
already have been adjusted by rtc_update_regb so the call from
rtc_update_rega is not needed. This now matches what qemu and
other emulators are doing too.

This has been running fine for a few days in a number of VMs.

OK?

Index: mc146818.c
===
RCS file: /cvs/src/usr.sbin/vmd/mc146818.c,v
retrieving revision 1.18
diff -u -p -r1.18 mc146818.c
--- mc146818.c  12 Jul 2018 10:15:44 -  1.18
+++ mc146818.c  26 May 2019 12:13:32 -
@@ -216,7 +216,7 @@ rtc_update_rega(uint32_t data)
__func__);
 
rtc.regs[MC_REGA] = data;
-   if (rtc.regs[MC_REGB] & MC_REGB_PIE)
+   if ((rtc.regs[MC_REGA] ^ data) & 0x0f)
rtc_reschedule_per();
 }
 

-- 
jasper