fix timeWaiting computation in TimeUtil
authorAdam Simpkins <simpkins@fb.com>
Tue, 6 Jun 2017 21:09:39 +0000 (14:09 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 6 Jun 2017 21:21:27 +0000 (14:21 -0700)
commit68f55ed0e97dea446cf66d429e8b46331cfb9f12
treeb8e312a340d258b0d7a7ad43e8e970c04a11975a
parent5ba3126fb76f1d81100b34e429c79cd21f8cd142
fix timeWaiting computation in TimeUtil

Summary:
Some of the code in TimeUtil.cpp computes how long the current thread has spent
waiting to be schedule on the CPU, so we can discount this time when testing
timeout behavior.

It appears that this code has been broken for a fairly long time.  Older Linux
kernels reported values in /proc/<pid>/schedstat using jiffies.  However, it
appears that this was changed in Linux 2.6.23 to report values using
nanoseconds.  (It looks to me like this was changed in commit 425e0968a25f,
which purports to simply be moving code from sched.c to sched_stats.h,
but it appears to also have also changed this behavior.)

This updates TimeUtil.cpp to compute the value correctly in modern Linux
kernels.

Reviewed By: yfeldblum

Differential Revision: D5173598

fbshipit-source-id: 98436d3a687400bf68661156ffce93eea7232632
folly/io/async/test/TimeUtil.cpp
folly/io/async/test/TimeUtilTest.cpp [new file with mode: 0644]