Add initial portable time abstraction (WIP)#738
Conversation
|
Thanks for submitting this change. I'm very interested in this, but clearly I'm going to need to study it. I note that you've tested on two of the main development platforms for iperf3 (Linux and macOS), and it looks like the third supported platform (FreeBSD) also supports clock_gettime(2). |
|
Of course, let me know if you have any questions. I've since tested it on a system which requires I still haven't found a system without |
|
I'm writing some (probably trivial) things down to prove I actually looked at this. :-) I don't need a diff for I was a little concerned about an apparent API change in So far I've tested a bit on macOS and not seen any regressions. I'll try on other platforms too. Not sure what I have easy access to that doesn't have Could you provide a few details about what kind of issues you ran into with the stock code? Not that I don't believe you, just want to learn what the problems are with |
|
@ben-foxmore: D'oh. I merged someone else's PR (#767) and this caused a merge conflict with your PR, as I was going to merge your PR. Do you feel up to trying to resolve this? If not I can give it a try. I'm not too worried about the auto-generated files because I'll re-run |
|
@ben-foxmoore: I'm still interested in merging this. I just tried merging the PR against the current master and only ran into a couple of easily-fixed merge conflicts in Would you be able to answer the questions I had in my last comment here? It looks like this code works correctly on the officially supported platforms, so absent the easy ability to test on anything else I feel like I could go ahead and merge this (resolving the conflicts as I go along). Thoughts? EDIT: And I just now realized I misspelled your username in my last comment, so you probably didn't even read it yet. Sorry about that! |
From author's notes (@ben-foxmore): The current usage of gettimeofday causes issues for us when performing tests shortly after restarting a system. In our setup, this occurs often as we restart the system before each test to ensure reliable results. We already maintain our own version of iperf for some subtle changes, but this change feels like it might be useful to upstream. (It's also a reasonable size change, so we'd prefer not maintain it with each new version of iperf.) It uses clock_gettime on systems that have it available, and falls back to gettimeofday when it's not. These two options use different structures for storing time - clock_gettime uses timespec, and gettimeofday uses timeval. To provide abstraction to which one is available, a separate iperf_time struct is defined to store time. timespec has nanosecond accuracy, while timeval only has microseconds. For the purposes of iperf, I don't think nanosecond accuracy is neccesary, so iperf_time only uses microseconds, throwing away any additional accuracy. Currently I have used the MONOTONIC clock, as I think we only need a consistent time interval measure.
|
Shoot, sorry @bmah888 - I missed your last comment (Gmail filtered it out to some different tab or another). I see you've merged this over the weekend. Were there any problems, or anything you still want me to look at? Looking back, I realise I've neglected this post a bit. As you predicted the main issues we were having was with gettimeofday being stepped quite aggressively against our internal NTP server. |
|
@ben-foxmoore : Nah I'm good, thanks. Sorry it took so long for me to actually merge this...I didn't quite give it the testing I wanted but I finally concluded I needed to merge this into master to get more eyes on it. |
|
No problem. Tag me if you have any issues raised due to this change and I'll try to help out. |
This is a WIP proposal for providing a portable replacement to gettimeofday. Discussion is welcomed!
The current usage of
gettimeofdaycauses issues for us when performing tests shortly after restarting a system. In our setup, this occurs often as we restart the system before each test to ensure reliable results. We already maintain our own version of iperf for some subtle changes, but this change feels like it might be useful to upstream. (It's also a reasonable size change, so we'd prefer not maintain it with each new version of iperf.)It uses
clock_gettimeon systems that have it available, and falls back togettimeofdaywhen it's not. These two options use different structures for storing time -clock_gettimeusestimespec, andgettimeofdayusestimeval. To provide abstraction to which one is available, a separateiperf_timestruct is defined to store time.timespec has nanosecond accuracy, while timeval only has microseconds. For the purposes of iperf, I don't think nanosecond accuracy is neccesary, so iperf_time only uses microseconds, throwing away any additional accuracy. Currently I have used the MONOTONIC clock, as I think we only need a consistent time interval measure.
The following functions are provided to work with iperf_time structs:
I'm not totally satisfied with the behaviour of
iperf_time_diff. I may change it to return the same values asiperf_time_compareto be consistent. It was written the way it currently is so thattimer.ccan use the return code as a "timer is expired" flag. I'm also sure the implementation ofiperf_time_diffcould be greatly improved.Unfortunately, this change has only been tested on environments that have
clock_gettime- Linux 4.16.3 with glibc 2.27, and OSX 10.13.4. I don't have much experience with autoconf/automake, so this should be tested on a system withoutclock_gettime, and on a system which requires-lrt, before it is considered for merging.Related to #210 and #253