소스 검색

Keep things simple. Remove gpr_atm64

Sree Kuchibhotla 7 년 전
부모
커밋
f2f5a9a0a7

+ 0 - 71
include/grpc/impl/codegen/atm64.h

@@ -1,71 +0,0 @@
-/*
- *
- * Copyright 2018 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_IMPL_CODEGEN_ATM64_H
-#define GRPC_IMPL_CODEGEN_ATM64_H
-
-/** This interface provides atomic operations and barriers for 64 bit integer
-   data types (instead of intptr_t so that this works on both 32-bit and 64-bit
-   systems.
-
-   It is internal to gpr support code and should not be used outside it.
-
-   If an operation with acquire semantics precedes another memory access by the
-   same thread, the operation will precede that other access as seen by other
-   threads.
-
-   If an operation with release semantics follows another memory access by the
-   same thread, the operation will follow that other access as seen by other
-   threads.
-
-   Routines with "acq" or "full" in the name have acquire semantics.  Routines
-   with "rel" or "full" in the name have release semantics.  Routines with
-   "no_barrier" in the name have neither acquire not release semantics.
-
-   The routines may be implemented as macros.
-
-   // Atomic operations act on an intergral_type gpr_atm64 that is 64 bit wide
-   typedef int64_t gpr_atm64;
-
-   gpr_atm64 gpr_atm64_no_barrier_load(gpr_atm64 *p);
-
-   // Atomically set *p = value, with release semantics.
-   void gpr_atm64_no_barrier_store(gpr_atm64 *p, gpr_atm64 value);
-*/
-
-#include <grpc/impl/codegen/port_platform.h>
-
-#if defined(GPR_GCC_ATOMIC)
-#include <grpc/impl/codegen/atm64_gcc_atomic.h>
-#elif defined(GPR_GCC_SYNC)
-#include <grpc/impl/codegen/atm64_gcc_sync.h>
-#elif defined(GPR_WINDOWS_ATOMIC)
-#include <grpc/impl/codegen/atm64_windows.h>
-#else
-#error could not determine platform for atm
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* GRPC_IMPL_CODEGEN_ATM64_H */

+ 0 - 42
include/grpc/impl/codegen/atm64_gcc_atomic.h

@@ -1,42 +0,0 @@
-/*
- *
- * Copyright 2018 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_IMPL_CODEGEN_ATM64_GCC_ATOMIC_H
-#define GRPC_IMPL_CODEGEN_ATM64_GCC_ATOMIC_H
-
-/* atm_platform.h for gcc and gcc-like compilers with the
-   __atomic_* interface.  */
-#include <grpc/impl/codegen/port_platform.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef int64_t gpr_atm64;
-#define GPR_ATM64_MAX INT64_MAX
-#define GPR_ATM64_MIN INT64_MIN
-
-#define gpr_atm64_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
-#define gpr_atm64_no_barrier_store(p, value) \
-  (__atomic_store_n((p), (int64_t)(value), __ATOMIC_RELAXED))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* GRPC_IMPL_CODEGEN_ATM64_GCC_ATOMIC_H */

+ 0 - 43
include/grpc/impl/codegen/atm64_gcc_sync.h

@@ -1,43 +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.
- *
- */
-
-#ifndef GRPC_IMPL_CODEGEN_ATM64_GCC_SYNC64_H
-#define GRPC_IMPL_CODEGEN_ATM64_GCC_SYNC64_H
-
-/* variant of atm_platform.h for gcc and gcc-like compiers with __sync_*
-   interface */
-#include <grpc/impl/codegen/port_platform.h>
-
-typedef int64_t gpr_atm64;
-#define GPR_ATM64_MAX INT64_MAX
-#define GPR_ATM64_MIN INT64_MIN
-
-#define GPR_ATM64_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory")
-
-static __inline gpr_atm64 gpr_atm64_no_barrier_load(const gpr_atm64* p) {
-  gpr_atm64 value = *p;
-  GPR_ATM64_COMPILE_BARRIER_();
-  return value;
-}
-
-static __inline void gpr_atm64_no_barrier_store(gpr_atm64* p, gpr_atm64 value) {
-  GPR_ATM64_COMPILE_BARRIER_();
-  *p = value;
-}
-
-#endif /* GRPC_IMPL_CODEGEN_ATM64_GCC_SYNC64_H */

+ 0 - 50
include/grpc/impl/codegen/atm64_windows.h

@@ -1,50 +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.
- *
- */
-
-#ifndef GRPC_IMPL_CODEGEN_ATM64_WINDOWS_H
-#define GRPC_IMPL_CODEGEN_ATM64_WINDOWS_H
-
-/** Win32 variant of atm_platform.h */
-#include <grpc/impl/codegen/port_platform.h>
-
-typedef int64_t gpr_atm64;
-#define GPR_ATM64_MAX INT64_MAX
-#define GPR_ATM64_MIN INT64_MIN
-
-#define gpr_atm64_full_barrier MemoryBarrier
-
-static __inline gpr_atm64 gpr_atm64_acq_load(const gpr_atm64* p) {
-  gpr_atm64 result = *p;
-  gpr_atm64_full_barrier();
-  return result;
-}
-
-static __inline gpr_atm64 gpr_atm64_no_barrier_load(const gpr_atm64* p) {
-  return gpr_atm64_acq_load(p);
-}
-
-static __inline void gpr_atm64_rel_store(gpr_atm64* p, gpr_atm64 value) {
-  gpr_atm64_full_barrier();
-  *p = value;
-}
-
-static __inline void gpr_atm64_no_barrier_store(gpr_atm64* p, gpr_atm64 value) {
-  gpr_atm64_rel_store(p, value);
-}
-
-#endif /* GRPC_IMPL_CODEGEN_ATM64_WINDOWS_H */

