diff mbox series

[v2,1/4] malloc: Remove atomic_* usage

Message ID 20211223173706.1179720-2-adhemerval.zanella@linaro.org
State Committed
Commit 5a5f7a160da6ac3d141013e9a08f78edc216e434
Headers show
Series libmemusage code cleanup | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Dec. 23, 2021, 5:37 p.m. UTC
These typedef are used solely on memusage and can be replaced with
generic types.
---
 malloc/memusage.c          | 36 ++++++++++++++++++------------------
 sysdeps/arc/memusage.h     |  2 --
 sysdeps/generic/memusage.h | 14 --------------
 sysdeps/nios2/memusage.h   |  2 --
 4 files changed, 18 insertions(+), 36 deletions(-)

Comments

Stafford Horne Dec. 27, 2021, 6:09 a.m. UTC | #1
On Thu, Dec 23, 2021 at 02:37:03PM -0300, Adhemerval Zanella via Libc-alpha wrote:
> These typedef are used solely on memusage and can be replaced with
> generic types.
> ---
>  malloc/memusage.c          | 36 ++++++++++++++++++------------------
>  sysdeps/arc/memusage.h     |  2 --
>  sysdeps/generic/memusage.h | 14 --------------
>  sysdeps/nios2/memusage.h   |  2 --
>  4 files changed, 18 insertions(+), 36 deletions(-)
> 
> diff --git a/malloc/memusage.c b/malloc/memusage.c
> index e99f0c1c14..de39ad1c1a 100644
> --- a/malloc/memusage.c
> +++ b/malloc/memusage.c
> @@ -71,20 +71,20 @@ struct header
>  #define MAGIC 0xfeedbeaf
>  
>  
> -static memusage_cntr_t calls[idx_last];
> -static memusage_cntr_t failed[idx_last];
> -static memusage_size_t total[idx_last];
> -static memusage_size_t grand_total;
> -static memusage_cntr_t histogram[65536 / 16];
> -static memusage_cntr_t large;
> -static memusage_cntr_t calls_total;
> -static memusage_cntr_t inplace;
> -static memusage_cntr_t decreasing;
> -static memusage_cntr_t realloc_free;
> -static memusage_cntr_t inplace_mremap;
> -static memusage_cntr_t decreasing_mremap;
> -static memusage_size_t current_heap;
> -static memusage_size_t peak_use[3];
> +static unsigned long int calls[idx_last];
> +static unsigned long int failed[idx_last];
> +static size_t total[idx_last];
> +static size_t grand_total;
> +static unsigned long int histogram[65536 / 16];
> +static unsigned long int large;
> +static unsigned long int calls_total;
> +static unsigned long int inplace;
> +static unsigned long int decreasing;
> +static unsigned long int realloc_free;
> +static unsigned long int inplace_mremap;
> +static unsigned long int decreasing_mremap;
> +static size_t current_heap;
> +static size_t peak_use[3];
>  static __thread uintptr_t start_sp;

OK.

>  /* A few macros to make the source more readable.  */
> @@ -111,7 +111,7 @@ struct entry
>  };
>  
>  static struct entry buffer[2 * DEFAULT_BUFFER_SIZE];
> -static uatomic32_t buffer_cnt;
> +static uint32_t buffer_cnt;
>  static struct entry first;
>  
>  
> @@ -128,7 +128,7 @@ update_data (struct header *result, size_t len, size_t old_len)
>      }
>  
>    /* Compute current heap usage and compare it with the maximum value.  */
> -  memusage_size_t heap
> +  size_t heap
>      = catomic_exchange_and_add (&current_heap, len - old_len) + len - old_len;
>    catomic_max (&peak_heap, heap);
>  
> @@ -161,14 +161,14 @@ update_data (struct header *result, size_t len, size_t old_len)
>    /* Store the value only if we are writing to a file.  */
>    if (fd != -1)
>      {
> -      uatomic32_t idx = catomic_exchange_and_add (&buffer_cnt, 1);
> +      uint32_t idx = catomic_exchange_and_add (&buffer_cnt, 1);
>        if (idx + 1 >= 2 * buffer_size)
>          {
>            /* We try to reset the counter to the correct range.  If
>               this fails because of another thread increasing the
>               counter it does not matter since that thread will take
>               care of the correction.  */
> -          uatomic32_t reset = (idx + 1) % (2 * buffer_size);
> +          uint32_t reset = (idx + 1) % (2 * buffer_size);
>            catomic_compare_and_exchange_val_acq (&buffer_cnt, reset, idx + 1);
>            if (idx >= 2 * buffer_size)
>              idx = reset - 1;

OK.

> diff --git a/sysdeps/arc/memusage.h b/sysdeps/arc/memusage.h
> index 290252a92f..e8a508a8ff 100644
> --- a/sysdeps/arc/memusage.h
> +++ b/sysdeps/arc/memusage.h
> @@ -18,6 +18,4 @@
>  
>  #define GETSP() ({ register uintptr_t stack_ptr asm ("sp"); stack_ptr; })
>  
> -#define uatomic32_t unsigned int
> -
>  #include <sysdeps/generic/memusage.h>
> diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
> index 408e0b891b..c9bde5cd11 100644
> --- a/sysdeps/generic/memusage.h
> +++ b/sysdeps/generic/memusage.h
> @@ -17,7 +17,6 @@
>  
>  
>  #include <limits.h>
> -#include <atomic.h>
>  #include <stdint.h>
>  
>  #ifndef GETSP
> @@ -36,16 +35,3 @@
>      high = usecs >> 32;							   \
>    }
>  #endif
> -
> -#if LONG_BIT == 32
> -# define memusage_cntr_t uatomic32_t
> -#else
> -# define memusage_cntr_t uatomic64_t
> -#endif
> -#ifndef memusage_size_t
> -# if LONG_BIT == 32
> -#  define memusage_size_t uatomic32_t
> -# else
> -#  define memusage_size_t uatomic64_t
> -# endif
> -#endif

OK.

> diff --git a/sysdeps/nios2/memusage.h b/sysdeps/nios2/memusage.h
> index 01618e44a8..6f1c78812d 100644
> --- a/sysdeps/nios2/memusage.h
> +++ b/sysdeps/nios2/memusage.h
> @@ -18,6 +18,4 @@
>  
>  #define GETSP() ({ register uintptr_t stack_ptr asm ("%sp"); stack_ptr; })
>  
> -#define uatomic32_t unsigned int
> -
>  #include <sysdeps/generic/memusage.h>

As I see it, the arch specific bits replace uatomic32_t with unsigned long int from
unsigned int.  However, there should be no physical change so I think it's OK.

This looks good to me.

-Stafford
diff mbox series

Patch

diff --git a/malloc/memusage.c b/malloc/memusage.c
index e99f0c1c14..de39ad1c1a 100644
--- a/malloc/memusage.c
+++ b/malloc/memusage.c
@@ -71,20 +71,20 @@  struct header
 #define MAGIC 0xfeedbeaf
 
 
-static memusage_cntr_t calls[idx_last];
-static memusage_cntr_t failed[idx_last];
-static memusage_size_t total[idx_last];
-static memusage_size_t grand_total;
-static memusage_cntr_t histogram[65536 / 16];
-static memusage_cntr_t large;
-static memusage_cntr_t calls_total;
-static memusage_cntr_t inplace;
-static memusage_cntr_t decreasing;
-static memusage_cntr_t realloc_free;
-static memusage_cntr_t inplace_mremap;
-static memusage_cntr_t decreasing_mremap;
-static memusage_size_t current_heap;
-static memusage_size_t peak_use[3];
+static unsigned long int calls[idx_last];
+static unsigned long int failed[idx_last];
+static size_t total[idx_last];
+static size_t grand_total;
+static unsigned long int histogram[65536 / 16];
+static unsigned long int large;
+static unsigned long int calls_total;
+static unsigned long int inplace;
+static unsigned long int decreasing;
+static unsigned long int realloc_free;
+static unsigned long int inplace_mremap;
+static unsigned long int decreasing_mremap;
+static size_t current_heap;
+static size_t peak_use[3];
 static __thread uintptr_t start_sp;
 
 /* A few macros to make the source more readable.  */
@@ -111,7 +111,7 @@  struct entry
 };
 
 static struct entry buffer[2 * DEFAULT_BUFFER_SIZE];
