Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HPET-enabled Stopwatch class #575

Merged
merged 4 commits into from
Jan 2, 2021

Conversation

AbstractQbit
Copy link
Contributor

It replaces DateTime.Now in ms-critical sections,
as per .net documentation, DateTime.Now's resolution
can have an impact on sub 100ms time intervals.
https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=net-5.0#datetime-resolution

AbstractQbit and others added 2 commits December 20, 2020 14:55
It replaces DateTime.Now in ms-critical sections,
as per .net documentation, DateTime.Now's resolution
can have an impact on sub 100ms time intervals.
https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=net-5.0#datetime-resolution
Co-Authored-By: X9VoiD <oscar.silvestrexx@gmail.com>
@InfinityGhost InfinityGhost added enhancement New feature or request core OpenTabletDriver core library labels Dec 22, 2020
DeltaStopwatch wraps regular Stopwatch, providing incremental restarts with one kernel call without losing ticks.
It also provides static methods to get app runtime timespan.
@InfinityGhost InfinityGhost modified the milestones: v0.5.0, v0.5.x Jan 1, 2021
@InfinityGhost
Copy link
Member

The stopwatch based timer is only more accurate than DateTime.Now when the hardware supports it, and having a constantly running stopwatch also can have performance penalties.

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch.ishighresolution?view=net-5.0#remarks

return delta;
}
}
public double RestartMs() => Restart().TotalMilliseconds;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these unnecessary helper methods, since they're only referenced like twice ever

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it looks out of place, then sure, will remove those. Made them because most of the time milliseconds are what's being used in the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looks odd for it to be exposed like that the main method going unused

Comment on lines 4 to 6
namespace OpenTabletDriver.Plugin.Utils
{
public class DeltaStopwatch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change namespace to OpenTabletDriver.Plugin.Timing and class name to HighPrecisionEventStopwatch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a wrapper for an already existing class? This seems kinda pointless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeltaStopwach name was used because it allows for measuring laps without redundant queries, in contrast to regular Stopwatch. HighPrecisionEventStopwatch doesn't really reflect the difference between those classes, and is very long imo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class name length isn't an issue. Can we compromise on HPETDeltaStopwatch as the class name?

@AbstractQbit
Copy link
Contributor Author

AbstractQbit commented Jan 1, 2021

The stopwatch based timer is only more accurate than DateTime.Now when the hardware supports it, and having a constantly running stopwatch also can have performance penalties.

HPET was introduced by intel in ~2005 and is included in basically every platform since. It starts running at a system startup and only ever costs you anything when you query it. The wrapper is there so that we can "lap" the stopwatch with just 1 kernel call/HPET query instead of two when querying elapsed and then restarting. This also eliminates the possibility of missing some ticks between checking the time and restarting.

@InfinityGhost InfinityGhost modified the milestones: v0.5.x, v0.5.0 Jan 2, 2021
@InfinityGhost InfinityGhost merged commit df44351 into OpenTabletDriver:master Jan 2, 2021
@AbstractQbit AbstractQbit deleted the HPET-stopwatch branch January 2, 2021 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core OpenTabletDriver core library enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants