Skip to content

Commit

Permalink
[OpenMP] Fix build errors when building with KMP_DEBUG_ADAPTIVE_LOCKS=1
Browse files Browse the repository at this point in the history
This change fixes build errors when building a runtime with adaptive lock stats
enabled. Most of the errors were due to the recent changes in the runtime, but
it seems that we have not tried to build this debug runtime on Windows for a
long time.

Patch by Hansang Bae

Differential Revision: https://reviews.llvm.org/D49823

llvm-svn: 338277
  • Loading branch information
jpeyton52 committed Jul 30, 2018
1 parent f0682ac commit 8692e14
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion openmp/runtime/src/kmp.h
Expand Up @@ -3017,7 +3017,7 @@ struct kmp_adaptive_backoff_params_t {
extern kmp_adaptive_backoff_params_t __kmp_adaptive_backoff_params;

#if KMP_DEBUG_ADAPTIVE_LOCKS
extern char *__kmp_speculative_statsfile;
extern const char *__kmp_speculative_statsfile;
#endif

#endif // KMP_USE_ADAPTIVE_LOCKS
Expand Down
2 changes: 1 addition & 1 deletion openmp/runtime/src/kmp_global.cpp
Expand Up @@ -204,7 +204,7 @@ kmp_adaptive_backoff_params_t __kmp_adaptive_backoff_params = {
1, 1024}; // TODO: tune it!

#if KMP_DEBUG_ADAPTIVE_LOCKS
char *__kmp_speculative_statsfile = "-";
const char *__kmp_speculative_statsfile = "-";
#endif

#endif // KMP_USE_ADAPTIVE_LOCKS
Expand Down
21 changes: 11 additions & 10 deletions openmp/runtime/src/kmp_lock.cpp
Expand Up @@ -20,6 +20,7 @@
#include "kmp_itt.h"
#include "kmp_lock.h"
#include "kmp_wait_release.h"
#include "kmp_wrapper_getpid.h"

#include "tsan_annotations.h"

Expand Down Expand Up @@ -1870,13 +1871,15 @@ static kmp_adaptive_lock_statistics_t destroyedStats;
static kmp_adaptive_lock_info_t liveLocks;

// A lock so we can safely update the list of locks.
static kmp_bootstrap_lock_t chain_lock;
static kmp_bootstrap_lock_t chain_lock =
KMP_BOOTSTRAP_LOCK_INITIALIZER(chain_lock);

// Initialize the list of stats.
void __kmp_init_speculative_stats() {
kmp_adaptive_lock_info_t *lck = &liveLocks;

memset((void *)&(lck->stats), 0, sizeof(lck->stats));
memset(CCAST(kmp_adaptive_lock_statistics_t *, &(lck->stats)), 0,
sizeof(lck->stats));
lck->stats.next = lck;
lck->stats.prev = lck;

Expand Down Expand Up @@ -1914,7 +1917,8 @@ static void __kmp_forget_lock(kmp_adaptive_lock_info_t *lck) {
}

static void __kmp_zero_speculative_stats(kmp_adaptive_lock_info_t *lck) {
memset((void *)&lck->stats, 0, sizeof(lck->stats));
memset(CCAST(kmp_adaptive_lock_statistics_t *, &lck->stats), 0,
sizeof(lck->stats));
__kmp_remember_lock(lck);
}

Expand All @@ -1931,8 +1935,6 @@ static void __kmp_add_stats(kmp_adaptive_lock_statistics_t *t,
}

static void __kmp_accumulate_speculative_stats(kmp_adaptive_lock_info_t *lck) {
kmp_adaptive_lock_statistics_t *t = &destroyedStats;

__kmp_acquire_bootstrap_lock(&chain_lock);

__kmp_add_stats(&destroyedStats, lck);
Expand Down Expand Up @@ -1960,11 +1962,6 @@ static FILE *__kmp_open_stats_file() {
}

void __kmp_print_speculative_stats() {
if (__kmp_user_lock_kind != lk_adaptive)
return;

FILE *statsFile = __kmp_open_stats_file();

kmp_adaptive_lock_statistics_t total = destroyedStats;
kmp_adaptive_lock_info_t *lck;

Expand All @@ -1977,6 +1974,10 @@ void __kmp_print_speculative_stats() {
kmp_uint32 totalSpeculations = t->successfulSpeculations +
t->hardFailedSpeculations +
t->softFailedSpeculations;
if (totalSections <= 0)
return;

FILE *statsFile = __kmp_open_stats_file();

fprintf(statsFile, "Speculative lock statistics (all approximate!)\n");
fprintf(statsFile, " Lock parameters: \n"
Expand Down
4 changes: 2 additions & 2 deletions openmp/runtime/src/kmp_settings.cpp
Expand Up @@ -385,7 +385,7 @@ static void __kmp_stg_parse_int(

#if KMP_DEBUG_ADAPTIVE_LOCKS
static void __kmp_stg_parse_file(char const *name, char const *value,
char *suffix, char **out) {
const char *suffix, char **out) {
char buffer[256];
char *t;
int hasSuffix;
Expand Down Expand Up @@ -4236,7 +4236,7 @@ static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
static void __kmp_stg_parse_speculative_statsfile(char const *name,
char const *value,
void *data) {
__kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
__kmp_stg_parse_file(name, value, "", CCAST(char**, &__kmp_speculative_statsfile));
} // __kmp_stg_parse_speculative_statsfile

static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
Expand Down

0 comments on commit 8692e14

Please sign in to comment.