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

TLS support problem #47

Open
gcongiu opened this issue Jul 11, 2023 · 3 comments
Open

TLS support problem #47

gcongiu opened this issue Jul 11, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@gcongiu
Copy link
Contributor

gcongiu commented Jul 11, 2023

_papi_hwi_my_thread is a TLS global variable. The variable, currently, is guarded in both threads.c & threads.h and declared only if the PAPI configure script can detect TLS support (either by default or as selected by the user through the --with-tls=<keyword> configure option). If TLS support is not detected the variable is undeclared and the build fails, as following reported by static analysis:

/spack/opt/spack/linux-rocky8-x86_64/gcc-9.5.0/llvm-16.0.6-gweege3utpobgkimb4fej76zih53yc6i/bin/../libexec/ccc-analyzer -fPIC -DPIC -shared -Wl,-soname -Wl,libpapi.so.7.0 -Xlinker "-rpath" -Xlinker "/usr/local/lib" -DPAPI_NO_MEMORY_MANAGEMENT -DSTATIC_PAPI_EVENTS_TABLE  -DUSE_PERFEVENT_RDPMC=1 -DPEINCLUDE=\"libpfm4/include/perfmon/perf_event.h\" -D_REENTRANT -D_GNU_SOURCE -DNO_TLS -Ilibpfm4/include -fvisibility=hidden -I. -g -Wextra  -Wall -DPAPI_NUM_COMP=3 -DOSLOCK=\"linux-lock.h\" -DOSCONTEXT=\"linux-context.h\" -O2 x86_cpuid_info.c papi_libpfm4_events.c papi.c papi_internal.c high-level/papi_hl.c extras.c sw_multiplex.c upper_PAPI_FWRAPPERS.c papi_fwrappers_.c papi_fwrappers__.c threads.c cpus.c linux-memory.c linux-timer.c linux-common.c  papi_preset.c papi_vector.c papi_memory.c components/perf_event/perf_event.c components/perf_event/pe_libpfm4_events.c components/perf_event_uncore/perf_event_uncore.c components/sysdetect/sysdetect.c components/sysdetect/nvidia_gpu.c components/sysdetect/amd_gpu.c components/sysdetect/cpu.c components/sysdetect/cpu_utils.c components/sysdetect/os_cpu_utils.c components/sysdetect/linux_cpu_utils.c components/sysdetect/x86_cpu_utils.c  -o libpapi.so.7.0.1.0 -Bdynamic -Llibpfm4/lib -lpfm 
[402](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:403)
papi_internal.c: In function ‘_papi_hwi_set_papi_event_code’:
[403](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:404)
papi_internal.c:124:3: error: ‘_papi_hwi_my_thread’ undeclared (first use in this function); did you mean ‘_papi_hwi_read’?
[404](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:405)
   _papi_hwi_my_thread->tls_papi_event_code_changed = -1;
[405](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:406)
   ^~~~~~~~~~~~~~~~~~~
[406](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:407)
   _papi_hwi_read
[407](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:408)
papi_internal.c:124:3: note: each undeclared identifier is reported only once for each function it appears in
[408](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:409)
papi_internal.c: In function ‘_papi_hwi_get_papi_event_code’:
[409](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:410)
papi_internal.c:138:9: error: ‘_papi_hwi_my_thread’ undeclared (first use in this function); did you mean ‘_papi_hwi_read’?
[410](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:411)
  return _papi_hwi_my_thread->tls_papi_event_code;
[411](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:412)
         ^~~~~~~~~~~~~~~~~~~
[412](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:413)
         _papi_hwi_read
[413](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:414)
papi_internal.c: In function ‘_papi_hwi_native_to_eventcode’:
[414](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:415)
papi_internal.c:565:7: error: ‘_papi_hwi_my_thread’ undeclared (first use in this function); did you mean ‘_papi_hwi_read’?
[415](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:416)
   if (_papi_hwi_my_thread->tls_papi_event_code_changed > 0) {
[416](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:417)
       ^~~~~~~~~~~~~~~~~~~
[417](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:418)
       _papi_hwi_read
[418](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:419)
papi_internal.c: In function ‘_papi_hwi_get_papi_event_code’:
[419](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:420)
papi_internal.c:139:1: warning: control reaches end of non-void function [-Wreturn-type]
[420](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:421)
 }
[421](https://github.com/icl-utk-edu/papi/actions/runs/5519307326/jobs/10064398824?pr=45#step:3:422)
 ^
@gcongiu gcongiu added the bug Something isn't working label Jul 11, 2023
@gcongiu
Copy link
Contributor Author

gcongiu commented Jul 11, 2023

@jagode, threads.c contains the following code:

#ifdef HAVE_THREAD_LOCAL_STORAGE
#define THREAD_LOCAL_STORAGE_KEYWORD HAVE_THREAD_LOCAL_STORAGE
#else
#define THREAD_LOCAL_STORAGE_KEYWORD
#endif

#if defined(HAVE_THREAD_LOCAL_STORAGE)
extern THREAD_LOCAL_STORAGE_KEYWORD ThreadInfo_t *_papi_hwi_my_thread;
#endif

The code above has the following problem: if, for some reason, the PAPI configure script is unable to automatically detect the supported TLS and set HAVE_THREAD_LOCAL_STORAGE to the right keyword (e.g. __thread), PAPI fails to build. I don't think this is reasonable and we should have a fallback for when this happens. It almost looks like the code above had some logic to account for a fallback through the THREAD_LOCAL_STORAGE_KEYWORD, but that seems an half baked solution to me. In reality there is no real fallback.

@ashterenli
Copy link

I think I'm hitting this problem, when trying to build papi-7.0.1 with AMD aocc 4.1.0, which is based on clang-16.

I get:

checking for high performance thread local storage... no

and than

cc -fPIC -DPIC -shared -Wl,-soname -Wl,libpapi.so.7.0 -Xlinker "-rpath" -Xlinker "/localhome/shterenlikht/install/u_aocc/4.1.0/papi-7.0.1/lib" -DPAPI_NO_MEMORY_MANAGEMENT -DSTATIC_PAPI     _EVENTS_TABLE  -DUSE_PERFEVENT_RDPMC=1 -DPEINCLUDE=\"libpfm4/include/perfmon/perf_event.h\" -D_REENTRANT -D_GNU_SOURCE -DNO_TLS

Note -DNO_TLS

and finally:

2741 papi_internal.c:124:3: error: use of undeclared identifier '_papi_hwi_my_thread'; did you mean '_papi_hwi_read'?
2742                 _papi_hwi_my_thread->tls_papi_event_code_changed = -1;
2743                 ^~~~~~~~~~~~~~~~~~~
2744                 _papi_hwi_read
2745 ./papi_internal.h:466:5: note: '_papi_hwi_read' declared here
2746 int _papi_hwi_read( hwd_context_t * context, EventSetInfo_t * ESI,
2747     ^

@ashterenli
Copy link

Adding --with-tls=_Thread_local seems to work:

checking for high performance thread local storage... _Thread_local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants