From: Mark Wielaard <mark@klomp.org>
To: Jonathon Anderson <jma14@rice.edu>
Cc: elfutils-devel@sourceware.org, Srdan Milakovic <sm108@rice.edu>
Subject: Re: [PATCH 2/3] libdw: Rewrite the memory handler to be thread-safe.
Date: Thu, 24 Oct 2019 16:47:00 -0000 [thread overview]
Message-ID: <a0e0c7464aea79ae9862b59a7c17725d7e5fdde0.camel@klomp.org> (raw)
In-Reply-To: <f44f9d433ef8b859b9d1a3f42d7ac9a00712a1a2.camel@klomp.org>
Hi,
On Mon, 2019-10-21 at 20:00 +0200, Mark Wielaard wrote:
> I think we cannot use the atomic_load () function, but have to use
> atomic_load_explicit. So it would become:
>
> diff --git a/libdw/dwarf_end.c b/libdw/dwarf_end.c
> index fc573cb3..a2e94436 100644
> --- a/libdw/dwarf_end.c
> +++ b/libdw/dwarf_end.c
> @@ -95,7 +95,10 @@ dwarf_end (Dwarf *dwarf)
> tdestroy (dwarf->split_tree, noop_free);
>
> /* Free the internally allocated memory. */
> - struct libdw_memblock *memp = (struct libdw_memblock *)dwarf->mem_tail;
> + struct libdw_memblock *memp;
> + memp = (struct libdw_memblock *) (atomic_load_explicit
> + (&dwarf->mem_tail,
> + memory_order_relaxed));
> while (memp != NULL)
> {
> struct libdw_memblock *prevp = memp->prev;
I made two more small changes to add error checking for
pthread_key_create and pthread_setspecific, even though I couldn't
trigger any of them to fail in this code, it seemed bad to just ignore
if they would fail:
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index f865f69c..8d137414 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -418,7 +418,12 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp)
actual allocation. */
result->mem_default_size = mem_default_size;
result->oom_handler = __libdw_oom;
- pthread_key_create (&result->mem_key, NULL);
+ if (pthread_key_create (&result->mem_key, NULL) != 0)
+ {
+ free (result);
+ __libdw_seterrno (DWARF_E_NOMEM); /* no memory or max pthread keys. */
+ return NULL;
+ }
atomic_init (&result->mem_tail, (uintptr_t)NULL);
if (cmd == DWARF_C_READ || cmd == DWARF_C_RDWR)
diff --git a/libdw/libdw_alloc.c b/libdw/libdw_alloc.c
index 78977e54..f2e74d18 100644
--- a/libdw/libdw_alloc.c
+++ b/libdw/libdw_alloc.c
@@ -54,7 +54,8 @@ __libdw_allocate (Dwarf *dbg, size_t minsize, size_t align)
newp->prev = (struct libdw_memblock*)atomic_exchange_explicit(
&dbg->mem_tail, (uintptr_t)newp, memory_order_relaxed);
- pthread_setspecific(dbg->mem_key, newp);
+ if (pthread_setspecific (dbg->mem_key, newp) != 0)
+ dbg->oom_handler ();
return (void *) result;
}
With that I pushed it to master. Thanks a lot for this code.
To my surprise the code was actually slightly (although almost in the
noise) faster in the single threaded cases I tested. Well done!
Cheers,
Mark
next prev parent reply other threads:[~2019-10-24 16:47 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-16 19:24 [PATCH] libdw: add thread-safety to dwarf_getabbrev() Jonathon Anderson
2019-08-21 11:16 ` Mark Wielaard
2019-08-21 14:21 ` Jonathon Anderson
2019-08-23 21:22 ` Mark Wielaard
[not found] ` <1566396518.5389.0@smtp.mail.rice.edu>
2019-08-23 18:25 ` Mark Wielaard
2019-08-23 22:36 ` Jonathon Anderson
2019-08-21 21:50 ` Mark Wielaard
2019-08-21 22:01 ` Mark Wielaard
2019-08-21 22:21 ` Jonathon Anderson
2019-08-23 21:26 ` Mark Wielaard
2019-08-24 23:24 ` Mark Wielaard
2019-08-25 1:11 ` Jonathon Anderson
2019-08-25 10:05 ` Mark Wielaard
2019-08-26 1:25 ` Jonathon Anderson
2019-08-26 13:18 ` Mark Wielaard
2019-08-26 13:37 ` Jonathon Anderson
2019-08-27 3:52 ` Jonathon Anderson
2019-08-29 13:16 ` Mark Wielaard
2019-08-29 13:16 ` [PATCH 3/3] lib + libdw: Add and use a concurrent version of the dynamic-size hash table Mark Wielaard
2019-10-25 23:50 ` Mark Wielaard
2019-10-26 4:11 ` Jonathon Anderson
2019-10-27 16:13 ` Mark Wielaard
2019-10-27 17:49 ` Jonathon Anderson
2019-10-28 14:08 ` Mark Wielaard
2019-10-28 20:12 ` Mark Wielaard
2019-11-04 16:21 ` Mark Wielaard
2019-11-04 16:19 ` Mark Wielaard
2019-11-04 17:03 ` [PATCH] " Jonathon Anderson
2019-11-07 11:07 ` Mark Wielaard
2019-11-07 15:25 ` Jonathon Anderson
2019-11-08 14:07 ` Mark Wielaard
2019-11-08 15:29 ` Jonathon Anderson
2019-11-10 23:24 ` Mark Wielaard
2019-11-11 23:38 ` Jonathon Anderson
2019-11-12 21:45 ` Mark Wielaard
2019-08-29 13:16 ` [PATCH 1/3] Add some supporting framework for C11-style atomics Mark Wielaard
2019-10-22 16:31 ` Mark Wielaard
2019-08-29 13:16 ` [PATCH 2/3] libdw: Rewrite the memory handler to be thread-safe Mark Wielaard
2019-10-21 16:13 ` Mark Wielaard
2019-10-21 16:28 ` Jonathon Anderson
2019-10-21 18:00 ` Mark Wielaard
2019-10-24 16:47 ` Mark Wielaard [this message]
2019-10-26 10:54 ` [PATCH] libdw: add thread-safety to dwarf_getabbrev() Florian Weimer
2019-10-26 12:06 ` Mark Wielaard
2019-10-26 16:14 ` Florian Weimer
2019-10-26 16:45 ` Jonathon Anderson
2019-10-26 16:50 ` Florian Weimer
2019-10-26 22:53 ` Mark Wielaard
2019-10-27 8:59 ` Florian Weimer
2019-10-27 18:11 ` Jonathon Anderson
2019-10-27 18:44 ` Florian Weimer
2019-10-26 22:50 ` Mark Wielaard
2019-10-27 0:56 ` Jonathon Anderson
2019-10-28 13:26 ` Mark Wielaard
2019-10-28 15:32 ` Jonathon Anderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a0e0c7464aea79ae9862b59a7c17725d7e5fdde0.camel@klomp.org \
--to=mark@klomp.org \
--cc=elfutils-devel@sourceware.org \
--cc=jma14@rice.edu \
--cc=sm108@rice.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).