diff options
author | Craig Tiller <ctiller@google.com> | 2016-06-28 13:53:16 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-06-28 13:53:16 -0700 |
commit | a439859c73f34bec8f38e28fe818e2d3305d7873 (patch) | |
tree | a0e7550346ebc6a4112ced216ac16025e30a75a9 /src/core/lib/iomgr | |
parent | 3203c372477785a7114df3caed255f028a1766e6 (diff) | |
parent | fe466b0e170120263811ab12a4406c7438201481 (diff) |
Merge github.com:grpc/grpc into %s
Diffstat (limited to 'src/core/lib/iomgr')
-rw-r--r-- | src/core/lib/iomgr/error.c | 61 | ||||
-rw-r--r-- | src/core/lib/iomgr/ev_epoll_linux.c | 32 |
2 files changed, 62 insertions, 31 deletions
diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index aa94bb7fdf..e20a0169c5 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -48,6 +48,8 @@ #include <grpc/support/log_windows.h> #endif +#include "src/core/lib/profiling/timers.h" + static void destroy_integer(void *key) {} static void *copy_integer(void *key) { return key; } @@ -216,6 +218,7 @@ void grpc_error_unref(grpc_error *err) { grpc_error *grpc_error_create(const char *file, int line, const char *desc, grpc_error **referencing, size_t num_referencing) { + GPR_TIMER_BEGIN("grpc_error_create", 0); grpc_error *err = gpr_malloc(sizeof(*err)); if (err == NULL) { // TODO(ctiller): make gpr_malloc return NULL return GRPC_ERROR_OOM; @@ -241,61 +244,78 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, (void *)(uintptr_t)GRPC_ERROR_TIME_CREATED, box_time(gpr_now(GPR_CLOCK_REALTIME))); gpr_ref_init(&err->refs, 1); + GPR_TIMER_END("grpc_error_create", 0); return err; } static grpc_error *copy_error_and_unref(grpc_error *in) { + GPR_TIMER_BEGIN("copy_error_and_unref", 0); + grpc_error *out; if (is_special(in)) { - if (in == GRPC_ERROR_NONE) return GRPC_ERROR_CREATE("no error"); - if (in == GRPC_ERROR_OOM) return GRPC_ERROR_CREATE("oom"); - if (in == GRPC_ERROR_CANCELLED) - return grpc_error_set_int(GRPC_ERROR_CREATE("cancelled"), - GRPC_ERROR_INT_GRPC_STATUS, - GRPC_STATUS_CANCELLED); - return GRPC_ERROR_CREATE("unknown"); - } - grpc_error *out = gpr_malloc(sizeof(*out)); + if (in == GRPC_ERROR_NONE) + out = GRPC_ERROR_CREATE("no error"); + else if (in == GRPC_ERROR_OOM) + out = GRPC_ERROR_CREATE("oom"); + else if (in == GRPC_ERROR_CANCELLED) + out = + grpc_error_set_int(GRPC_ERROR_CREATE("cancelled"), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_CANCELLED); + else + out = GRPC_ERROR_CREATE("unknown"); + } else { + out = gpr_malloc(sizeof(*out)); #ifdef GRPC_ERROR_REFCOUNT_DEBUG - gpr_log(GPR_DEBUG, "%p create copying", out); + gpr_log(GPR_DEBUG, "%p create copying", out); #endif - out->ints = gpr_avl_ref(in->ints); - out->strs = gpr_avl_ref(in->strs); - out->errs = gpr_avl_ref(in->errs); - out->times = gpr_avl_ref(in->times); - out->next_err = in->next_err; - gpr_ref_init(&out->refs, 1); - GRPC_ERROR_UNREF(in); + out->ints = gpr_avl_ref(in->ints); + out->strs = gpr_avl_ref(in->strs); + out->errs = gpr_avl_ref(in->errs); + out->times = gpr_avl_ref(in->times); + out->next_err = in->next_err; + gpr_ref_init(&out->refs, 1); + GRPC_ERROR_UNREF(in); + } + GPR_TIMER_END("copy_error_and_unref", 0); return out; } grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, intptr_t value) { + GPR_TIMER_BEGIN("grpc_error_set_int", 0); grpc_error *new = copy_error_and_unref(src); new->ints = gpr_avl_add(new->ints, (void *)(uintptr_t)which, (void *)value); + GPR_TIMER_END("grpc_error_set_int", 0); return new; } bool grpc_error_get_int(grpc_error *err, grpc_error_ints which, intptr_t *p) { + GPR_TIMER_BEGIN("grpc_error_get_int", 0); void *pp; if (is_special(err)) { if (err == GRPC_ERROR_CANCELLED && which == GRPC_ERROR_INT_GRPC_STATUS) { *p = GRPC_STATUS_CANCELLED; + GPR_TIMER_END("grpc_error_get_int", 0); return true; } + GPR_TIMER_END("grpc_error_get_int", 0); return false; } if (gpr_avl_maybe_get(err->ints, (void *)(uintptr_t)which, &pp)) { if (p != NULL) *p = (intptr_t)pp; + GPR_TIMER_END("grpc_error_get_int", 0); return true; } + GPR_TIMER_END("grpc_error_get_int", 0); return false; } grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, const char *value) { + GPR_TIMER_BEGIN("grpc_error_set_str", 0); grpc_error *new = copy_error_and_unref(src); new->strs = gpr_avl_add(new->strs, (void *)(uintptr_t)which, gpr_strdup(value)); + GPR_TIMER_END("grpc_error_set_str", 0); return new; } @@ -305,8 +325,10 @@ const char *grpc_error_get_str(grpc_error *err, grpc_error_strs which) { } grpc_error *grpc_error_add_child(grpc_error *src, grpc_error *child) { + GPR_TIMER_BEGIN("grpc_error_add_child", 0); grpc_error *new = copy_error_and_unref(src); new->errs = gpr_avl_add(new->errs, (void *)(new->next_err++), child); + GPR_TIMER_END("grpc_error_add_child", 0); return new; } @@ -498,6 +520,7 @@ void grpc_error_free_string(const char *str) { } const char *grpc_error_string(grpc_error *err) { + GPR_TIMER_BEGIN("grpc_error_string", 0); if (err == GRPC_ERROR_NONE) return no_error_string; if (err == GRPC_ERROR_OOM) return oom_error_string; if (err == GRPC_ERROR_CANCELLED) return cancelled_error_string; @@ -514,7 +537,9 @@ const char *grpc_error_string(grpc_error *err) { qsort(kvs.kvs, kvs.num_kvs, sizeof(kv_pair), cmp_kvs); - return finish_kvs(&kvs); + const char *out = finish_kvs(&kvs); + GPR_TIMER_END("grpc_error_string", 0); + return out; } grpc_error *grpc_os_error(const char *file, int line, int err, diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c index 5460d72734..475bd3c1df 100644 --- a/src/core/lib/iomgr/ev_epoll_linux.c +++ b/src/core/lib/iomgr/ev_epoll_linux.c @@ -1031,6 +1031,8 @@ static void fd_notify_on_write(grpc_exec_ctx *exec_ctx, grpc_fd *fd, */ GPR_TLS_DECL(g_current_thread_pollset); GPR_TLS_DECL(g_current_thread_worker); +static __thread bool g_initialized_sigmask; +static __thread sigset_t g_orig_sigmask; static void sig_handler(int sig_num) { #ifdef GRPC_EPOLL_DEBUG @@ -1388,7 +1390,6 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, int timeout_ms = poll_deadline_to_millis_timeout(deadline, now); sigset_t new_mask; - sigset_t orig_mask; grpc_pollset_worker worker; worker.next = worker.prev = NULL; @@ -1423,21 +1424,26 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, times *except* when it is in epoll_pwait(). This way, the worker never misses acting on a kick */ - sigemptyset(&new_mask); - sigaddset(&new_mask, grpc_wakeup_signal); - pthread_sigmask(SIG_BLOCK, &new_mask, &orig_mask); - sigdelset(&orig_mask, grpc_wakeup_signal); - /* new_mask: The new thread mask which blocks 'grpc_wakeup_signal'. This is - the mask used at all times *except during epoll_wait()*" - orig_mask: The thread mask which allows 'grpc_wakeup_signal' and this is - the mask to use *during epoll_wait()* - - The new_mask is set on the worker before it is added to the pollset (i.e - before it can be kicked) */ + if (!g_initialized_sigmask) { + sigemptyset(&new_mask); + sigaddset(&new_mask, grpc_wakeup_signal); + pthread_sigmask(SIG_BLOCK, &new_mask, &g_orig_sigmask); + sigdelset(&g_orig_sigmask, grpc_wakeup_signal); + g_initialized_sigmask = true; + /* new_mask: The new thread mask which blocks 'grpc_wakeup_signal'. + This is the mask used at all times *except during + epoll_wait()*" + g_orig_sigmask: The thread mask which allows 'grpc_wakeup_signal' and + this is the mask to use *during epoll_wait()* + + The new_mask is set on the worker before it is added to the pollset + (i.e before it can be kicked) */ + } push_front_worker(pollset, &worker); /* Add worker to pollset */ - pollset_work_and_unlock(exec_ctx, pollset, timeout_ms, &orig_mask, &error); + pollset_work_and_unlock(exec_ctx, pollset, timeout_ms, &g_orig_sigmask, + &error); grpc_exec_ctx_flush(exec_ctx); gpr_mu_lock(&pollset->mu); |