-static uatomic32_t buffer_cnt;
+static uint32_t buffer_cnt;
 static struct entry first;
 
 
@@ -128,7 +128,7 @@  update_data (struct header *result, size_t len, size_t old_len)
     }
 
   /* Compute current heap usage and compare it with the maximum value.  */
-  memusage_size_t heap
+  size_t heap
     = catomic_exchange_and_add (&current_heap, len - old_len) + len - old_len;
   catomic_max (&peak_heap, heap);
 
@@ -161,14 +161,14 @@  update_data (struct header *result, size_t len, size_t old_len)
   /* Store the value only if we are writing to a file.  */
   if (fd != -1)
     {
-      uatomic32_t idx = catomic_exchange_and_add (&buffer_cnt, 1);
+      uint32_t idx = catomic_exchange_and_add (&buffer_cnt, 1);
       if (idx + 1 >= 2 * buffer_size)
         {
           /* We try to reset the counter to the correct range.  If
              this fails because of another thread increasing the
              counter it does not matter since that thread will take
              care of the correction.  */
-          uatomic32_t reset = (idx + 1) % (2 * buffer_size);
+          uint32_t reset = (idx + 1) % (2 * buffer_size);
           catomic_compare_and_exchange_val_acq (&buffer_cnt, reset, idx + 1);
           if (idx >= 2 * buffer_size)
             idx = reset - 1;
diff --git a/sysdeps/arc/memusage.h b/sysdeps/arc/memusage.h
index 290252a92f..e8a508a8ff 100644
--- a/sysdeps/arc/memusage.h
+++ b/sysdeps/arc/memusage.h
@@ -18,6 +18,4 @@ 
 
 #define GETSP() ({ register uintptr_t stack_ptr asm ("sp"); stack_ptr; })
 
-#define uatomic32_t unsigned int
-
 #include <sysdeps/generic/memusage.h>
diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
index 408e0b891b..c9bde5cd11 100644
--- a/sysdeps/generic/memusage.h
+++ b/sysdeps/generic/memusage.h
@@ -17,7 +17,6 @@ 
 
 
 #include <limits.h>
-#include <atomic.h>
 #include <stdint.h>
 
 #ifndef GETSP
@@ -36,16 +35,3 @@ 
     high = usecs >> 32;							   \
   }
 #endif
-
-#if LONG_BIT == 32
-# define memusage_cntr_t uatomic32_t
-#else
-# define memusage_cntr_t uatomic64_t
-#endif
-#ifndef memusage_size_t
-# if LONG_BIT == 32
-#  define memusage_size_t uatomic32_t
-# else
-#  define memusage_size_t uatomic64_t
-# endif
-#endif
diff --git a/sysdeps/nios2/memusage.h b/sysdeps/nios2/memusage.h
index 01618e44a8..6f1c78812d 100644
--- a/sysdeps/nios2/memusage.h
+++ b/sysdeps/nios2/memusage.h
@@ -18,6 +18,4 @@ 
 
 #define GETSP() ({ register uintptr_t stack_ptr asm ("%sp"); stack_ptr; })
 
-#define uatomic32_t unsigned int
-
 #include <sysdeps/generic/memusage.h>