-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchonization hazards on multicore systems #6241
Comments
thanks for the explanations. this might help a lot in fixing the current performance problems. |
Mirrored from Codeberg Thanks carli2.
Are you really sure about that? As far i remember there were no performance issues, except with debug builds. But also with mutlithreading debug builds tend to slow down after a while. IMHO, the reason to implement multithreading was just this bugreport (originally from the year 2016). On my old laptop with a celeron 900 processor widelands did always run fine. Will test widelands on this laptop again. Please don't get me wrong, im not against multithreading, but i have the feeling it has more drawbacks than profits. Anyway: Isn't this a duplicate of #6230 ? Or is this another issue? At least <@>hessenfarmer should check his processor specs, because he had such an issue (lags) as well. Here are mine (no issue):
|
I cite from #2056 :
this should have been done before someone just adds multithreading to such a codebase. |
i tested limiting the processs to one core on windows as well, and I still could provoke the lags even in singleplayer with the inventory and 2 warehouse windows. |
Furthermore even 1.1 had multithreading enabled, and did not suffer from such lagging, so it is an issue of 1.2 perhaps related to multithreading, but not originally caused by the multithreading. So I believe this issue is misleading here. |
Mirrored from Codeberg <@>carli2, can you provoke the issue with v1.1? |
I took the time to compile good old release 1.1. Here are the results: I tried both, single and multicore. This time, in both cases, the game ran fine for the first few seconds (speed 22.0) but then got stuck and laggy. After returning to gamespeed 1.0, it didn't fix the lag. The lag stayed until I saved, quitted and reloaded the game. |
Another interesting fact: If I just save the game, leave the game and then reenter the game from a loadgame, the lag stays. However if I close widelands, the lag disappears for the first few minutes. |
Thanks for the test with 1.1. Playing at speed 22 will probably always slow down the game. You may had many warnings in the console like "Warning: Gamespeed too high for the AI, it is past x sec now" (or similar). Did you test the lags caused by opening inventory and warehouse windows? |
I did not test the difference between with/without warehouse. Do you need the test on 1.1? |
Yes. Since hessenfarmer can't provoke the lags with open inventory and warehouse windows in v1.1 it would be interesting if you can provoke it. If not then the issue is somewhere in v1.2, if the lags happens on your machine with v1.1 then this is really a different problem, imho. |
I tested it extensively and it seems to work lagless now. |
The problem occurs on the following system:
OS: linux
Widelands versions: All since rendering and game logic has been separated into different threads.
CPU:
Now to the problem:
In normal operation, widelands game speed drops down to 0.1 and slower, even on medium and small maps. My CPU has 12 cores, 24 threads and 4 GHz, so ressources aren't a problem.
However when I run widelands with
taskset -c 0 ./widelands
, the performance is great.What does
taskset -c
do? It pins a process to a single CPU core, so it effectively disables multicore processing and turns to preemptive scheduling.What is the cause of widelands performance drops in multicore systems?
Widelands experiences the effects of so called synchronization hazards which means that two threads are operating on the same piece of memory (in this case e.g. the GUI thread renders a warehouse statistic and the game logic thread updates numbers in the statistics) - this means two threads accesss the same piece of memory.
The CPU will in this case flush all caches, write back the memory cache line, let the other CPU load the cache lines and so forth. This all takes a 100-fold of the time in comparison to a single-core mode where no cache lines have to be exchanged.
There are multiple ways to fix this issue:
a) remove the multicore code and go back to single core processing
b) separate the memory either locally or timely
b.1) locally -> after game logic has updated the map, the whole map gets copied into a second instance on which the GUI thread can now operate (so both threads operate on completely disjunct memory parts)
b.2) timely -> multicore code is kept but logic and GUI are synced so that the logic thread waits for the GUI thread to finish a render cycle before starting the next logic cycle. The logic cycle can last multiple GUI cycles but at least during "normal" game operation with enough CPU resources, the sync should evade most synchronization hazards.
The text was updated successfully, but these errors were encountered: