diff mbox series

[v3] elf: Use C11 atomics on _dl_mcount

Message ID 20220920190413.3160597-1-adhemerval.zanella@linaro.org
State New
Headers show
Series [v3] elf: Use C11 atomics on _dl_mcount | expand

Commit Message

Adhemerval Zanella Sept. 20, 2022, 7:04 p.m. UTC
All atomic operation are counters, so relaxed MO should be suffice.

Checked on x86_64-linux-gnu.
---
 elf/dl-profile.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Wilco Dijkstra Sept. 20, 2022, 10:59 p.m. UTC | #1
Hi Adhemerval,


@@ -558,14 +558,14 @@ _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
           /* If we still have no entry stop searching and insert.  */
           if (*topcindex == 0)
             {
-             unsigned int newarc = catomic_exchange_and_add (narcsp, 1);
+             unsigned int newarc = atomic_fetch_add_relaxed (narcsp, 1) + 1;
 
This adds a spurious + 1. Other than that it looks good to me.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>

Cheers,
Wilco
Adhemerval Zanella Sept. 21, 2022, 2:01 p.m. UTC | #2
On 20/09/22 19:59, Wilco Dijkstra wrote:
> Hi Adhemerval,
> 
> 
> @@ -558,14 +558,14 @@ _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
>            /* If we still have no entry stop searching and insert.  */
>            if (*topcindex == 0)
>              {
> -             unsigned int newarc = catomic_exchange_and_add (narcsp, 1);
> +             unsigned int newarc = atomic_fetch_add_relaxed (narcsp, 1) + 1;
>  
> This adds a spurious + 1. Other than that it looks good to me.

Thanks, I have removed it.

> 
> Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
> 
> Cheers,
> Wilco
diff mbox series

Patch

diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index ec57e3a965..c5ac9b5a3e 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -548,7 +548,7 @@  _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
 	      size_t newfromidx;
 	      to_index = (data[narcs].self_pc
 			  / (HASHFRACTION * sizeof (*tos)));
-	      newfromidx = catomic_exchange_and_add (&fromidx, 1) + 1;
+	      newfromidx = atomic_fetch_add_relaxed (&fromidx, 1) + 1;
 	      froms[newfromidx].here = &data[narcs];
 	      froms[newfromidx].link = tos[to_index];
 	      tos[to_index] = newfromidx;
@@ -558,14 +558,14 @@  _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
 	  /* If we still have no entry stop searching and insert.  */
 	  if (*topcindex == 0)
 	    {
-	      unsigned int newarc = catomic_exchange_and_add (narcsp, 1);
+	      unsigned int newarc = atomic_fetch_add_relaxed (narcsp, 1) + 1;
 
 	      /* In rare cases it could happen that all entries in FROMS are
 		 occupied.  So we cannot count this anymore.  */
 	      if (newarc >= fromlimit)
 		goto done;
 
-	      *topcindex = catomic_exchange_and_add (&fromidx, 1) + 1;
+	      *topcindex = atomic_fetch_add_relaxed (&fromidx, 1) + 1;
 	      fromp = &froms[*topcindex];
 
 	      fromp->here = &data[newarc];
@@ -573,7 +573,7 @@  _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
 	      data[newarc].self_pc = selfpc;
 	      data[newarc].count = 0;
 	      fromp->link = 0;
-	      catomic_increment (&narcs);
+	      atomic_fetch_add_relaxed (&narcs, 1);
 
 	      break;
 	    }
@@ -586,7 +586,7 @@  _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
     }
 
   /* Increment the counter.  */
-  catomic_increment (&fromp->here->count);
+  atomic_fetch_add_relaxed (&fromp->here->count, 1);
 
  done:
   ;