OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cubic.h" | 5 #include "net/quic/congestion_control/cubic.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "net/quic/congestion_control/cube_root.h" | 12 #include "net/quic/congestion_control/cube_root.h" |
| 13 #include "net/quic/quic_flags.h" |
13 #include "net/quic/quic_protocol.h" | 14 #include "net/quic/quic_protocol.h" |
14 | 15 |
15 using std::max; | 16 using std::max; |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Constants based on TCP defaults. | 22 // Constants based on TCP defaults. |
22 // The following constants are in 2^10 fractions of a second instead of ms to | 23 // The following constants are in 2^10 fractions of a second instead of ms to |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 last_max_congestion_window_ = 0; | 74 last_max_congestion_window_ = 0; |
74 acked_packets_count_ = 0; | 75 acked_packets_count_ = 0; |
75 estimated_tcp_congestion_window_ = 0; | 76 estimated_tcp_congestion_window_ = 0; |
76 origin_point_congestion_window_ = 0; | 77 origin_point_congestion_window_ = 0; |
77 time_to_origin_point_ = 0; | 78 time_to_origin_point_ = 0; |
78 last_target_congestion_window_ = 0; | 79 last_target_congestion_window_ = 0; |
79 } | 80 } |
80 | 81 |
81 void Cubic::UpdateCongestionControlStats(QuicPacketCount new_cubic_mode_cwnd, | 82 void Cubic::UpdateCongestionControlStats(QuicPacketCount new_cubic_mode_cwnd, |
82 QuicPacketCount new_reno_mode_cwnd) { | 83 QuicPacketCount new_reno_mode_cwnd) { |
83 | |
84 QuicPacketCount highest_new_cwnd = max(new_cubic_mode_cwnd, | 84 QuicPacketCount highest_new_cwnd = max(new_cubic_mode_cwnd, |
85 new_reno_mode_cwnd); | 85 new_reno_mode_cwnd); |
86 if (last_congestion_window_ < highest_new_cwnd) { | 86 if (last_congestion_window_ < highest_new_cwnd) { |
87 // cwnd will increase to highest_new_cwnd. | 87 // cwnd will increase to highest_new_cwnd. |
88 stats_->cwnd_increase_congestion_avoidance += | 88 stats_->cwnd_increase_congestion_avoidance += |
89 highest_new_cwnd - last_congestion_window_; | 89 highest_new_cwnd - last_congestion_window_; |
90 if (new_cubic_mode_cwnd > new_reno_mode_cwnd) { | 90 if (new_cubic_mode_cwnd > new_reno_mode_cwnd) { |
91 // This cwnd increase is due to cubic mode. | 91 // This cwnd increase is due to cubic mode. |
92 stats_->cwnd_increase_cubic_mode += | 92 stats_->cwnd_increase_cubic_mode += |
93 new_cubic_mode_cwnd - last_congestion_window_; | 93 new_cubic_mode_cwnd - last_congestion_window_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // First ACK after a loss event. | 128 // First ACK after a loss event. |
129 DVLOG(1) << "Start of epoch"; | 129 DVLOG(1) << "Start of epoch"; |
130 epoch_ = current_time; // Start of epoch. | 130 epoch_ = current_time; // Start of epoch. |
131 acked_packets_count_ = 1; // Reset count. | 131 acked_packets_count_ = 1; // Reset count. |
132 // Reset estimated_tcp_congestion_window_ to be in sync with cubic. | 132 // Reset estimated_tcp_congestion_window_ to be in sync with cubic. |
133 estimated_tcp_congestion_window_ = current_congestion_window; | 133 estimated_tcp_congestion_window_ = current_congestion_window; |
134 if (last_max_congestion_window_ <= current_congestion_window) { | 134 if (last_max_congestion_window_ <= current_congestion_window) { |
135 time_to_origin_point_ = 0; | 135 time_to_origin_point_ = 0; |
136 origin_point_congestion_window_ = current_congestion_window; | 136 origin_point_congestion_window_ = current_congestion_window; |
137 } else { | 137 } else { |
138 time_to_origin_point_ = CubeRoot::Root(kCubeFactor * | 138 if (FLAGS_quic_use_std_cbrt) { |
139 (last_max_congestion_window_ - current_congestion_window)); | 139 time_to_origin_point_ = |
| 140 std::cbrt(kCubeFactor * (last_max_congestion_window_ - |
| 141 current_congestion_window)); |
| 142 } else { |
| 143 // TODO(rjshade): Remove CubeRoot source when removing |
| 144 // FLAGS_quic_use_std_cbrt. |
| 145 time_to_origin_point_ = |
| 146 CubeRoot::Root(kCubeFactor * (last_max_congestion_window_ - |
| 147 current_congestion_window)); |
| 148 } |
140 origin_point_congestion_window_ = | 149 origin_point_congestion_window_ = |
141 last_max_congestion_window_; | 150 last_max_congestion_window_; |
142 } | 151 } |
143 } | 152 } |
144 // Change the time unit from microseconds to 2^10 fractions per second. Take | 153 // Change the time unit from microseconds to 2^10 fractions per second. Take |
145 // the round trip time in account. This is done to allow us to use shift as a | 154 // the round trip time in account. This is done to allow us to use shift as a |
146 // divide operator. | 155 // divide operator. |
147 int64 elapsed_time = | 156 int64 elapsed_time = |
148 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / | 157 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / |
149 base::Time::kMicrosecondsPerSecond; | 158 base::Time::kMicrosecondsPerSecond; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // congestion_window, use highest (fastest). | 190 // congestion_window, use highest (fastest). |
182 if (target_congestion_window < estimated_tcp_congestion_window_) { | 191 if (target_congestion_window < estimated_tcp_congestion_window_) { |
183 target_congestion_window = estimated_tcp_congestion_window_; | 192 target_congestion_window = estimated_tcp_congestion_window_; |
184 } | 193 } |
185 | 194 |
186 DVLOG(1) << "Target congestion_window: " << target_congestion_window; | 195 DVLOG(1) << "Target congestion_window: " << target_congestion_window; |
187 return target_congestion_window; | 196 return target_congestion_window; |
188 } | 197 } |
189 | 198 |
190 } // namespace net | 199 } // namespace net |
OLD | NEW |