[cleanup] Remove low level counters (#30611)

* [cleanup] Remove low level counters

* clean up code

* Automated change: Fix sanity tests

* fix

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/30801/head
Craig Tiller 2 years ago committed by GitHub
parent 2c28b44852
commit 6746f670c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      include/grpc/impl/codegen/atm_gcc_atomic.h
  2. 2
      include/grpc/impl/codegen/atm_gcc_sync.h
  3. 2
      include/grpc/impl/codegen/atm_windows.h
  4. 6
      src/core/lib/gpr/sync_abseil.cc
  5. 9
      src/core/lib/gpr/sync_posix.cc
  6. 6
      src/core/lib/gpr/time_posix.cc
  7. 18
      test/cpp/microbenchmarks/helpers.cc
  8. 16
      test/cpp/microbenchmarks/helpers.h

@ -33,20 +33,6 @@ typedef intptr_t gpr_atm;
#define GPR_ATM_MAX INTPTR_MAX
#define GPR_ATM_MIN INTPTR_MIN
#ifdef GPR_LOW_LEVEL_COUNTERS
extern gpr_atm gpr_counter_atm_cas;
extern gpr_atm gpr_counter_atm_add;
#define GPR_ATM_INC_COUNTER(counter) \
__atomic_fetch_add(&counter, 1, __ATOMIC_RELAXED)
#define GPR_ATM_INC_CAS_THEN(blah) \
(GPR_ATM_INC_COUNTER(gpr_counter_atm_cas), blah)
#define GPR_ATM_INC_ADD_THEN(blah) \
(GPR_ATM_INC_COUNTER(gpr_counter_atm_add), blah)
#else
#define GPR_ATM_INC_CAS_THEN(blah) blah
#define GPR_ATM_INC_ADD_THEN(blah) blah
#endif
#define gpr_atm_full_barrier() (__atomic_thread_fence(__ATOMIC_SEQ_CST))
#define gpr_atm_acq_load(p) (__atomic_load_n((p), __ATOMIC_ACQUIRE))
@ -57,34 +43,39 @@ extern gpr_atm gpr_counter_atm_add;
(__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELAXED))
#define gpr_atm_no_barrier_fetch_add(p, delta) \
GPR_ATM_INC_ADD_THEN( \
__atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_RELAXED))
__atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_RELAXED)
#define gpr_atm_full_fetch_add(p, delta) \
GPR_ATM_INC_ADD_THEN( \
__atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_ACQ_REL))
__atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_ACQ_REL)
static __inline int gpr_atm_no_barrier_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
p, &o, n, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED));
// Need to be c89 compatible, so we can't use false for the fourth argument.
// NOLINTNEXTLINE(modernize-use-bool-literals)
return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_RELAXED,
__ATOMIC_RELAXED);
}
static __inline int gpr_atm_acq_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
p, &o, n, 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED));
// Need to be c89 compatible, so we can't use false for the fourth argument.
// NOLINTNEXTLINE(modernize-use-bool-literals)
return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_ACQUIRE,
__ATOMIC_RELAXED);
}
static __inline int gpr_atm_rel_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
p, &o, n, 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED));
// Need to be c89 compatible, so we can't use false for the fourth argument.
// NOLINTNEXTLINE(modernize-use-bool-literals)
return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_RELEASE,
__ATOMIC_RELAXED);
}
static __inline int gpr_atm_full_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
p, &o, n, 0, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED));
// Need to be c89 compatible, so we can't use false for the fourth argument.
// NOLINTNEXTLINE(modernize-use-bool-literals)
return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_ACQ_REL,
__ATOMIC_RELAXED);
}
#define gpr_atm_full_xchg(p, n) \
GPR_ATM_INC_CAS_THEN(__atomic_exchange_n((p), (n), __ATOMIC_ACQ_REL))
#define gpr_atm_full_xchg(p, n) __atomic_exchange_n((p), (n), __ATOMIC_ACQ_REL)
#ifdef __cplusplus
}

@ -28,8 +28,6 @@
typedef intptr_t gpr_atm;
#define GPR_ATM_MAX INTPTR_MAX
#define GPR_ATM_MIN INTPTR_MIN
#define GPR_ATM_INC_CAS_THEN(blah) blah
#define GPR_ATM_INC_ADD_THEN(blah) blah
#define GPR_ATM_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory")

