Merge branch 'master' into cc-tsan-1

pull/13294/head
Sree Kuchibhotla 7 years ago
commit 3a128c098f
  1. 31
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  2. 12
      src/core/ext/transport/chttp2/transport/internal.h
  3. 6
      src/core/ext/transport/chttp2/transport/parsing.cc
  4. 30
      src/core/lib/iomgr/ev_epoll1_linux.cc
  5. 28
      src/core/lib/iomgr/ev_epollex_linux.cc
  6. 28
      src/core/lib/iomgr/ev_epollsig_linux.cc
  7. 130
      src/core/lib/iomgr/lockfree_event.cc
  8. 44
      src/core/lib/iomgr/lockfree_event.h
  9. 20
      src/core/lib/iomgr/pollset_uv.cc
  10. 2
      test/core/support/cpu_test.cc
  11. 88
      tools/dockerfile/grpc_artifact_linux_x64/Dockerfile
  12. 73
      tools/dockerfile/grpc_artifact_linux_x86/Dockerfile

@ -205,6 +205,8 @@ static void destruct_transport(grpc_exec_ctx* exec_ctx,
GPR_ASSERT(t->lists[i].tail == NULL);
}
GRPC_ERROR_UNREF(t->goaway_error);
GPR_ASSERT(grpc_chttp2_stream_map_size(&t->stream_map) == 0);
grpc_chttp2_stream_map_destroy(&t->stream_map);
@ -320,6 +322,7 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t,
keepalive_watchdog_fired_locked, t,
grpc_combiner_scheduler(t->combiner));
t->goaway_error = GRPC_ERROR_NONE;
grpc_chttp2_goaway_parser_init(&t->goaway_parser);
grpc_chttp2_hpack_parser_init(exec_ctx, &t->hpack_parser);
@ -1123,7 +1126,16 @@ void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx,
grpc_slice goaway_text) {
// GRPC_CHTTP2_IF_TRACING(
// gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg));
t->seen_goaway = 1;
// Discard the error from a previous goaway frame (if any)
if (t->goaway_error != GRPC_ERROR_NONE) {
GRPC_ERROR_UNREF(t->goaway_error);
}
t->goaway_error = grpc_error_set_str(
grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"),
GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)goaway_error),
GRPC_ERROR_STR_RAW_BYTES, goaway_text);
/* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug
* data equal to "too_many_pings", it should log the occurrence at a log level
@ -1144,14 +1156,8 @@ void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx,
/* lie: use transient failure from the transport to indicate goaway has been
* received */
connectivity_state_set(
exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
grpc_error_set_str(
grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"),
GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)goaway_error),
GRPC_ERROR_STR_RAW_BYTES, goaway_text),
"got_goaway");
connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
GRPC_ERROR_REF(t->goaway_error), "got_goaway");
}
static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx,
@ -2078,7 +2084,6 @@ void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t,
grpc_status_code status;
grpc_slice slice;
grpc_error_get_status(exec_ctx, error, s->deadline, &status, &slice, NULL);
if (status != GRPC_STATUS_OK) {
s->seen_error = true;
}
@ -2546,6 +2551,12 @@ static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp,
"Transport closed", &t->closed_with_error, 1);
}
if (error != GRPC_ERROR_NONE) {
/* If a goaway frame was received, this might be the reason why the read
* failed. Add this info to the error */
if (t->goaway_error != GRPC_ERROR_NONE) {
error = grpc_error_add_child(error, GRPC_ERROR_REF(t->goaway_error));
}
close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error));
t->endpoint_reading = 0;
} else if (t->closed_with_error == GRPC_ERROR_NONE) {

@ -306,9 +306,10 @@ struct grpc_chttp2_transport {
*/
uint32_t write_buffer_size;
/** have we seen a goaway */
bool seen_goaway;
/** have we sent a goaway */
/** Set to a grpc_error object if a goaway frame is received. By default, set
* to GRPC_ERROR_NONE */
grpc_error* goaway_error;
grpc_chttp2_sent_goaway_state sent_goaway_state;
/** are the local settings dirty and need to be sent? */
@ -376,11 +377,6 @@ struct grpc_chttp2_transport {
grpc_chttp2_transport* t, grpc_chttp2_stream* s,
grpc_slice slice, int is_last);
/* goaway data */
grpc_status_code goaway_error;
uint32_t goaway_last_stream_index;
grpc_slice goaway_text;
grpc_chttp2_write_cb* write_cb_pool;
/* bdp estimator */

@ -590,7 +590,11 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx,
GRPC_CHTTP2_IF_TRACING(gpr_log(
GPR_ERROR, "ignoring new grpc_chttp2_stream creation on client"));
}
return init_skip_frame_parser(exec_ctx, t, 1);
grpc_error* err = init_skip_frame_parser(exec_ctx, t, 1);
if (t->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY) {
grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser);
}
return err;
} else if (t->last_new_stream_id >= t->incoming_stream_id) {
GRPC_CHTTP2_IF_TRACING(gpr_log(
GPR_ERROR,

@ -46,6 +46,7 @@
#include "src/core/lib/iomgr/lockfree_event.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/support/manual_constructor.h"
#include "src/core/lib/support/string.h"
static grpc_wakeup_fd global_wakeup_fd;
@ -111,8 +112,8 @@ static void epoll_set_shutdown() {
struct grpc_fd {
int fd;
gpr_atm read_closure;
gpr_atm write_closure;
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> read_closure;
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> write_closure;
struct grpc_fd* freelist_next;
@ -264,8 +265,8 @@ static grpc_fd* fd_create(int fd, const char* name) {
}
new_fd->fd = fd;
grpc_lfev_init(&new_fd->read_closure);
grpc_lfev_init(&new_fd->write_closure);
new_fd->read_closure.Init();
new_fd->write_closure.Init();
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
new_fd->freelist_next = NULL;
@ -297,12 +298,11 @@ static int fd_wrapped_fd(grpc_fd* fd) { return fd->fd; }
* shutdown() syscall on that fd) */
static void fd_shutdown_internal(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_error* why, bool releasing_fd) {
if (grpc_lfev_set_shutdown(exec_ctx, &fd->read_closure,
GRPC_ERROR_REF(why))) {
if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) {
if (!releasing_fd) {
shutdown(fd->fd, SHUT_RDWR);
}
grpc_lfev_set_shutdown(exec_ctx, &fd->write_closure, GRPC_ERROR_REF(why));
fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why));
}
GRPC_ERROR_UNREF(why);
}
@ -318,7 +318,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_error* error = GRPC_ERROR_NONE;
bool is_release_fd = (release_fd != NULL);
if (!grpc_lfev_is_shutdown(&fd->read_closure)) {
if (!fd->read_closure->IsShutdown()) {
fd_shutdown_internal(exec_ctx, fd,
GRPC_ERROR_CREATE_FROM_COPIED_STRING(reason),
is_release_fd);
@ -335,8 +335,8 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_REF(error));
grpc_iomgr_unregister_object(&fd->iomgr_object);
grpc_lfev_destroy(&fd->read_closure);
grpc_lfev_destroy(&fd->write_closure);
fd->read_closure.Destroy();
fd->write_closure.Destroy();
gpr_mu_lock(&fd_freelist_mu);
fd->freelist_next = fd_freelist;
@ -351,28 +351,28 @@ static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx,
}
static bool fd_is_shutdown(grpc_fd* fd) {
return grpc_lfev_is_shutdown(&fd->read_closure);
return fd->read_closure->IsShutdown();
}
static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_closure* closure) {
grpc_lfev_notify_on(exec_ctx, &fd->read_closure, closure, "read");
fd->read_closure->NotifyOn(exec_ctx, closure);
}
static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_closure* closure) {
grpc_lfev_notify_on(exec_ctx, &fd->write_closure, closure, "write");
fd->write_closure->NotifyOn(exec_ctx, closure);
}
static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_pollset* notifier) {
grpc_lfev_set_ready(exec_ctx, &fd->read_closure, "read");
fd->read_closure->SetReady(exec_ctx);
/* Use release store to match with acquire load in fd_get_read_notifier */
gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier);
}
static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) {
grpc_lfev_set_ready(exec_ctx, &fd->write_closure, "write");
fd->write_closure->SetReady(exec_ctx);
}
/*******************************************************************************

@ -48,6 +48,7 @@
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/support/manual_constructor.h"
#include "src/core/lib/support/spinlock.h"
// debug aid: create workers on the heap (allows asan to spot
@ -153,8 +154,8 @@ struct grpc_fd {
gpr_mu pollable_mu;
pollable* pollable_obj;
gpr_atm read_closure;
gpr_atm write_closure;
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> read_closure;
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> write_closure;
struct grpc_fd* freelist_next;
grpc_closure* on_done_closure;
@ -286,8 +287,8 @@ static void fd_destroy(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {
fd->freelist_next = fd_freelist;
fd_freelist = fd;
grpc_lfev_destroy(&fd->read_closure);
grpc_lfev_destroy(&fd->write_closure);
fd->read_closure.Destroy();
fd->write_closure.Destroy();
gpr_mu_unlock(&fd_freelist_mu);
}
@ -347,8 +348,8 @@ static grpc_fd* fd_create(int fd, const char* name) {
new_fd->pollable_obj = NULL;
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
new_fd->fd = fd;
grpc_lfev_init(&new_fd->read_closure);
grpc_lfev_init(&new_fd->write_closure);
new_fd->read_closure.Init();
new_fd->write_closure.Init();
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
new_fd->freelist_next = NULL;
@ -411,27 +412,26 @@ static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx,
}
static bool fd_is_shutdown(grpc_fd* fd) {
return grpc_lfev_is_shutdown(&fd->read_closure);
return fd->read_closure->IsShutdown();
}
/* Might be called multiple times */
static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) {
if (grpc_lfev_set_shutdown(exec_ctx, &fd->read_closure,
GRPC_ERROR_REF(why))) {
if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) {
shutdown(fd->fd, SHUT_RDWR);
grpc_lfev_set_shutdown(exec_ctx, &fd->write_closure, GRPC_ERROR_REF(why));
fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why));
}
GRPC_ERROR_UNREF(why);
}
static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_closure* closure) {
grpc_lfev_notify_on(exec_ctx, &fd->read_closure, closure, "read");
fd->read_closure->NotifyOn(exec_ctx, closure);
}
static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_closure* closure) {
grpc_lfev_notify_on(exec_ctx, &fd->write_closure, closure, "write");
fd->write_closure->NotifyOn(exec_ctx, closure);
}
/*******************************************************************************
@ -702,7 +702,7 @@ static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx,
static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_pollset* notifier) {
grpc_lfev_set_ready(exec_ctx, &fd->read_closure, "read");
fd->read_closure->SetReady(exec_ctx);
/* Note, it is possible that fd_become_readable might be called twice with
different 'notifier's when an fd becomes readable and it is in two epoll
@ -714,7 +714,7 @@ static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
}
static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) {
grpc_lfev_set_ready(exec_ctx, &fd->write_closure, "write");
fd->write_closure->SetReady(exec_ctx);
}
static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) {

@ -50,6 +50,7 @@
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/support/manual_constructor.h"
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker*)1)
@ -127,8 +128,8 @@ struct grpc_fd {
valid */
bool orphaned;
gpr_atm read_closure;
gpr_atm write_closure;
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> read_closure;
grpc_core::ManualConstructor<grpc_core::LockfreeEvent> write_closure;
struct grpc_fd* freelist_next;
grpc_closure* on_done_closure;
@ -766,8 +767,8 @@ static void unref_by(grpc_fd* fd, int n) {
fd_freelist = fd;
grpc_iomgr_unregister_object(&fd->iomgr_object);
grpc_lfev_destroy(&fd->read_closure);
grpc_lfev_destroy(&fd->write_closure);
fd->read_closure.Destroy();
fd->write_closure.Destroy();
gpr_mu_unlock(&fd_freelist_mu);
} else {
@ -832,8 +833,8 @@ static grpc_fd* fd_create(int fd, const char* name) {
gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1);
new_fd->fd = fd;
new_fd->orphaned = false;
grpc_lfev_init(&new_fd->read_closure);
grpc_lfev_init(&new_fd->write_closure);
new_fd->read_closure.Init();
new_fd->write_closure.Init();
gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL);
new_fd->freelist_next = NULL;
@ -924,27 +925,26 @@ static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx,
}
static bool fd_is_shutdown(grpc_fd* fd) {
return grpc_lfev_is_shutdown(&fd->read_closure);
return fd->read_closure->IsShutdown();
}
/* Might be called multiple times */
static void fd_shutdown(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_error* why) {
if (grpc_lfev_set_shutdown(exec_ctx, &fd->read_closure,
GRPC_ERROR_REF(why))) {
if (fd->read_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why))) {
shutdown(fd->fd, SHUT_RDWR);
grpc_lfev_set_shutdown(exec_ctx, &fd->write_closure, GRPC_ERROR_REF(why));
fd->write_closure->SetShutdown(exec_ctx, GRPC_ERROR_REF(why));
}
GRPC_ERROR_UNREF(why);
}
static void fd_notify_on_read(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_closure* closure) {
grpc_lfev_notify_on(exec_ctx, &fd->read_closure, closure, "read");
fd->read_closure->NotifyOn(exec_ctx, closure);
}
static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_closure* closure) {
grpc_lfev_notify_on(exec_ctx, &fd->write_closure, closure, "write");
fd->write_closure->NotifyOn(exec_ctx, closure);
}
/*******************************************************************************
@ -1108,7 +1108,7 @@ static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx,
static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
grpc_pollset* notifier) {
grpc_lfev_set_ready(exec_ctx, &fd->read_closure, "read");
fd->read_closure->SetReady(exec_ctx);
/* Note, it is possible that fd_become_readable might be called twice with
different 'notifier's when an fd becomes readable and it is in two epoll
@ -1120,7 +1120,7 @@ static void fd_become_readable(grpc_exec_ctx* exec_ctx, grpc_fd* fd,
}
static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) {
grpc_lfev_set_ready(exec_ctx, &fd->write_closure, "write");
fd->write_closure->SetReady(exec_ctx);
}
static void pollset_release_polling_island(grpc_exec_ctx* exec_ctx,

@ -26,92 +26,96 @@ extern grpc_tracer_flag grpc_polling_trace;
/* 'state' holds the to call when the fd is readable or writable respectively.
It can contain one of the following values:
CLOSURE_READY : The fd has an I/O event of interest but there is no
kClosureReady : The fd has an I/O event of interest but there is no
closure yet to execute
CLOSURE_NOT_READY : The fd has no I/O event of interest
kClosureNotReady : The fd has no I/O event of interest
closure ptr : The closure to be executed when the fd has an I/O
event of interest
shutdown_error | FD_SHUTDOWN_BIT :
'shutdown_error' field ORed with FD_SHUTDOWN_BIT.
shutdown_error | kShutdownBit :
'shutdown_error' field ORed with kShutdownBit.
This indicates that the fd is shutdown. Since all
memory allocations are word-aligned, the lower two
bits of the shutdown_error pointer are always 0. So
it is safe to OR these with FD_SHUTDOWN_BIT
it is safe to OR these with kShutdownBit
Valid state transitions:
<closure ptr> <-----3------ CLOSURE_NOT_READY ----1----> CLOSURE_READY
<closure ptr> <-----3------ kClosureNotReady -----1-------> kClosureReady
| | ^ | ^ | |
| | | | | | |
| +--------------4----------+ 6 +---------2---------------+ |
| | |
| v |
+-----5-------> [shutdown_error | FD_SHUTDOWN_BIT] <----7---------+
+-----5-------> [shutdown_error | kShutdownBit] <-------7---------+
For 1, 4 : See grpc_lfev_set_ready() function
For 2, 3 : See grpc_lfev_notify_on() function
For 5,6,7: See grpc_lfev_set_shutdown() function */
For 1, 4 : See SetReady() function
For 2, 3 : See NotifyOn() function
For 5,6,7: See SetShutdown() function */
#define CLOSURE_NOT_READY ((gpr_atm)0)
#define CLOSURE_READY ((gpr_atm)2)
namespace grpc_core {
#define FD_SHUTDOWN_BIT ((gpr_atm)1)
LockfreeEvent::LockfreeEvent() {
/* Perform an atomic store to start the state machine.
void grpc_lfev_init(gpr_atm* state) {
gpr_atm_no_barrier_store(state, CLOSURE_NOT_READY);
Note carefully that LockfreeEvent *MAY* be used whilst in a destroyed
state, while a file descriptor is on a freelist. In such a state it may
be SetReady'd, and so we need to perform an atomic operation here to
ensure no races */
gpr_atm_no_barrier_store(&state_, kClosureNotReady);
}
void grpc_lfev_destroy(gpr_atm* state) {
gpr_atm curr = gpr_atm_no_barrier_load(state);
if (curr & FD_SHUTDOWN_BIT) {
GRPC_ERROR_UNREF((grpc_error*)(curr & ~FD_SHUTDOWN_BIT));
} else {
GPR_ASSERT(curr == CLOSURE_NOT_READY || curr == CLOSURE_READY);
}
}
bool grpc_lfev_is_shutdown(gpr_atm* state) {
gpr_atm curr = gpr_atm_no_barrier_load(state);
return (curr & FD_SHUTDOWN_BIT) != 0;
LockfreeEvent::~LockfreeEvent() {
gpr_atm curr;
do {
curr = gpr_atm_no_barrier_load(&state_);
if (curr & kShutdownBit) {
GRPC_ERROR_UNREF((grpc_error*)(curr & ~kShutdownBit));
} else {
GPR_ASSERT(curr == kClosureNotReady || curr == kClosureReady);
}
/* we CAS in a shutdown, no error value here. If this event is interacted
with post-deletion (see the note in the constructor) we want the bit
pattern to prevent error retention in a deleted object */
} while (!gpr_atm_no_barrier_cas(&state_, curr,
kShutdownBit /* shutdown, no error */));
}
void grpc_lfev_notify_on(grpc_exec_ctx* exec_ctx, gpr_atm* state,
grpc_closure* closure, const char* variable) {
void LockfreeEvent::NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure) {
while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(state);
gpr_atm curr = gpr_atm_no_barrier_load(&state_);
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_ERROR, "lfev_notify_on[%s]: %p curr=%p closure=%p", variable,
state, (void*)curr, closure);
gpr_log(GPR_ERROR, "LockfreeEvent::NotifyOn: %p curr=%p closure=%p", this,
(void*)curr, closure);
}
switch (curr) {
case CLOSURE_NOT_READY: {
/* CLOSURE_NOT_READY -> <closure>.
case kClosureNotReady: {
/* kClosureNotReady -> <closure>.
We're guaranteed by API that there's an acquire barrier before here,
so there's no need to double-dip and this can be a release-only.
The release itself pairs with the acquire half of a set_ready full
barrier. */
if (gpr_atm_rel_cas(state, CLOSURE_NOT_READY, (gpr_atm)closure)) {
if (gpr_atm_rel_cas(&state_, kClosureNotReady, (gpr_atm)closure)) {
return; /* Successful. Return */
}
break; /* retry */
}
case CLOSURE_READY: {
/* Change the state to CLOSURE_NOT_READY. Schedule the closure if
case kClosureReady: {
/* Change the state to kClosureNotReady. Schedule the closure if
successful. If not, the state most likely transitioned to shutdown.
We should retry.
This can be a no-barrier cas since the state is being transitioned to
CLOSURE_NOT_READY; set_ready and set_shutdown do not schedule any
kClosureNotReady; set_ready and set_shutdown do not schedule any
closure when transitioning out of CLOSURE_NO_READY state (i.e there
is no other code that needs to 'happen-after' this) */
if (gpr_atm_no_barrier_cas(state, CLOSURE_READY, CLOSURE_NOT_READY)) {
if (gpr_atm_no_barrier_cas(&state_, kClosureReady, kClosureNotReady)) {
GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE);
return; /* Successful. Return */
}
@ -123,8 +127,8 @@ void grpc_lfev_notify_on(grpc_exec_ctx* exec_ctx, gpr_atm* state,
/* 'curr' is either a closure or the fd is shutdown(in which case 'curr'
contains a pointer to the shutdown-error). If the fd is shutdown,
schedule the closure with the shutdown error */
if ((curr & FD_SHUTDOWN_BIT) > 0) {
grpc_error* shutdown_err = (grpc_error*)(curr & ~FD_SHUTDOWN_BIT);
if ((curr & kShutdownBit) > 0) {
grpc_error* shutdown_err = (grpc_error*)(curr & ~kShutdownBit);
GRPC_CLOSURE_SCHED(exec_ctx, closure,
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
"FD Shutdown", &shutdown_err, 1));
@ -133,7 +137,8 @@ void grpc_lfev_notify_on(grpc_exec_ctx* exec_ctx, gpr_atm* state,
/* There is already a closure!. This indicates a bug in the code */
gpr_log(GPR_ERROR,
"notify_on called with a previous callback still pending");
"LockfreeEvent::NotifyOn: notify_on called with a previous "
"callback still pending");
abort();
}
}
@ -142,22 +147,22 @@ void grpc_lfev_notify_on(grpc_exec_ctx* exec_ctx, gpr_atm* state,
GPR_UNREACHABLE_CODE(return );
}
bool grpc_lfev_set_shutdown(grpc_exec_ctx* exec_ctx, gpr_atm* state,
grpc_error* shutdown_err) {
gpr_atm new_state = (gpr_atm)shutdown_err | FD_SHUTDOWN_BIT;
bool LockfreeEvent::SetShutdown(grpc_exec_ctx* exec_ctx,
grpc_error* shutdown_err) {
gpr_atm new_state = (gpr_atm)shutdown_err | kShutdownBit;
while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(state);
gpr_atm curr = gpr_atm_no_barrier_load(&state_);
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_ERROR, "lfev_set_shutdown: %p curr=%p err=%s", state,
(void*)curr, grpc_error_string(shutdown_err));
gpr_log(GPR_ERROR, "LockfreeEvent::SetShutdown: %p curr=%p err=%s",
&state_, (void*)curr, grpc_error_string(shutdown_err));
}
switch (curr) {
case CLOSURE_READY:
case CLOSURE_NOT_READY:
case kClosureReady:
case kClosureNotReady:
/* Need a full barrier here so that the initial load in notify_on
doesn't need a barrier */
if (gpr_atm_full_cas(state, curr, new_state)) {
if (gpr_atm_full_cas(&state_, curr, new_state)) {
return true; /* early out */
}
break; /* retry */
@ -166,7 +171,7 @@ bool grpc_lfev_set_shutdown(grpc_exec_ctx* exec_ctx, gpr_atm* state,
/* 'curr' is either a closure or the fd is already shutdown */
/* If fd is already shutdown, we are done */
if ((curr & FD_SHUTDOWN_BIT) > 0) {
if ((curr & kShutdownBit) > 0) {
GRPC_ERROR_UNREF(shutdown_err);
return false;
}
@ -176,7 +181,7 @@ bool grpc_lfev_set_shutdown(grpc_exec_ctx* exec_ctx, gpr_atm* state,
Needs an acquire to pair with setting the closure (and get a
happens-after on that edge), and a release to pair with anything
loading the shutdown state. */
if (gpr_atm_full_cas(state, curr, new_state)) {
if (gpr_atm_full_cas(&state_, curr, new_state)) {
GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)curr,
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
"FD Shutdown", &shutdown_err, 1));
@ -193,26 +198,25 @@ bool grpc_lfev_set_shutdown(grpc_exec_ctx* exec_ctx, gpr_atm* state,
GPR_UNREACHABLE_CODE(return false);
}
void grpc_lfev_set_ready(grpc_exec_ctx* exec_ctx, gpr_atm* state,
const char* variable) {
void LockfreeEvent::SetReady(grpc_exec_ctx* exec_ctx) {
while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(state);
gpr_atm curr = gpr_atm_no_barrier_load(&state_);
if (GRPC_TRACER_ON(grpc_polling_trace)) {
gpr_log(GPR_ERROR, "lfev_set_ready[%s]: %p curr=%p", variable, state,
gpr_log(GPR_ERROR, "LockfreeEvent::SetReady: %p curr=%p", &state_,
(void*)curr);
}
switch (curr) {
case CLOSURE_READY: {
case kClosureReady: {
/* Already ready. We are done here */
return;
}
case CLOSURE_NOT_READY: {
case kClosureNotReady: {
/* No barrier required as we're transitioning to a state that does not
involve a closure */
if (gpr_atm_no_barrier_cas(state, CLOSURE_NOT_READY, CLOSURE_READY)) {
if (gpr_atm_no_barrier_cas(&state_, kClosureNotReady, kClosureReady)) {
return; /* early out */
}
break; /* retry */
@ -220,14 +224,14 @@ void grpc_lfev_set_ready(grpc_exec_ctx* exec_ctx, gpr_atm* state,
default: {
/* 'curr' is either a closure or the fd is shutdown */
if ((curr & FD_SHUTDOWN_BIT) > 0) {
if ((curr & kShutdownBit) > 0) {
/* The fd is shutdown. Do nothing */
return;
}
/* Full cas: acquire pairs with this cas' release in the event of a
spurious set_ready; release pairs with this or the acquire in
notify_on (or set_shutdown) */
else if (gpr_atm_full_cas(state, curr, CLOSURE_NOT_READY)) {
else if (gpr_atm_full_cas(&state_, curr, kClosureNotReady)) {
GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)curr, GRPC_ERROR_NONE);
return;
}
@ -239,3 +243,5 @@ void grpc_lfev_set_ready(grpc_exec_ctx* exec_ctx, gpr_atm* state,
}
}
}
} // namespace grpc_core

@ -25,24 +25,30 @@
#include "src/core/lib/iomgr/exec_ctx.h"
#ifdef __cplusplus
extern "C" {
#endif
void grpc_lfev_init(gpr_atm* state);
void grpc_lfev_destroy(gpr_atm* state);
bool grpc_lfev_is_shutdown(gpr_atm* state);
void grpc_lfev_notify_on(grpc_exec_ctx* exec_ctx, gpr_atm* state,
grpc_closure* closure, const char* variable);
/* Returns true on first successful shutdown */
bool grpc_lfev_set_shutdown(grpc_exec_ctx* exec_ctx, gpr_atm* state,
grpc_error* shutdown_err);
void grpc_lfev_set_ready(grpc_exec_ctx* exec_ctx, gpr_atm* state,
const char* variable);
#ifdef __cplusplus
}
#endif
namespace grpc_core {
class LockfreeEvent {
public:
LockfreeEvent();
~LockfreeEvent();
LockfreeEvent(const LockfreeEvent&) = delete;
LockfreeEvent& operator=(const LockfreeEvent&) = delete;
bool IsShutdown() const {
return (gpr_atm_no_barrier_load(&state_) & kShutdownBit) != 0;
}
void NotifyOn(grpc_exec_ctx* exec_ctx, grpc_closure* closure);
bool SetShutdown(grpc_exec_ctx* exec_ctx, grpc_error* error);
void SetReady(grpc_exec_ctx* exec_ctx);
private:
enum State { kClosureNotReady = 0, kClosureReady = 2, kShutdownBit = 1 };
gpr_atm state_;
};
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_IOMGR_LOCKFREE_EVENT_H */

@ -40,7 +40,7 @@ grpc_tracer_flag grpc_trace_fd_refcount =
#endif
struct grpc_pollset {
uv_timer_t timer;
uv_timer_t* timer;
int shutting_down;
};
@ -78,12 +78,16 @@ void grpc_pollset_global_shutdown(void) {
static void timer_run_cb(uv_timer_t* timer) {}
static void timer_close_cb(uv_handle_t* handle) { handle->data = (void*)1; }
static void timer_close_cb(uv_handle_t* handle) {
handle->data = (void*)1;
gpr_free(handle);
}
void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) {
GRPC_UV_ASSERT_SAME_THREAD();
*mu = &grpc_polling_mu;
uv_timer_init(uv_default_loop(), &pollset->timer);
pollset->timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t));
uv_timer_init(uv_default_loop(), pollset->timer);
pollset->shutting_down = 0;
}
@ -104,11 +108,11 @@ void grpc_pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
void grpc_pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) {
GRPC_UV_ASSERT_SAME_THREAD();
uv_close((uv_handle_t*)&pollset->timer, timer_close_cb);
uv_close((uv_handle_t*)pollset->timer, timer_close_cb);
// timer.data is a boolean indicating that the timer has finished closing
pollset->timer.data = (void*)0;
pollset->timer->data = (void*)0;
if (grpc_pollset_work_run_loop) {
while (!pollset->timer.data) {
while (!pollset->timer->data) {
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
}
}
@ -130,11 +134,11 @@ grpc_error* grpc_pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset,
/* We special-case timeout=0 so that we don't bother with the timer when
the loop won't block anyway */
if (timeout > 0) {
uv_timer_start(&pollset->timer, timer_run_cb, timeout, 0);
uv_timer_start(pollset->timer, timer_run_cb, timeout, 0);
/* Run until there is some I/O activity or the timer triggers. It doesn't
matter which happens */
uv_run(uv_default_loop(), UV_RUN_ONCE);
uv_timer_stop(&pollset->timer);
uv_timer_stop(pollset->timer);
} else {
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
}

@ -68,7 +68,7 @@ static void worker_thread(void* arg) {
unsigned i, j;
/* Avoid repetitive division calculations */
int64_t max_i = 1000 / grpc_test_slowdown_factor();
int64_t max_j = 1000000 / grpc_test_slowdown_factor();
int64_t max_j = 1000 / grpc_test_slowdown_factor();
for (i = 0; i < max_i; i++) {
/* run for a bit - just calculate something random. */
for (j = 0; j < max_j; j++) {

@ -0,0 +1,88 @@
# Copyright 2016 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Docker file for building gRPC artifacts.
FROM debian:jessie
RUN apt-get update && apt-get install debian-keyring && apt-key update
# Install Git and basic packages.
RUN apt-get update && apt-key update && apt-get install -y \
autoconf \
autotools-dev \
build-essential \
bzip2 \
clang \
curl \
gcc \
gcc-multilib \
git \
golang \
libc6 \
libc6-dbg \
libc6-dev \
libgtest-dev \
libtool \
make \
perl \
strace \
python-dev \
python-setuptools \
python-yaml \
telnet \
unzip \
wget \
zip && apt-get clean
# Install Node dependencies
RUN touch .profile
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
RUN /bin/bash -l -c "nvm install 8 && npm install -g node-pre-gyp"
##################
# Ruby dependencies
# Install rvm
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN \curl -sSL https://get.rvm.io | bash -s stable
# Install Ruby 2.1
RUN /bin/bash -l -c "rvm install ruby-2.1"
RUN /bin/bash -l -c "rvm use --default ruby-2.1"
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc"
RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
##################
# PHP dependencies
RUN apt-get update && apt-get install -y \
php5 php5-dev php-pear phpunit
##################
# Install cross compiler for ARM
RUN echo 'deb http://emdebian.org/tools/debian/ jessie main' | tee -a /etc/apt/sources.list.d/crosstools.list && \
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
RUN dpkg --add-architecture armhf && apt-get update && apt-get install -y crossbuild-essential-armhf
RUN mkdir /var/local/jenkins
# Define the default command.
CMD ["bash"]

@ -0,0 +1,73 @@
# Copyright 2016 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Docker file for building gRPC artifacts.
FROM 32bit/debian:jessie
RUN apt-get update && apt-get install debian-keyring && apt-key update
# Install Git and basic packages.
RUN apt-get update && apt-key update && apt-get install -y \
autoconf \
autotools-dev \
build-essential \
bzip2 \
clang \
curl \
gcc \
gcc-multilib \
git \
golang \
libc6 \
libc6-dbg \
libc6-dev \
libgtest-dev \
libtool \
make \
perl \
strace \
python-dev \
python-setuptools \
python-yaml \
telnet \
unzip \
wget \
zip && apt-get clean
# Install Node dependencies
RUN touch .profile
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
RUN /bin/bash -l -c "nvm install 8 && npm install -g node-pre-gyp"
##################
# Ruby dependencies
# Install rvm
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN \curl -sSL https://get.rvm.io | bash -s stable
# Install Ruby 2.1
RUN /bin/bash -l -c "rvm install ruby-2.1"
RUN /bin/bash -l -c "rvm use --default ruby-2.1"
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc"
RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
RUN mkdir /var/local/jenkins
# Define the default command.
CMD ["bash"]
Loading…
Cancel
Save