svn commit: r233063 - stable/9/libexec/rtld-elf
Konstantin Belousov
kib at FreeBSD.org
Sat Mar 17 01:37:41 UTC 2012
Author: kib
Date: Sat Mar 17 01:37:40 2012
New Revision: 233063
URL: http://svn.freebsd.org/changeset/base/233063
Log:
MFC r232777:
Optimize tls_get_addr_common().
Modified:
stable/9/libexec/rtld-elf/rtld.c
Directory Properties:
stable/9/libexec/rtld-elf/ (props changed)
Modified: stable/9/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/9/libexec/rtld-elf/rtld.c Sat Mar 17 01:27:09 2012 (r233062)
+++ stable/9/libexec/rtld-elf/rtld.c Sat Mar 17 01:37:40 2012 (r233063)
@@ -3507,17 +3507,17 @@ unref_dag(Obj_Entry *root)
/*
* Common code for MD __tls_get_addr().
*/
-void *
-tls_get_addr_common(Elf_Addr** dtvp, int index, size_t offset)
+static void *tls_get_addr_slow(Elf_Addr **, int, size_t) __noinline;
+static void *
+tls_get_addr_slow(Elf_Addr **dtvp, int index, size_t offset)
{
- Elf_Addr* dtv = *dtvp;
+ Elf_Addr *newdtv, *dtv;
RtldLockState lockstate;
+ int to_copy;
+ dtv = *dtvp;
/* Check dtv generation in case new modules have arrived */
if (dtv[0] != tls_dtv_generation) {
- Elf_Addr* newdtv;
- int to_copy;
-
wlock_acquire(rtld_bind_lock, &lockstate);
newdtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
to_copy = dtv[1];
@@ -3532,14 +3532,27 @@ tls_get_addr_common(Elf_Addr** dtvp, int
}
/* Dynamically allocate module TLS if necessary */
- if (!dtv[index + 1]) {
+ if (dtv[index + 1] == 0) {
/* Signal safe, wlock will block out signals. */
- wlock_acquire(rtld_bind_lock, &lockstate);
+ wlock_acquire(rtld_bind_lock, &lockstate);
if (!dtv[index + 1])
dtv[index + 1] = (Elf_Addr)allocate_module_tls(index);
lock_release(rtld_bind_lock, &lockstate);
}
- return (void*) (dtv[index + 1] + offset);
+ return ((void *)(dtv[index + 1] + offset));
+}
+
+void *
+tls_get_addr_common(Elf_Addr **dtvp, int index, size_t offset)
+{
+ Elf_Addr *dtv;
+
+ dtv = *dtvp;
+ /* Check dtv generation in case new modules have arrived */
+ if (__predict_true(dtv[0] == tls_dtv_generation &&
+ dtv[index + 1] != 0))
+ return ((void *)(dtv[index + 1] + offset));
+ return (tls_get_addr_slow(dtvp, index, offset));
}
/* XXX not sure what variants to use for arm. */
More information about the svn-src-stable-9
mailing list