Bug 237341

Summary: [libpas] Add missing PlayStation implementation.
Product: WebKit Reporter: Basuke Suzuki <Basuke.Suzuki>
Component: bmallocAssignee: Basuke Suzuki <Basuke.Suzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: Basuke.Suzuki, darin, don.olmstead, fpizlo, ggaren, ross.kirsling, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
PATCH
none
PATCH
ysuzuki: review+
PATCH none

Description Basuke Suzuki 2022-03-01 13:24:07 PST
Add pas_get_current_monotonic_time_nanoseconds
Comment 1 Basuke Suzuki 2022-03-01 13:28:42 PST
Created attachment 453535 [details]
PATCH
Comment 2 Yusuke Suzuki 2022-03-01 13:34:00 PST
Comment on attachment 453535 [details]
PATCH

View in context: https://bugs.webkit.org/attachment.cgi?id=453535&action=review

> Source/bmalloc/libpas/src/libpas/pas_monotonic_time.c:88
> +    clock_gettime_np(CLOCK_MONOTONIC, &ts);

Is it possible to use CLOCK_MONOTONIC_FAST in this playstation platform? (FreeBSD has this one).
This function needs to be super fast, so full CLOCK_MONOTONIC is not ideal if the platform has an alternative.
Comment 3 Basuke Suzuki 2022-03-01 13:53:10 PST
(In reply to Yusuke Suzuki from comment #2)
> Comment on attachment 453535 [details]
> PATCH
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=453535&action=review
> 
> > Source/bmalloc/libpas/src/libpas/pas_monotonic_time.c:88
> > +    clock_gettime_np(CLOCK_MONOTONIC, &ts);
> 
> Is it possible to use CLOCK_MONOTONIC_FAST in this playstation platform?
> (FreeBSD has this one).
> This function needs to be super fast, so full CLOCK_MONOTONIC is not ideal
> if the platform has an alternative.

Sure. Sorry, I've forgotten your advice.
Comment 4 Basuke Suzuki 2022-03-01 13:57:14 PST
Created attachment 453539 [details]
PATCH
Comment 5 Darin Adler 2022-03-01 14:01:32 PST
Comment on attachment 453539 [details]
PATCH

View in context: https://bugs.webkit.org/attachment.cgi?id=453539&action=review

> Source/bmalloc/libpas/src/libpas/pas_monotonic_time.c:89
> +    return ts.tv_sec * 1.0e9 + ts.tv_nsec;

Do you really want to do floating point double precision multiplication here, and then convert back to integer? Maybe uint64_t multiplication would be better?
Comment 6 Basuke Suzuki 2022-03-01 14:08:10 PST
(In reply to Darin Adler from comment #5)
> Comment on attachment 453539 [details]
> PATCH
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=453539&action=review
> 
> > Source/bmalloc/libpas/src/libpas/pas_monotonic_time.c:89
> > +    return ts.tv_sec * 1.0e9 + ts.tv_nsec;
> 
> Do you really want to do floating point double precision multiplication
> here, and then convert back to integer? Maybe uint64_t multiplication would
> be better?

Yusuke, what do you think? I think Darin's point is reasonable, but any reason to use float? I've followed Linux implementation.
Comment 7 Basuke Suzuki 2022-03-01 14:09:06 PST
We need to add special rule to check-webkit-style for libpas C files...
https://ews-build.webkit.org/#/builders/6/builds/70223
Comment 8 Yusuke Suzuki 2022-03-01 14:11:49 PST
Comment on attachment 453539 [details]
PATCH

View in context: https://bugs.webkit.org/attachment.cgi?id=453539&action=review

>>> Source/bmalloc/libpas/src/libpas/pas_monotonic_time.c:89
>>> +    return ts.tv_sec * 1.0e9 + ts.tv_nsec;
>> 
>> Do you really want to do floating point double precision multiplication here, and then convert back to integer? Maybe uint64_t multiplication would be better?
> 
> Yusuke, what do you think? I think Darin's point is reasonable, but any reason to use float? I've followed Linux implementation.

I think either is fine.
Comment 9 Basuke Suzuki 2022-03-01 14:23:12 PST
https://godbolt.org/z/dq34fn6xz

Quick code comparison seems compact and looks faster. I'm building this and comparing with JetStream2 result.
Comment 10 Basuke Suzuki 2022-03-01 19:06:00 PST
original:
Total Score:  28.991

integer version:
Total Score:  29.347

So the later is a bit faster. I'll go with this for PlayStation port. Thanks!
Comment 11 Basuke Suzuki 2022-03-01 21:04:11 PST
Created attachment 453568 [details]
PATCH

Thanks, Yusuke and Darin.
Comment 12 EWS 2022-03-01 22:06:48 PST
Committed r290719 (247966@main): <https://commits.webkit.org/247966@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 453568 [details].
Comment 13 Radar WebKit Bug Importer 2022-03-01 22:07:17 PST
<rdar://problem/89665276>
Comment 14 Darin Adler 2022-03-02 08:12:05 PST
Comment on attachment 453568 [details]
PATCH

View in context: https://bugs.webkit.org/attachment.cgi?id=453568&action=review

> Source/bmalloc/libpas/src/libpas/pas_monotonic_time.c:89
> +    return ts.tv_sec * 1000u * 1000u * 1000u + ts.tv_nsec;

This looks wrong given C type promotion rules. The multiplication will not be done as uint64_t, since the things we are multiplying are unsigned (32 bit). So it may be truncated at 32 bits unless tv_sec already a has 64-bit type, then addition also done as 32-bit and only then put into 64-bit. Need to convert one of the integers being multiplied to uint64_t before multiplying. I suggest putting tv_sec into a uint64_t local.