4f751f
commit 617eeabe0bbfb5357c10b22ebd72b24a4a872e52
4f751f
Author: Anthony <adanalis@icl.utk.edu>
4f751f
Date:   Mon Jan 6 15:09:42 2020 -0500
4f751f
4f751f
    Updated the variables that are used in the debug messages in accordance to a previous commit that made these variables thread safe.
4f751f
4f751f
diff --git a/src/papi_internal.c b/src/papi_internal.c
4f751f
index f0e457bf7..69b2914d0 100644
4f751f
--- a/src/papi_internal.c
4f751f
+++ b/src/papi_internal.c
4f751f
@@ -114,7 +114,7 @@ _papi_hwi_free_papi_event_string() {
4f751f
 
4f751f
 void
4f751f
 _papi_hwi_set_papi_event_code (unsigned int event_code, int update_flag) {
4f751f
-	INTDBG("new event_code: %#x, update_flag: %d, previous event_code: %#x\n", event_code, update_flag, papi_event_code);
4f751f
+	INTDBG("new event_code: %#x, update_flag: %d, previous event_code: %#x\n", event_code, update_flag, _papi_hwi_my_thread->tls_papi_event_code);
4f751f
 
4f751f
 	// if call is just to reset and start over, set both flags to show nothing saved yet
4f751f
 	if (update_flag < 0) {
4f751f
@@ -131,7 +131,7 @@ _papi_hwi_set_papi_event_code (unsigned int event_code, int update_flag) {
4f751f
 }
4f751f
 unsigned int
4f751f
 _papi_hwi_get_papi_event_code () {
4f751f
-	INTDBG("papi_event_code: %#x\n", papi_event_code);
4f751f
+	INTDBG("papi_event_code: %#x\n", _papi_hwi_my_thread->tls_papi_event_code);
4f751f
 	return _papi_hwi_my_thread->tls_papi_event_code;
4f751f
 }
4f751f
 /* Get the index into the ESI->NativeInfoArray for the current PAPI event code */
4f751f
From 3cc3b6679e1ace7516c3037105ad16410ce7d3db Mon Sep 17 00:00:00 2001
4f751f
From: William Cohen <wcohen@redhat.com>
4f751f
Date: Wed, 12 Aug 2020 10:12:59 -0400
4f751f
Subject: [PATCH] Initialize component globals before threads globals
4f751f
4f751f
An earlier commit (979e80136) swapped the order of initializing
4f751f
globals and threads.  This caused issues with the perf_event, appio,
4f751f
and stealtime components which could be observed with the
4f751f
all_native_events, appio_test_pthreads, and stealtime_basic tests
4f751f
respectively.  The component initialization needs to be performed
4f751f
before the thread initialization.
4f751f
4f751f
The order of initialization has been changed back to initializing the
4f751f
component then the threads.  One complication is that papi_internal.c
4f751f
had functions (_papi_hwi_set_papi_event_code and
4f751f
_papi_hwi_get_papi_event_code) that required thread local storage that
4f751f
was being setup in commit 979e80136 by the thread initialization.
4f751f
This was the original reason for swapping the order of initialization
4f751f
of component and thread.  Using __thread on the file scope
4f751f
declarations of the variables allow the original order of
4f751f
initialization.
4f751f
---
4f751f
 src/papi.c          | 10 +++++-----
4f751f
 src/papi_internal.c | 21 +++++++++++++--------
4f751f
 2 files changed, 18 insertions(+), 13 deletions(-)
4f751f
4f751f
diff --git a/src/papi.c b/src/papi.c
4f751f
index 33cc29935..107a15044 100644
4f751f
--- a/src/papi.c
4f751f
+++ b/src/papi.c
4f751f
@@ -1151,19 +1151,19 @@ PAPI_library_init( int version )
4f751f
 	   papi_return( init_retval );
4f751f
 	}
4f751f
 
4f751f
-	/* Initialize thread globals, including the main threads  */
4f751f
+	/* Initialize component globals */
4f751f
 
4f751f
-	tmp = _papi_hwi_init_global_threads(  );
4f751f
+	tmp = _papi_hwi_init_global(  );
4f751f
 	if ( tmp ) {
4f751f
 		init_retval = tmp;
4f751f
 		_papi_hwi_shutdown_global_internal(  );
4f751f
-   	_in_papi_library_init_cnt--;
4f751f
+		_in_papi_library_init_cnt--;
4f751f
 		papi_return( init_retval );
4f751f
 	}
4f751f
 
4f751f
-	/* Initialize component globals */
4f751f
+	/* Initialize thread globals, including the main threads  */
4f751f
 
4f751f
-	tmp = _papi_hwi_init_global(  );
4f751f
+	tmp = _papi_hwi_init_global_threads(  );
4f751f
 	if ( tmp ) {
4f751f
 		init_retval = tmp;
4f751f
 		_papi_hwi_shutdown_global_internal(  );
4f751f
diff --git a/src/papi_internal.c b/src/papi_internal.c
4f751f
index 5a1ccd433..bdf30f875 100644
4f751f
--- a/src/papi_internal.c
4f751f
+++ b/src/papi_internal.c
4f751f
@@ -115,27 +115,32 @@ _papi_hwi_free_papi_event_string() {
4f751f
 	return;
4f751f
 }
4f751f
 
4f751f
+// A place to keep the current papi event code so some component functions can fetch its value
4f751f
+// The current event code can be stored here prior to component calls and cleared after the component returns
4f751f
+static THREAD_LOCAL_STORAGE_KEYWORD unsigned int papi_event_code = -1;
4f751f
+static THREAD_LOCAL_STORAGE_KEYWORD int papi_event_code_changed = -1;
4f751f
+
4f751f
 void
4f751f
 _papi_hwi_set_papi_event_code (unsigned int event_code, int update_flag) {
4f751f
-	INTDBG("new event_code: %#x, update_flag: %d, previous event_code: %#x\n", event_code, update_flag, _papi_hwi_my_thread->tls_papi_event_code);
4f751f
+	INTDBG("new event_code: %#x, update_flag: %d, previous event_code: %#x\n", event_code, update_flag, papi_event_code);
4f751f
 
4f751f
 	// if call is just to reset and start over, set both flags to show nothing saved yet
4f751f
 	if (update_flag < 0) {
4f751f
-		_papi_hwi_my_thread->tls_papi_event_code_changed = -1;
4f751f
-		_papi_hwi_my_thread->tls_papi_event_code = -1;
4f751f
+		papi_event_code_changed = -1;
4f751f
+		papi_event_code = -1;
4f751f
 		return;
4f751f
 	}
4f751f
 
4f751f
 	// if 0, it is being set prior to calling a component, if >0 it is being changed by the component
4f751f
-	_papi_hwi_my_thread->tls_papi_event_code_changed = update_flag;
4f751f
+	papi_event_code_changed = update_flag;
4f751f
 	// save the event code passed in
4f751f
-	_papi_hwi_my_thread->tls_papi_event_code = event_code;
4f751f
+	papi_event_code = event_code;
4f751f
 	return;
4f751f
 }
4f751f
 unsigned int
4f751f
 _papi_hwi_get_papi_event_code () {
4f751f
-	INTDBG("papi_event_code: %#x\n", _papi_hwi_my_thread->tls_papi_event_code);
4f751f
-	return _papi_hwi_my_thread->tls_papi_event_code;
4f751f
+	INTDBG("papi_event_code: %#x\n", papi_event_code);
4f751f
+	return papi_event_code;
4f751f
 }
4f751f
 /* Get the index into the ESI->NativeInfoArray for the current PAPI event code */
4f751f
 int
4f751f
@@ -560,7 +565,7 @@ _papi_hwi_native_to_eventcode(int cidx, int event_code, int ntv_idx, const char
4f751f
 
4f751f
   int result;
4f751f
 
4f751f
-  if (_papi_hwi_my_thread->tls_papi_event_code_changed > 0) {
4f751f
+  if (papi_event_code_changed > 0) {
4f751f
 	  result = _papi_hwi_get_papi_event_code();
4f751f
 	  INTDBG("EXIT: papi_event_code: %#x set by the component\n", result);
4f751f
 	  return result;
4f751f
-- 
4f751f
2.26.2
4f751f