-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
313 additions
and
69 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Flash/Pipeline/Schedule/Tasks/NotifyFuture.h> | ||
|
||
namespace DB | ||
{ | ||
#if __APPLE__ && __clang__ | ||
__thread NotifyFuturePtr current_notify_future = nullptr; | ||
#else | ||
thread_local NotifyFuturePtr current_notify_future = nullptr; | ||
#endif | ||
|
||
void setNotifyFuture(NotifyFuturePtr new_future) | ||
{ | ||
assert(current_notify_future == nullptr); | ||
current_notify_future = std::move(new_future); | ||
} | ||
|
||
void clearNotifyFuture() | ||
{ | ||
current_notify_future.reset(); | ||
} | ||
|
||
void registerTaskToFuture(TaskPtr && task) | ||
{ | ||
assert(current_notify_future != nullptr); | ||
current_notify_future->registerTask(std::move(task)); | ||
current_notify_future.reset(); | ||
} | ||
} // namespace DB |
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,39 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Flash/Pipeline/Schedule/Tasks/Task.h> | ||
|
||
namespace DB | ||
{ | ||
struct NotifyFuture | ||
{ | ||
NotifyFuture() = default; | ||
virtual ~NotifyFuture() = default; | ||
virtual void registerTask(TaskPtr && task) = 0; | ||
}; | ||
using NotifyFuturePtr = std::shared_ptr<NotifyFuture>; | ||
|
||
#if __APPLE__ && __clang__ | ||
extern __thread NotifyFuturePtr current_notify_future; | ||
#else | ||
extern thread_local NotifyFuturePtr current_notify_future; | ||
#endif | ||
|
||
void setNotifyFuture(NotifyFuturePtr new_future); | ||
void clearNotifyFuture(); | ||
void registerTaskToFuture(TaskPtr && task); | ||
|
||
} // namespace DB |
100 changes: 100 additions & 0 deletions
100
dbms/src/Flash/Pipeline/Schedule/Tasks/PipeConditionVariable.h
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,100 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Flash/Pipeline/Schedule/TaskScheduler.h> | ||
#include <Flash/Pipeline/Schedule/Tasks/Task.h> | ||
|
||
#include <deque> | ||
|
||
namespace DB | ||
{ | ||
class PipeConditionVariable | ||
{ | ||
public: | ||
inline void registerTask(TaskPtr && task) | ||
{ | ||
assert(task); | ||
assert(task->getStatus() == ExecTaskStatus::WAIT_FOR_NOTIFY); | ||
{ | ||
std::lock_guard lock(mu); | ||
tasks.push_back(std::move(task)); | ||
} | ||
|
||
#if __APPLE__ && __clang__ | ||
__thread auto & metrics = GET_METRIC(tiflash_pipeline_scheduler, type_wait_for_notify_tasks_count); | ||
#else | ||
thread_local auto & metrics = GET_METRIC(tiflash_pipeline_scheduler, type_wait_for_notify_tasks_count); | ||
#endif | ||
metrics.Increment(); | ||
} | ||
|
||
inline void notifyOne() | ||
{ | ||
TaskPtr task; | ||
{ | ||
std::lock_guard lock(mu); | ||
if (tasks.empty()) | ||
return; | ||
task = std::move(tasks.front()); | ||
tasks.pop_front(); | ||
} | ||
assert(task); | ||
notifyTaskDirectly(std::move(task)); | ||
|
||
#if __APPLE__ && __clang__ | ||
__thread auto & metrics = GET_METRIC(tiflash_pipeline_scheduler, type_wait_for_notify_tasks_count); | ||
#else | ||
thread_local auto & metrics = GET_METRIC(tiflash_pipeline_scheduler, type_wait_for_notify_tasks_count); | ||
#endif | ||
metrics.Decrement(); | ||
} | ||
|
||
inline void notifyAll() | ||
{ | ||
std::deque<TaskPtr> cur_tasks; | ||
{ | ||
std::lock_guard lock(mu); | ||
std::swap(cur_tasks, tasks); | ||
} | ||
size_t tasks_cnt = cur_tasks.size(); | ||
while (!cur_tasks.empty()) | ||
{ | ||
notifyTaskDirectly(std::move(cur_tasks.front())); | ||
cur_tasks.pop_front(); | ||
} | ||
|
||
#if __APPLE__ && __clang__ | ||
__thread auto & metrics = GET_METRIC(tiflash_pipeline_scheduler, type_wait_for_notify_tasks_count); | ||
#else | ||
thread_local auto & metrics = GET_METRIC(tiflash_pipeline_scheduler, type_wait_for_notify_tasks_count); | ||
#endif | ||
metrics.Decrement(tasks_cnt); | ||
} | ||
|
||
static inline void notifyTaskDirectly(TaskPtr && task) | ||
{ | ||
assert(task); | ||
task->notify(); | ||
task->profile_info.elapsedWaitForNotifyTime(); | ||
assert(TaskScheduler::instance); | ||
TaskScheduler::instance->submitToCPUTaskThreadPool(std::move(task)); | ||
} | ||
|
||
private: | ||
std::mutex mu; | ||
std::deque<TaskPtr> tasks; | ||
}; | ||
} // namespace DB |
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
Oops, something went wrong.