Skip to content

Commit

Permalink
Runtime events should never be conditional on debug log level.
Browse files Browse the repository at this point in the history
  • Loading branch information
NickBarnes committed Feb 17, 2025
1 parent f937946 commit a127933
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
18 changes: 7 additions & 11 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,28 +1835,24 @@ static void major_collection_slice(intnat howmuch,
/* Opportunistic slices may run concurrently with gc phase updates. */
int may_access_gc_phase = (mode != Slice_opportunistic);

int log_events = mode != Slice_opportunistic ||
(atomic_load_relaxed(&caml_verb_gc) & 0x40);

update_major_slice_work(howmuch, may_access_gc_phase);

/* When a full slice of major GC work is done,
or the slice is interrupted (in mode Slice_interruptible),
get_major_slice_work(mode) will return a budget <= 0 */

/* shortcut out if there is no opportunistic work to be done
* NB: needed particularly to avoid caml_ev spam when polling */
/* shortcut out if there is no opportunistic work to be done */
if (mode == Slice_opportunistic &&
!caml_opportunistic_major_work_available(domain_state)) {
commit_major_slice_work (0);
return;
}

if (log_events) CAML_EV_BEGIN(EV_MAJOR_SLICE);
CAML_EV_BEGIN(EV_MAJOR_SLICE);
call_timing_hook(&caml_major_slice_begin_hook);

if (!domain_state->sweeping_done) {
if (log_events) CAML_EV_BEGIN(EV_MAJOR_SWEEP);
CAML_EV_BEGIN(EV_MAJOR_SWEEP);

while (!domain_state->sweeping_done &&
(budget = get_major_slice_work(mode)) > 0) {
Expand All @@ -1871,7 +1867,7 @@ static void major_collection_slice(intnat howmuch,
}
}

if (log_events) CAML_EV_END(EV_MAJOR_SWEEP);
CAML_EV_END(EV_MAJOR_SWEEP);
}

if (domain_state->sweeping_done) {
Expand All @@ -1892,7 +1888,7 @@ static void major_collection_slice(intnat howmuch,
if (caml_marking_started() &&
!domain_state->marking_done &&
get_major_slice_work(mode) > 0) {
if (log_events) CAML_EV_BEGIN(EV_MAJOR_MARK);
CAML_EV_BEGIN(EV_MAJOR_MARK);

while (!domain_state->marking_done &&
(budget = get_major_slice_work(mode)) > 0) {
Expand All @@ -1902,7 +1898,7 @@ static void major_collection_slice(intnat howmuch,
commit_major_slice_work(work_done);
}

if (log_events) CAML_EV_END(EV_MAJOR_MARK);
CAML_EV_END(EV_MAJOR_MARK);
}

if (mode != Slice_opportunistic && caml_marking_started()) {
Expand Down Expand Up @@ -2032,7 +2028,7 @@ static void major_collection_slice(intnat howmuch,
}

call_timing_hook(&caml_major_slice_end_hook);
if (log_events) CAML_EV_END(EV_MAJOR_SLICE);
CAML_EV_END(EV_MAJOR_SLICE);

#define F_U "%"ARCH_INTNAT_PRINTF_FORMAT"u"

Expand Down
6 changes: 2 additions & 4 deletions runtime/minor_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,9 @@ int caml_do_opportunistic_major_slice
{
int work_available = caml_opportunistic_major_work_available(domain_state);
if (work_available) {
/* NB: need to put guard around the ev logs to prevent spam when we poll */
uintnat log_events = atomic_load_relaxed(&caml_verb_gc) & 0x40;
if (log_events) CAML_EV_BEGIN(EV_MAJOR_MARK_OPPORTUNISTIC);
CAML_EV_BEGIN(EV_MAJOR_MARK_OPPORTUNISTIC);
caml_opportunistic_major_collection_slice(Major_slice_work_min);
if (log_events) CAML_EV_END(EV_MAJOR_MARK_OPPORTUNISTIC);
CAML_EV_END(EV_MAJOR_MARK_OPPORTUNISTIC);
}
return work_available;
}
Expand Down

0 comments on commit a127933

Please sign in to comment.