News:

Simutrans Forum Archive
A complete record of the old Simutrans Forum.

[patch] less calls of INT_CHECK in simhalt.cc

Started by gerw, March 19, 2009, 04:54:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gerw

According to a profile of prissi, haltestelle_t::rebuild_destination consumes much time due to many calls of INT_CHECK. This patch will reduce this calls.

prissi


gerw

But according to your profile, it comsumes more time, then the routine itself:
[19]     8.5    0.22   19.87    1181         haltestelle_t::rebuild_destinations() [19]
                5.10   12.70 1878971/14080882     interrupt_check() <cycle 1> [483]
                0.15    0.00 3121383/54706884     quickstone_tpl<simline_t>::is_bound() const [88]
                0.01    0.05 9753879/11926653     schedule_t::get_count() const [414]
                0.05    0.00 7874908/292124749     quickstone_tpl<haltestelle_t>::operator==(quickstone_tpl<haltestelle_t> const&) const [95]
                0.05    0.00 6898686/39292142     quickstone_tpl<convoi_t>::operator->() const [223]

Spike

Just be sure it's called often enough to let the sync steps be executed smoothly.

prissi

The total time contains also the time needed for doing an actual sync_step, i.e. redrawing the map etc. The log above shows that the routine itself cost only 0.17s or less than 0.07%.

gerw

Yes, of course. And I think 1.8m calls of INT_CHECK is too much, if the routine needs only 0.17s.

prissi

Well, without those calls the screen updates would be much less smooth.

Simutrans has two loops, one does the step, events etc. The other is invoked (whenever it is save) by INT_CHECK() which check if the time between two frames has passed and either than starts an update loop iteration or returns otherwise. Not calling INT_CHECK() will just make the game more jitery. And since it consumer itself only 0.17s time or less than 0.06% one should do INT_CHECK() not too seldomly.

jamespetts

Prissi,

that's very interesting information about how the game works :-) Tell me - which one of step() and sync_step() is the one called by INT_CHECK()? Or am I getting confused between two different aspects of the threading system?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

prissi

No, sync_step is most often called by int_check. (In fast forward, things are different, but we ignore this here.)

jamespetts

Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

gerw

Quote from: prissi on March 21, 2009, 09:06:31 PM
And since it consumer itself only 0.17s time or less than 0.06% one should do INT_CHECK() not too seldomly.
I didn't get this.

And please note, that in this profile rebuild_destinations was only called during loading. IMHO a call of INT_CHECK everytime a lineless vehicle is found, is too much. And if there are no lineless vehicles, this function won't call INT_CHECK anymore...

prissi

Int check itself is verz fast. However, from time to time, it will actually does a redraw, and those is the value in front, because it shows the accumulated time. Forget this, just have a look at the first part, where the time consumed by all functions is listened. And here for 300s CPU time 0.17s are due to int_check - neglible.

Spike

Simutrans initially had a main program loop and a interrupt routine, which was supposed to be called every 20ms or so.

It turned out that it is hard to handle vehicle movement and display in the interrupt routine, because it might be called any time, even in the middle of executing what appears to be one statement in C++ and therefore operates on inconsistent data).

I changed the hardware driven interrupts to the current mechanism then. The program calls INT_CHECK() frequently, but in places that are safe to be interrupted, and the check routine checks if it's time to call the real interrupt routine.

Just to explain why this is called INT_CHECK, it means "check if it time to interrupt the main loop now".