Showing posts with label timer. Show all posts
Showing posts with label timer. Show all posts

Tuesday, May 22, 2018

Is the HPET directly accessible in Windows?

Leave a Comment

I would like to use the High Performance Event Timer (HPET) for an profiling tool to take very high precision measurements, quickly. timeGetTime does not provide sufficient resolution at 1ms, and QueryPerformanceCounter is much slower per read than I'd like. I came across the HPET while researching the problem, but I can't see any samples of how to actually get at it.

So can I use it directly (assembly is fine), or do I have to rely on the multimedia/high performance timing tools already built into the Win32 API?

2 Answers

Answers 1

I found this info while digging around, and it seems it can be the most cost effective way. I will try it out when I get the guts to dig into assembly. :)

UPDATE

I tested this with my profiler. although a bit faster, it seems I still have tonnes of other overhead :( (I did not bother with timing as I it did not seem to be enough benefit)

Answers 2

I am also interested in using the HPET, but as a timer. The way I understand it, QueryPerformanceCounter and QueryPerformanceFrequency are actually accessing the counter and clock for the HPET, and this works under Windows XP (see, for example, http://www.geisswerks.com/ryan/FAQS/timing.html).

So as far as timing code, I think by using QueryPerformanceCounter you are in fact getting access to the counter that form the base of HPET, and this is all present in the chipset (rather than the processor).

Read More

Monday, April 25, 2016

How to maintain clock session between two different devices?

Leave a Comment

I am working on iOS application which requires to maintain a clock timer session between two devices upon acceptance of both device users?

But I am not sure how this can be achieved without getting a flaw in timing on both devices?

I have already look on following ideas:

1)Maintain state of both devices with help of Webservices or push notification so that timer on both devices will start at the same time. But if network is not working properly this approach is getting failed and there is flaw in timer on both devices.

In addition, I also want to know how can I prevent application clock remain unchanged even after changing device date and time.

Any help over this would be appreciated.

Thanks in advance.

3 Answers

Answers 1

You can use ios-ntp to get network time and calculate time offset between local and network time on both devices. When you start timer on one device, you subtract the offset from the local timestamp and send the resulting network timestamp to another device. On another device you append the local offset to the network timestamp and get the timestamp of timer start in the local time.

You can use UIApplicationDelegate.applicationSignificantTimeChange(_ application: UIApplication) to monitor time changes on the device and recalculate the offset by updating network time.

Answers 2

Some thoughts:

  • keep track of your own time, be independent of the system clock. Only use the system clock to convert your time to user-wall-clock time when you need to display something.

  • a time-unit (like a second) on one device should equal a second on the other device, e.g. trust that the duration of it is equal on both devices)

  • network delay is a fundamental problem. Consider that there might always be an offset between the two devices. Maybe you can come up with a way that reveals the lag, or you could come up with a way where the absolute time is not relevant

Here is an idea: when device1 sends a sync-packet every 5 seconds, device2 should have this packet before it does whatever happens at second 6. So if the packet is not there yet in device2 at 5 seconds, it could wait for the packet to arrive before it continues to do whatever needs to be done next. When the packet arrives at 3 seconds, device2 should hold on to it and process it at second 5. Do this in a bi-directional way, and both apps are in sync within a 5 seconds time-frame. Depending on your requirements and the network, you have to decide what 'waiting' means and how often to send a sync-packet.

Answers 3

You can achieve by the webservice in which you just send flag to global clock,In this you just set flag for start and end time so by using this method you can easily synchronize the time between two ro more devices.

Read More

Node.js setTimeout not fired after system time change

Leave a Comment

I have such script

setTimeout(function()  {     console.log("Timeout"); }, 1000 * 60); 

When I run it and change system time back for one hour, the timeout not fires. If I change time forward for one hour, timeout works correctly.

Time is changed by external program which makes call like ioctl( rtcFd, RTC_SET_TIME, &newTime);

How to fix this problem?

We use Node.js v0.10.15 on OpenWRT Attitude Adjustment

Thank you

2 Answers

Answers 1

I just founded that this is a bug fixed in newer version. It fixed by this commit in v0.10.33.

If you meet this problem, you need to update or patch your node.js

Answers 2

Use node scheduler this is for time-based scheduling

npm install node-schedule

var jobId="123456abc"; schedule.scheduleJob(jobId, new Date(1), function()  {                                                                                                                   schedule.cancelJob(jobId);     // your code here. }); 
Read More