Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

discuss both original and modern hardware for the bbc micro/electron
dp11
Posts: 1357
Joined: Sun Aug 12, 2012 9:47 pm
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by dp11 »

KenLowe wrote:
Thu Nov 25, 2021 2:16 am
hoglet wrote:
Fri Nov 19, 2021 2:22 pm
Hi all,

There's been a fair bit of work on PiTubeDirect, so time for another pre-release (Hognose-beta1):
https://github.com/hoglet67/PiTubeDirec ... nose-beta1
Similar to the issues I had some time ago, on Break there is an approx. 50% chance that the computer will boot to the 2nd processor. Sometimes I will get the 'Acorn Tube 6502 64K' prompt, and other times I will get the 'BBC Computer 32K' prompt. This is with the default CoPro 24. Switching to CoPro 0, it boots reliably to the 2nd processor every time.
I assume this is with a pizero?
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

dp11 wrote:
Thu Nov 25, 2021 3:14 am
I assume this is with a pizero?
Yes. That's with the PiZero. I've also just tested a few others, with the following results:
  • PiZeroW behaves in the same way
  • PiZero2W works fine
  • Pi3B works fine
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

And this is with a Model B, rather than a Master?

Is this issue only on the power-up boot, or does it happen on every BREAK?

(Some Model B's have very bad switch bounce on reset)

Unfortunately I doubt there is much we can do about the power-up boor time of the Pi. A large part of the boot time is down to the Broadcom firmware blob, which we needed to update to support the Zero 2 W. The other part is loading the PiTubeDirect kernel. More features means a larger kernel, which takes a bit longer to load.

It's far far worse with a Pi 4, which seems to take 2-3 seconds to boot.

Dave
Last edited by hoglet on Thu Nov 25, 2021 10:42 am, edited 5 times in total.
dp11
Posts: 1357
Joined: Sun Aug 12, 2012 9:47 pm
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by dp11 »

There is a chance there could be some improvement. This little setup loop ends up touch 512Kbytes of memory.

Code: Select all

loopdejitsetup:
   subs  r3,r3,#1
   str   temp2,[r0],#NEXTJITLET
   sub   temp2,temp2,#NEXTJITLET>>2
   str   temp,[r4],#4   // JITTEDTABLE16
   bne   loopdejitsetup
   
Breaking it up into two loops and writing 4 four words at once would improve its performance and memory utilisation on Pizero where the cache is very small.
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

hoglet wrote:
Thu Nov 25, 2021 6:57 am
And this is with a Model B, rather than a Master?

Is this issue only on the power-up boot, or does it happen on every BREAK?

(Some Model B's have very bad switch bounce on reset)

Unfortunately I doubt there is much we can do about the power-up boor time of the Pi. A large part of the boot time is down to the Broadcom firmware blob, which we needed to update to support the Zero 2 W. The other part is loading the PiTubeDirect kernel. More features means a larger kernel, which takes a bit longer to load.

It's far far worse with a Pi 4, which seems to take 2-3 seconds to boot.

Dave
It was a Model B, and it occurs on every BREAK, so not a power up boot time issue. It almost always toggles between Tube / BBC on every BREAK.
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

KenLowe wrote:
Thu Nov 25, 2021 11:21 am
It was a Model B, and it occurs on every BREAK, so not a power up boot time issue. It almost always toggles between Tube / BBC on every BREAK.
I've been able to reproduce this (frequently) on one of my Model B machines, and much more rarely on another.

I suspect it is to do with reset switch bounce, somehow causing the JIT 6502 Co Pro to fall over.

I'll do a bit more testing and try to exclude any recent changes.

Dave
cmorley
Posts: 1603
Joined: Sat Jul 30, 2016 8:11 pm
Location: Oxford
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by cmorley »

I found on my dev B that I got bad BREAK reset bounce causing multiple reset interrupts on my 1MHz bus STM32 project.

I debounced the input in software and split the reset functions into two groups. One group runs at the first falling edge, the second group after the debounce timeout with /RESET high. I could shuffle nearly everything except the "GO" semaphore into the falling edge routine which was especially good for slow tasks (e.g. SD card) but maintain a decent debounce timer (couple hundred ms IIRC) without risking failing to complete the reset init before say ADFS queries the 1MHz bus.

Perhaps you might be able to adapt similar.
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

KenLowe wrote:
Thu Nov 25, 2021 11:21 am
It was a Model B, and it occurs on every BREAK, so not a power up boot time issue. It almost always toggles between Tube / BBC on every BREAK.
I can't reproduce this with the alpha4 release, so it's starting to look like a regression between the alpha4 and beta1.

Ken, do you think you could possibly try the alpha4 release, and see if that shows the problem or not?
https://github.com/hoglet67/PiTubeDirec ... ose-alpha4

Dave
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

hoglet wrote:
Thu Nov 25, 2021 12:29 pm
Ken, do you think you could possibly try the alpha4 release, and see if that shows the problem or not?
https://github.com/hoglet67/PiTubeDirec ... ose-alpha4
I'll try that later this evening and report back.
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

hoglet wrote:
Thu Nov 25, 2021 12:29 pm
Ken, do you think you could possibly try the alpha4 release, and see if that shows the problem or not?
https://github.com/hoglet67/PiTubeDirec ... ose-alpha4
Alpha4 works without any problem.

Thanks
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

KenLowe wrote:
Thu Nov 25, 2021 6:09 pm
Alpha4 works without any problem.
Thanks Ken, that's matches what I'm seeing.

Unfortunately, this isn't an obvious regression.

I've bisected all the commits between alpha4 and beta1 and this is the one where the behaviour changes significantly: 4b6710d6.

However, looking at the that commit, the changes don't relate in any way to the JIT-6502, and with the default value of vdu=0 in the cmdline.txt, this code is never even executed.

As far as I can tell, this new issue:
- affects the nornal build, not the debug build
- affects the BBC B, and not the Master
- affects the Pi Zero, not that faster Pi Zero 2 and 3A+
- seems worse if the Ctrl key is held down
- causes the Tube Detect code to fail, even though the JIT 6502 appears to start normally

The Model B Tube Detect code is pretty simple:

Code: Select all

LDA #&81
STA &FEE0
LDA &FEE0
ROR A
BCC &DB4D
I've instrumented this using the ICE-6502.

What seems to be happening is the read of &FEE0 is returning &CE where as it should be reading &CF.

If I set a breakpoint and manually read &FEE0 a second time, then the correct value &CE is returned. So I think what's happening is that when the JIT-6502 is "cold" after a reset, effect of the write of &81 to &FEE0 (which is meant to set bit 0) is being delayed, and is happening too late.

What I'm not clear on is why the Master seems to be immune. I can think of two possibilities:
- it's related to the reset bounce - on my Model B the characterisc of RST bounce on release of the break key is a burst of short (2us) high pulses approx 2ms before a clean rising RST edge. The Master has a clean reset.
- it's related to nTUBE glitches. The Master doesn't seem to have these.

Ken, when you had this back in 2017, the cause then was a bug in the nTUBE deglitching code that runs on the GPU. That code has not changed recently, so though the syptoms are the same, the cause this time is likely different.

I'm sure Dominic will have some theories as to what's happening here.

I've created a new github issue for this:
https://github.com/hoglet67/PiTubeDirect/issues/141

Subscribe to the discussion there if you want to track this as we work on it over the next few days....

Dave
dp11
Posts: 1357
Joined: Sun Aug 12, 2012 9:47 pm
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by dp11 »

hoglet wrote:
Thu Nov 25, 2021 6:45 pm

I'm sure Dominic will have some theories as to what's happening here.
Only a guess, the timing is just on the edge. I think breaking up the JIT init setup loop into two loops will give a significant performance improvement. which if we are too close timing wise should help.
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

KenLowe wrote:
Thu Nov 25, 2021 6:09 pm
Alpha4 works without any problem.
Ken, just a quick update on the issue you raised.

As you might know, PiTubeDirect handles part of the TubeULA emulation in the GPU and the rest in the ARM core. Reads of tube registers are serviced immediately by the GPU, but writes need to be processed by the ARM core before they take effect.

The Model B tube detection code does this:

Code: Select all

LDA #&81
STA &FEE0
LDA &FEE0
A write followed immediately by a read of the same Tube ULA register creates a real-time constraint of three 6502 bus cycles, or ~1.5us.

Normally this works fine, because 1.5us is ~1,500 ARM instruction cycles (on the Pi Zero).

However, for various reasons, the JIT-6502 Co Processor invalidates the instruction cache on reset, so the handling of the first write after reset is much slower that is typical, because it experiences many cache misses. And the first write is typically the tube detection code.

(It turns out the same problem also shows up occasionally on the Native ARM Co Pro as well.)

We have prototyped two possible fixes for this issue:
1. Have the JIT-6502 Co Pro warm up the cache after reset, by executing the tube_io_handler() code once
2. Optimise the tube_io_handler() code, so the writes done by the tube detection code are handled more quickly

I'm waiting for feedback from Dominic on which of these approaches he perfers, or indeed whether to use both. We'll then release a Beta 2 version.

What I found fascinating here is that the original issue only happens on the Model B, because the Master tube reset code is more complex:

Code: Select all

.LE375
LDX #&01
STX LFEE0   ; Set bit 0 of the tube control register to 0
LDA LFEE0   ; and read it back
EOR #&01
LDX #&81
STX LFEE0   ; Set bit 0 of tube control register to 1
AND LFEE0   ; and read it back  
ROR A
RTS
On the Master, it's very likely due to this issue that the first of these two writes is also delayed, so the first LDA &FEE0 reads back stale data. However, this doesn't actually matter, because on reset bit 0 of the tube control register is cleared. So the stale data will always match what was written.

There's a few more details in the issue, if anyone is interested:
https://github.com/hoglet67/PiTubeDirect/issues/141

So in the end, this had nothing to do with reset switch bounce, which was my original hypothesis (guess).

Dave
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

Here's a new beta release that fixes the tube detection issues that Ken reported, plus a few other things:
https://github.com/hoglet67/PiTubeDirec ... nose-beta2

Changes since Hognose Beta1:

- All: Add a tube detection fast path to tube_io_handler()
- 32016 Co Pro: Avoid blatting 16MB of RAM on power-up reset (makes switching to the 32016 unreliable)
- Native ARM Co Pro: Simplify reset sequence; delay copy of ARM Basic
- Native ARM Co Pro: Fix bug in OS_SynchroniseCodeAreas that broke ARM Basic on Pi 4 (#114)
- Native ARM Co Pro: Fix an incorrect start address for ARM Basic
- JIT 6502 Co Pro: Revert "improve a53 I cache flush." - fixes hang on Pi 4
- Frame Buffer: Fix overlap when XOR plotting filled triangle
- Frame Buffer: Rewrite block move/copy to be correct (but slow)
- Frame Buffer: Use 2-pass flood fill where possible
- Frame Buffer: Added test_pixel_fn to flood fill to improve efficiency
- Frame Buffer: Improve use of ECF patterns in flood fill (fixes GXR sierpinski demo)
- Frame Buffer: Fix bug when plot mode is logical inverse
- Frame Buffer: Fix bug in VDU 23,12-15 (Simple ECF patterns)
Last edited by hoglet on Tue Nov 30, 2021 3:53 pm, edited 1 time in total.
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

Thank you very much for looking into this, and finding a solution. I'll give this a test later this evening.
User avatar
Mince
Posts: 213
Joined: Thu Sep 05, 2019 11:25 pm
Location: Cambridge, UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by Mince »

I think I might have noticed the same issue as Ken but I upgraded the Pi on my Model B to a 2W recently and I think it went away with that and I didn't think any more about this. (I don't know what release of PiTubeDirect would have been running at the time, but I would have thought it was prior to beta 1.)

Anyway, I've upgraded my Master (3B+) and Model B (2W) and they're running fine, in my quick tests of copro 24 and the ARM on 15, including my Mandelbrot code on both to exercise the bulk transfer and the Level 3 fileserver on the B and it all looks good so far.

I only run the Pi framebuffer on the Master but that seems to work and some things are now fixed that weren't before. I can't immediately find anything that doesn't work (that you don't know about).

Every release of PiTubeDirect I can't think how you can make it even better but you do, although that, RGBtoHDMI and the Pi1MHz are probably the reason there's a shortage of Pi Zeros out there!
BBC Master, PiTubeDirect w/ Pi 3A+ PIVDU, GoSDC, Pi1MHz SCSI, MMFS, RGBtoHDMI, MultiOS
BBC B, Integra ß, PiTubeDirect w/ Pi Zero 2W, Pi1MHz SCSI, MMFS, RGBtoHDMI
Electron, ElkSD 64 or Plus 1 w/ AP6 2V2, ATI/ABR w/ Pi 3A+, ElkSD Plus 1
User avatar
hoglet
Posts: 10716
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by hoglet »

Thanks for the feedback Mince...

The final hognose release will happen shortly before Christmas, so there's a bit of time remaining to find more bugs.

Dave
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

Mince wrote:
Wed Dec 01, 2021 10:02 am
Every release of PiTubeDirect I can't think how you can make it even better but you do, although that, RGBtoHDMI and the Pi1MHz are probably the reason there's a shortage of Pi Zeros out there!
Oh. I thought the world wide shortage was down to me!

viewtopic.php?p=263546#p263546
shifters74
Posts: 77
Joined: Mon Mar 04, 2019 9:44 am
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by shifters74 »

Hehe almost Ken almost!

Between the RGBToHDMI adapters and the Pitube - well its no surprise they are hard to come by!

cheers

shifters
User avatar
KenLowe
Posts: 2208
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Pi-based Co-Pro on the cheap - 100MHz 6502 for £10? (now 290MHz)

Post by KenLowe »

hoglet wrote:
Tue Nov 30, 2021 3:46 pm
Here's a new beta release that fixes the tube detection issues that Ken reported
KenLowe wrote:
Tue Nov 30, 2021 3:52 pm
Thank you very much for looking into this, and finding a solution. I'll give this a test later this evening.
Sorry, I never got the chance to test yesterday, but I've just given it a quick test now and can confirm that it's solved the issue I was seeing. Thanks again for fixing this.
Post Reply

Return to “8-bit acorn hardware”