Skip to content

Commit

Permalink
Fixes necessary to build benchmark tests on OSX Monterey (#1847)
Browse files Browse the repository at this point in the history
Summary:
ToT (Top of Tree) will fail to build if benchmarks are enabled (i.e.  cmake ../ -DBUILD_BENCHMARKS=ON) on Monterey with clang++ 13.1.6.

This patchset will fix the build.

Pull Request resolved: #1847

Reviewed By: Gownta

Differential Revision: D39107587

Pulled By: Orvid

fbshipit-source-id: 0bec33e64ee4d869fd00f8c77ae3aa8a0b0be9a7
  • Loading branch information
Adenilson Cavalcanti authored and facebook-github-bot committed Sep 19, 2022
1 parent f2600f2 commit b0d26c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,8 @@ if (BUILD_TESTS OR BUILD_BENCHMARKS)
TEST padded_test SOURCES PaddedTest.cpp
#TEST poly_test SOURCES PolyTest.cpp
TEST portability_test SOURCES PortabilityTest.cpp
BENCHMARK producer_consumer_queue_benchmark
SOURCES ProducerConsumerQueueBenchmark.cpp
# Turns out this benchmark uses Linux only API for setting CPU affinity i.e. cpu_set_t.
BENCHMARK producer_consumer_queue_benchmark APPLE_DISABLED SOURCES ProducerConsumerQueueBenchmark.cpp
TEST producer_consumer_queue_test SLOW
SOURCES ProducerConsumerQueueTest.cpp
BENCHMARK range_find_benchmark SOURCES RangeFindBenchmark.cpp
Expand Down
9 changes: 8 additions & 1 deletion folly/futures/test/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ void throwWrappedAndCatchWrappedImpl() {
});
}

// Apparently OSX doesn't implement barriers since it is an optional part of
// POSIX realtime threads extension, therefore we test for its presence.
// Details:
// https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html
#if defined(_POSIX_BARRIERS) && (_POSIX_BARRIERS > 0)
// Simulate heavy contention on func
void contend(void (*func)()) {
folly::BenchmarkSuspender s;
Expand All @@ -302,6 +307,7 @@ void contend(void (*func)()) {
s.rehire();
pthread_barrier_destroy(&barrier);
}
#endif

BENCHMARK(throwAndCatch) {
throwAndCatchImpl();
Expand All @@ -321,6 +327,7 @@ BENCHMARK_RELATIVE(throwWrappedAndCatchWrapped) {

BENCHMARK_DRAW_LINE();

#if defined(_POSIX_BARRIERS) && (_POSIX_BARRIERS > 0)
BENCHMARK(throwAndCatchContended) {
contend(throwAndCatchImpl);
}
Expand All @@ -336,8 +343,8 @@ BENCHMARK_RELATIVE(throwWrappedAndCatchContended) {
BENCHMARK_RELATIVE(throwWrappedAndCatchWrappedContended) {
contend(throwWrappedAndCatchWrappedImpl);
}

BENCHMARK_DRAW_LINE();
#endif

namespace {
struct Bulky {
Expand Down
3 changes: 3 additions & 0 deletions folly/test/ProducerConsumerQueueBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct ThroughputTest {
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu0_, &cpuset);
/* TODO(cavalcanti): enable this bench on OSX and use
* pthread_set_qos_self_np for handling big.LITTLE macs.
*/
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
}
for (int i = 0; i < iters_; ++i) {
Expand Down

0 comments on commit b0d26c2

Please sign in to comment.