multi threading

Developer's Forum, for discussion of bugs, code, and other developmental aspects of DOSBox.

multi threading

Postby robertmo » 2018-7-11 @ 07:28

would it be possible to make it this way?

while one core is trying to count the result for either 1 or 0

two other cores could at the same time follow the code:
second core with the result of 1
and the third core with the result of 0

By the time the first core gets the result we will have the result for next operation.

8 cores cpu would be 3x faster than 1 core cpu this way.
User avatar
robertmo
l33t
 
Posts: 4398
Joined: 2003-6-18 @ 10:35

Re: multi threading

Postby root42 » 2018-7-11 @ 07:42

A similar thing happens on CPUs with speculative execution. The main problem is that not all code is simply calculating a result. You basically have these kinds of operations: arithmetic functions, reading of data, writing of data. The first two can be easily parallelized. However the writing of data has side effects and may influence computations further down the line. That is why speculative execution will eventually fail, given a long enough lookahead. Same problem would apply to your multi-core speculative execution model.
Soldering, retro game reviews and more on YouTube and Bonus videos
Me playing games on my 286 and on my Sega MD2 on Twitch
80286@12 MHz, 2 MiB RAM, Tseng ET4000 1 MiB, schlae AdLib, PC MIDI Card + SC55MkII, XT CF Lite, OSSC 1.6
User avatar
root42
Oldbie
 
Posts: 572
Joined: 2018-1-27 @ 13:23

Re: multi threading

Postby robertmo » 2018-7-11 @ 07:48

I think it would be enough to write into two separate temporary areas and write to a solid area only when we got the final result.
User avatar
robertmo
l33t
 
Posts: 4398
Joined: 2003-6-18 @ 10:35

Re: multi threading

Postby root42 » 2018-7-11 @ 07:56

Then you lose performance. Suddenly you will be bandwidth limited, because you will be writing multiple times the amound of data you would normally write.
The pipelines in a normal CPU will delay writing results, and can probably keep as much state as the pipeline is deep. But if you try to emulate this on a core level, you will have to write to real memory, which is much slower and much more costly.
Soldering, retro game reviews and more on YouTube and Bonus videos
Me playing games on my 286 and on my Sega MD2 on Twitch
80286@12 MHz, 2 MiB RAM, Tseng ET4000 1 MiB, schlae AdLib, PC MIDI Card + SC55MkII, XT CF Lite, OSSC 1.6
User avatar
root42
Oldbie
 
Posts: 572
Joined: 2018-1-27 @ 13:23

Re: multi threading

Postby robertmo » 2018-7-11 @ 08:09

I think that would be true with modern software.

But DOSBox uses very little amount of data (old small 16-bit games).
User avatar
robertmo
l33t
 
Posts: 4398
Joined: 2003-6-18 @ 10:35

Re: multi threading

Postby krcroft » 2018-7-11 @ 08:15

Great writeup here on latency, including the concept you mention in the fully optimized scenario.

https://byuu.org/articles/latency/
User avatar
krcroft
Member
 
Posts: 100
Joined: 2017-4-29 @ 15:07
Location: Ogden's Retreat

Re: multi threading

Postby aqrit » 2018-7-11 @ 22:42

no.
1. most instructions depend on the output of prior instruction.
2. the real cpu is already speculating, where possible.
3. 300+ cycles needed for synchronization between threads, every time.
aqrit
Member
 
Posts: 198
Joined: 2009-6-22 @ 19:53

Re: multi threading

Postby Pickle » 2018-8-16 @ 14:15

Actually there are some cases that multithreading can help for instance a long time ago there was a device called the GP2X. It actually had 2 arm cores, the second core was limited but could so some processing in parallel.
Another user created a method of running the OPL emulation on the second core which resulted in the main application getting a boost. Keep in mind the main core arm chip even with the dynarec we had at time was only capable of 100's of cycles. So the offloading of the OPL emulation was more noticeable.
But running such a setup on your i7 is not likely to be noticeable.
Pickle
Newbie
 
Posts: 95
Joined: 2008-4-14 @ 13:15

Re: multi threading

Postby gdjacobs » 2018-8-16 @ 22:19

I believe there are patches in the wild for multithreaded/multiprocess peripheral emulation. This is an important thing for unified builds on *Pi boards.
User avatar
gdjacobs
l33t++
 
Posts: 5598
Joined: 2015-11-03 @ 05:51
Location: The Great White North

Re: multi threading

Postby cyclone3d » 2018-8-16 @ 23:49

In theory it should not be that difficult to multi-thread DOSBox. You should be able to have one thread run the CPU, one for video, one for sound, and maybe one for input.

Maybe I will look into that once I get somewhere with optimizing the current code which should give about a 20% decrease in needed CPU cycles from my past work doing the same thing and then dropping it and eventually losing the code because all I got when I did that and released the optimized code was complaints asking why I didn't released a compiled binary.

So yeah.. it really put me off on doing anything else with it for quite a few years.
User avatar
cyclone3d
l33t
 
Posts: 2176
Joined: 2015-4-08 @ 06:06
Location: Huntsville, AL USA

Re: multi threading

Postby aqrit » 2018-10-16 @ 02:59

Track 16 possible inputs using AVX-512. :exclamation:
https://gamozolabs.github.io/fuzzing/20 ... ation.html
aqrit
Member
 
Posts: 198
Joined: 2009-6-22 @ 19:53


Return to DOSBox Development

Who is online

Users browsing this forum: No registered users and 3 guests