All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
To: Laurent Vivier <laurent@vivier.eu>, BALATON Zoltan <balaton@eik.bme.hu>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 6/7] mac_via: fix 60Hz VIA1 timer interval
Date: Wed, 10 Mar 2021 22:11:07 +0000	[thread overview]
Message-ID: <4d88313a-c067-163d-2d80-c60786bc9d85@ilande.co.uk> (raw)
In-Reply-To: <762713e4-96a8-e989-fa76-2febad83afce@vivier.eu>

On 10/03/2021 13:24, Laurent Vivier wrote:

> Le 10/03/2021 à 14:10, Laurent Vivier a écrit :
>> Le 10/03/2021 à 13:56, Laurent Vivier a écrit :
>>> Le 10/03/2021 à 13:32, BALATON Zoltan a écrit :
>>>> On Wed, 10 Mar 2021, Mark Cave-Ayland wrote:
>>>>> The 60Hz timer is initialised using timer_new_ns() meaning that the timer
>>>>> interval should be measured in ns, and therefore its period is a thousand
>>>>> times too short.
>>>>>
>>>>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>>>>> ---
>>>>> hw/misc/mac_via.c | 4 ++--
>>>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
>>>>> index f994fefa7c..c6e1552a59 100644
>>>>> --- a/hw/misc/mac_via.c
>>>>> +++ b/hw/misc/mac_via.c
>>>>> @@ -302,8 +302,8 @@ static void via1_sixty_hz_update(MOS6522Q800VIA1State *v1s)
>>>>>      MOS6522State *s = MOS6522(v1s);
>>>>>
>>>>>      /* 60 Hz irq */
>>>>> -    v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 16630) /
>>>>> -                          16630 * 16630;
>>>>> +    v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 16630000) /
>>>>> +                          16630000 * 16630000;
>>>>
>>>> Can you put this magic number in a #define maybe also rewriting it in a way that shows it
>>>> corresponds to a 60 Hz interval. (There's NANOSECONDS_PER_SECOND defined in include/qemu/timer.h
>>>> that could be used for that, there's also SCALE_MS that might replace 1000 * 1000 elsewhere in this
>>>> file). Also NANOSECONDS_PER_SECOND / 60 is 16666666, should that value be used here instead?
>>>
>>> In fact, the Mac Frequency is not exactly 60 Hz, in docs we can find 60.147 Hz, in kernel 60.15 Hz.
>>> I Think there are several ways to compute it...
>>>
>>
>> In fact, we can read:
>>
>> "the vertical retrace frequency is approximately 60.15 Hz, resulting in a period of approximately
>> 16.63 milliseconds"
>>
>> https://developer.apple.com/library/archive/documentation/mac/pdf/Processes/Vertical_Retrace_Mgr.pdf
> 
> The exact value is 16625800 ns
> 
> "Macintosh Family Hardware Reference" ISBN 0-201-19255-1
> "The video interface"
> p. 13-3
> 
> "[...] This means the full frame is redisplayed every 370 scan lines, or once every 166625.8 µs."

Thanks Laurent! Given that the exact precision is 6 digits I don't think it's 
possible to make use of conversion macros without either making it harder to read or 
reducing the precision.

I think the best solution here would be to #define VIA1_60HZ_TIMER_PERIOD_NS with a 
comment containing the above reference, and use that in the period calculation. Would 
that be sufficient?


ATB,

Mark.


  reply	other threads:[~2021-03-10 22:28 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10  8:09 [PATCH 0/7] mac_via: fixes and improvements Mark Cave-Ayland
2021-03-10  8:09 ` [PATCH 1/7] mac_via: switch rtc pram trace-events to use hex rather than decimal for addresses Mark Cave-Ayland
2021-03-10  8:42   ` Laurent Vivier
2021-03-10  8:09 ` [PATCH 2/7] mac_via: fix up adb_via_receive() trace events Mark Cave-Ayland
2021-03-10  8:51   ` Laurent Vivier
2021-03-10  8:09 ` [PATCH 3/7] mac_via: allow long accesses to VIA registers Mark Cave-Ayland
2021-03-10  8:57   ` Laurent Vivier
2021-03-10  8:09 ` [PATCH 4/7] mac_via: don't re-inject ADB response when switching to IDLE state Mark Cave-Ayland
2021-03-10  8:09 ` [PATCH 5/7] mac_via: rename VBL timer to 60Hz timer Mark Cave-Ayland
2021-03-10  8:44   ` Laurent Vivier
2021-03-10  8:09 ` [PATCH 6/7] mac_via: fix 60Hz VIA1 timer interval Mark Cave-Ayland
2021-03-10  8:47   ` Laurent Vivier
2021-03-10 12:32   ` BALATON Zoltan
2021-03-10 12:56     ` Laurent Vivier
2021-03-10 13:10       ` Laurent Vivier
2021-03-10 13:24         ` Laurent Vivier
2021-03-10 22:11           ` Mark Cave-Ayland [this message]
2021-03-11  0:15             ` BALATON Zoltan
2021-03-11  9:04               ` Mark Cave-Ayland
2021-03-11  9:44                 ` Laurent Vivier
2021-03-11  9:50                   ` Mark Cave-Ayland
2021-03-10 13:27         ` Philippe Mathieu-Daudé
2021-03-10  8:09 ` [PATCH 7/7] mac_via: remove VIA1 timer optimisations Mark Cave-Ayland
2021-03-10  8:50   ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d88313a-c067-163d-2d80-c60786bc9d85@ilande.co.uk \
    --to=mark.cave-ayland@ilande.co.uk \
    --cc=balaton@eik.bme.hu \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.