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 19 matching lines...) Expand all Loading... |
30 min_rtt_(QuicTime::Delta::Zero()), | 30 min_rtt_(QuicTime::Delta::Zero()), |
31 smoothed_rtt_(QuicTime::Delta::Zero()), | 31 smoothed_rtt_(QuicTime::Delta::Zero()), |
32 previous_srtt_(QuicTime::Delta::Zero()), | 32 previous_srtt_(QuicTime::Delta::Zero()), |
33 mean_deviation_(QuicTime::Delta::Zero()), | 33 mean_deviation_(QuicTime::Delta::Zero()), |
34 initial_rtt_us_(kInitialRttMs * kNumMicrosPerMilli), | 34 initial_rtt_us_(kInitialRttMs * kNumMicrosPerMilli), |
35 forced_windowed_min_rtt_(QuicTime::Delta::Zero()), | 35 forced_windowed_min_rtt_(QuicTime::Delta::Zero()), |
36 forced_windowed_min_rtt_time_(QuicTime::Zero()), | 36 forced_windowed_min_rtt_time_(QuicTime::Zero()), |
37 num_samples_for_forced_min_(0), | 37 num_samples_for_forced_min_(0), |
38 windowed_min_rtt_( | 38 windowed_min_rtt_( |
39 QuicTime::Delta::FromMilliseconds(kMinRttWindowLengthMs), | 39 QuicTime::Delta::FromMilliseconds(kMinRttWindowLengthMs), |
40 QuicTime::Delta::Zero()) {} | 40 QuicTime::Delta::Zero(), |
| 41 QuicTime::Zero()) {} |
41 | 42 |
42 void RttStats::SampleNewWindowedMinRtt(uint32_t num_samples) { | 43 void RttStats::SampleNewWindowedMinRtt(uint32_t num_samples) { |
43 num_samples_for_forced_min_ = num_samples; | 44 num_samples_for_forced_min_ = num_samples; |
44 forced_windowed_min_rtt_ = QuicTime::Delta::Zero(); | 45 forced_windowed_min_rtt_ = QuicTime::Delta::Zero(); |
45 forced_windowed_min_rtt_time_ = QuicTime::Zero(); | 46 forced_windowed_min_rtt_time_ = QuicTime::Zero(); |
46 } | 47 } |
47 | 48 |
48 void RttStats::ExpireSmoothedMetrics() { | 49 void RttStats::ExpireSmoothedMetrics() { |
49 mean_deviation_ = | 50 mean_deviation_ = max(mean_deviation_, |
50 max(mean_deviation_, | 51 QuicTime::Delta::FromMicroseconds(std::abs( |
51 QuicTime::Delta::FromMicroseconds( | 52 (smoothed_rtt_ - latest_rtt_).ToMicroseconds()))); |
52 std::abs(smoothed_rtt_.Subtract(latest_rtt_).ToMicroseconds()))); | |
53 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); | 53 smoothed_rtt_ = max(smoothed_rtt_, latest_rtt_); |
54 } | 54 } |
55 | 55 |
56 // Updates the RTT based on a new sample. | 56 // Updates the RTT based on a new sample. |
57 void RttStats::UpdateRtt(QuicTime::Delta send_delta, | 57 void RttStats::UpdateRtt(QuicTime::Delta send_delta, |
58 QuicTime::Delta ack_delay, | 58 QuicTime::Delta ack_delay, |
59 QuicTime now) { | 59 QuicTime now) { |
60 if (send_delta.IsInfinite() || send_delta <= QuicTime::Delta::Zero()) { | 60 if (send_delta.IsInfinite() || send_delta <= QuicTime::Delta::Zero()) { |
61 LOG(WARNING) << "Ignoring measured send_delta, because it's is " | 61 LOG(WARNING) << "Ignoring measured send_delta, because it's is " |
62 << "either infinite, zero, or negative. send_delta = " | 62 << "either infinite, zero, or negative. send_delta = " |
(...skipping 10 matching lines...) Expand all Loading... |
73 } | 73 } |
74 UpdateWindowedMinRtt(send_delta, now); | 74 UpdateWindowedMinRtt(send_delta, now); |
75 | 75 |
76 // Correct for ack_delay if information received from the peer results in a | 76 // 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 | 77 // positive RTT sample. Otherwise, we use the send_delta as a reasonable |
78 // measure for smoothed_rtt. | 78 // measure for smoothed_rtt. |
79 QuicTime::Delta rtt_sample(send_delta); | 79 QuicTime::Delta rtt_sample(send_delta); |
80 previous_srtt_ = smoothed_rtt_; | 80 previous_srtt_ = smoothed_rtt_; |
81 | 81 |
82 if (rtt_sample > ack_delay) { | 82 if (rtt_sample > ack_delay) { |
83 rtt_sample = rtt_sample.Subtract(ack_delay); | 83 rtt_sample = rtt_sample - ack_delay; |
84 } | 84 } |
85 latest_rtt_ = rtt_sample; | 85 latest_rtt_ = rtt_sample; |
86 // First time call. | 86 // First time call. |
87 if (smoothed_rtt_.IsZero()) { | 87 if (smoothed_rtt_.IsZero()) { |
88 smoothed_rtt_ = rtt_sample; | 88 smoothed_rtt_ = rtt_sample; |
89 mean_deviation_ = | 89 mean_deviation_ = |
90 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); | 90 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2); |
91 } else { | 91 } else { |
92 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( | 92 mean_deviation_ = QuicTime::Delta::FromMicroseconds(static_cast<int64_t>( |
93 kOneMinusBeta * mean_deviation_.ToMicroseconds() + | 93 kOneMinusBeta * mean_deviation_.ToMicroseconds() + |
94 kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds()))); | 94 kBeta * std::abs((smoothed_rtt_ - rtt_sample).ToMicroseconds()))); |
95 smoothed_rtt_ = | 95 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() | 96 DVLOG(1) << " smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() |
98 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); | 97 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 void RttStats::UpdateWindowedMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { | 101 void RttStats::UpdateWindowedMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { |
103 // Update windowed_min_rtt. | 102 // Update windowed_min_rtt. |
104 windowed_min_rtt_.Update(rtt_sample, now); | 103 windowed_min_rtt_.Update(rtt_sample, now); |
105 if (num_samples_for_forced_min_ <= 0) { | 104 if (num_samples_for_forced_min_ <= 0) { |
106 return; | 105 return; |
(...skipping 15 matching lines...) Expand all Loading... |
122 latest_rtt_ = QuicTime::Delta::Zero(); | 121 latest_rtt_ = QuicTime::Delta::Zero(); |
123 min_rtt_ = QuicTime::Delta::Zero(); | 122 min_rtt_ = QuicTime::Delta::Zero(); |
124 smoothed_rtt_ = QuicTime::Delta::Zero(); | 123 smoothed_rtt_ = QuicTime::Delta::Zero(); |
125 mean_deviation_ = QuicTime::Delta::Zero(); | 124 mean_deviation_ = QuicTime::Delta::Zero(); |
126 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; | 125 initial_rtt_us_ = kInitialRttMs * kNumMicrosPerMilli; |
127 num_samples_for_forced_min_ = 0; | 126 num_samples_for_forced_min_ = 0; |
128 windowed_min_rtt_.Reset(QuicTime::Delta::Zero(), QuicTime::Zero()); | 127 windowed_min_rtt_.Reset(QuicTime::Delta::Zero(), QuicTime::Zero()); |
129 } | 128 } |
130 | 129 |
131 } // namespace net | 130 } // namespace net |
OLD | NEW |