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

dest.c: Use monotonic time for cups_enum_dest #1084

Open
wants to merge 2 commits into
base: 2.4.x
Choose a base branch
from

Conversation

zdohnal
Copy link
Member

@zdohnal zdohnal commented Oct 21, 2024

Patch written by Adam Williamson.

gettimeofday() is vulnerable to clock jumps, so it is better to use clock_gettime() to avoid issues with libcups if system changes clock, f.e. in Live CDs.

Copy link
Member

@michaelrsweet michaelrsweet left a comment

Choose a reason for hiding this comment

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

I'm thinking we need a CUPS API that returns a monotonic value, probably a double for portability.

double cupsGetClock(void);

If we back-port this to CUPS 2.4.x, we'll want to leave this as private API (_cupsGetClock).

cups/dest.c Outdated Show resolved Hide resolved
cups/dest.c Outdated Show resolved Hide resolved
cups/dest.c Outdated Show resolved Hide resolved
config-scripts/cups-common.m4 Outdated Show resolved Hide resolved
config-scripts/cups-common.m4 Outdated Show resolved Hide resolved
cups/dest.c Outdated Show resolved Hide resolved
@michaelrsweet michaelrsweet self-assigned this Oct 22, 2024
@michaelrsweet michaelrsweet added bug Something isn't working priority-medium labels Oct 22, 2024
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Oct 22, 2024
@michaelrsweet
Copy link
Member

[master 0350eba] Add cupsGetClock API.

Also in libcups repository.

@zdohnal zdohnal force-pushed the monotonic-time-24x branch from 3256ace to 8e7e192 Compare October 29, 2024 16:14
@zdohnal zdohnal force-pushed the monotonic-time-24x branch from 8e7e192 to 43e3319 Compare December 3, 2024 17:42
@zdohnal
Copy link
Member Author

zdohnal commented Dec 3, 2024

@michaelrsweet hmm, looks like Mac monotonic clock precision is buggy...

I've looked into Mac results on current master branch and there is something wrong with MacOS test suite - I see fail for cupsGetClock(), but the CI run shows as passed:

cupsGetClock(initial): PASS (0)
cupsGetClock(1 second): PASS (1.09793)
cupsGetClock(5 seconds): FAIL (got 5.14539, expected 5.0 +/- 0.1)
cupsGetClock(10 seconds): FAIL (got 10.2297, expected 10.0 +/- 0.1)
cupsGetClock(30 seconds): FAIL (got 30.3457, expected 30.0 +/- 0.1)
cupsGetClock(60 seconds): FAIL (got 60.3833, expected 60.0 +/- 0.1)
cupsGetClock(120 seconds): FAIL (got 120.406, expected 120.0 +/- 0.1)

I will try the CLOCK_MONOTONIC_RAW, if it helps MacOS...

@zdohnal
Copy link
Member Author

zdohnal commented Dec 3, 2024

To no avail... here is the post I found about Mac and CLOCK_MONOTONIC https://discussions.apple.com/thread/253778121?page=2&sortBy=rank .

@michaelrsweet
Copy link
Member

The CI failure might be cause by load on the system or virtualization speed - the testclock program is just seeing that the monotonic clock is increasing and roughly close to the expected (wall) clock time. Having jitter that large isn't ideal but as long as the values are increasing it won't cause a problem.

@zdohnal
Copy link
Member Author

zdohnal commented Dec 6, 2024

@michaelrsweet so I would ifdef the test binary and raise acceptable delta for Mac? Or introduce a new function which will allow us to set acceptable delta and use that with a different value on Mac?

@michaelrsweet
Copy link
Member

@michaelrsweet so I would ifdef the test binary and raise acceptable delta for Mac? Or introduce a new function which will allow us to set acceptable delta and use that with a different value on Mac?

This is just in the unit test program, so we can increase the acceptable delta (say to 1 second) or just drop it to avoid future woe. The key is to flag values going backwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants