* [PATCH v2] elf: Use C11 atomics on _dl_mcount
@ 2022-09-05 19:14 Adhemerval Zanella
2022-09-05 19:50 ` H.J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2022-09-05 19:14 UTC (permalink / raw)
To: libc-alpha, Wilco Dijkstra
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(-)
diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index ec57e3a965..67a356bf66 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_acquire (&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:
;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] elf: Use C11 atomics on _dl_mcount
2022-09-05 19:14 [PATCH v2] elf: Use C11 atomics on _dl_mcount Adhemerval Zanella
@ 2022-09-05 19:50 ` H.J. Lu
2022-09-06 10:22 ` Wilco Dijkstra
0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2022-09-05 19:50 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: libc-alpha, Wilco Dijkstra
On Mon, Sep 5, 2022 at 12:14 PM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> 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(-)
>
> diff --git a/elf/dl-profile.c b/elf/dl-profile.c
> index ec57e3a965..67a356bf66 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;
Shouldn't it be
unsigned int newarc = atomic_fetch_add_relaxed (narcsp, 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_acquire (&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:
> ;
> --
> 2.34.1
>
--
H.J.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] elf: Use C11 atomics on _dl_mcount
2022-09-05 19:50 ` H.J. Lu
@ 2022-09-06 10:22 ` Wilco Dijkstra
0 siblings, 0 replies; 3+ messages in thread
From: Wilco Dijkstra @ 2022-09-06 10:22 UTC (permalink / raw)
To: H.J. Lu, Adhemerval Zanella; +Cc: libc-alpha
Hi,
On Mon, Sep 5, 2022 at 12:14 PM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> 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(-)
>
> diff --git a/elf/dl-profile.c b/elf/dl-profile.c
> index ec57e3a965..67a356bf66 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;
> Shouldn't it be
>
> unsigned int newarc = atomic_fetch_add_relaxed (narcsp, 1);
Indeed.
>
> /* 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_acquire (&fromidx, 1) + 1;
And this still uses acquire.
Btw it would seem easier and less error prone to split the patches from my
atomics v3 patch - that has already been fully tested.
Cheers,
Wilco
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-06 10:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 19:14 [PATCH v2] elf: Use C11 atomics on _dl_mcount Adhemerval Zanella
2022-09-05 19:50 ` H.J. Lu
2022-09-06 10:22 ` Wilco Dijkstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).