summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport/tcp/snd.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2018-09-04 12:38:31 -0700
committerShentubot <shentubot@google.com>2018-09-04 12:39:47 -0700
commit3794cb6bff094820d78bc3199dc6910af3d194c0 (patch)
tree0a411818ffc54bc18250917b3a22131abe7aa9f0 /pkg/tcpip/transport/tcp/snd.go
parentc09f9acd7c7a2e85472b1ee47bf26f7c89ded43e (diff)
Expose TCP RTT
PiperOrigin-RevId: 211504634 Change-Id: I9a7bcbbdd40e5036894930f709278725ef477293
Diffstat (limited to 'pkg/tcpip/transport/tcp/snd.go')
-rw-r--r--pkg/tcpip/transport/tcp/snd.go35
1 files changed, 24 insertions, 11 deletions
diff --git a/pkg/tcpip/transport/tcp/snd.go b/pkg/tcpip/transport/tcp/snd.go
index 568bd7024..096ea9cd4 100644
--- a/pkg/tcpip/transport/tcp/snd.go
+++ b/pkg/tcpip/transport/tcp/snd.go
@@ -16,6 +16,7 @@ package tcp
import (
"math"
+ "sync"
"time"
"gvisor.googlesource.com/gvisor/pkg/sleep"
@@ -116,11 +117,10 @@ type sender struct {
resendTimer timer `state:"nosave"`
resendWaker sleep.Waker `state:"nosave"`
- // srtt, rttvar & rto are the "smoothed round-trip time", "round-trip
- // time variation" and "retransmit timeout", as defined in section 2 of
- // RFC 6298.
- srtt time.Duration
- rttvar time.Duration
+ // rtt.srtt, rtt.rttvar, and rto are the "smoothed round-trip time",
+ // "round-trip time variation" and "retransmit timeout", as defined in
+ // section 2 of RFC 6298.
+ rtt rtt
rto time.Duration
srttInited bool
@@ -139,6 +139,17 @@ type sender struct {
cc congestionControl
}
+// rtt is a synchronization wrapper used to appease stateify. See the comment
+// in sender, where it is used.
+//
+// +stateify savable
+type rtt struct {
+ sync.Mutex `state:"nosave"`
+
+ srtt time.Duration
+ rttvar time.Duration
+}
+
// fastRecovery holds information related to fast recovery from a packet loss.
//
// +stateify savable
@@ -265,20 +276,22 @@ func (s *sender) sendAck() {
// updateRTO updates the retransmit timeout when a new roud-trip time is
// available. This is done in accordance with section 2 of RFC 6298.
func (s *sender) updateRTO(rtt time.Duration) {
+ s.rtt.Lock()
if !s.srttInited {
- s.rttvar = rtt / 2
- s.srtt = rtt
+ s.rtt.rttvar = rtt / 2
+ s.rtt.srtt = rtt
s.srttInited = true
} else {
- diff := s.srtt - rtt
+ diff := s.rtt.srtt - rtt
if diff < 0 {
diff = -diff
}
- s.rttvar = (3*s.rttvar + diff) / 4
- s.srtt = (7*s.srtt + rtt) / 8
+ s.rtt.rttvar = (3*s.rtt.rttvar + diff) / 4
+ s.rtt.srtt = (7*s.rtt.srtt + rtt) / 8
}
- s.rto = s.srtt + 4*s.rttvar
+ s.rto = s.rtt.srtt + 4*s.rtt.rttvar
+ s.rtt.Unlock()
if s.rto < minRTO {
s.rto = minRTO
}