@ -29,8 +29,6 @@
typedef intptr_t gpr_atm;
#define GPR_ATM_MAX INTPTR_MAX
#define GPR_ATM_MIN INTPTR_MIN
#define GPR_ATM_INC_CAS_THEN(blah) blah
#define GPR_ATM_INC_ADD_THEN(blah) blah
#define gpr_atm_full_barrier MemoryBarrier

@ -33,12 +33,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#ifdef GPR_LOW_LEVEL_COUNTERS
gpr_atm gpr_mu_locks = 0;
gpr_atm gpr_counter_atm_cas = 0;
gpr_atm gpr_counter_atm_add = 0;
#endif
void gpr_mu_init(gpr_mu* mu) {
static_assert(sizeof(gpr_mu) == sizeof(absl::Mutex),
"gpr_mu and Mutex must be the same size");

@ -29,12 +29,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#ifdef GPR_LOW_LEVEL_COUNTERS
gpr_atm gpr_mu_locks = 0;
gpr_atm gpr_counter_atm_cas = 0;
gpr_atm gpr_counter_atm_add = 0;
#endif
void gpr_mu_init(gpr_mu* mu) {
#ifdef GRPC_ASAN_ENABLED
GPR_ASSERT(pthread_mutex_init(&mu->mutex, nullptr) == 0);
@ -55,9 +49,6 @@ void gpr_mu_destroy(gpr_mu* mu) {
}
void gpr_mu_lock(gpr_mu* mu) {
#ifdef GPR_LOW_LEVEL_COUNTERS
GPR_ATM_INC_COUNTER(gpr_mu_locks);
#endif
#ifdef GRPC_ASAN_ENABLED
GPR_ASSERT(pthread_mutex_lock(&mu->mutex) == 0);
#else

@ -140,13 +140,7 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl;
#ifdef GPR_LOW_LEVEL_COUNTERS
gpr_atm gpr_now_call_count;
#endif
gpr_timespec gpr_now(gpr_clock_type clock_type) {
#ifdef GPR_LOW_LEVEL_COUNTERS
__atomic_fetch_add(&gpr_now_call_count, 1, __ATOMIC_RELAXED);
#endif
// validate clock type
GPR_ASSERT(clock_type == GPR_CLOCK_MONOTONIC ||
clock_type == GPR_CLOCK_REALTIME ||

@ -76,22 +76,4 @@ void TrackCounters::AddToLabel(std::ostream& out, benchmark::State& state) {
<< grpc_stats_histo_percentile(
&stats, static_cast<grpc_stats_histograms>(i), 99.0);
}
#ifdef GPR_LOW_LEVEL_COUNTERS
out << " locks/iter:"
<< ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) -
mu_locks_at_start_) /
(double)state.iterations())
<< " atm_cas/iter:"
<< ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_cas) -
atm_cas_at_start_) /
(double)state.iterations())
<< " atm_add/iter:"
<< ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_add) -
atm_add_at_start_) /
(double)state.iterations())
<< " nows/iter:"
<< ((double)(gpr_atm_no_barrier_load(&gpr_now_call_count) -
now_calls_at_start_) /
(double)state.iterations());
#endif
}

@ -41,13 +41,6 @@ class LibraryInitializer {
grpc::internal::GrpcLibrary init_lib_;
};
#ifdef GPR_LOW_LEVEL_COUNTERS
extern gpr_atm gpr_mu_locks;
extern gpr_atm gpr_counter_atm_cas;
extern gpr_atm gpr_counter_atm_add;
extern gpr_atm gpr_now_call_count;
#endif
class TrackCounters {
public:
TrackCounters() { grpc_stats_collect(&stats_begin_); }
@ -59,15 +52,6 @@ class TrackCounters {
private:
grpc_stats_data stats_begin_;
std::vector<std::string> labels_;
#ifdef GPR_LOW_LEVEL_COUNTERS
const size_t mu_locks_at_start_ = gpr_atm_no_barrier_load(&gpr_mu_locks);
const size_t atm_cas_at_start_ =
gpr_atm_no_barrier_load(&gpr_counter_atm_cas);
const size_t atm_add_at_start_ =
gpr_atm_no_barrier_load(&gpr_counter_atm_add);
const size_t now_calls_at_start_ =
gpr_atm_no_barrier_load(&gpr_now_call_count);
#endif
};
#endif

Loading…
Cancel
Save