Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: net/quic/congestion_control/rtt_stats.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 namespace net { 7 namespace net {
8 8
9 namespace { 9 namespace {
10 10
11 // Default initial rtt used before any samples are received. 11 // Default initial rtt used before any samples are received.
12 const int kInitialRttMs = 100; 12 const int kInitialRttMs = 100;
13 const float kAlpha = 0.125f; 13 const float kAlpha = 0.125f;
14 const float kOneMinusAlpha = (1 - kAlpha); 14 const float kOneMinusAlpha = (1 - kAlpha);
15 const float kBeta = 0.25f; 15 const float kBeta = 0.25f;
16 const float kOneMinusBeta = (1 - kBeta); 16 const float kOneMinusBeta = (1 - kBeta);
17 const float kHalfWindow = 0.5f; 17 const float kHalfWindow = 0.5f;
18 const float kQuarterWindow = 0.25f; 18 const float kQuarterWindow = 0.25f;
19 19
20 } // namespace 20 } // namespace
21 21
22 RttStats::RttStats() 22 RttStats::RttStats()
23 : latest_rtt_(QuicTime::Delta::Zero()), 23 : latest_rtt_(QuicTime::Delta::Zero()),
24 min_rtt_(QuicTime::Delta::Zero()), 24 min_rtt_(QuicTime::Delta::Zero()),
25 smoothed_rtt_(QuicTime::Delta::Zero()), 25 smoothed_rtt_(QuicTime::Delta::Zero()),
26 mean_deviation_(QuicTime::Delta::Zero()), 26 mean_deviation_(QuicTime::Delta::Zero()),
27 initial_rtt_us_(kInitialRttMs * base::Time::kMicrosecondsPerMillisecond), 27 initial_rtt_us_(kInitialRttMs * base::Time::kMicrosecondsPerMillisecond),
28 num_min_rtt_samples_remaining_(0), 28 num_min_rtt_samples_remaining_(0),
29 recent_min_rtt_window_(QuicTime::Delta::Zero()) { } 29 recent_min_rtt_window_(QuicTime::Delta::Zero()) {
30 }
30 31
31 bool RttStats::HasUpdates() const { 32 bool RttStats::HasUpdates() const {
32 return !smoothed_rtt_.IsZero(); 33 return !smoothed_rtt_.IsZero();
33 } 34 }
34 35
35 void RttStats::SampleNewRecentMinRtt(uint32 num_samples) { 36 void RttStats::SampleNewRecentMinRtt(uint32 num_samples) {
36 num_min_rtt_samples_remaining_ = num_samples; 37 num_min_rtt_samples_remaining_ = num_samples;
37 new_min_rtt_ = RttSample(); 38 new_min_rtt_ = RttSample();
38 } 39 }
39 40
(...skipping 21 matching lines...) Expand all
61 62
62 latest_rtt_ = rtt_sample; 63 latest_rtt_ = rtt_sample;
63 // First time call or link delay decreases. 64 // First time call or link delay decreases.
64 if (min_rtt_.IsZero() || min_rtt_ > rtt_sample) { 65 if (min_rtt_.IsZero() || min_rtt_ > rtt_sample) {
65 min_rtt_ = rtt_sample; 66 min_rtt_ = rtt_sample;
66 } 67 }
67 UpdateRecentMinRtt(rtt_sample, now); 68 UpdateRecentMinRtt(rtt_sample, now);
68 // First time call. 69 // First time call.
69 if (!HasUpdates()) { 70 if (!HasUpdates()) {
70 smoothed_rtt_ = rtt_sample; 71 smoothed_rtt_ = rtt_sample;
71 mean_deviation_ = QuicTime::Delta::FromMicroseconds( 72 mean_deviation_ =
72 rtt_sample.ToMicroseconds() / 2); 73 QuicTime::Delta::FromMicroseconds(rtt_sample.ToMicroseconds() / 2);
73 } else { 74 } else {
74 mean_deviation_ = QuicTime::Delta::FromMicroseconds( 75 mean_deviation_ = QuicTime::Delta::FromMicroseconds(
75 kOneMinusBeta * mean_deviation_.ToMicroseconds() + 76 kOneMinusBeta * mean_deviation_.ToMicroseconds() +
76 kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds())); 77 kBeta * std::abs(smoothed_rtt_.Subtract(rtt_sample).ToMicroseconds()));
77 smoothed_rtt_ = smoothed_rtt_.Multiply(kOneMinusAlpha).Add( 78 smoothed_rtt_ =
78 rtt_sample.Multiply(kAlpha)); 79 smoothed_rtt_.Multiply(kOneMinusAlpha).Add(rtt_sample.Multiply(kAlpha));
79 DVLOG(1) << "Cubic; smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds() 80 DVLOG(1) << "Cubic; smoothed_rtt(us):" << smoothed_rtt_.ToMicroseconds()
80 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds(); 81 << " mean_deviation(us):" << mean_deviation_.ToMicroseconds();
81 } 82 }
82 } 83 }
83 84
84 void RttStats::UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now) { 85 void RttStats::UpdateRecentMinRtt(QuicTime::Delta rtt_sample, QuicTime now) {
85 // Recent min_rtt update. 86 // Recent min_rtt update.
86 if (num_min_rtt_samples_remaining_ > 0) { 87 if (num_min_rtt_samples_remaining_ > 0) {
87 --num_min_rtt_samples_remaining_; 88 --num_min_rtt_samples_remaining_;
88 if (new_min_rtt_.rtt.IsZero() || rtt_sample <= new_min_rtt_.rtt) { 89 if (new_min_rtt_.rtt.IsZero() || rtt_sample <= new_min_rtt_.rtt) {
(...skipping 14 matching lines...) Expand all
103 } else if (rtt_sample <= quarter_window_rtt_.rtt) { 104 } else if (rtt_sample <= quarter_window_rtt_.rtt) {
104 quarter_window_rtt_ = RttSample(rtt_sample, now); 105 quarter_window_rtt_ = RttSample(rtt_sample, now);
105 } 106 }
106 107
107 // Expire old min rtt samples. 108 // Expire old min rtt samples.
108 if (recent_min_rtt_.time < now.Subtract(recent_min_rtt_window_)) { 109 if (recent_min_rtt_.time < now.Subtract(recent_min_rtt_window_)) {
109 recent_min_rtt_ = half_window_rtt_; 110 recent_min_rtt_ = half_window_rtt_;
110 half_window_rtt_ = quarter_window_rtt_; 111 half_window_rtt_ = quarter_window_rtt_;
111 quarter_window_rtt_ = RttSample(rtt_sample, now); 112 quarter_window_rtt_ = RttSample(rtt_sample, now);
112 } else if (half_window_rtt_.time < 113 } else if (half_window_rtt_.time <
113 now.Subtract(recent_min_rtt_window_.Multiply(kHalfWindow))) { 114 now.Subtract(recent_min_rtt_window_.Multiply(kHalfWindow))) {
114 half_window_rtt_ = quarter_window_rtt_; 115 half_window_rtt_ = quarter_window_rtt_;
115 quarter_window_rtt_ = RttSample(rtt_sample, now); 116 quarter_window_rtt_ = RttSample(rtt_sample, now);
116 } else if (quarter_window_rtt_.time < 117 } else if (quarter_window_rtt_.time <
117 now.Subtract(recent_min_rtt_window_.Multiply(kQuarterWindow))) { 118 now.Subtract(recent_min_rtt_window_.Multiply(kQuarterWindow))) {
118 quarter_window_rtt_ = RttSample(rtt_sample, now); 119 quarter_window_rtt_ = RttSample(rtt_sample, now);
119 } 120 }
120 } 121 }
121 122
122 QuicTime::Delta RttStats::SmoothedRtt() const { 123 QuicTime::Delta RttStats::SmoothedRtt() const {
123 if (!HasUpdates()) { 124 if (!HasUpdates()) {
124 return QuicTime::Delta::FromMicroseconds(initial_rtt_us_); 125 return QuicTime::Delta::FromMicroseconds(initial_rtt_us_);
125 } 126 }
126 return smoothed_rtt_; 127 return smoothed_rtt_;
127 } 128 }
128 129
129 } // namespace net 130 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698