-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[DRAFT, don't review yet] Rewrite the IO scheduling algorithm to ensure cross-shard fairness of tokens #2596
Draft
michoecho
wants to merge
4
commits into
scylladb:master
Choose a base branch
from
michoecho:io_sched_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+342
−50
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
#pragma once | ||
|
||
#include <deque> | ||
#include <vector> | ||
#include <cstdint> | ||
#include <cstring> | ||
#include <seastar/core/byteorder.hh> | ||
|
||
namespace seastar { | ||
|
||
struct tracer { | ||
static constexpr size_t buffer_size = (128 * 1024); | ||
std::deque<std::vector<std::byte>> _old; | ||
std::vector<std::byte> _current; | ||
size_t _cur_pos = 0; | ||
|
||
tracer() { | ||
for (int i = 0; i < 480; ++i) { | ||
_old.push_back(std::vector<std::byte>()); | ||
} | ||
_current.resize(buffer_size); | ||
} | ||
|
||
void rotate() { | ||
_current.resize(_cur_pos); | ||
_old.push_back(std::move(_current)); | ||
_current = std::move(_old.front()); | ||
_old.pop_front(); | ||
_current.resize(buffer_size); | ||
_cur_pos = 0; | ||
} | ||
|
||
std::byte* write(size_t n) { | ||
if (_current.size() - _cur_pos < n) [[unlikely]] { | ||
rotate(); | ||
} | ||
auto result = &_current[_cur_pos]; | ||
_cur_pos += n; | ||
return result; | ||
} | ||
|
||
std::deque<std::vector<std::byte>> snapshot() { | ||
auto result = _old; | ||
auto cur = _current; | ||
cur.resize(_cur_pos); | ||
result.push_back(cur); | ||
return result; | ||
} | ||
|
||
uint64_t rdtsc() { | ||
uint64_t rax, rdx; | ||
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) ); | ||
return (uint64_t)(( rdx << 32 ) + rax); | ||
} | ||
}; | ||
extern thread_local tracer g_tracer; | ||
|
||
|
||
enum class trace_events { | ||
POLL, | ||
SLEEP, | ||
WAKEUP, | ||
RUN_TASK_QUEUE, | ||
RUN_TASK_QUEUE_END, | ||
RUN_TASK, | ||
RUN_EXECUTION_STAGE_TASK, | ||
GRAB_CAPACITY, | ||
GRAB_CAPACITY_PENDING, | ||
DISPATCH_REQUESTS, | ||
DISPATCH_QUEUE, | ||
REPLENISH, | ||
IO_QUEUE, | ||
IO_DISPATCH, | ||
IO_COMPLETE, | ||
IO_CANCEL, | ||
MONITORING_SCRAPE, | ||
COUNT, | ||
}; | ||
|
||
[[gnu::always_inline]] | ||
inline void tracepoint_nullary(trace_events header) { | ||
auto p = reinterpret_cast<char*>(g_tracer.write(12)); | ||
p = seastar::write_le<uint32_t>(p, static_cast<uint32_t>(header)); | ||
p = seastar::write_le<uint64_t>(p, g_tracer.rdtsc()); | ||
} | ||
|
||
template <typename T> | ||
[[gnu::always_inline]] | ||
inline void tracepoint_unary(uint32_t header, T arg) { | ||
auto p = reinterpret_cast<char*>(g_tracer.write(12 + sizeof(T))); | ||
p = seastar::write_le<uint32_t>(p, static_cast<uint32_t>(header)); | ||
p = seastar::write_le<uint64_t>(p, g_tracer.rdtsc()); | ||
p = seastar::write_le<T>(p, arg); | ||
} | ||
|
||
template <typename T> | ||
[[gnu::always_inline]] | ||
inline void tracepoint_unary(trace_events header, T arg) { | ||
tracepoint_unary(static_cast<uint32_t>(header), arg); | ||
} | ||
|
||
inline void tracepoint_poll() { | ||
tracepoint_nullary(trace_events::POLL); | ||
} | ||
|
||
inline void tracepoint_sleep() { | ||
tracepoint_nullary(trace_events::SLEEP); | ||
} | ||
|
||
inline void tracepoint_wakeup() { | ||
tracepoint_nullary(trace_events::WAKEUP); | ||
} | ||
|
||
inline void tracepoint_run_task_queue(uint8_t sg) { | ||
tracepoint_unary<uint8_t>(trace_events::RUN_TASK_QUEUE, sg); | ||
} | ||
|
||
inline void tracepoint_run_task_queue_end() { | ||
tracepoint_nullary(trace_events::RUN_TASK_QUEUE_END); | ||
} | ||
|
||
inline void tracepoint_run_task(int64_t task_id) { | ||
tracepoint_unary<uint64_t>(trace_events::RUN_TASK, task_id); | ||
} | ||
|
||
inline void tracepoint_run_execution_stage_task(int64_t task_id) { | ||
tracepoint_unary<uint64_t>(trace_events::RUN_EXECUTION_STAGE_TASK, task_id); | ||
} | ||
|
||
inline void tracepoint_io_queue(uint8_t direction, uint64_t tokens, uint64_t io_id) { | ||
auto p = reinterpret_cast<char*>(g_tracer.write(12 + 17)); | ||
p = seastar::write_le<uint32_t>(p, static_cast<uint32_t>(trace_events::IO_QUEUE)); | ||
p = seastar::write_le<uint64_t>(p, g_tracer.rdtsc()); | ||
p = seastar::write_le<uint8_t>(p, direction); | ||
p = seastar::write_le<uint64_t>(p, tokens); | ||
p = seastar::write_le<uint64_t>(p, io_id); | ||
} | ||
|
||
inline void tracepoint_io_dispatch(uint64_t io_id) { | ||
tracepoint_unary<uint64_t>(trace_events::IO_DISPATCH, io_id); | ||
} | ||
|
||
inline void tracepoint_io_complete(uint64_t io_id) { | ||
tracepoint_unary<uint64_t>(trace_events::IO_COMPLETE, io_id); | ||
} | ||
|
||
inline void tracepoint_io_cancel(uint64_t io_id) { | ||
tracepoint_unary<uint64_t>(trace_events::IO_CANCEL, io_id); | ||
} | ||
|
||
inline void tracepoint_grab_capacity(uint64_t cap, uint64_t want_head, uint64_t head) { | ||
auto p = reinterpret_cast<char*>(g_tracer.write(12 + 24)); | ||
p = seastar::write_le<uint32_t>(p, static_cast<uint32_t>(trace_events::GRAB_CAPACITY)); | ||
p = seastar::write_le<uint64_t>(p, g_tracer.rdtsc()); | ||
p = seastar::write_le<uint64_t>(p, cap); | ||
p = seastar::write_le<uint64_t>(p, want_head); | ||
p = seastar::write_le<uint64_t>(p, head); | ||
} | ||
|
||
inline void tracepoint_grab_capacity_pending(uint64_t cap, uint64_t head) { | ||
auto p = reinterpret_cast<char*>(g_tracer.write(12 + 16)); | ||
p = seastar::write_le<uint32_t>(p, static_cast<uint32_t>(trace_events::GRAB_CAPACITY_PENDING)); | ||
p = seastar::write_le<uint64_t>(p, g_tracer.rdtsc()); | ||
p = seastar::write_le<uint64_t>(p, cap); | ||
p = seastar::write_le<uint64_t>(p, head); | ||
} | ||
|
||
inline void tracepoint_replenish(uint64_t new_head) { | ||
tracepoint_unary<uint64_t>(trace_events::REPLENISH, new_head); | ||
} | ||
|
||
inline void tracepoint_dispatch_queue(uint8_t id) { | ||
tracepoint_unary<uint8_t>(trace_events::DISPATCH_QUEUE, id); | ||
} | ||
|
||
inline void tracepoint_dispatch_requests(uint64_t queued) { | ||
tracepoint_unary<uint64_t>(trace_events::DISPATCH_REQUESTS, queued); | ||
} | ||
|
||
inline void tracepoint_monitoring_scrape() { | ||
tracepoint_nullary(trace_events::MONITORING_SCRAPE); | ||
} | ||
|
||
|
||
} // namespace seastar |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reposting a comment by @xemul which he wrote in michoecho@b0ec97d#r150664671. (I created this PR just to anchor his comment to something. Comments attached to commits are hard to find).