Skip to content

Conversation

@mtrofin
Copy link
Contributor

@mtrofin mtrofin commented Aug 9, 2023

Using state.PauseTiming() / state.ResumeTiming() was broken.

Thanks @virajbshah for the the repro testcase.

}

static void CheckInstrCount(Results const& e) {
CHECK_COUNTER_VALUE(e, double, "INSTRUCTIONS", GT, kIters);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with pause and resume, shouldn't this be GT 2*kIters? i don't know how the INSTRUCTIONS perf counters work so i could be wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the point is that the second loop - the one within the pause/resume - is not counted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah ok.. but then if it is counted > kIters is still going to be true. so i think you need a LT check too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - the current test checks against the original regression, but I see what you mean. Ideally we'd check that the value in the "with pause resume" is < 2 * "value in the without pause resume". Is there a recommended way to do that, other than capturing the value in the "without pause resume" in some global and relying on execution order?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would LT, 1.5*kIters not be enough at least for an upper bound?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each iteration executes a bit of instructions, and it depends on opt level how many (and architecture)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't rely on execution order. we can guarantee that both have run when RunOutputTests completes, so maybe we can store the number of instructions for both BMs and compare them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is rather fragile, but seems fine in general.
Thank you.

@dmah42 dmah42 merged commit 1c64a36 into google:main Aug 11, 2023
@dmah42
Copy link
Member

dmah42 commented Aug 11, 2023

thanks!

jmr added a commit to jmr/benchmark that referenced this pull request Aug 21, 2023
Previously, `counters` was updated in `PauseTiming()` with
`counters[name] += Counter(measurement, kAvgIteration)`.

The first `counters[name]` call inserts a counter with no flags.

There is no `operator+=` for `Counter`, so the insertion is done
by converting the `Counter` to a `double`, then constructing a
`Counter` to insert from the `double`, which drops the flags.

Pre-insert the `Counter` with the correct flags, then only
update `Counter::value`.

Introduced in 1c64a36 ([perf-counters] Fix pause/resume (google#1643)).
dmah42 added a commit that referenced this pull request Aug 21, 2023
* State: Initialize counters with kAvgIteration in constructor

Previously, `counters` was updated in `PauseTiming()` with
`counters[name] += Counter(measurement, kAvgIteration)`.

The first `counters[name]` call inserts a counter with no flags.

There is no `operator+=` for `Counter`, so the insertion is done
by converting the `Counter` to a `double`, then constructing a
`Counter` to insert from the `double`, which drops the flags.

Pre-insert the `Counter` with the correct flags, then only
update `Counter::value`.

Introduced in 1c64a36 ([perf-counters] Fix pause/resume (#1643)).

* perf_counters_test.cc: Don't divide by iterations

Perf counters are now divided by iterations, so dividing again
in the test is wrong.

* State: Fix shadowed param error

* benchmark.cc: Fix clang-tidy error

---------

Co-authored-by: dominic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants