Skip to content

Commit

Permalink
ensure that get_timing_subsystem and DISABLE_SUBSYSTEM agree on u…
Browse files Browse the repository at this point in the history
…sing sorted indices

previously, `get_timing_subsystem` used sorted indices while `DISABLE_SUBSYSTEM` used non sorted which lead to the wrong zones getting disabled.
  • Loading branch information
KristofferC committed May 26, 2023
1 parent 68d05c4 commit 903ce26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ static const int indirect_strcmp(const void *a, const void *b) {
return strcmp(*(const char **)a, *(const char **)b);
}

static inline int get_timing_subsystem(const char *subsystem) {
const char **match = (const char **)bsearch(
&subsystem, jl_timing_subsystems, JL_TIMING_SUBSYSTEM_LAST,
sizeof(const char *), indirect_strcmp
);
if (!match)
return JL_TIMING_SUBSYSTEM_LAST;
return (int)(match - &jl_timing_subsystems[0]);
}

void jl_init_timing(void)
{
t0 = cycleclock();
Expand Down Expand Up @@ -154,7 +164,11 @@ void jl_init_timing(void)
* files, so we disable them by default.
**/
#ifdef DISABLE_FREQUENT_EVENTS
#define DISABLE_SUBSYSTEM(subsystem) jl_atomic_fetch_or_relaxed(jl_timing_disable_mask + (JL_TIMING_##subsystem / (sizeof(uint64_t) * CHAR_BIT)), 1 << (JL_TIMING_##subsystem % (sizeof(uint64_t) * CHAR_BIT)))
#define DISABLE_SUBSYSTEM(subsystem) \
do { \
int sorted_subsystem = get_timing_subsystem(#subsystem); \
jl_atomic_fetch_or_relaxed(jl_timing_disable_mask + (sorted_subsystem / (sizeof(uint64_t) * CHAR_BIT)), (uint64_t)1 << (sorted_subsystem % (sizeof(uint64_t) * CHAR_BIT))); \
} while (0)
DISABLE_SUBSYSTEM(ROOT);
DISABLE_SUBSYSTEM(TYPE_CACHE_LOOKUP);
DISABLE_SUBSYSTEM(METHOD_MATCH);
Expand All @@ -175,17 +189,6 @@ void jl_destroy_timing(void)
}
}

static const int get_timing_subsystem(const char *subsystem) {
const char **match = (const char **)bsearch(
&subsystem, jl_timing_subsystems, JL_TIMING_SUBSYSTEM_LAST,
sizeof(const char *), indirect_strcmp
);
if (!match)
return JL_TIMING_SUBSYSTEM_LAST;

return (int)(match - &jl_timing_subsystems[0]);
}

#ifdef USE_TIMING_COUNTS

// This function is analogous to __itt_event_create but for the counts backend
Expand Down
2 changes: 1 addition & 1 deletion src/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ struct _jl_timing_block_t { // typedef in julia.h
};

STATIC_INLINE int _jl_timing_enabled(int subsystem) JL_NOTSAFEPOINT {
return (jl_atomic_load_relaxed(jl_timing_disable_mask + subsystem / (sizeof(uint64_t) * CHAR_BIT)) & (1 << (subsystem % (sizeof(uint64_t) * CHAR_BIT)))) == 0;
return (jl_atomic_load_relaxed(jl_timing_disable_mask + subsystem / (sizeof(uint64_t) * CHAR_BIT)) & ((uint64_t)1 << (subsystem % (sizeof(uint64_t) * CHAR_BIT)))) == 0;
}

typedef struct _jl_timing_suspend_t {
Expand Down

0 comments on commit 903ce26

Please sign in to comment.