VOGONS


First post, by tigrou

User metadata
Rank Newbie
Rank
Newbie

I'm trying to understand what is the main logic behind cycles = auto mode (eg : which heuristics it use to balance CPU cycles).

I took a look at code and as far as I can tell most of the logic is in increaseticks() function.
It seems fairly complicated so my goal is not to understand every bit of it but rather have a general idea about how it works.

AFAIK (I might be totally wrong on this) what is done is to measure how much time has elapsed between two increaseticks() calls and adjust cycles accordingly.
That method is called from time to time from Normal_Loop() (eg: CPU_Cycles variable has reach 0, an interrupt need be handled by PIC, HLT instruction has been executed, ...)

Reply 1 of 5, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

it looks at the ratio of time spend (by instructions that have been emulated) inside dosbox (the non-sleeping part) and the time that has passed "outside" dosbox.

The main line:

Bit32s ratio = (ticksScheduled * (CPU_CyclePercUsed*90*1024/100/100)) / ticksDone;

afterwards corrections are being done for dosbox "wasting" time, so the cycles aren't jumping up because dosbox is doing very light "work (nothing)" and counting it as full. (ratioremoved)

Water flows down the stream
How to ask questions the smart way!

Reply 2 of 5, by tigrou

User metadata
Rank Newbie
Rank
Newbie

Thanks for you help.

* Just above that line there is this comment :

/* ratio we are aiming for is around 90% usage*/

Does it means it try to have host CPU spending 90% running DOSBox code and 10% idling (sleeping) ?
It this the same as cycles = max 90% ?

* If I set a very high fixed number of cycles (eg: 200000000) and have a program which consist of doing a simple loop (eg: while(1); )

Will does DOSBox have a chance to actually exit the CPU_Core_xxx_Run() method before cycles to be executed has reach zero ? (in order to pool events).
By looking at code, I would say no but maybe I miss something.

* I have notified that cycles auto is only turned on with programs running in protected mode (see CPU_SET_CRX() method in CPU.cpp).
Reason I can see is protected mode is usually for programs that are very CPU hungry (eg : Win 95, Doom, Duke 3D, ...). DOSBox will not bother to adjust CPU cycles for programs running in real mode.
Is that right or is there another reason ?

Reply 3 of 5, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author
tigrou wrote on 2020-07-02, 08:17:
Thanks for you help. […]
Show full quote

Thanks for you help.

* Just above that line there is this comment :

/* ratio we are aiming for is around 90% usage*/

Does it means it try to have host CPU spending 90% running DOSBox code and 10% idling (sleeping) ?

Yes, although idle, means time for other things, like playing audio/updating screen, flushing disk buffers etc

It this the same as cycles = max 90% ?

No. the 90% is multiplied with the percentage you set. (hence we allow max 105% which boils down to 0.9 *1.05 as percentage used of your host)

* If I set a very high fixed number of cycles (eg: 200000000) and have a program which consist of doing a simple loop (eg: while(1); )

Will does DOSBox have a chance to actually exit the CPU_Core_xxx_Run() method before cycles to be executed has reach zero ? (in order to pool events).
By looking at code, I would say no but maybe I miss something.

the cycles number can be "split" into blocks if needed by dosbox, but setting a very high number isn't a good idea as if there is nothing scheduled within the current millisecond, dosbox will try to execute what you set.

* I have notified that cycles auto is only turned on with programs running in protected mode (see CPU_SET_CRX() method in CPU.cpp).
Reason I can see is protected mode is usually for programs that are very CPU hungry (eg : Win 95, Doom, Duke 3D, ...). DOSBox will not bother to adjust CPU cycles for programs running in real mode.
Is that right or is there another reason ?

It's not a matter of bothering, it is more that usually the non-protected mode games are much older and need lower speeds to play correctly. trying to maximize the cycles will make those games run too fast.

Water flows down the stream
How to ask questions the smart way!

Reply 4 of 5, by tigrou

User metadata
Rank Newbie
Rank
Newbie
Qbix wrote on 2020-07-02, 08:33:

No. the 90% is multiplied with the percentage you set. (hence we allow max 105% which boils down to 0.9 *1.05 as percentage used of your host)

So there is no difference between cycles = max 100% (0.9 * 1.00) and cycles = auto (0.9) ?
In other words, is cycles = max in DOSBox configuration file vs cycles = auto the same ?

Reply 5 of 5, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

no

max also does also do cycle guessing in real mode.
auto does max for protected mode and 3000 in real mode (or whatever you set it to. auto supports a lot of parameters)

Water flows down the stream
How to ask questions the smart way!