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