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