Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

future: hint need_preempt() accordingly to SEASTAR_DEBUG #8

Open
wants to merge 2 commits into
base: ceph-octopus
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions include/seastar/core/preempt.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ struct preemption_monitor {
std::atomic<uint32_t> tail;
};

}
} // namespace internal

extern __thread const internal::preemption_monitor* g_need_preempt;

inline bool need_preempt() {
namespace internal {

#ifndef SEASTAR_DEBUG
inline bool _need_preempt() {
tchaikov marked this conversation as resolved.
Show resolved Hide resolved
// prevent compiler from eliminating loads in a loop
std::atomic_signal_fence(std::memory_order_seq_cst);
auto np = g_need_preempt;
Expand All @@ -50,9 +52,15 @@ inline bool need_preempt() {
// Possible optimization: read head and tail in a single 64-bit load,
// and find a funky way to compare the two 32-bit halves.
return __builtin_expect(head != tail, false);
#else
return true;
#endif
}
#endif // not SEASTAR_DEBUG

}
} // namespace internal

} // namespace seastar

#ifndef SEASTAR_DEBUG
#define need_preempt() __builtin_expect(::seastar::internal::_need_preempt(), false)
#else
#define need_preempt() true
#endif // not SEASTAR_DEBUG