-
Notifications
You must be signed in to change notification settings - Fork 114
[WIP] Make get-internal-real-time monotonic #46
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
eugeneia
wants to merge
5
commits into
Clozure:master
Choose a base branch
from
eugeneia:issue-20
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
568cd66
move ccl:current-time-in-nanoseconds from lib/time to l1-lisp-threads
eugeneia 874f224
remove dead code
eugeneia b9d7fe8
get-internal-realtime / ccl::get-tick-count - use current-time-in-nan…
eugeneia 84af35a
ccl:current-time-in-nanoseconds - fix for Darwin/Windows
eugeneia 3b966c5
Use defconstant for constants in l1-lisp-threads
eugeneia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,17 @@ | |
| #-windows-target | ||
| (max 1000 (#_sysconf #$_SC_CLK_TCK))) | ||
|
|
||
| (defloadvar *ns-per-second* | ||
| 1000000000) | ||
|
|
||
| (defloadvar *ns-per-millisecond* | ||
| (floor *ns-per-second* 1000)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also defconstant. |
||
|
|
||
| (defloadvar *ns-per-tick* | ||
| (floor 1000000000 *ticks-per-second*)) | ||
| (floor *ns-per-second* *ticks-per-second*)) | ||
|
|
||
| (defloadvar *ns-per-internal-time-unit* | ||
| (floor *ns-per-second* internal-time-units-per-second)) | ||
|
|
||
| #-windows-target | ||
| (defun %nanosleep (seconds nanoseconds) | ||
|
|
@@ -76,40 +85,40 @@ | |
| :address (or ptz (%null-ptr)) | ||
| :int)) | ||
|
|
||
| (defloadvar *lisp-start-timeval* | ||
| (progn | ||
| (let* ((r (make-record :timeval))) | ||
| (gettimeofday r) | ||
| r))) | ||
|
|
||
|
|
||
| (defloadvar *internal-real-time-session-seconds* nil) | ||
|
|
||
| #-(or darwin-target windows-target) | ||
| (defloadvar preferred-posix-clock-id | ||
| (rlet ((ts :timespec)) | ||
| (if (eql 0 (#_clock_gettime #$CLOCK_MONOTONIC ts)) | ||
| #$CLOCK_MONOTONIC | ||
| #$CLOCK_REALTIME))) | ||
|
|
||
| #+darwin-target | ||
| (defloadvar darwin-ns-per-unit | ||
| (rlet ((timebase-info :mach_timebase_info_data_t)) | ||
| (#_mach_timebase_info timebase-info) | ||
| (floor (pref timebase-info :mach_timebase_info_data_t.numer) | ||
| (pref timebase-info :mach_timebase_info_data_t.denom)))) | ||
|
|
||
| (defun current-time-in-nanoseconds () | ||
| #-(or darwin-target windows-target) | ||
| (rlet ((ts :timespec)) | ||
| (#_clock_gettime preferred-posix-clock-id ts) | ||
| (+ (* (pref ts :timespec.tv_sec) *ns-per-second*) | ||
| (pref ts :timespec.tv_nsec))) | ||
| #+darwin-target | ||
| (* (#_mach_absolute_time) darwin-ns-per-unit) | ||
| #+windows-target | ||
| (* (#_GetTickCount64) *ns-per-millisecond*)) | ||
|
|
||
| (defun get-internal-real-time () | ||
| "Return the real time in the internal time format. (See | ||
| INTERNAL-TIME-UNITS-PER-SECOND.) This is useful for finding elapsed time." | ||
| (rlet ((tv :timeval)) | ||
| (gettimeofday tv) | ||
| (let* ((units (truncate (the fixnum (pref tv :timeval.tv_usec)) (/ 1000000 internal-time-units-per-second))) | ||
| (initial *internal-real-time-session-seconds*)) | ||
| (if initial | ||
| (locally | ||
| (declare (type (unsigned-byte 32) initial)) | ||
| (+ (* internal-time-units-per-second | ||
| (the (unsigned-byte 32) | ||
| (- (the (unsigned-byte 32) (pref tv :timeval.tv_sec)) | ||
| initial))) | ||
| units)) | ||
| (progn | ||
| (setq *internal-real-time-session-seconds* | ||
| (pref tv :timeval.tv_sec)) | ||
| units))))) | ||
| (values (truncate (current-time-in-nanoseconds) | ||
| *ns-per-internal-time-unit*))) | ||
|
|
||
| (defun get-tick-count () | ||
| (values (floor (get-internal-real-time) | ||
| (floor internal-time-units-per-second | ||
| *ticks-per-second*)))) | ||
| (values (truncate (current-time-in-nanoseconds) | ||
| *ns-per-tick*))) | ||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a job for defconstant.