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

RFC: virtual (overlay) system clock #504

Merged
merged 10 commits into from
Sep 20, 2024
Merged

Conversation

teodly
Copy link
Contributor

@teodly teodly commented Aug 1, 2024

As discussed in #389

This adds configuration option virtual-system-clock which is disabled by default which means that OS clock will be used directly as it always was.

If set to true, OS clock will be read-only. Overlay clock will be based on it and used for synchronization.

Tested with Dante device, both master and slave. Seems to work. Hardware timestamping not tested yet due to #503 and pendulum-project/timestamped-socket#66

Exporting the clock to other processes using usrvclock local protocol (currently draft) is planned.

@teodly
Copy link
Contributor Author

teodly commented Aug 14, 2024

Added ability to export clock to other apps using usrvclock protocol. Not tested yet - currently I don't have access to PTP hardware, will test in 2 weeks.

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 0.54945% with 181 lines in your changes missing coverage. Please review.

Project coverage is 62.20%. Comparing base (38e5307) to head (49a2d47).

Files with missing lines Patch % Lines
statime-linux/src/main.rs 0.00% 88 Missing ⚠️
statime/src/overlay_clock.rs 0.00% 47 Missing ⚠️
statime/src/shared_clock.rs 0.00% 21 Missing ⚠️
statime-linux/src/clock/mod.rs 0.00% 13 Missing ⚠️
statime/src/clock.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #504      +/-   ##
==========================================
- Coverage   63.11%   62.20%   -0.92%     
==========================================
  Files          60       63       +3     
  Lines        8104     8225     +121     
==========================================
+ Hits         5115     5116       +1     
- Misses       2989     3109     +120     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidv1992
Copy link
Member

Thank you for the contribution. This is looking interesting, however I have a few concerns. First, I would like to ask you to split the usrvclock stuff into it's own PR. It needs additional consideration due to the extra dependencies and the fact that it is not yet a widely accepted standard, and splitting it would make adoption of the rest of the changes here easier. Also, #517 might be better for the current use cases for this.

Beyond that, having had a short look at the changes, the rest looks decent. There are a few formatting issues and some commented out code that should be fixed before this is ready for merging, and I would like to ask you to reconsider the auto_impls dependency. We are looking to reduce the number of dependencies as we progress to version 1.0, and this would go against that goal.

But again, other than those minor things, this is some nice work that we would be interested in.

Copy link
Member

@davidv1992 davidv1992 left a comment

Choose a reason for hiding this comment

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

See above comment

@teodly
Copy link
Contributor Author

teodly commented Aug 28, 2024

First, I would like to ask you to split the usrvclock stuff into it's own PR.

OK, reverted this commit in this branch.

There are a few formatting issues

Ran cargo fmt, let me know if there is something left requiring manual intervention.

I would like to ask you to reconsider the auto_impls dependency.

Done. The commented out code in clock.rs was my first failed attempt to implement it manually, but after further research I've found that it is possible to display the macro output which helped me do it successfully.

Tested with Dante PTPv2, both master and slave.

Copy link
Member

@davidv1992 davidv1992 left a comment

Choose a reason for hiding this comment

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

Few minor things that still need improving, but definitely on the right track I think.

Comment on lines 57 to 63
fn step_clock(&mut self, offset: Duration) -> Result<Time, Self::Error> {
self.last_sync = self.roclock.now();
self.shift += offset;
Ok(self.time_from_underlying(self.last_sync))
}
Copy link
Member

Choose a reason for hiding this comment

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

This won't work if self.freq_scale_ppm_diff is not zero, as we change the last sync time, and the shift is not update to match that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, offset is in overlay timescale, not underlying.

@@ -249,7 +303,7 @@ async fn actual_main() {
for port_config in config.ports {
let interface = port_config.interface;
let network_mode = port_config.network_mode;
let (port_clock, timestamping) = match port_config.hardware_clock {
let (port_clock, port_clock2, timestamping) = match port_config.hardware_clock {
Copy link
Member

Choose a reason for hiding this comment

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

Why are the two clock variables needed here? Can't we get away with one? looking at the code below they essentially always are the same clock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we need separate owned impl Clock instances: for instance.add_port and port_task. Originally port_clock.clone() was used for this but we can't clone a Box. So we need to clone before boxing.

Copy link
Member

Choose a reason for hiding this comment

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

boxes can be cloned assuming the inner thing is clone, which we can guarantee here I think, so I would strongly prefer that approach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

statime-linux/src/main.rs Outdated Show resolved Hide resolved
statime-linux/src/clock/mod.rs Outdated Show resolved Hide resolved
@davidv1992
Copy link
Member

Can you fix the failing style check?

@davidv1992 davidv1992 added this pull request to the merge queue Sep 20, 2024
Merged via the queue into pendulum-project:main with commit 207b15d Sep 20, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants