Allocate tcp_info on the heap to avoid stack frame limits

pull/17757/head
Yash Tibrewal 6 years ago
parent 222e93a2bc
commit dc85d5b556
  1. 17
      src/core/lib/iomgr/buffer_list.cc
  2. 5
      src/core/lib/iomgr/buffer_list.h
  3. 13
      src/core/lib/iomgr/tcp_posix.cc
  4. 4
      test/core/iomgr/buffer_list_test.cc

@ -24,6 +24,7 @@
#include <grpc/support/log.h>
#ifdef GRPC_LINUX_ERRQUEUE
#include <netinet/in.h>
#include <string.h>
#include <time.h>
@ -185,10 +186,16 @@ void extract_opt_stats_from_cmsg(ConnectionMetrics* metrics,
offset += NLA_ALIGN(attr->nla_len);
}
}
static int get_socket_tcp_info(grpc_core::tcp_info* info, int fd) {
info->length = sizeof(*info) - sizeof(socklen_t);
memset(info, 0, sizeof(*info));
return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &(info->length));
}
} /* namespace */
void TracedBuffer::AddNewEntry(TracedBuffer** head, uint32_t seq_no,
const grpc_core::tcp_info* info, void* arg) {
void TracedBuffer::AddNewEntry(TracedBuffer** head, uint32_t seq_no, int fd,
void* arg) {
GPR_DEBUG_ASSERT(head != nullptr);
TracedBuffer* new_elem = New<TracedBuffer>(seq_no, arg);
/* Store the current time as the sendmsg time. */
@ -196,7 +203,11 @@ void TracedBuffer::AddNewEntry(TracedBuffer** head, uint32_t seq_no,
new_elem->ts_.scheduled_time.time = gpr_inf_past(GPR_CLOCK_REALTIME);
new_elem->ts_.sent_time.time = gpr_inf_past(GPR_CLOCK_REALTIME);
new_elem->ts_.acked_time.time = gpr_inf_past(GPR_CLOCK_REALTIME);
extract_opt_stats_from_tcp_info(&new_elem->ts_.sendmsg_time.metrics, info);
if (get_socket_tcp_info(&new_elem->ts_.info, fd) == 0) {
extract_opt_stats_from_tcp_info(&new_elem->ts_.sendmsg_time.metrics,
&new_elem->ts_.info);
}
if (*head == nullptr) {
*head = new_elem;
return;

@ -93,7 +93,8 @@ struct Timestamps {
Timestamp sent_time;
Timestamp acked_time;
uint32_t byte_offset; /* byte offset relative to the start of the RPC */
uint32_t byte_offset; /* byte offset relative to the start of the RPC */
grpc_core::tcp_info info; /* tcp_info collected on sendmsg */
};
/** TracedBuffer is a class to keep track of timestamps for a specific buffer in
@ -113,7 +114,7 @@ class TracedBuffer {
/** Add a new entry in the TracedBuffer list pointed to by head. Also saves
* sendmsg_time with the current timestamp. */
static void AddNewEntry(grpc_core::TracedBuffer** head, uint32_t seq_no,
const grpc_core::tcp_info* info, void* arg);
int fd, void* arg);
/** Processes a received timestamp based on sock_extended_err and
* scm_timestamping structures. It will invoke the timestamps callback if the

@ -593,11 +593,6 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error);
#ifdef GRPC_LINUX_ERRQUEUE
static int get_socket_tcp_info(grpc_core::tcp_info* info, int fd) {
info->length = sizeof(*info) - sizeof(socklen_t);
memset(info, 0, sizeof(*info));
return getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &(info->length));
}
static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
size_t sending_length,
@ -635,15 +630,9 @@ static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
/* Only save timestamps if all the bytes were taken by sendmsg. */
if (sending_length == static_cast<size_t>(length)) {
gpr_mu_lock(&tcp->tb_mu);
grpc_core::tcp_info info;
auto* info_ptr = &info;
if (get_socket_tcp_info(info_ptr, tcp->fd) != 0) {
/* Failed to get tcp_info */
info_ptr = nullptr;
}
grpc_core::TracedBuffer::AddNewEntry(
&tcp->tb_head, static_cast<uint32_t>(tcp->bytes_counter + length),
info_ptr, tcp->outgoing_buffer_arg);
tcp->fd, tcp->outgoing_buffer_arg);
gpr_mu_unlock(&tcp->tb_mu);
tcp->outgoing_buffer_arg = nullptr;
}

@ -48,7 +48,7 @@ static void TestShutdownFlushesList() {
for (auto i = 0; i < NUM_ELEM; i++) {
gpr_atm_rel_store(&verifier_called[i], static_cast<gpr_atm>(0));
grpc_core::TracedBuffer::AddNewEntry(
&list, i, nullptr, static_cast<void*>(&verifier_called[i]));
&list, i, 0, static_cast<void*>(&verifier_called[i]));
}
grpc_core::TracedBuffer::Shutdown(&list, nullptr, GRPC_ERROR_NONE);
GPR_ASSERT(list == nullptr);
@ -84,7 +84,7 @@ static void TestVerifierCalledOnAck() {
grpc_core::TracedBuffer* list = nullptr;
gpr_atm verifier_called;
gpr_atm_rel_store(&verifier_called, static_cast<gpr_atm>(0));
grpc_core::TracedBuffer::AddNewEntry(&list, 213, nullptr, &verifier_called);
grpc_core::TracedBuffer::AddNewEntry(&list, 213, 0, &verifier_called);
grpc_core::TracedBuffer::ProcessTimestamp(&list, &serr, nullptr, &tss);
GPR_ASSERT(gpr_atm_acq_load(&verifier_called) == static_cast<gpr_atm>(1));
GPR_ASSERT(list == nullptr);

Loading…
Cancel
Save