tsan: speed up pthread_setname_np
authorDmitry Vyukov <dvyukov@google.com>
Mon, 15 Nov 2021 18:00:31 +0000 (19:00 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 16 Nov 2021 06:51:08 +0000 (07:51 +0100)
commit64b45399e5c547dc59ea3c72891fccdda7284eaa
treed5001173f660d45f644fd4e2270db9beee78ad6d
parentb85f97bc00ae7813e8667e2e87561a490ae1e68e
tsan: speed up pthread_setname_np

pthread_setname_np does linear search over all thread descriptors
to map pthread_t to the thread descriptor. This has O(N^2) complexity
and becomes much worse in the new tsan runtime that keeps all ever
existed threads in the thread registry.
Replace linear search with direct access if pthread_setname_np
is called for the current thread (a very common case).

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D113916
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
compiler-rt/test/tsan/bench_threads.cpp [new file with mode: 0644]