Can you access the HPET timer in Wine on Linux?

Questions about Wine on Linux
Locked
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Can you access the HPET timer in Wine on Linux?

Post by robertinventor »

First want to make clear - I'm a Windows developer and not knowledgeable about Linux. But am working on compatibility of my Windows program for Wine and Linux.

Anyway - my program is a metronome and so accurate timing is very important. On Windows it works around timing issues using sleeps ending in short busy waits - which works fine if you have a high resolution, and also accurate source of time.

For this the HPET timer seems ideal because it is guaranteed not to drift by more than e.g. 0.1 ms in 200 ms. Fine for multimedia work. Most other timers are too slow to access, or have no guarantees about amounts of frequency drift at all.

Sadly though Windows doesn't use it by default. You can set it to use it with bcdedit on Windows normally, don't know what the situation is for Wine on Linux.

So anyway - I wondered what is the situation on Wine - and if there is any way to directly access the HPET timer in Wine running on Linux as the host - even if the timers in Wine don't use it.

If I could do that then I could guarantee sub millisecond timing with busy waits, even in normal Linux kernel even not low latency never mind realtime, so long as the computer is quiet enough and my program can run at a reasonable priority with a core pretty much to itself, at least on multi-core machines.

I understand that you can directly access it in Linux as described on this page
https://access.redhat.com/knowledge/doc ... mping.html

So - just wondered, is there any Wine routine I can call to access it? Maybe some routine that I can find in the dlls? Or any other way a program running under Wine on Linux could directly access the Hpet timer?

Anyone got any ideas or thoughts about this?

Also - especially in case this doesn't work out or for other programs using time stamps under Wine - I am interested to know if there is a way to set Wine to use HPET similarly to the Windows bcdedit useplatformclock true -as a tweak to suggest to users.
lahmbi5678
Level 7
Level 7
Posts: 823
Joined: Thu Aug 27, 2009 6:23 am

Re: Can you access the HPET timer in Wine on Linux?

Post by lahmbi5678 »

Hi,

this is one of that typical questions that noone on this list will be able to answer. If I had to guess, I'd say, that functionality is very probably not implemented in wine. You could write a small test program, that just calls the timer, and try that under wine. If it wouldn't work, file a bug.

In theory it should be possible to call linux timer functions from windows code using winelib, that means that you'd have to compile your windows app under linux using winelib, see http://www.winehq.org/docs/winelib-guide/index . I'm not sure if that would actually work out, regarding timing issues.

Maybe it would be easier to port your application using a toolkit like qt, and compile it under linux, when compiled under linux, you'd have to call the linux equivalent of the HPET timer.
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Re: Can you access the HPET timer in Wine on Linux?

Post by robertinventor »

Thanks, yes, I hope to do it without needing to make a separate Wine app. It is a large complex app that uses many low level Windows routines, so though it works fine now with Wine, I suspect that compiling using WineLib would be tricky, but haven't tried it certainly.

The thing is - Windows doesn't use the HPET timer by default. There is no Windows routine that lets you call it. Though you can set it to use the HPET timer using bcdedit which is done by opening an MSDOS prompt in Windows with admin privileges and rebooting.

On Windows I hope to get around that by using a special driver to access the HPET timer by Jan Wassenberg. Maybe that will work in Wine too, will see.
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Re: Can you access the HPET timer in Wine on Linux?

Post by robertinventor »

Just to explain a bit more:

When you do that bcdedit tweak in Windows normally, the various timer routines use HPET but if you don't do that then they ignore it, and there is no way normally to access it.

I'm not sure what Wine does with Linux as a native OS, as here I test it in a virtual machine under Windows.

Anyway - so that's why it is a bit tricky filing a bug report because I don't know what Wine actually does (does it try to exactly emulate how Windows does the timers with the default of HPET ignored) or what it should do.

If there was some way to call the linux time routines directly while running within Wine though, I could access the HPET timer and know for sure that that is what my app is using, and just not care what Wine does when it emulates the Window timers.
lahmbi5678
Level 7
Level 7
Posts: 823
Joined: Thu Aug 27, 2009 6:23 am

Re: Can you access the HPET timer in Wine on Linux?

Post by lahmbi5678 »

In general hardware drivers are not supported in wine, i.e. graphics/printer/USB/etc drivers won't work at all, maybe your driver would still work, as it wouldn't be the typical hardware driver, yet I doubt, that the functionality, that such a driver would need, is implemented in wine.

You probably should create a small test application and try it on wine. I'm not even sure, if the timer functionality you need is implemented in wine at all (apart from the question, if HPET or another timer is used). If the timer functionality isn't there in wine, you'd have to file a bug for that first. The probably 'simplest' way to get what you need might be to get a patch for an HPET timer into wine, this wouldn't be easy, you'd have to understand the wine code, create a clean patch (not a quick and dirty hack) and convince the wine maintainer, that HPET is needed and that it doesn't hurt wine or produce side effects. Wine itself (its server) might have some additional latency, too, and the linux kernel on which you'd run your application would have to support HPET (or another efficient timer).
Locked