Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Yet another) Optimization for TLS access #17220

Merged
merged 1 commit into from
Jul 1, 2016
Merged

Conversation

yuyichao
Copy link
Contributor

@yuyichao yuyichao commented Jun 30, 2016

This time for C code on Linux. (I've probably hit a linker bug on aarch64..... Found workaround)

  • Use indirect function (ifunc) to set the address of a symbol at runtime.
  • Use weak symbol to detect (in ifunc) whether the static version of
    TLS is available.

This is actually pretty much the original plan for #14083 (i.e. resolve the symbol to the better version at linker level) before realizing that undefined symbol in shared library is not really well supported on all platforms, and weak symbol doesn't do what most people (me included) would naively assume ;-p....

The use of ifunc in this PR is not particularly reliably in that the weak symbol check might return missing of the static version when it actually exist if the linker does the relocation in the wrong order (ld tries to do it in the right order though and I haven't seen any issue like that on the platforms I've tested). In such case, this should just fallback to the same code with the one on current master.

This is the last bit of optimization I can imagine for linux (apart from starting to pass it around more). The actual performance gain is a hard to measure.

@yuyichao yuyichao added the multithreading Base.Threads and related functionality label Jun 30, 2016
@yuyichao yuyichao force-pushed the yyc/threads/ifunc branch from 840efd5 to 88000ba Compare June 30, 2016 23:06
@yuyichao
Copy link
Contributor Author

Also switch to using __attribute__((constructor)) to register the TLS getter in the main executable now that we don't need to do this on windows and mac anymore.

@yuyichao yuyichao force-pushed the yyc/threads/ifunc branch 3 times, most recently from 83a9fcf to 107acab Compare July 1, 2016 02:10
// more efficient since we can have better control over the creation and
// initialization of the TLS buffer.
//
// On platforms that use ELF (Linux, FreeBSD), we use a `__thread` variable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sentence continues to next line?

@yuyichao yuyichao force-pushed the yyc/threads/ifunc branch from 107acab to 8cf54df Compare July 1, 2016 13:02
* Use indirect function (`ifunc`) to set the address of a symbol at runtime.
* Use `weak` symbol to detect (in `ifunc`) whether the static version of
  TLS is available.
@yuyichao yuyichao force-pushed the yyc/threads/ifunc branch from 8cf54df to 12e32e9 Compare July 1, 2016 13:04
@vtjnash vtjnash merged commit 51464fb into master Jul 1, 2016
@vtjnash vtjnash deleted the yyc/threads/ifunc branch July 1, 2016 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants