Remove clock calibration logic from QuicClock. It's been unused since all of the Quartc code got removed. PiperOrigin-RevId: 443490482
diff --git a/quiche/quic/core/quic_clock.cc b/quiche/quic/core/quic_clock.cc index 94ca72f..571dc59 100644 --- a/quiche/quic/core/quic_clock.cc +++ b/quiche/quic/core/quic_clock.cc
@@ -10,46 +10,8 @@ namespace quic { -QuicClock::QuicClock() - : is_calibrated_(false), calibration_offset_(QuicTime::Delta::Zero()) {} - -QuicClock::~QuicClock() {} - -QuicTime::Delta QuicClock::ComputeCalibrationOffset() const { - // In the ideal world, all we need to do is to return the difference of - // WallNow() and Now(). In the real world, things like context switch may - // happen between the calls to WallNow() and Now(), causing their difference - // to be arbitrarily large, so we repeat the calculation many times and use - // the one with the minimum difference as the true offset. - int64_t min_offset_us = std::numeric_limits<int64_t>::max(); - - for (int i = 0; i < 128; ++i) { - int64_t now_in_us = (Now() - QuicTime::Zero()).ToMicroseconds(); - int64_t wallnow_in_us = - static_cast<int64_t>(WallNow().ToUNIXMicroseconds()); - - int64_t offset_us = wallnow_in_us - now_in_us; - if (offset_us < min_offset_us) { - min_offset_us = offset_us; - } - } - - return QuicTime::Delta::FromMicroseconds(min_offset_us); -} - -void QuicClock::SetCalibrationOffset(QuicTime::Delta offset) { - QUICHE_DCHECK(!is_calibrated_) << "A clock should only be calibrated once"; - calibration_offset_ = offset; - is_calibrated_ = true; -} - QuicTime QuicClock::ConvertWallTimeToQuicTime( const QuicWallTime& walltime) const { - if (is_calibrated_) { - int64_t time_in_us = static_cast<int64_t>(walltime.ToUNIXMicroseconds()) - - calibration_offset_.ToMicroseconds(); - return QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(time_in_us); - } // .......................... // | | |
diff --git a/quiche/quic/core/quic_clock.h b/quiche/quic/core/quic_clock.h index f128f9e..69aed4e 100644 --- a/quiche/quic/core/quic_clock.h +++ b/quiche/quic/core/quic_clock.h
@@ -18,25 +18,12 @@ // Interface for retrieving the current time. class QUIC_EXPORT_PRIVATE QuicClock { public: - QuicClock(); - virtual ~QuicClock(); + QuicClock() = default; + virtual ~QuicClock() = default; QuicClock(const QuicClock&) = delete; QuicClock& operator=(const QuicClock&) = delete; - // Compute the offset between this clock with the Unix Epoch clock. - // Return the calibrated offset between WallNow() and Now(), in the form of - // (wallnow_in_us - now_in_us). - // The return value can be used by SetCalibrationOffset() to actually - // calibrate the clock, or all instances of this clock type. - QuicTime::Delta ComputeCalibrationOffset() const; - - // Calibrate this clock. A calibrated clock guarantees that the - // ConvertWallTimeToQuicTime() function always return the same result for the - // same walltime. - // Should not be called more than once for each QuicClock. - void SetCalibrationOffset(QuicTime::Delta offset); - // Returns the approximate current time as a QuicTime object. virtual QuicTime ApproximateNow() const = 0; @@ -57,14 +44,6 @@ QuicTime CreateTimeFromMicroseconds(uint64_t time_us) const { return QuicTime(time_us); } - - private: - // True if |calibration_offset_| is valid. - bool is_calibrated_; - // If |is_calibrated_|, |calibration_offset_| is the (fixed) offset between - // the Unix Epoch clock and this clock. - // In other words, the offset between WallNow() and Now(). - QuicTime::Delta calibration_offset_; }; } // namespace quic
diff --git a/quiche/quic/core/quic_epoll_clock_test.cc b/quiche/quic/core/quic_epoll_clock_test.cc index e501fc4..617230f 100644 --- a/quiche/quic/core/quic_epoll_clock_test.cc +++ b/quiche/quic/core/quic_epoll_clock_test.cc
@@ -44,70 +44,6 @@ EXPECT_EQ(1000005, (clock.Now() - QuicTime::Zero()).ToMicroseconds()); } -TEST_F(QuicEpollClockTest, CalibrateRealEpollClock) { - QuicEpollServer epoll_server; - - QuicEpollClock uncalibrated_clock(&epoll_server); - QuicEpollClock calibrated_clock(&epoll_server); - EXPECT_TRUE(calibrated_clock.ComputeCalibrationOffset().IsZero()); - - for (int i = 0; i < 100; ++i) { - QuicWallTime wallnow = uncalibrated_clock.WallNow(); - EXPECT_EQ(uncalibrated_clock.ConvertWallTimeToQuicTime(wallnow), - calibrated_clock.ConvertWallTimeToQuicTime(wallnow)); - } -} - -// ClockWithOffset is a clock whose offset(WallNow() - Now() at any instant) is -// given at construction time. -class ClockWithOffset : public QuicEpollClock { - public: - ClockWithOffset(QuicEpollServer* epoll_server, QuicTime::Delta offset) - : QuicEpollClock(epoll_server), offset_(offset) {} - - QuicTime Now() const override { return QuicEpollClock::Now() - offset_; } - - // QuicEpollClock disables ConvertWallTimeToQuicTime since it always have a - // zero offset. We need to re-enable it here in order to test the calibration - // and conversion code in QuicClock. - QuicTime ConvertWallTimeToQuicTime( - const QuicWallTime& walltime) const override { - return QuicClock::ConvertWallTimeToQuicTime(walltime); - } - - private: - QuicTime::Delta offset_; -}; - -TEST_F(QuicEpollClockTest, CalibrateClockWithOffset) { - QuicEpollServer epoll_server; - - for (const QuicTime::Delta& offset : {QuicTime::Delta::FromSeconds(5000), - QuicTime::Delta::FromSeconds(-8000)}) { - ClockWithOffset clock(&epoll_server, offset); - ASSERT_EQ(offset, clock.ComputeCalibrationOffset()) - << "offset (us): " << offset.ToMicroseconds(); - // Test fails without this. - clock.SetCalibrationOffset(offset); - - QuicWallTime last_walltime = clock.WallNow(); - QuicTime last_time = clock.ConvertWallTimeToQuicTime(last_walltime); - - for (int i = 0; i < 1e5; ++i) { - QuicWallTime wallnow = clock.WallNow(); - QuicTime now = clock.ConvertWallTimeToQuicTime(wallnow); - - if (wallnow.IsAfter(last_walltime)) { - ASSERT_LT(0, (now - last_time).ToMicroseconds()) - << "offset (us): " << offset.ToMicroseconds(); - - last_walltime = wallnow; - last_time = now; - } - } - } -} - TEST_F(QuicEpollClockTest, MonotonicityWithRealEpollClock) { QuicEpollServer epoll_server; QuicEpollClock clock(&epoll_server);