diff options
Diffstat (limited to 'src/core/lib/surface')
-rw-r--r-- | src/core/lib/surface/alarm.cc | 137 | ||||
-rw-r--r-- | src/core/lib/surface/alarm_internal.h | 40 | ||||
-rw-r--r-- | src/core/lib/surface/call.cc | 36 | ||||
-rw-r--r-- | src/core/lib/surface/completion_queue.cc | 37 | ||||
-rw-r--r-- | src/core/lib/surface/init.cc | 3 | ||||
-rw-r--r-- | src/core/lib/surface/version.cc | 4 |
6 files changed, 27 insertions, 230 deletions
diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc deleted file mode 100644 index f6ea016c33..0000000000 --- a/src/core/lib/surface/alarm.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * Copyright 2015 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. - * - */ -#include <grpc/support/port_platform.h> - -#include <inttypes.h> - -#include "src/core/lib/surface/alarm_internal.h" - -#include <grpc/grpc.h> -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> -#include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/surface/completion_queue.h" - -grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount(false, - "alarm_refcount"); - -struct grpc_alarm { - gpr_refcount refs; - grpc_timer alarm; - grpc_closure on_alarm; - grpc_cq_completion completion; - /** completion queue where events about this alarm will be posted */ - grpc_completion_queue* cq; - /** user supplied tag */ - void* tag; -}; - -static void alarm_ref(grpc_alarm* alarm) { gpr_ref(&alarm->refs); } - -static void alarm_unref(grpc_alarm* alarm) { - if (gpr_unref(&alarm->refs)) { - grpc_core::ExecCtx exec_ctx; - if (alarm->cq != nullptr) { - GRPC_CQ_INTERNAL_UNREF(alarm->cq, "alarm"); - } - - gpr_free(alarm); - } -} - -#ifndef NDEBUG -static void alarm_ref_dbg(grpc_alarm* alarm, const char* reason, - const char* file, int line) { - if (grpc_trace_alarm_refcount.enabled()) { - gpr_atm val = gpr_atm_no_barrier_load(&alarm->refs.count); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "Alarm:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, - val + 1, reason); - } - - alarm_ref(alarm); -} - -static void alarm_unref_dbg(grpc_alarm* alarm, const char* reason, - const char* file, int line) { - if (grpc_trace_alarm_refcount.enabled()) { - gpr_atm val = gpr_atm_no_barrier_load(&alarm->refs.count); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "Alarm:%p Unref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, - val - 1, reason); - } - - alarm_unref(alarm); -} -#endif - -static void alarm_end_completion(void* arg, grpc_cq_completion* c) { - grpc_alarm* alarm = (grpc_alarm*)arg; - GRPC_ALARM_UNREF(alarm, "dequeue-end-op"); -} - -static void alarm_cb(void* arg, grpc_error* error) { - grpc_alarm* alarm = (grpc_alarm*)arg; - - /* We are queuing an op on completion queue. This means, the alarm's structure - cannot be destroyed until the op is dequeued. Adding an extra ref - here and unref'ing when the op is dequeued will achieve this */ - GRPC_ALARM_REF(alarm, "queue-end-op"); - grpc_cq_end_op(alarm->cq, alarm->tag, error, alarm_end_completion, - (void*)alarm, &alarm->completion); -} - -grpc_alarm* grpc_alarm_create(void* reserved) { - grpc_alarm* alarm = (grpc_alarm*)gpr_malloc(sizeof(grpc_alarm)); - -#ifndef NDEBUG - if (grpc_trace_alarm_refcount.enabled()) { - gpr_log(GPR_DEBUG, "Alarm:%p created (ref: 1)", alarm); - } -#endif - - gpr_ref_init(&alarm->refs, 1); - grpc_timer_init_unset(&alarm->alarm); - alarm->cq = nullptr; - GRPC_CLOSURE_INIT(&alarm->on_alarm, alarm_cb, alarm, - grpc_schedule_on_exec_ctx); - return alarm; -} - -void grpc_alarm_set(grpc_alarm* alarm, grpc_completion_queue* cq, - gpr_timespec deadline, void* tag, void* reserved) { - grpc_core::ExecCtx exec_ctx; - - GRPC_CQ_INTERNAL_REF(cq, "alarm"); - alarm->cq = cq; - alarm->tag = tag; - - GPR_ASSERT(grpc_cq_begin_op(cq, tag)); - grpc_timer_init(&alarm->alarm, grpc_timespec_to_millis_round_up(deadline), - &alarm->on_alarm); -} - -void grpc_alarm_cancel(grpc_alarm* alarm, void* reserved) { - grpc_core::ExecCtx exec_ctx; - grpc_timer_cancel(&alarm->alarm); -} - -void grpc_alarm_destroy(grpc_alarm* alarm, void* reserved) { - grpc_alarm_cancel(alarm, reserved); - GRPC_ALARM_UNREF(alarm, "alarm_destroy"); -} diff --git a/src/core/lib/surface/alarm_internal.h b/src/core/lib/surface/alarm_internal.h deleted file mode 100644 index 99e981234d..0000000000 --- a/src/core/lib/surface/alarm_internal.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Copyright 2015-2017 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. - * - */ - -#ifndef GRPC_CORE_LIB_SURFACE_ALARM_INTERNAL_H -#define GRPC_CORE_LIB_SURFACE_ALARM_INTERNAL_H - -#include <grpc/support/log.h> -#include "src/core/lib/debug/trace.h" - -extern grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount; - -#ifndef NDEBUG - -#define GRPC_ALARM_REF(a, reason) alarm_ref_dbg(a, reason, __FILE__, __LINE__) -#define GRPC_ALARM_UNREF(a, reason) \ - alarm_unref_dbg(a, reason, __FILE__, __LINE__) - -#else /* !defined(NDEBUG) */ - -#define GRPC_ALARM_REF(a, reason) alarm_ref(a) -#define GRPC_ALARM_UNREF(a, reason) alarm_unref(a) - -#endif /* defined(NDEBUG) */ - -#endif /* GRPC_CORE_LIB_SURFACE_ALARM_INTERNAL_H */ diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index ce63fa4d67..f2096d8937 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -321,12 +321,12 @@ static parent_call* get_parent_call(grpc_call* call) { grpc_error* grpc_call_create(const grpc_call_create_args* args, grpc_call** out_call) { + GPR_TIMER_SCOPE("grpc_call_create", 0); size_t i, j; grpc_error* error = GRPC_ERROR_NONE; grpc_channel_stack* channel_stack = grpc_channel_get_channel_stack(args->channel); grpc_call* call; - GPR_TIMER_BEGIN("grpc_call_create", 0); size_t initial_size = grpc_channel_get_call_size_estimate(args->channel); GRPC_STATS_INC_CALL_INITIAL_SIZE(initial_size); gpr_arena* arena = gpr_arena_create(initial_size); @@ -467,7 +467,6 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args, grpc_slice_unref_internal(path); - GPR_TIMER_END("grpc_call_create", 0); return error; } @@ -511,10 +510,10 @@ static void release_call(void* call, grpc_error* error) { static void set_status_value_directly(grpc_status_code status, void* dest); static void destroy_call(void* call, grpc_error* error) { + GPR_TIMER_SCOPE("destroy_call", 0); size_t i; int ii; grpc_call* c = (grpc_call*)call; - GPR_TIMER_BEGIN("destroy_call", 0); for (i = 0; i < 2; i++) { grpc_metadata_batch_destroy( &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); @@ -551,7 +550,6 @@ static void destroy_call(void* call, grpc_error* error) { grpc_call_stack_destroy(CALL_STACK_FROM_CALL(c), &c->final_info, GRPC_CLOSURE_INIT(&c->release_call, release_call, c, grpc_schedule_on_exec_ctx)); - GPR_TIMER_END("destroy_call", 0); } void grpc_call_ref(grpc_call* c) { gpr_ref(&c->ext_ref); } @@ -559,10 +557,11 @@ void grpc_call_ref(grpc_call* c) { gpr_ref(&c->ext_ref); } void grpc_call_unref(grpc_call* c) { if (!gpr_unref(&c->ext_ref)) return; + GPR_TIMER_SCOPE("grpc_call_unref", 0); + child_call* cc = c->child; grpc_core::ExecCtx exec_ctx; - GPR_TIMER_BEGIN("grpc_call_unref", 0); GRPC_API_TRACE("grpc_call_unref(c=%p)", 1, (c)); if (cc) { @@ -594,8 +593,6 @@ void grpc_call_unref(grpc_call* c) { grpc_call_combiner_set_notify_on_cancel(&c->call_combiner, nullptr); } GRPC_CALL_INTERNAL_UNREF(c, "destroy"); - - GPR_TIMER_END("grpc_call_unref", 0); } grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { @@ -610,13 +607,12 @@ grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved) { // This is called via the call combiner to start sending a batch down // the filter stack. static void execute_batch_in_call_combiner(void* arg, grpc_error* ignored) { + GPR_TIMER_SCOPE("execute_batch", 0); grpc_transport_stream_op_batch* batch = (grpc_transport_stream_op_batch*)arg; grpc_call* call = (grpc_call*)batch->handler_private.extra_arg; - GPR_TIMER_BEGIN("execute_batch", 0); grpc_call_element* elem = CALL_ELEM_FROM_CALL(call, 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, batch); elem->filter->start_transport_stream_op_batch(elem, batch); - GPR_TIMER_END("execute_batch", 0); } // start_batch_closure points to a caller-allocated closure to be used @@ -1036,7 +1032,7 @@ static grpc_stream_compression_algorithm decode_stream_compression( static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, int is_trailing) { if (b->list.count == 0) return; - GPR_TIMER_BEGIN("publish_app_metadata", 0); + GPR_TIMER_SCOPE("publish_app_metadata", 0); grpc_metadata_array* dest; grpc_metadata* mdusr; dest = call->buffered_metadata[is_trailing]; @@ -1052,39 +1048,34 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, mdusr->key = GRPC_MDKEY(l->md); mdusr->value = GRPC_MDVALUE(l->md); } - GPR_TIMER_END("publish_app_metadata", 0); } static void recv_initial_filter(grpc_call* call, grpc_metadata_batch* b) { if (b->idx.named.content_encoding != nullptr) { - GPR_TIMER_BEGIN("incoming_stream_compression_algorithm", 0); + GPR_TIMER_SCOPE("incoming_stream_compression_algorithm", 0); set_incoming_stream_compression_algorithm( call, decode_stream_compression(b->idx.named.content_encoding->md)); - GPR_TIMER_END("incoming_stream_compression_algorithm", 0); grpc_metadata_batch_remove(b, b->idx.named.content_encoding); } if (b->idx.named.grpc_encoding != nullptr) { - GPR_TIMER_BEGIN("incoming_message_compression_algorithm", 0); + GPR_TIMER_SCOPE("incoming_message_compression_algorithm", 0); set_incoming_message_compression_algorithm( call, decode_message_compression(b->idx.named.grpc_encoding->md)); - GPR_TIMER_END("incoming_message_compression_algorithm", 0); grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); } uint32_t message_encodings_accepted_by_peer = 1u; uint32_t stream_encodings_accepted_by_peer = 1u; if (b->idx.named.grpc_accept_encoding != nullptr) { - GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); + GPR_TIMER_SCOPE("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(call, b->idx.named.grpc_accept_encoding->md, &message_encodings_accepted_by_peer, false); grpc_metadata_batch_remove(b, b->idx.named.grpc_accept_encoding); - GPR_TIMER_END("encodings_accepted_by_peer", 0); } if (b->idx.named.accept_encoding != nullptr) { - GPR_TIMER_BEGIN("stream_encodings_accepted_by_peer", 0); + GPR_TIMER_SCOPE("stream_encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(call, b->idx.named.accept_encoding->md, &stream_encodings_accepted_by_peer, true); grpc_metadata_batch_remove(b, b->idx.named.accept_encoding); - GPR_TIMER_END("stream_encodings_accepted_by_peer", 0); } call->encodings_accepted_by_peer = grpc_compression_bitset_from_message_stream_compression_bitset( @@ -1523,9 +1514,8 @@ static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) { recv_initial_filter(call, md); /* TODO(ctiller): this could be moved into recv_initial_filter now */ - GPR_TIMER_BEGIN("validate_filtered_metadata", 0); + GPR_TIMER_SCOPE("validate_filtered_metadata", 0); validate_filtered_metadata(bctl); - GPR_TIMER_END("validate_filtered_metadata", 0); if (md->deadline != GRPC_MILLIS_INF_FUTURE && !call->is_client) { call->send_deadline = md->deadline; @@ -1578,6 +1568,8 @@ static void free_no_op_completion(void* p, grpc_cq_completion* completion) { static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* notify_tag, int is_notify_tag_closure) { + GPR_TIMER_SCOPE("grpc_call_start_batch", 0); + size_t i; const grpc_op* op; batch_control* bctl; @@ -1586,7 +1578,6 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, grpc_transport_stream_op_batch* stream_op; grpc_transport_stream_op_batch_payload* stream_op_payload; - GPR_TIMER_BEGIN("grpc_call_start_batch", 0); GRPC_CALL_LOG_BATCH(GPR_INFO, call, ops, nops, notify_tag); if (nops == 0) { @@ -1923,7 +1914,6 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, execute_batch(call, stream_op, &bctl->start_batch); done: - GPR_TIMER_END("grpc_call_start_batch", 0); return error; done_with_error: diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index e731e2139f..8362522fa1 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -421,9 +421,9 @@ static long cq_event_queue_num_items(grpc_cq_event_queue* q) { grpc_completion_queue* grpc_completion_queue_create_internal( grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type) { - grpc_completion_queue* cq; + GPR_TIMER_SCOPE("grpc_completion_queue_create_internal", 0); - GPR_TIMER_BEGIN("grpc_completion_queue_create_internal", 0); + grpc_completion_queue* cq; GRPC_API_TRACE( "grpc_completion_queue_create_internal(completion_type=%d, " @@ -452,9 +452,6 @@ grpc_completion_queue* grpc_completion_queue_create_internal( GRPC_CLOSURE_INIT(&cq->pollset_shutdown_done, on_pollset_shutdown_done, cq, grpc_schedule_on_exec_ctx); - - GPR_TIMER_END("grpc_completion_queue_create_internal", 0); - return cq; } @@ -622,7 +619,7 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { - GPR_TIMER_BEGIN("cq_end_op_for_next", 0); + GPR_TIMER_SCOPE("cq_end_op_for_next", 0); if (grpc_api_trace.enabled() || (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { @@ -691,8 +688,6 @@ static void cq_end_op_for_next(grpc_completion_queue* cq, void* tag, } } - GPR_TIMER_END("cq_end_op_for_next", 0); - GRPC_ERROR_UNREF(error); } @@ -704,11 +699,11 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage) { + GPR_TIMER_SCOPE("cq_end_op_for_pluck", 0); + cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); int is_success = (error == GRPC_ERROR_NONE); - GPR_TIMER_BEGIN("cq_end_op_for_pluck", 0); - if (grpc_api_trace.enabled() || (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); @@ -760,8 +755,6 @@ static void cq_end_op_for_pluck(grpc_completion_queue* cq, void* tag, } } - GPR_TIMER_END("cq_end_op_for_pluck", 0); - GRPC_ERROR_UNREF(error); } @@ -840,11 +833,11 @@ static void dump_pending_tags(grpc_completion_queue* cq) {} static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, void* reserved) { + GPR_TIMER_SCOPE("grpc_completion_queue_next", 0); + grpc_event ret; cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); - GPR_TIMER_BEGIN("grpc_completion_queue_next", 0); - GRPC_API_TRACE( "grpc_completion_queue_next(" "cq=%p, " @@ -958,8 +951,6 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); - GPR_TIMER_END("grpc_completion_queue_next", 0); - return ret; } @@ -1078,14 +1069,14 @@ class ExecCtxPluck : public grpc_core::ExecCtx { static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, void* reserved) { + GPR_TIMER_SCOPE("grpc_completion_queue_pluck", 0); + grpc_event ret; grpc_cq_completion* c; grpc_cq_completion* prev; grpc_pollset_worker* worker = nullptr; cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); - GPR_TIMER_BEGIN("grpc_completion_queue_pluck", 0); - if (grpc_cq_pluck_trace.enabled()) { GRPC_API_TRACE( "grpc_completion_queue_pluck(" @@ -1191,8 +1182,6 @@ done: GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); - GPR_TIMER_END("grpc_completion_queue_pluck", 0); - return ret; } @@ -1240,23 +1229,19 @@ static void cq_shutdown_pluck(grpc_completion_queue* cq) { /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { + GPR_TIMER_SCOPE("grpc_completion_queue_shutdown", 0); grpc_core::ExecCtx exec_ctx; - GPR_TIMER_BEGIN("grpc_completion_queue_shutdown", 0); GRPC_API_TRACE("grpc_completion_queue_shutdown(cq=%p)", 1, (cq)); cq->vtable->shutdown(cq); - - GPR_TIMER_END("grpc_completion_queue_shutdown", 0); } void grpc_completion_queue_destroy(grpc_completion_queue* cq) { + GPR_TIMER_SCOPE("grpc_completion_queue_destroy", 0); GRPC_API_TRACE("grpc_completion_queue_destroy(cq=%p)", 1, (cq)); - GPR_TIMER_BEGIN("grpc_completion_queue_destroy", 0); grpc_completion_queue_shutdown(cq); grpc_core::ExecCtx exec_ctx; GRPC_CQ_INTERNAL_UNREF(cq, "destroy"); - - GPR_TIMER_END("grpc_completion_queue_destroy", 0); } grpc_pollset* grpc_cq_pollset(grpc_completion_queue* cq) { diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 70329b09f4..7f7947faaa 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -42,7 +42,6 @@ #include "src/core/lib/iomgr/timer_manager.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/surface/alarm_internal.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel_init.h" @@ -162,9 +161,9 @@ void grpc_shutdown(void) { { grpc_core::ExecCtx exec_ctx(0); { - grpc_executor_shutdown(); grpc_timer_manager_set_threading( false); // shutdown timer_manager thread + grpc_executor_shutdown(); for (i = g_number_of_plugins; i >= 0; i--) { if (g_all_of_the_plugins[i].destroy != nullptr) { g_all_of_the_plugins[i].destroy(); diff --git a/src/core/lib/surface/version.cc b/src/core/lib/surface/version.cc index 19498a6df7..153b6e0297 100644 --- a/src/core/lib/surface/version.cc +++ b/src/core/lib/surface/version.cc @@ -21,6 +21,6 @@ #include <grpc/grpc.h> -const char* grpc_version_string(void) { return "5.0.0-dev"; } +const char* grpc_version_string(void) { return "6.0.0-dev"; } -const char* grpc_g_stands_for(void) { return "glamorous"; } +const char* grpc_g_stands_for(void) { return "glossy"; } |