mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Finn Thain <fthain@telegraphics.com.au>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Kars de Jong <jongk@linux-m68k.org>,
	Philip Blundell <philb@gnu.org>,
	Andreas Schwab <schwab@linux-m68k.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Stephen N Chivers <schivers@csc.com.au>,
	Thomas Gleixner <tglx@linutronix.de>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Michael Schmitz <schmitzmic@gmail.com>,
	John Stultz <john.stultz@linaro.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-m68k <linux-m68k@lists.linux-m68k.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v2 09/14] m68k: hp300: Remove hp300_gettimeoffset()
Date: Sun, 25 Nov 2018 12:15:07 +1100 (AEDT)	[thread overview]
Message-ID: <alpine.LNX.2.21.1811250953120.10@nippy.intranet> (raw)
In-Reply-To: <alpine.LNX.2.21.1811212129520.275@nippy.intranet>

On Wed, 21 Nov 2018, I wrote:

> On Wed, 21 Nov 2018, Geert Uytterhoeven wrote:
> 
> > > This suggests that either 0 or N (the latched value) would result 
> > > from a read from the counter immediately following an interrupt. Who 
> > > can say which? Just have to try it. The answer should allow us to 
> > > avoid the risk of a clocksource that jumps forwards and backwards.
> > 
> > The code in amiga_gettimeoffset() does:
> > 
> >         ticks = hi << 8 | lo;
> > 
> >         if (ticks > jiffy_ticks / 2)
> >                 /* check for pending interrupt */
> >                 if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
> >                         offset = 10000;
> > 
> 
> That _suggests_ that there's no interrupt when ticks == 0.
> 
> But look what happens next:
> 
> >         ticks = jiffy_ticks - ticks;
> > 
> >         ticks = (10000 * ticks) / jiffy_ticks;
> > 
> >         return (ticks + offset) * 1000;
> 
> If (hi << 8 | lo) == 0, and you set offset = 10000, then the return 
> value would be maximal.
> 
> Let's immediately call this function again. This time (hi << 8 | lo) == 
> N. Let's add the offset again. I'm afraid the clock just jumped 
> backwards.
> 
> So the logic you quoted has a rationale which is unrelated to the 
> question.
> 

I've learned that emulators like MAME [1] and VICE [2] have used a 
reverse-engineered description of the CIA called "A Software Model of the 
CIA6526" by Wolfgang Lorenz and an accompanying test suite [3].

That document says, "When the counter has reached zero, it is reloaded 
from the latch as soon as there is another clock waiting in the pipeline. 
In phase 2 mode, this is always the case. This explains why you are 
reading zeros in cascaded mode only (2-2-2-1-1-1-0-0-2) but not in phase 2 
mode (2-1-2)."

I think this is a good argument that a zero count will never be observed 
by reading the counter register. Hence, it seems that this conditional in 
the v3 patch,

	if (msb > 0)

is redundant and should be removed.

It could be reverted to,

	if (ticks > jiffy_ticks / 2)

which is intended to reduce the number of calls to cia_set_irq() but 
assumes low interrupt latency (below 5 ms).

Maybe the timer interrupt has a sufficiently high priority and latency is 
low? Maybe cia_set_irq() is really expensive?

I don't know the platform well enough so I'm inclined to revert. We can 
benchmark gettimeofday syscalls on elgar but is that hardware 
representative of other relevant models?

[1] 
https://github.com/mamedev/mame/commit/e2ed0490520f538c346c8bdaa9084bcbc43427cb

[2]
http://vice-emu.sourceforge.net/vice_9.html

[3]
https://www.commodore.ca/manuals/funet/cbm/documents/chipdata/cia6526.zip

-- 

  reply	other threads:[~2018-11-25  1:15 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19  1:10 [RFC PATCH v2 00/14] m68k: Drop arch_gettimeoffset and adopt clocksource API Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 06/14] m68k: amiga: Convert to " Finn Thain
2018-11-20  8:04   ` Linus Walleij
2018-11-19  1:10 ` [RFC PATCH v2 04/14] m68k: apollo, q40, sun3, sun3x: Remove arch_gettimeoffset implementations Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 03/14] m68k: mac: Clean up unused timer definitions Finn Thain
2018-11-20  1:02   ` Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 12/14] m68k: mvme147: Handle timer counter overflow Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 09/14] m68k: hp300: Remove hp300_gettimeoffset() Finn Thain
2018-11-20  9:09   ` Kars de Jong
2018-11-20 23:13     ` Finn Thain
2018-11-21  8:10       ` Geert Uytterhoeven
2018-11-21  8:41         ` Finn Thain
2018-11-21  8:55           ` Geert Uytterhoeven
2018-11-21  9:47             ` Finn Thain
2018-11-21 10:02               ` Geert Uytterhoeven
2018-11-21 11:14                 ` Finn Thain
2018-11-25  1:15                   ` Finn Thain [this message]
2018-11-25  2:44                     ` Michael Schmitz
2018-11-25  3:25                       ` Finn Thain
2018-11-21  8:22       ` Kars de Jong
2018-11-19  1:10 ` [RFC PATCH v2 07/14] m68k: atari: Convert to clocksource API Finn Thain
2018-11-19  8:35   ` Michael Schmitz
2018-11-20  8:10   ` Linus Walleij
2018-11-20  8:19     ` Geert Uytterhoeven
2018-11-20  9:30     ` Finn Thain
2018-11-20  9:53       ` Linus Walleij
2018-11-20 10:02     ` Andreas Schwab
2018-11-24  2:03       ` Michael Schmitz
2018-11-24  3:08         ` Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 01/14] m68k: Call timer_interrupt() with interrupts disabled Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 02/14] m68k: mac: Fix VIA timer counter accesses Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 11/14] m68k: mvme147: Convert to clocksource API Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 10/14] m68k: mac: " Finn Thain
2018-11-20  8:15   ` Linus Walleij
2018-11-20  9:00     ` Finn Thain
2018-11-20  9:59       ` Linus Walleij
2018-11-19  1:10 ` [RFC PATCH v2 05/14] m68k: Drop ARCH_USES_GETTIMEOFFSET Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 13/14] m68k: mvme16x: Convert to clocksource API Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 08/14] m68k: bvme6000: " Finn Thain
2018-11-19  1:10 ` [RFC PATCH v2 14/14] m68k: mvme16x: Handle timer counter overflow Finn Thain

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=alpine.LNX.2.21.1811250953120.10@nippy.intranet \
    --to=fthain@telegraphics.com.au \
    --cc=arnd@arndb.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=geert@linux-m68k.org \
    --cc=john.stultz@linaro.org \
    --cc=jongk@linux-m68k.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=philb@gnu.org \
    --cc=schivers@csc.com.au \
    --cc=schmitzmic@gmail.com \
    --cc=schwab@linux-m68k.org \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®