+ 0 - 26
include/grpc/support/atm64.h

@@ -1,26 +0,0 @@
-/*
- *
- * Copyright 2018 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_SUPPORT_ATM64_H
-#define GRPC_SUPPORT_ATM64_H
-
-#include <grpc/support/port_platform.h>
-
-#include <grpc/impl/codegen/atm64.h>
-
-#endif /* GRPC_SUPPORT_ATM64_H */

+ 39 - 7
src/core/lib/iomgr/timer_generic.cc

@@ -218,7 +218,7 @@ GPR_TLS_DECL(g_last_seen_min_timer);
 
 struct shared_mutables {
   /* The deadline of the next timer due across all timer shards */
-  gpr_atm64 min_timer;
+  grpc_millis min_timer;
   /* Allow only one run_some_expired_timers at once */
   gpr_spinlock checker_mu;
   bool initialized;
@@ -418,7 +418,14 @@ static void timer_init(grpc_timer* timer, grpc_millis deadline,
       shard->min_deadline = deadline;
       note_deadline_change(shard);
       if (shard->shard_queue_index == 0 && deadline < old_min_deadline) {
-        gpr_atm64_no_barrier_store(&g_shared_mutables.min_timer, deadline);
+#if GPR_ARCH_64
+        gpr_atm_no_barrier_store(&g_shared_mutables.min_timer, deadline);
+#else
+        // On a 32-bit system, gpr_atm_no_barrier_store does not work on 64-bit
+        // types (like grpc_millis). So all reads and writes to
+        // g_shared_mutables.min_timer varialbe under g_shared_mutables.mu
+        g_shared_mutables.min_timer = deadline;
+#endif
         grpc_kick_poller();
       }
     }
@@ -559,10 +566,16 @@ static grpc_timer_check_result run_some_expired_timers(grpc_millis now,
                                                        grpc_error* error) {
   grpc_timer_check_result result = GRPC_TIMERS_NOT_CHECKED;
 
-  grpc_millis min_timer =
-      gpr_atm64_no_barrier_load(&g_shared_mutables.min_timer);
 #if GPR_ARCH_64
+  grpc_millis min_timer =
+      gpr_atm_no_barrier_load(&g_shared_mutables.min_timer);
   gpr_tls_set(&g_last_seen_min_timer, min_timer);
+#else
+  // On a 32-bit system, gpr_atm_no_barrier_load does not work on 64-bit types
+  // (like grpc_millis). So we need to do the read under g_shared_mutables.mu
+  gpr_mu_lock(&g_shared_mutables.mu);
+  grpc_millis min_timer = g_shared_mutables.min_timer;
+  gpr_mu_unlock(&g_shared_mutables.mu);
 #endif
   if (now < min_timer) {
     if (next != nullptr) *next = GPR_MIN(*next, min_timer);
@@ -613,8 +626,15 @@ static grpc_timer_check_result run_some_expired_timers(grpc_millis now,
       *next = GPR_MIN(*next, g_shard_queue[0]->min_deadline);
     }
 
-    gpr_atm64_no_barrier_store(&g_shared_mutables.min_timer,
+#if GPR_ARCH_64
+    gpr_atm_no_barrier_store(&g_shared_mutables.min_timer,
                                g_shard_queue[0]->min_deadline);
+#else
+    // On a 32-bit system, gpr_atm_no_barrier_store does not work on 64-bit
+    // types (like grpc_millis). So all reads and writes to
+    // g_shared_mutables.min_timer are done under g_shared_mutables.mu
+    g_shared_mutables.min_timer = g_shard_queue[0]->min_deadline;
+#endif
     gpr_mu_unlock(&g_shared_mutables.mu);
     gpr_spinlock_unlock(&g_shared_mutables.checker_mu);
   }
@@ -633,8 +653,14 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
      mutable cacheline in the common case */
   grpc_millis min_timer = gpr_tls_get(&g_last_seen_min_timer);
 #else
-  grpc_millis min_timer =
-      gpr_atm64_no_barrier_load(&g_shared_mutables.min_timer);
+  // On a 32-bit system, we do not have thread local support for 64-bit types.
+  // Directly read the valye from g_shared_mutables.min_timer
+  // Also, note that on 32-bit systems, gpr_atm_no_barrier_store does not work
+  // on 64-bit types like grpc_millis. So all reads and writes to
+  // g_shared_mutables.min_timer are done under g_shared_mutables.mu
+  gpr_mu_lock(&g_shared_mutables.mu);
+  grpc_millis min_timer = g_shared_mutables.min_timer;
+  gpr_mu_unlock(&g_shared_mutables.mu);
 #endif
 
   if (now < min_timer) {
@@ -661,11 +687,17 @@ static grpc_timer_check_result timer_check(grpc_millis* next) {
     } else {
       gpr_asprintf(&next_str, "%" PRId64, *next);
     }
+#if GPR_ARCH_64
     gpr_log(GPR_DEBUG,
             "TIMER CHECK BEGIN: now=%" PRId64 " next=%s tls_min=%" PRId64
             " glob_min=%" PRId64,
             now, next_str, min_timer,
             gpr_atm_no_barrier_load(&g_shared_mutables.min_timer));
+#else
+    gpr_log(GPR_DEBUG,
+            "TIMER CHECK BEGIN: now=%" PRId64 " next=%s min=%" PRId64, now,
+            next_str, min_timer);
+#endif
     gpr_free(next_str);
   }
   // actual code