Put in blocking point annotations at places in the code where we may block for reasons other than synchronization

pull/3476/head
Vijay Pai 9 years ago
parent 9e71674ab9
commit ba130550fc
  1. 44
      src/core/iomgr/block_annotate.h
  2. 5
      src/core/iomgr/pollset_multipoller_with_epoll.c
  3. 3
      src/core/iomgr/pollset_multipoller_with_poll_posix.c
  4. 3
      src/core/iomgr/pollset_posix.c
  5. 6
      src/core/iomgr/resolve_address_posix.c
  6. 3
      src/core/iomgr/resolve_address_windows.c

@ -0,0 +1,44 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef GRPC_INTERNAL_CORE_IOMGR_BLOCK_ANNOTATE_H
#define GRPC_INTERNAL_CORE_IOMGR_BLOCK_ANNOTATE_H
/* These annotations identify the beginning and end of regions where
the code may block for reasons other than synchronization functions.
These include poll, epoll, and getaddrinfo. */
#define GRPC_IOMGR_START_BLOCKING_REGION do {} while (0)
#define GRPC_IOMGR_END_BLOCKING_REGION do {} while (0)
#endif /* GRPC_INTERNAL_CORE_IOMGR_BLOCK_ANNOTATE_H */

@ -41,6 +41,7 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#include <unistd.h> #include <unistd.h>
#include "src/core/iomgr/block_annotate.h"
#include "src/core/iomgr/fd_posix.h" #include "src/core/iomgr/fd_posix.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
@ -180,7 +181,9 @@ static void multipoll_with_epoll_pollset_maybe_work(
pfds[1].events = POLLIN; pfds[1].events = POLLIN;
pfds[1].revents = 0; pfds[1].revents = 0;
GRPC_IOMGR_START_BLOCKING_REGION;
poll_rv = grpc_poll_function(pfds, 2, timeout_ms); poll_rv = grpc_poll_function(pfds, 2, timeout_ms);
GRPC_IOMGR_END_BLOCKING_REGION;
if (poll_rv < 0) { if (poll_rv < 0) {
if (errno != EINTR) { if (errno != EINTR) {
@ -194,7 +197,9 @@ static void multipoll_with_epoll_pollset_maybe_work(
} }
if (pfds[1].revents) { if (pfds[1].revents) {
do { do {
GRPC_IOMGR_START_BLOCKING_REGION;
ep_rv = epoll_wait(h->epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, 0); ep_rv = epoll_wait(h->epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, 0);
GRPC_IOMGR_END_BLOCKING_REGION;
if (ep_rv < 0) { if (ep_rv < 0) {
if (errno != EINTR) { if (errno != EINTR) {
gpr_log(GPR_ERROR, "epoll_wait() failed: %s", strerror(errno)); gpr_log(GPR_ERROR, "epoll_wait() failed: %s", strerror(errno));

@ -42,6 +42,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "src/core/iomgr/block_annotate.h"
#include "src/core/iomgr/fd_posix.h" #include "src/core/iomgr/fd_posix.h"
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
@ -145,7 +146,9 @@ static void multipoll_with_poll_pollset_maybe_work(
POLLOUT, &watchers[i]); POLLOUT, &watchers[i]);
} }
GRPC_IOMGR_START_BLOCKING_REGION;
r = grpc_poll_function(pfds, pfd_count, timeout); r = grpc_poll_function(pfds, pfd_count, timeout);
GRPC_IOMGR_END_BLOCKING_REGION;
for (i = 1; i < pfd_count; i++) { for (i = 1; i < pfd_count; i++) {
grpc_fd_end_poll(&watchers[i], pfds[i].revents & POLLIN, grpc_fd_end_poll(&watchers[i], pfds[i].revents & POLLIN,

@ -43,6 +43,7 @@
#include <unistd.h> #include <unistd.h>
#include "src/core/iomgr/alarm_internal.h" #include "src/core/iomgr/alarm_internal.h"
#include "src/core/iomgr/block_annotate.h"
#include "src/core/iomgr/fd_posix.h" #include "src/core/iomgr/fd_posix.h"
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/socket_utils_posix.h" #include "src/core/iomgr/socket_utils_posix.h"
@ -453,7 +454,9 @@ static void basic_pollset_maybe_work(grpc_pollset *pollset,
/* poll fd count (argument 2) is shortened by one if we have no events /* poll fd count (argument 2) is shortened by one if we have no events
to poll on - such that it only includes the kicker */ to poll on - such that it only includes the kicker */
GRPC_IOMGR_START_BLOCKING_REGION;
r = grpc_poll_function(pfd, nfds, timeout); r = grpc_poll_function(pfd, nfds, timeout);
GRPC_IOMGR_END_BLOCKING_REGION;
GRPC_TIMER_MARK(GRPC_PTAG_POLL_FINISHED, r); GRPC_TIMER_MARK(GRPC_PTAG_POLL_FINISHED, r);
if (fd) { if (fd) {

@ -41,6 +41,7 @@
#include <sys/un.h> #include <sys/un.h>
#include <string.h> #include <string.h>
#include "src/core/iomgr/block_annotate.h"
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/support/string.h" #include "src/core/support/string.h"
@ -102,14 +103,19 @@ grpc_resolved_addresses *grpc_blocking_resolve_address(
hints.ai_socktype = SOCK_STREAM; /* stream socket */ hints.ai_socktype = SOCK_STREAM; /* stream socket */
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
GRPC_IOMGR_START_BLOCKING_REGION;
s = getaddrinfo(host, port, &hints, &result); s = getaddrinfo(host, port, &hints, &result);
GRPC_IOMGR_END_BLOCKING_REGION;
if (s != 0) { if (s != 0) {
/* Retry if well-known service name is recognized */ /* Retry if well-known service name is recognized */
char *svc[][2] = {{"http", "80"}, {"https", "443"}}; char *svc[][2] = {{"http", "80"}, {"https", "443"}};
int i; int i;
for (i = 0; i < (int)(sizeof(svc) / sizeof(svc[0])); i++) { for (i = 0; i < (int)(sizeof(svc) / sizeof(svc[0])); i++) {
if (strcmp(port, svc[i][0]) == 0) { if (strcmp(port, svc[i][0]) == 0) {
GRPC_IOMGR_START_BLOCKING_REGION;
s = getaddrinfo(host, svc[i][1], &hints, &result); s = getaddrinfo(host, svc[i][1], &hints, &result);
GRPC_IOMGR_END_BLOCKING_REGION;
break; break;
} }
} }

@ -40,6 +40,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
#include "src/core/iomgr/block_annotate.h"
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/support/string.h" #include "src/core/support/string.h"
@ -88,7 +89,9 @@ grpc_resolved_addresses *grpc_blocking_resolve_address(
hints.ai_socktype = SOCK_STREAM; /* stream socket */ hints.ai_socktype = SOCK_STREAM; /* stream socket */
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
GRPC_IOMGR_START_BLOCKING_REGION;
s = getaddrinfo(host, port, &hints, &result); s = getaddrinfo(host, port, &hints, &result);
GRPC_IOMGR_END_BLOCKING_REGION;
if (s != 0) { if (s != 0) {
gpr_log(GPR_ERROR, "getaddrinfo: %s", gai_strerror(s)); gpr_log(GPR_ERROR, "getaddrinfo: %s", gai_strerror(s));
goto done; goto done;

Loading…
Cancel
Save