-
Notifications
You must be signed in to change notification settings - Fork 637
Add high resolution time support (nanoseconds) to Time::HiRes via a new method: hrtime()
#24471
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
base: blead
Are you sure you want to change the base?
Changes from all commits
b733a0c
30fa55f
c44f3fe
195c1c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1409,6 +1409,42 @@ clock_gettime(clock_id = 0) | |
|
|
||
| #endif /* #if defined(TIME_HIRES_CLOCK_GETTIME) */ | ||
|
|
||
| #if defined(TIME_HIRES_CLOCK_GETTIME) | ||
|
|
||
| void | ||
| hrtime(as_array = 0) | ||
| bool as_array | ||
| PREINIT: | ||
| struct timespec ts; | ||
| int status; | ||
| PPCODE: | ||
| # ifdef TIME_HIRES_CLOCK_GETTIME_SYSCALL | ||
| status = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts); | ||
| # else | ||
| status = clock_gettime(CLOCK_MONOTONIC, &ts); | ||
| # endif | ||
| if (status != 0) | ||
| XSRETURN_EMPTY; | ||
|
Contributor
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. XSRETURN_EMPTY should not be used in a PPCODE: block. XSRETURN_FOOs are intended for CODE: blocks where local nor global SP has never been rewound to zero, or the validity/non-SEGV Ness of local var SP is unknown, such as in EU::PXS codegen blocks that can not determine if call_sv() indirectly ever got executed in the body of a XSUB thus causing a possible Perl stack realloc grow event, and the end dev was sloppy or careless in writing SPAGAIN in the correct locations. PPCODE: puts a XSprePuSH: in the codegen at the top, rewinding local SP to 0. "PUTBACK; return;" is all that is needed to return an empty list in a PPCODE block. |
||
| if (as_array) { | ||
| EXTEND(sp, 2); | ||
| PUSHs(sv_2mortal(newSViv(ts.tv_sec))); | ||
| PUSHs(sv_2mortal(newSViv(ts.tv_nsec))); | ||
| } else { | ||
| EXTEND(sp, 1); | ||
|
Contributor
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. Eliminate EXTEND 1, it's not needed, all XSUBs are guaranteed 1 slot on PL_stack_sp bc pp_entersub removes 1 SV* from the stack to invoke your CV*. The alternative is to do EXTEND 2 on all paths, the Perl stack is incapable of shrinking for the life of the process. If 8 bytes of malloc() space is the difference between the kernel OOM killing Perl and a successful app run, there r much bigger problems going on. It's not worth the code space or CPU wall Time to bother branching between bounds check of 1 and 2. just do 2 always, or check for 2 on the list return path and no check on scalar return path. |
||
| PUSHs(sv_2mortal(newSVuv((UV)ts.tv_sec * (UV)IV_1E9 + (UV)ts.tv_nsec))); | ||
| } | ||
|
Contributor
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. What if UV is size 32bits such as on i386 Perl? You might want type U64 math here or throw a C syntax error. Truncate to 32 bits 3 times silently is a bad idea here if all 3 inputs are size 64b. Even Visual C 6.0 can be beaten with a heavy stick to cough up support for types U64 and I64 . |
||
|
|
||
| #else /* if defined(TIME_HIRES_CLOCK_GETTIME) */ | ||
|
|
||
| void | ||
| hrtime(as_array = 0) | ||
| bool as_array | ||
| PPCODE: | ||
| PERL_UNUSED_ARG(as_array); | ||
| croak("Time::HiRes::hrtime(): unimplemented in this platform"); | ||
|
Contributor
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. Replace with "%s" and Split off string "Time::HiRes::hrtime" into arg 1 of croak(), nobody needs ASCII string "Time::HiRes::hrtime" to appear twice in the .so/.dll file. |
||
|
|
||
| #endif /* #if defined(TIME_HIRES_CLOCK_GETTIME) */ | ||
|
|
||
| #if defined(TIME_HIRES_CLOCK_GETRES) | ||
|
|
||
| NV | ||
|
|
||
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 argument is illogical in the Perl 5 language and shows zero knowledge of Perl coding.
Either call PP
wantarrayor CGIMME_Vto learn this information the PP Grammar correct way.