This is an archive of the discontinued LLVM Phabricator instance.

[libc] Implement gettimeofday
ClosedPublic

Authored by rtenneti on Nov 11 2022, 6:02 PM.

Details

Summary

Implement gettimeofday per
.../onlinepubs/9699919799/functions/gettimeofday.html.
This call clock_gettime to implement gettimeofday function.

Tested:
Limited unit test: This makes a call and checks that no error was
returned. Used nanosleep for 100 microseconds and verfified it
returns a value that elapses more than 100 microseconds and less
than 300 microseconds.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

Diff Detail

Event Timeline

rtenneti created this revision.Nov 11 2022, 6:02 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 11 2022, 6:02 PM
rtenneti requested review of this revision.Nov 11 2022, 6:02 PM
This revision was not accepted when it landed; it landed in state Needs Review.Nov 11 2022, 6:11 PM
This revision was automatically updated to reflect the committed changes.

Did you intend to land this without review?

It was a mistake, I was trying to upload an update to the patch by removing
tabs (I am guessing I must have have done git push and that might have
submitted the changes).

I would appreciate it if the following changes could be reviewed.

Thanks much
Raman

michaelrj added inline comments.Nov 14 2022, 10:57 AM
libc/spec/posix.td
48

these are already defined in spec.td as StructTimevalType and StructTimevalPtr

1083–1087

why did you move this?

libc/src/time/gettimeofday.cpp
13

we try to avoid calling entrypoints from other entrypoints. Here instead of calling clock_gettime it would be better to copy the code since it's just a simple syscall wrapper. If it was more complex then it would be better to extract it into a shared utility.

sivachandra added inline comments.Nov 14 2022, 12:12 PM
libc/spec/posix.td
1083–1087

They were likely rearranged to be in alphabetical order.

libc/test/src/time/gettimeofday_test.cpp
32

The less than check is always going to be flaky. Instead, verify that the next value is greater than or equal to 200 microseconds from the old value. Repeat with a 1000 microsecond delay to reinforce.

rtenneti marked 5 inline comments as done.Nov 15 2022, 2:22 PM

Made the changes in https://reviews.llvm.org/D138064

Thanks for the comments.