Skip to content
Tcl Source Code View Ticket
Login

View Ticket

MS-Win Time: QueryPerformanceFrequency does not return NULL since Win XP -> remove legacy code

Closed1238d4fdb0a41e6912b353a03732a001a1351850Created 1 year agoUpdated 1 year ago
Descriptionwiki2025-11-01 12:54:33
Following this description:

https://learn.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancefrequency

the command "QueryPerformanceFrequency" never retruns NULL since WIndows XP. So, we can assume for 9.1 to always get a non-null.

Some code in tclWinTime.c may be removed.

Same for QueryPerformanceCounter https://learn.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter

Thanks, Harald

Referenced by1
  • 6549447cdfNew ticket [7e47f55993] MS-Win Time: why not use GetSystemTimePreciseAsFileTime(). ticket2025-11-15 10:07:56
oehhar Ticket [1238d4fdb0]: 3 changes [History diff]2025-11-01 18:05:53
oehharwiki2025-11-01 18:37:46

Implemented by checkin [7a350b5f95] starting branch [1238d4fd-mswin-queryperformancefrequency].

If I run the timer.test file, it panics in line 780: https://core.tcl-lang.org/tcl/file?udc=1&ln=on&name=win%2FtclWinTime.c&ln=780 (I don't know how to show a file of a distinct branch, this is apparently the last commited branch)

I have added this panic, as the description says, that this should never happen. Ok.

Sorry, Wizard questions for Sergey, Jan, Ashok:

  • Is this generally a good idea?
  • Do we still need the calibration thread which runs each second?
  • Is the deleted part about Pentium 4 really outdated? Line 470-505 of main branch.

Thanks for all, Harald

apnadkarnimarkdown2025-11-02 10:10:29

Harald, there was a missing initialization in your changes that caused the panic. Kudos for being paranoid and including that check!

Fixed in your branch. timer.test passes

Sergey is obviously the best person to answer your queries, but my opinions -

  • Good idea? I'm all for removing obsolete/dead code.

  • Need for calibration thread - I would imagine we still need it. Nothing has changed in that regard, has it?

  • Pentium 4 - I seriously doubt any recent Windows (Win7 on) will run on it and would think it is safe to remove.

/Ashok

oehharwiki2025-11-03 08:26:31

Thanks, Ashok, great. Sorry, my fault, to have removed the initialisation.

I have replaced the panic by an assert in commit [d468a678d1].

I think, this can be merged now.

We always use the high performance timers now on Windows.

Thanks, Harald

sebreswiki2025-11-03 13:52:26

Regarding not-zero return code of QPF/QPC, I'm unsure - the docu says also "if the installed hardware supports a high-resolution performance counter"... And IIRC, a VM may lack high-resolution performance counters if the underlying hypervisor or specific monitoring tools are not configured correctly or are missing certain drivers, so maybe it is too hard to remove it.

As regards the calibration thread - I removed it in [fdfbd5e10] (rewritten windows high-resolution time completely without calibration thread), so however it is indeed unneeded, but certain internal adjustment is necessary to avoid "heavy" time drifts (basically part of calibration moved to time API and invoked at some circumstances by any thread to adjust QPC timer to low-resolution clock).

oehharplain2025-11-03 14:22:58
Thanks, Sergey, I have hoped (and feared) your reponse.
"1000 times faster".
But nobody will ever touch it, as we have nobody who understands only 5 % of it.

So, your answer is: "do not merge".

I respect this, no problem.
Neverhteless, I read the documentation differently. IMHO, there is a clear statement, that the two functions will never return NULL starting with Windows XP.

If would be sooo great to rewrite all this, but I see no hope, sorry.

Thanks for all,
Harald
oehhar Closed ticket [1238d4fdb0]. [History diff]2025-11-03 14:23:14
oehharwiki2025-11-03 14:34:36

Restored Tcl_Panic by [c39d459072] as seen as critical.

Closed ticket and branch as seen as not safe for VMs.

Thanks for all and take care, Harald

Log in (anonymous is fine) to add a comment.