Lets actually try Hybrid Emulation

foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

Late now, but have to try turning off the OS and disabling interrupts next. Then I guess changing background colour to see how long things take.
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

I can't think I'm doing much to slow it down, but one thing springs to mind is how I handle interrupts. Updated with a ptimer in qemu that fires 50000 times/second and also on irq register writes. This may not be a root cause of this issue (still TBD) but I think I should update this to do it correctly in any case.

The plan:
i) Use f2h_irq bridge
ii) Write a kernel module that provides an ioctl to wait for an irq
iii) High priority user space thread that waits on this irq and calls set_irq in qemu when woken.

+ some notes:
// qemu_mutex_lock_iothread();
// mpc8xxx_gpio_set_irq(arg,mg->pin,mg->state);
// qemu_mutex_unlock_iothread();
// see:
// ../svn/Linux-Kernel_MiSTer/drivers/video/fbdev/MiSTer_fb.c
// also:
//../svn/Minimig-AGA_MiSTer/sys/sys_top.v
// wire [63:0] f2h_irq = {video_sync,HDMI_TX_VS};
// cyclonev_hps_interface_interrupts interrupts
// (
// .irq(f2h_irq)
// );
// if (ioctl(fb, FBIO_WAITFORVSYNC, &zero) == -1)

In the meantime going to also try to build my own rom from C which gives more flexiblity. + try diagrom without that interrupt polling, I think it works without.
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

Turned off the 'device' that does the interrupts and stuff - raster test is near perfect now. So I think this is a good track.
ByteMavericks
Posts: 26
Joined: Tue Oct 27, 2020 4:52 pm
Has thanked: 28 times
Been thanked: 5 times

Re: Lets actually try Hybrid Emulation

Unread post by ByteMavericks »

That sounds promising: are you saying you were actively polling thousands of times for interrupts? I can see that being an issue!
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

Well yeah, but what is 50000 times/second when you have 800000000 cycles? 16000 cycles/poll. That is like half a frame vs say 2-3 instructions in the 8-bit world that I'm used to.

Anyway I tried changing it to a thread that polls 5000 times/second and ... while the raster stuff looks better and it feels better it didn't fix the core perf issues. Still I'm going to implement this.
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

OK, this has been an adventure.
Built uboot and kernel (only actually needed the kernel).
Updated kernel device tree to add the irqs.
Wrote a kernel module that has an ioctl to wait for irqs.
So far so good, lets try waiting for them now!
allyourbasekris
Posts: 34
Joined: Wed Sep 23, 2020 11:47 pm
Has thanked: 13 times
Been thanked: 12 times

Re: Lets actually try Hybrid Emulation

Unread post by allyourbasekris »

Just saw this project, It's a 68k emulator written for ARM that targets the amiga processors. I don't know how useful it would be. https://github.com/captain-amygdala/pistorm
kolla
Posts: 126
Joined: Sat Jun 13, 2020 7:56 am
Has thanked: 11 times
Been thanked: 12 times

Re: Lets actually try Hybrid Emulation

Unread post by kolla »

allyourbasekris wrote: Sun May 02, 2021 8:56 pm Just saw this project, It's a 68k emulator written for ARM that targets the amiga processors. I don't know how useful it would be. https://github.com/captain-amygdala/pistorm
See earlier discussions here, any time you see “musashi” mentioned, it’s the pistorm emulator :)
allyourbasekris
Posts: 34
Joined: Wed Sep 23, 2020 11:47 pm
Has thanked: 13 times
Been thanked: 12 times

Re: Lets actually try Hybrid Emulation

Unread post by allyourbasekris »

kolla wrote: Sun May 02, 2021 9:06 pm
allyourbasekris wrote: Sun May 02, 2021 8:56 pm Just saw this project, It's a 68k emulator written for ARM that targets the amiga processors. I don't know how useful it would be. https://github.com/captain-amygdala/pistorm
See earlier discussions here, any time you see “musashi” mentioned, it’s the pistorm emulator :)
Got ya, I wasn't sure if they were doing anything different in the project.
ByteMavericks
Posts: 26
Joined: Tue Oct 27, 2020 4:52 pm
Has thanked: 28 times
Been thanked: 5 times

Re: Lets actually try Hybrid Emulation

Unread post by ByteMavericks »

Interestingly the pistorm developer is reworking irqs as they’re causing some compatibility problems: is there a chance to team up on this as it sounds like a common challenge?
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

IRQs are running better with the new kernel module.

Still performance is lower than I'd expect, but its getting there.
Attachments
IMG_8712.JPG
IMG_8712.JPG (3.21 MiB) Viewed 839 times
IMG_8711.JPG
IMG_8711.JPG (2.94 MiB) Viewed 848 times
ByteMavericks
Posts: 26
Joined: Tue Oct 27, 2020 4:52 pm
Has thanked: 28 times
Been thanked: 5 times

Re: Lets actually try Hybrid Emulation

Unread post by ByteMavericks »

That’s good progress, and pretty incredible to get a kernel module up and working so quickly! Kudos
User avatar
Caldor
Posts: 414
Joined: Sat Jul 25, 2020 11:20 am
Has thanked: 13 times
Been thanked: 21 times

Re: Lets actually try Hybrid Emulation

Unread post by Caldor »

That is impressive performance. Especially since it now has FPU enabled... and MMU?
robinsonb5
Posts: 75
Joined: Fri Jun 19, 2020 8:54 pm
Has thanked: 7 times
Been thanked: 21 times

Re: Lets actually try Hybrid Emulation

