I can across a little problem with the system timer resolution.
Whenever I use my little PB exe, it seems to hold the system timer resolution at 1 ms
after it is being set by another application.
When the other application ends (e.g. PB IDE), the system timer resolution persists.
This can be worked out by means of "powercfg -energy". The result of this is the file
"energy-report.html" which tells that the timer resolution was requested by my application.
I do not use functions like timeBeginPeriod() or Nt_SetTimerResolution().
Note: This only occurs when my exe was started with admin rights.
Why would my exe own that timer resolution?
PB exe owns system timer resolution of 10000
Re: PB exe owns system timer resolution of 10000
Check what functions your EXE imports, maybe some library affects timer.. nothing to say without sourcesHannesH wrote: I do not use functions like timeBeginPeriod() or Nt_SetTimerResolution().
Note: This only occurs when my exe was started with admin rights.
Why would my exe own that timer resolution?
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Re: PB exe owns system timer resolution of 10000
My goodness, that was as simple as this:
Delay() needs to be called only once to obtain this result. So the first call of Delay() will modify the system timer resolution.
I'd understand this to be not a bug but a feature to obtain a higher resolution for Delay(). However, it shall be noted in the documentation.
A timer tool to monitor/set the system timer resolution can be found here: https://vvvv.org/contribution/windows-system-timer-tool
So it seems something related to PB itself.
I simply replaced all Delay() occurrences with Sleep_(), that was it.
Code: Select all
While #True
Delay(1000) ; using this, the system timer resolution is set to 10000 (1 ms) by this application!
; Sleep_(1000) ; using this, the system timer resolution remains whatever it is/was
Wend
End
I'd understand this to be not a bug but a feature to obtain a higher resolution for Delay(). However, it shall be noted in the documentation.
A timer tool to monitor/set the system timer resolution can be found here: https://vvvv.org/contribution/windows-system-timer-tool
So it seems something related to PB itself.
I simply replaced all Delay() occurrences with Sleep_(), that was it.
Re: PB exe owns system timer resolution of 10000
well, it was not so simple.
the timertool can only switch between 0,5 and 1 msecs here.
your small code does nothing here with the timer, they remain the same.
note, i also used admin privileges to start timertool and the testcode.
Windows 10, 64 Bit .
anyone else can conform or decline ?
as far as i know, all Delay() commands are apis calls to sleep_() .
maybe i'm wrong, need investigation via fred .
the timertool can only switch between 0,5 and 1 msecs here.
your small code does nothing here with the timer, they remain the same.
note, i also used admin privileges to start timertool and the testcode.
Windows 10, 64 Bit .
anyone else can conform or decline ?
as far as i know, all Delay() commands are apis calls to sleep_() .
maybe i'm wrong, need investigation via fred .
SPAMINATOR NR.1
Re: PB exe owns system timer resolution of 10000
Delay() does more than simply call Sleep_(). It also internally calls timeBeginPeriod_().Rings wrote:as far as i know, all Delay() commands are apis calls to sleep_() .
maybe i'm wrong, need investigation via fred .
EDIT:
It looks like timeBeginPeriod_() is called only once (on first call to Delay() function). You can revert this behavior with these 2 lines of code at start of your project:
Code: Select all
Delay(0) ;will internally call timeBeginPeriod_(1)
timeEndPeriod_(1); clear previously set minimum timer resolution
EDIT2:
Actually, easiest way (and also future-proof) is to put this at start of your project:
Code: Select all
CompilerIf #PB_Compiler_OS=#PB_OS_Windows
Macro Delay(ms)
Sleep_(ms)
EndMacro
CompilerEndIf
Re: PB exe owns system timer resolution of 10000
Thanks very much, so my suspicion was correct.
@Rings: If you've not seen timer resolutions other than 0.5/1 ms, you have other applications running and holding
1 ms timer resolution. Before doing the test, you should stop all of those (media player, browser, etc) until you
see a timer resolution > 1. Only than, the test makes sense.
@cas:
I take that as a result. Can anyone in charge confirm this (and maybe add it to the documentation)?
@Rings: If you've not seen timer resolutions other than 0.5/1 ms, you have other applications running and holding
1 ms timer resolution. Before doing the test, you should stop all of those (media player, browser, etc) until you
see a timer resolution > 1. Only than, the test makes sense.
@cas:
It looks like timeBeginPeriod_() is called only once (on first call to Delay() function).
I take that as a result. Can anyone in charge confirm this (and maybe add it to the documentation)?