Skip to content

Monotonic time on macOS 10.12+ should use mach_continuous_time() #86273

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

Open
xsetech mannequin opened this issue Oct 21, 2020 · 2 comments · May be fixed by #134521
Open

Monotonic time on macOS 10.12+ should use mach_continuous_time() #86273

xsetech mannequin opened this issue Oct 21, 2020 · 2 comments · May be fixed by #134521
Labels
3.10 only security fixes OS-mac type-bug An unexpected behavior, bug, or error

Comments

@xsetech
Copy link
Mannequin

xsetech mannequin commented Oct 21, 2020

BPO 42107
Nosy @ronaldoussoren, @vstinner, @ned-deily, @xSetech

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-10-21.10:37:25.123>
labels = ['OS-mac', 'type-bug', '3.10']
title = 'Monotonic time on macOS 10.12+ should use mach_continuous_time()'
updated_at = <Date 2020-10-21.18:55:54.519>
user = 'https://github.com/xsetech'

bugs.python.org fields:

activity = <Date 2020-10-21.18:55:54.519>
actor = 'ronaldoussoren'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['macOS']
creation = <Date 2020-10-21.10:37:25.123>
creator = 'sjunot'
dependencies = []
files = []
hgrepos = []
issue_num = 42107
keywords = []
message_count = 2.0
messages = ['379204', '379231']
nosy_count = 4.0
nosy_names = ['ronaldoussoren', 'vstinner', 'ned.deily', 'sjunot']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42107'
versions = ['Python 3.10']

Linked PRs

@xsetech
Copy link
Mannequin Author

xsetech mannequin commented Oct 21, 2020

This blog post describes an issue with Apple's "CLOCK_UPTIME_RAW" where the clock is reset after a system that hibernates:

https://rachelbythebay.com/w/2020/10/20/ticktock/

According to Apple's documentation, CLOCK_UPTIME_RAW corresponds to mach_absolute_time():

https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time

CPython is using mach_absolute_time() for its time.monotonic() implementation:

https://github.com/python/cpython/blob/f660567/Python/pytime.c#L7

time.monotonic() ought to be backed by the more appropriate mach_continuous_time() ("CLOCK_MONOTONIC_RAW"). Note it was introduced in macOS 10.12+:

https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time

@xsetech xsetech mannequin added 3.10 only security fixes OS-mac type-bug An unexpected behavior, bug, or error labels Oct 21, 2020
@ronaldoussoren
Copy link
Contributor

See also bpo-41303, which discusses using mach_continuous_time in another context.

If using a different clock is necessary I'd prefer to use clock_gettime(CLOCK_MONOTONIC_RAW) instead of mach_continuous_time(), as the former is a more cross-platform API.

BTW. Please hold off from merging a patch for this until the macOS 11 support code in bpo-41100 is in, this is bound to cause a merge conflict otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes OS-mac type-bug An unexpected behavior, bug, or error
Projects
Development

Successfully merging a pull request may close this issue.

1 participant