Reland removing some global initialization functions (#30420)

* Revert "Revert "Remove empty function grpc_cq_global_init and grpc_executor_global_init (#30370)" (#30417)"

This reverts commit 1067982390.

* fix

* fix

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/30415/head
Craig Tiller 3 years ago committed by GitHub
parent 1067982390
commit 43e66cc29a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      src/core/lib/debug/stats.cc
  2. 14
      src/core/lib/debug/stats.h
  3. 2
      src/core/lib/iomgr/executor.cc
  4. 3
      src/core/lib/iomgr/executor.h
  5. 2
      src/core/lib/surface/completion_queue.cc
  6. 3
      src/core/lib/surface/completion_queue.h
  7. 6
      src/core/lib/surface/init.cc

@ -31,30 +31,27 @@
#include <grpc/support/alloc.h>
#include <grpc/support/cpu.h>
#include <grpc/support/sync.h>
grpc_stats_data* grpc_stats_per_cpu_storage = nullptr;
static size_t g_num_cores;
static gpr_once g_once = GPR_ONCE_INIT;
void grpc_stats_init(void) {
gpr_once_init(&g_once, []() {
g_num_cores = gpr_cpu_num_cores();
grpc_stats_per_cpu_storage = static_cast<grpc_stats_data*>(
gpr_zalloc(sizeof(grpc_stats_data) * g_num_cores));
});
}
namespace grpc_core {
Stats* const g_stats_data = [] {
size_t num_cores = gpr_cpu_num_cores();
Stats* stats = static_cast<Stats*>(
gpr_zalloc(sizeof(Stats) + num_cores * sizeof(grpc_stats_data)));
stats->num_cores = num_cores;
return stats;
}();
} // namespace grpc_core
void grpc_stats_collect(grpc_stats_data* output) {
memset(output, 0, sizeof(*output));
for (size_t core = 0; core < g_num_cores; core++) {
for (size_t core = 0; core < grpc_core::g_stats_data->num_cores; core++) {
for (size_t i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
output->counters[i] += gpr_atm_no_barrier_load(
&grpc_stats_per_cpu_storage[core].counters[i]);
&grpc_core::g_stats_data->per_cpu[core].counters[i]);
}
for (size_t i = 0; i < GRPC_STATS_HISTOGRAM_BUCKETS; i++) {
output->histograms[i] += gpr_atm_no_barrier_load(
&grpc_stats_per_cpu_storage[core].histograms[i]);
&grpc_core::g_stats_data->per_cpu[core].histograms[i]);
}
}
}

@ -35,10 +35,17 @@ typedef struct grpc_stats_data {
gpr_atm histograms[GRPC_STATS_HISTOGRAM_BUCKETS];
} grpc_stats_data;
extern grpc_stats_data* grpc_stats_per_cpu_storage;
namespace grpc_core {
struct Stats {
size_t num_cores;
grpc_stats_data per_cpu[0];
};
extern Stats* const g_stats_data;
} // namespace grpc_core
#define GRPC_THREAD_STATS_DATA() \
(&grpc_stats_per_cpu_storage[grpc_core::ExecCtx::Get()->starting_cpu()])
(&::grpc_core::g_stats_data \
->per_cpu[grpc_core::ExecCtx::Get()->starting_cpu()])
/* Only collect stats if GRPC_COLLECT_STATS is defined or it is a debug build.
*/
@ -55,7 +62,8 @@ extern grpc_stats_data* grpc_stats_per_cpu_storage;
#define GRPC_STATS_INC_HISTOGRAM(histogram, index)
#endif /* defined(GRPC_COLLECT_STATS) || !defined(NDEBUG) */
void grpc_stats_init(void);
GRPC_DEPRECATED("function is no longer needed")
inline void grpc_stats_init(void) {}
void grpc_stats_collect(grpc_stats_data* output);
// c = b-a
void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a,

@ -448,6 +448,4 @@ void Executor::SetThreadingDefault(bool enable) {
executors[static_cast<size_t>(ExecutorType::DEFAULT)]->SetThreading(enable);
}
void grpc_executor_global_init() {}
} // namespace grpc_core

@ -114,9 +114,6 @@ class Executor {
gpr_spinlock adding_thread_lock_;
};
// Global initializer for executor
void grpc_executor_global_init();
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */

@ -447,8 +447,6 @@ grpc_core::TraceFlag grpc_cq_pluck_trace(false, "queue_pluck");
static void on_pollset_shutdown_done(void* arg, grpc_error_handle error);
void grpc_cq_global_init() {}
void grpc_completion_queue_thread_local_cache_init(grpc_completion_queue* cq) {
if (g_cached_cq == nullptr) {
g_cached_event = nullptr;

@ -71,9 +71,6 @@ void grpc_cq_internal_unref(grpc_completion_queue* cq);
#define GRPC_CQ_INTERNAL_UNREF(cq, reason) grpc_cq_internal_unref(cq)
#endif
/* Initializes global variables used by completion queues */
void grpc_cq_global_init();
/* Flag that an operation is beginning: the completion channel will not finish
shutdown until a corrensponding grpc_cq_end_* call is made.
\a tag is currently used only in debug builds. Return true on success, and

@ -36,13 +36,11 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/timer_manager.h"
#include "src/core/lib/profiling/timers.h"
@ -53,7 +51,6 @@
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/completion_queue.h"
/* (generated) built in registry of plugins */
extern void grpc_register_built_in_plugins(void);
@ -120,8 +117,6 @@ static void do_basic_init(void) {
g_init_mu = new grpc_core::Mutex();
g_shutting_down_cv = new grpc_core::CondVar();
grpc_register_built_in_plugins();
grpc_cq_global_init();
grpc_core::grpc_executor_global_init();
gpr_time_init();
}
@ -153,7 +148,6 @@ void grpc_init(void) {
}
grpc_core::Fork::GlobalInit();
grpc_fork_handlers_auto_register();
grpc_stats_init();
grpc_core::ApplicationCallbackExecCtx::GlobalInit();
grpc_iomgr_init();
gpr_timers_global_init();

Loading…
Cancel
Save