GRPC C++  1.26.0
buffer_list.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_IOMGR_BUFFER_LIST_H
20 #define GRPC_CORE_LIB_IOMGR_BUFFER_LIST_H
21 
23 
25 
26 #include <grpc/support/time.h>
27 
32 
33 namespace grpc_core {
34 
36  /* Delivery rate in Bytes/s. */
38  /* If the delivery rate is limited by the application, this is set to true. */
40  /* Total packets retransmitted. */
42  /* Total packets retransmitted spuriously. This metric is smaller than or
43  equal to packet_retx. */
45  /* Total packets sent. */
47  /* Total packets delivered. */
49  /* Total packets delivered with ECE marked. This metric is smaller than or
50  equal to packet_delivered. */
52  /* Total bytes lost so far. */
54  /* Total bytes sent so far. */
56  /* Total bytes in write queue but not sent. */
58  /* Pacing rate of the connection in Bps */
60  /* Minimum RTT observed in usec. */
62  /* Smoothed RTT in usec */
64  /* Send congestion window. */
66  /* Slow start threshold in packets. */
68  /* Maximum degree of reordering (i.e., maximum number of packets reodered)
69  on the connection. */
71  /* Represents the number of recurring retransmissions of the first sequence
72  that is not acknowledged yet. */
74  /* The cumulative time (in usec) that the transport protocol was busy
75  sending data. */
77  /* The cumulative time (in usec) that the transport protocol was limited by
78  the receive window size. */
80  /* The cumulative time (in usec) that the transport protocol was limited by
81  the send buffer size. */
83 };
84 
85 struct Timestamp {
87  ConnectionMetrics metrics; /* Metrics collected with this timestamp */
88 };
89 
90 struct Timestamps {
95 
96  uint32_t byte_offset; /* byte offset relative to the start of the RPC */
97 
98 #ifdef GRPC_LINUX_ERRQUEUE
99  grpc_core::tcp_info info; /* tcp_info collected on sendmsg */
100 #endif /* GRPC_LINUX_ERRQUEUE */
101 };
102 
114 #ifdef GRPC_LINUX_ERRQUEUE
115 class TracedBuffer {
116  public:
118  TracedBuffer(uint32_t seq_no, void* arg)
119  : seq_no_(seq_no), arg_(arg), next_(nullptr) {}
120 
123  static void AddNewEntry(grpc_core::TracedBuffer** head, uint32_t seq_no,
124  int fd, void* arg);
125 
129  static void ProcessTimestamp(grpc_core::TracedBuffer** head,
130  struct sock_extended_err* serr,
131  struct cmsghdr* opt_stats,
132  struct scm_timestamping* tss);
133 
136  static void Shutdown(grpc_core::TracedBuffer** head, void* remaining,
137  grpc_error* shutdown_err);
138 
139  private:
140  uint32_t seq_no_; /* The sequence number for the last byte in the buffer */
141  void* arg_; /* The arg to pass to timestamps_callback */
142  grpc_core::Timestamps ts_; /* The timestamps corresponding to this buffer */
143  grpc_core::TracedBuffer* next_; /* The next TracedBuffer in the list */
144 };
145 #else /* GRPC_LINUX_ERRQUEUE */
147  public:
148  /* Dummy shutdown function */
149  static void Shutdown(grpc_core::TracedBuffer** /*head*/, void* /*remaining*/,
150  grpc_error* shutdown_err) {
151  GRPC_ERROR_UNREF(shutdown_err);
152  }
153 };
154 #endif /* GRPC_LINUX_ERRQUEUE */
155 
158 void grpc_tcp_set_write_timestamps_callback(void (*fn)(void*,
160  grpc_error* error));
161 
162 } /* namespace grpc_core */
163 
164 #endif /* GRPC_CORE_LIB_IOMGR_BUFFER_LIST_H */
Timestamp acked_time
Definition: buffer_list.h:94
Optional< uint64_t > busy_usec
Definition: buffer_list.h:76
Optional< uint32_t > srtt
Definition: buffer_list.h:63
uint32_t byte_offset
Definition: buffer_list.h:96
void grpc_tcp_set_write_timestamps_callback(void(*fn)(void *, grpc_core::Timestamps *, grpc_error *error))
Sets the callback function to call when timestamps for a write are collected.
Optional< uint64_t > data_notsent
Definition: buffer_list.h:57
Optional< uint32_t > packet_delivered
Definition: buffer_list.h:48
Optional< uint32_t > packet_delivered_ce
Definition: buffer_list.h:51
Definition: error_internal.h:39
Optional< uint32_t > reordering
Definition: buffer_list.h:70
Optional< uint32_t > snd_ssthresh
Definition: buffer_list.h:67
gpr_timespec time
Definition: buffer_list.h:86
Optional< uint32_t > congestion_window
Definition: buffer_list.h:65
Internal thread interface.
Definition: backoff.h:26
Timestamp sendmsg_time
Definition: buffer_list.h:91
Optional< bool > is_delivery_rate_app_limited
Definition: buffer_list.h:39
Optional< uint64_t > pacing_rate
Definition: buffer_list.h:59
Optional< uint8_t > recurring_retrans
Definition: buffer_list.h:73
Timestamp scheduled_time
Definition: buffer_list.h:92
Definition: buffer_list.h:90
static void Shutdown(grpc_core::TracedBuffer **, void *, grpc_error *shutdown_err)
Definition: buffer_list.h:149
TracedBuffer is a class to keep track of timestamps for a specific buffer in the TCP layer...
Definition: buffer_list.h:146
Optional< uint32_t > packet_retx
Definition: buffer_list.h:41
Optional< uint64_t > rwnd_limited_usec
Definition: buffer_list.h:79
Optional< uint32_t > packet_sent
Definition: buffer_list.h:46
Analogous to struct timespec.
Definition: gpr_types.h:47
#define GRPC_ERROR_UNREF(err)
Definition: error.h:186
ConnectionMetrics metrics
Definition: buffer_list.h:87
Optional< uint32_t > min_rtt
Definition: buffer_list.h:61
Optional< uint32_t > packet_spurious_retx
Definition: buffer_list.h:44
Optional< uint64_t > data_retx
Definition: buffer_list.h:53
Optional< uint64_t > data_sent
Definition: buffer_list.h:55
Optional< uint64_t > sndbuf_limited_usec
Definition: buffer_list.h:82
Definition: buffer_list.h:85
Optional< uint64_t > delivery_rate
Definition: buffer_list.h:37
Timestamp sent_time
Definition: buffer_list.h:93
Definition: buffer_list.h:35