Unread post by robinsonb5 »

That's more like it! Congrats!
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

I've been doing some more performance testing.

Some of the qemu api seems expensive.

Time for 1000000 dhrystones in (unoptimised code):
i) user mode: 11 seconds
ii) system mode: 30 seconds

So that (optimised) 400000 dhrystones/sec becomes 130000 dhrystones/sec due to overhead of using system mode.
kolla
Posts: 126
Joined: Sat Jun 13, 2020 7:56 am
Has thanked: 11 times
Been thanked: 12 times

Re: Lets actually try Hybrid Emulation

Unread post by kolla »

I wanted to ask earlier, what is the reason for using system mode? Normallly, system mode is used for emulating a particular hardware configuration in addition to CPU, but is that really the case here?

Thinking a little more, I suppose it is - interfaces to the real hardware only exists in system-mode I guess :)

Btw - I am ready to try out the new stuff, I always build my own kernels for MiSTer anyways (to add IPv6 and various) so I can easily drop in another kernel module in the build :)
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

System mode is a much better fit in general:
Define machine memory app
Add virtual peripherals to memory map (I use it for irq règ writes to react faster).
Simple irq support

I didn’t expect this magnitude of overhead though. I’m going to try tomorrow running the same test code in the maintainers simple virtual machine to see if it’s the same. If it is then I’ll have to dig deeper.

I do wonder though, could user mode work...
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

I’ll post code/binaries tomorrow!

Probably this is enough performance for v1 now, I should focus on the main problems:
i) Crashes often on clicking icons!
ii) Crashes when I put in 68040.library

Any 68k gurus here?
Fularu
Posts: 22
Joined: Sat Jun 13, 2020 3:25 am

Re: Lets actually try Hybrid Emulation

Unread post by Fularu »

foft wrote: Mon May 03, 2021 8:57 pm I’ll post code/binaries tomorrow!

Probably this is enough performance for v1 now, I should focus on the main problems:
i) Crashes often on clicking icons!
ii) Crashes when I put in 68040.library

Any 68k gurus here?
Never click on icons, problem solved!

Did you try with the 68060 library? afaik the 060 is just a refined, lower voltage version of the 040 (just like the 030 was to the 020)
User avatar
Caldor
Posts: 414
Joined: Sat Jul 25, 2020 11:20 am
Has thanked: 13 times
Been thanked: 21 times

Re: Lets actually try Hybrid Emulation

Unread post by Caldor »

I experimented some more and managed to get it to run. I used the test7 files and the newest files BBond007 shared. I am able to consistently boot and I can run an old version of SysInfo which does show a 68040 CPU and it does seem to have FPU and MMU but "not in use". It is SysInfo 3.24. But when I try SysInfo 4.3 or 4.4 it seems to freeze and I cannot boot Workbench either, or maybe its just that its really really slow.

Its speed tests as about the 030 25Mhz in SysInfo 3.24, but with 4.3 and 4.4 not working it seems unstable. I have also not been able to boot Workbench, at least not any of the setups I have been running before. It seems to have some hard crashes now and then where I need powercycle the MiSTer. Not sure if its because I maybe have not used the correct memory configuration or something like that. I tried switching between 8MB and 384MB to see if it would make a difference. Both seemed to have the same issues though.

But I am happy I got it to be able to run at all and that its possible to use the uncompiled CPU cores. I suspect many of my problems might be solved by using the new 3.14 ROM.
kolla
Posts: 126
Joined: Sat Jun 13, 2020 7:56 am
Has thanked: 11 times
Been thanked: 12 times

Re: Lets actually try Hybrid Emulation

Unread post by kolla »

Oh, use 68040.library from OS 3.1, it works :)
Attachments
94AC3EA3-1207-457F-863B-3A24B3929173.jpeg
94AC3EA3-1207-457F-863B-3A24B3929173.jpeg (3.42 MiB) Viewed 532 times
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

For anyone who wants to try the current state 'as-is'...

OK, here is a new core and kernel module.
http://www.64kib.com/minimig_irq_core.tar.gz

After booting up you can install it using:
./minimig_module/setup
Then you can check /proc/interrupts and dmesg to check it is happy.

Next you need a new qemu:
http://www.64kib.com/qemu_system_testv8.tar.xz

Clicking on icons is crashy but you can run stuff from the cli!
foft
Posts: 178
Joined: Thu Dec 03, 2020 11:05 am
Has thanked: 20 times
Been thanked: 53 times

Re: Lets actually try Hybrid Emulation

Unread post by foft »

Thanks Kolla, with the old 68040 library it seems happier.

Grab it from here:
https://aminet.net/package/driver/other/040_060Libs
copy 68040old.library libs:68040.library

No crashes yet from clicking on icons! edit: spoke too soon... just rebooted and clicked on an icon -> boom
hitm4n
Posts: 31
Joined: Sat Jan 30, 2021 9:20 am
Has thanked: 1 time
Been thanked: 7 times

Re: Lets actually try Hybrid Emulation

Unread post by hitm4n »

Amazing work going on here, enjoying dipping in each day to see progress... Keep the chat going, its cool to follow along, even if i don't understand most of it :) Keep it up guys.
Jeruro
Posts: 7
Joined: Mon May 25, 2020 7:24 am
Has thanked: 1 time
Been thanked: 2 times

Re: Lets actually try Hybrid Emulation

Unread post by Jeruro »

It's awesome. I refresh this thread every day to see the progress. I'm going to try last version you posted. Thanks fort!
Post Reply