OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/congestion_control/rtt_stats.h" | 5 #include "net/quic/congestion_control/rtt_stats.h" |
6 | 6 |
7 #include <cstdlib> // std::abs | 7 #include <cstdlib> // std::abs |
8 | 8 |
9 #include "net/quic/quic_flags.h" | 9 #include "net/quic/quic_flags.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 QuicTime::Delta::FromMilliseconds(kMinRttWindowLengthMs), | 39 QuicTime::Delta::FromMilliseconds(kMinRttWindowLengthMs), |
40 QuicTime::Delta::Zero()) {} | 40 QuicTime::Delta::Zero()) {} |
41 | 41 |
42 void RttStats::SampleNewWindowedMinRtt(uint32_t num_samples) { | 42 void RttStats::SampleNewWindowedMinRtt(uint32_t num_samples) { |
43 num_samples_for_forced_min_ = num_samples; | 43 num_samples_for_forced_min_ = num_samples; |
44 forced_windowed_min_rtt_ = QuicTime::Delta::Zero(); | 44 forced_windowed_min_rtt_ = QuicTime::Delta::Zero(); |
45 forced_windowed_min_rtt_time_ = QuicTime::Zero(); | 45 forced_windowed_min_rtt_time_ = QuicTime::Zero(); |
46 } | 46 } |
47 | 47 |
48 void RttStats::ExpireSmoothedMetrics() { | 48 void RttStats::ExpireSmoothedMetrics() { |
49 mean_deviation_ = | 49 mean_deviation_ = max(mean_deviation_, |
50 max(mean_deviation_, | 50 QuicTime::Delta::FromMicroseconds(std::abs( |
51 QuicTime::Delta::FromMicroseconds( | 51 (smoothed_rtt_ - latest_rtt_).ToMicroseconds()))); |
52 std::abs(smoothed_rtt_.Subtract(latest_rtt_).ToMicroseconds()))); | |
53 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); | 52 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); |
54 } | 53 } |
55 | 54 |
56 // Updates the RTT based on a new sample. | 55 // Updates the RTT based on a new sample. |
57 void RttStats::UpdateRtt(QuicTime::Delta send_delta, | 56 void RttStats::UpdateRtt(QuicTime::Delta send_delta, |
58 QuicTime::Delta ack_delay, | 57 QuicTime::Delta ack_delay, |
59 QuicTime now) { | 58 QuicTime now) { |
60 if (send_delta.IsInfinite() || send_delta <= QuicTime::Delta::Zero()) { | 59 if (send_delta.IsInfinite() || send_delta <= QuicTime::Delta::Zero()) { |
61 LOG(WARNING) << "Ignoring measured send_delta, because it's is " | 60 LOG(WARNING) << "Ignoring measured send_delta, because it's is " |
62 << "either infinite, zero, or negative. send_delta = " | 61 << "either infinite, zero, or negative. send_delta = " |
(...skipping 10 matching lines...) Expand all Loading... |
73 } | 72 } |
74 UpdateWindowedMinRtt(send_delta, now); | 73 UpdateWindowedMinRtt(send_delta, now); |
75 | 74 |
76 // Correct for ack_delay if information received from the peer results in a | 75 // Correct for ack_delay if information received from the peer results in a |
77 // positive RTT sample. Otherwise, we use the send_delta as a reasonable | 76 // positive RTT sample. Otherwise, we use the send_delta as a reasonable |
78 // measure for smoothed_rtt. | 77 // measure for smoothed_rtt. |
79 QuicTime::Delta rtt_sample(send_delta); | 78 QuicTime::Delta rtt_sample(send_delta); |
80 previous_srtt_ = smoothed_rtt_; | 79 previous_srtt_ = smoothed_rtt_; |
81 | 80 |
82 if (rtt_sample > ack_delay) { | 81 if (rtt_sample > ack_delay) { |
83 rtt_sample = rtt_sample.Subtract(ack_delay); | 82 rtt_sample = rtt_sample - ack_delay; |
84 } | 83 } |
85 latest_rtt_ = rtt_sample; | 84 latest_rtt_ = rtt_sample; |
86 // First time call. | 85 // First time call. |
87 if (smoothed_rtt_.IsZero()) { | 86 if (smoothed_rtt_.IsZero()) { |
88 smoothed_rtt_ = rtt_sample; | 87 smoothed_rtt_ = rtt_sample; |
89 mean_deviation_ = | 88 mean_deviation_ = |
90 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); | 89 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); |
91 } else { | 90 } else { |
92 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( | 91 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( |
93 kOneMinusBeta * mean_deviation_.ToMicroseconds() + | 92 kOneMinusBeta * mean_deviation_.ToMicroseconds() + |
94 kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds()))); | 93 kBeta * std::abs((smoothed_rtt_ - rtt_sample).ToMicroseconds()))); |
95 smoothed_rtt_ = | 94 smoothed_rtt_ = kOneMinusAlpha * smoothed_rtt_ + kAlpha * rtt_sample; |
96 smoothed_rtt_.Multiply(kOneMinusAlpha).Add(rtt_sample.Multiply(kAlpha)); | |
97 DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() | 95 DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() |
98 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); | 96 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); |
99 } | 97 } |
100 } | 98 } |
101 | 99 |
102 void RttStats::UpdateWindowedMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { | 100 void RttStats::UpdateWindowedMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { |
103 // Update windowed_min_rtt. | 101 // Update windowed_min_rtt. |
104 windowed_min_rtt_.Update(rtt_sample, now); | 102 windowed_min_rtt_.Update(rtt_sample, now); |
105 if (num_samples_for_forced_min_ <= 0) { | 103 if (num_samples_for_forced_min_ <= 0) { |
106 return; | 104 return; |
(...skipping 15 matching lines...) Expand all Loading... |
122 latest_rtt_ = QuicTime::Delta::Zero(); | 120 latest_rtt_ = QuicTime::Delta::Zero(); |
123 min_rtt_ = QuicTime::Delta::Zero(); | 121 min_rtt_ = QuicTime::Delta::Zero(); |
124 smoothed_rtt_ = QuicTime::Delta::Zero(); | 122 smoothed_rtt_ = QuicTime::Delta::Zero(); |
125 mean_deviation_ = QuicTime::Delta::Zero(); | 123 mean_deviation_ = QuicTime::Delta::Zero(); |
126 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; | 124 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; |
127 num_samples_for_forced_min_ = 0; | 125 num_samples_for_forced_min_ = 0; |
128 windowed_min_rtt_.Reset(QuicTime::Delta::Zero(), QuicTime::Zero()); | 126 windowed_min_rtt_.Reset(QuicTime::Delta::Zero(), QuicTime::Zero()); |
129 } | 127 } |
130 | 128 |
131 } // namespace net | 129 } // namespace net |
OLD | NEW |