OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_bytes.h" | 5 #include "net/quic/congestion_control/cubic_bytes.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 QuicByteCount CubicBytes::CongestionWindowAfterAck( | 106 QuicByteCount CubicBytes::CongestionWindowAfterAck( |
107 QuicByteCount acked_bytes, | 107 QuicByteCount acked_bytes, |
108 QuicByteCount current_congestion_window, | 108 QuicByteCount current_congestion_window, |
109 QuicTime::Delta delay_min) { | 109 QuicTime::Delta delay_min) { |
110 acked_bytes_count_ += acked_bytes; | 110 acked_bytes_count_ += acked_bytes; |
111 QuicTime current_time = clock_->ApproximateNow(); | 111 QuicTime current_time = clock_->ApproximateNow(); |
112 | 112 |
113 // Cubic is "independent" of RTT, the update is limited by the time elapsed. | 113 // Cubic is "independent" of RTT, the update is limited by the time elapsed. |
114 if (last_congestion_window_ == current_congestion_window && | 114 if (last_congestion_window_ == current_congestion_window && |
115 (current_time.Subtract(last_update_time_) <= MaxCubicTimeInterval())) { | 115 (current_time - last_update_time_ <= MaxCubicTimeInterval())) { |
116 return max(last_target_congestion_window_, | 116 return max(last_target_congestion_window_, |
117 estimated_tcp_congestion_window_); | 117 estimated_tcp_congestion_window_); |
118 } | 118 } |
119 last_congestion_window_ = current_congestion_window; | 119 last_congestion_window_ = current_congestion_window; |
120 last_update_time_ = current_time; | 120 last_update_time_ = current_time; |
121 | 121 |
122 if (!epoch_.IsInitialized()) { | 122 if (!epoch_.IsInitialized()) { |
123 // First ACK after a loss event. | 123 // First ACK after a loss event. |
124 DVLOG(1) << "Start of epoch"; | 124 DVLOG(1) << "Start of epoch"; |
125 epoch_ = current_time; // Start of epoch. | 125 epoch_ = current_time; // Start of epoch. |
126 acked_bytes_count_ = acked_bytes; // Reset count. | 126 acked_bytes_count_ = acked_bytes; // Reset count. |
127 // Reset estimated_tcp_congestion_window_ to be in sync with cubic. | 127 // Reset estimated_tcp_congestion_window_ to be in sync with cubic. |
128 estimated_tcp_congestion_window_ = current_congestion_window; | 128 estimated_tcp_congestion_window_ = current_congestion_window; |
129 if (last_max_congestion_window_ <= current_congestion_window) { | 129 if (last_max_congestion_window_ <= current_congestion_window) { |
130 time_to_origin_point_ = 0; | 130 time_to_origin_point_ = 0; |
131 origin_point_congestion_window_ = current_congestion_window; | 131 origin_point_congestion_window_ = current_congestion_window; |
132 } else { | 132 } else { |
133 time_to_origin_point_ = static_cast<uint32_t>( | 133 time_to_origin_point_ = static_cast<uint32_t>( |
134 cbrt(kCubeFactor * | 134 cbrt(kCubeFactor * |
135 (last_max_congestion_window_ - current_congestion_window))); | 135 (last_max_congestion_window_ - current_congestion_window))); |
136 origin_point_congestion_window_ = last_max_congestion_window_; | 136 origin_point_congestion_window_ = last_max_congestion_window_; |
137 } | 137 } |
138 } | 138 } |
139 // Change the time unit from microseconds to 2^10 fractions per second. Take | 139 // Change the time unit from microseconds to 2^10 fractions per second. Take |
140 // the round trip time in account. This is done to allow us to use shift as a | 140 // the round trip time in account. This is done to allow us to use shift as a |
141 // divide operator. | 141 // divide operator. |
142 int64_t elapsed_time = | 142 int64_t elapsed_time = |
143 (current_time.Add(delay_min).Subtract(epoch_).ToMicroseconds() << 10) / | 143 ((current_time + delay_min - epoch_).ToMicroseconds() << 10) / |
144 kNumMicrosPerSecond; | 144 kNumMicrosPerSecond; |
145 | 145 |
146 int64_t offset = time_to_origin_point_ - elapsed_time; | 146 int64_t offset = time_to_origin_point_ - elapsed_time; |
147 QuicByteCount delta_congestion_window = | 147 QuicByteCount delta_congestion_window = |
148 ((kCubeCongestionWindowScale * offset * offset * offset) >> kCubeScale) * | 148 ((kCubeCongestionWindowScale * offset * offset * offset) >> kCubeScale) * |
149 kDefaultTCPMSS; | 149 kDefaultTCPMSS; |
150 | 150 |
151 QuicByteCount target_congestion_window = | 151 QuicByteCount target_congestion_window = |
152 origin_point_congestion_window_ - delta_congestion_window; | 152 origin_point_congestion_window_ - delta_congestion_window; |
153 | 153 |
(...skipping 12 matching lines...) Expand all Loading... |
166 // congestion_window, use highest (fastest). | 166 // congestion_window, use highest (fastest). |
167 if (target_congestion_window < estimated_tcp_congestion_window_) { | 167 if (target_congestion_window < estimated_tcp_congestion_window_) { |
168 target_congestion_window = estimated_tcp_congestion_window_; | 168 target_congestion_window = estimated_tcp_congestion_window_; |
169 } | 169 } |
170 | 170 |
171 DVLOG(1) << "Final target congestion_window: " << target_congestion_window; | 171 DVLOG(1) << "Final target congestion_window: " << target_congestion_window; |
172 return target_congestion_window; | 172 return target_congestion_window; |
173 } | 173 } |
174 | 174 |
175 } // namespace net | 175 } // namespace net |
OLD | NEW |