diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 616aeafc480af04072ba15d5fbf6d2df7059b91f..fdbe55a7b3a9645a8fd074ecd47f95daa77f9916 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -34,6 +34,10 @@ Please mark all change in change log and use the ticket from JIRA. - MS-380 - Update resource loader and executor, work util all finished - MS-383 - Modify condition variable usage in scheduler - MS-384 - Add global instance of ResourceMgr and Scheduler +- MS-389 - Add clone interface in Task +- MS-390 - Update resource construct function +- MS-391 - Add PushTaskToNeighbourHasExecutor action +- MS-394 - Update scheduler unittest ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/ResourceFactory.cpp b/cpp/src/scheduler/ResourceFactory.cpp index 496802cd195ed11c25c9a9648ff9ff19f4956952..82dae5eb251a8748c5f7d038abbe0451f6e4895b 100644 --- a/cpp/src/scheduler/ResourceFactory.cpp +++ b/cpp/src/scheduler/ResourceFactory.cpp @@ -12,13 +12,16 @@ namespace milvus { namespace engine { std::shared_ptr -ResourceFactory::Create(const std::string &name, const std::string &alias) { +ResourceFactory::Create(const std::string &name, + const std::string &alias, + bool enable_loader, + bool enable_executor) { if (name == "disk") { - return std::make_shared(alias); + return std::make_shared(alias, enable_loader, enable_executor); } else if (name == "cpu") { - return std::make_shared(alias); + return std::make_shared(alias, enable_loader, enable_executor); } else if (name == "gpu") { - return std::make_shared(alias); + return std::make_shared(alias, enable_loader, enable_executor); } else { return nullptr; } diff --git a/cpp/src/scheduler/ResourceFactory.h b/cpp/src/scheduler/ResourceFactory.h index 6a2ab2ab341fb37016d61096cf8a6fbb92bd8b94..c91fd72938085322e69400457c5957dabf549bc8 100644 --- a/cpp/src/scheduler/ResourceFactory.h +++ b/cpp/src/scheduler/ResourceFactory.h @@ -21,7 +21,10 @@ namespace engine { class ResourceFactory { public: static std::shared_ptr - Create(const std::string &name, const std::string &alias = ""); + Create(const std::string &name, + const std::string &alias = "", + bool enable_loader = true, + bool enable_executor = true); }; diff --git a/cpp/src/scheduler/Scheduler.cpp b/cpp/src/scheduler/Scheduler.cpp index 6eef6014fb4ca2f4a6b02a2abda75b2b0b3f82e2..85fa90585c532aca9b1b63bc8f99689e0e62ae31 100644 --- a/cpp/src/scheduler/Scheduler.cpp +++ b/cpp/src/scheduler/Scheduler.cpp @@ -114,13 +114,14 @@ Scheduler::OnCopyCompleted(const EventPtr &event) { resource->WakeupExecutor(); if (resource->Type() == ResourceType::DISK) { Action::PushTaskToNeighbour(event->resource_); + } else { + Action::PushTaskToNeighbourHasExecutor(event->resource_); } } } void Scheduler::OnTaskTableUpdated(const EventPtr &event) { -// Action::PushTaskToNeighbour(event->resource_); if (auto resource = event->resource_.lock()) { resource->WakeupLoader(); } diff --git a/cpp/src/scheduler/action/Action.h b/cpp/src/scheduler/action/Action.h index d72bbefc8d7bb6ef7630493d85aefacae0781aa5..715088718563ca1e67fa11e41b559e68fd6b9a33 100644 --- a/cpp/src/scheduler/action/Action.h +++ b/cpp/src/scheduler/action/Action.h @@ -20,6 +20,11 @@ public: static void PushTaskToNeighbour(const ResourceWPtr &self); + /* + * Push task to neighbour that has executor; + */ + static void + PushTaskToNeighbourHasExecutor(const ResourceWPtr &self); /* * Pull task From neighbour; diff --git a/cpp/src/scheduler/action/PushTaskToNeighbour.cpp b/cpp/src/scheduler/action/PushTaskToNeighbour.cpp index 3c01fc492840fd72ba34ce9959dadcda3985c7cd..f253e4c6129aaf348aaba7f0c3225d98f9b52194 100644 --- a/cpp/src/scheduler/action/PushTaskToNeighbour.cpp +++ b/cpp/src/scheduler/action/PushTaskToNeighbour.cpp @@ -4,7 +4,7 @@ * Proprietary and confidential. ******************************************************************************/ -#include +#include #include "Action.h" @@ -13,29 +13,65 @@ namespace milvus { namespace engine { void -push_task(const ResourcePtr &self, const ResourcePtr &other) { - auto &self_task_table = self->task_table(); - auto &other_task_table = other->task_table(); +next(std::list &neighbours, std::list::iterator &it) { + it++; + if (neighbours.end() == it) { + it = neighbours.begin(); + } +} + + +void +push_task_round_robin(TaskTable &self_task_table, std::list &neighbours) { CacheMgr cache; - auto indexes = PickToMove(self_task_table, cache, 10); + auto it = neighbours.begin(); + if (it == neighbours.end()) return; + auto indexes = PickToMove(self_task_table, cache, self_task_table.Size()); + for (auto index : indexes) { if (self_task_table.Move(index)) { auto task = self_task_table.Get(index)->task; - other_task_table.Put(task); - // TODO: mark moved future + task = task->Clone(); + (*it)->task_table().Put(task); + next(neighbours, it); } } } void Action::PushTaskToNeighbour(const ResourceWPtr &res) { - if (auto self = res.lock()) { - for (auto &neighbour : self->GetNeighbours()) { - if (auto n = neighbour.neighbour_node.lock()) { - push_task(self, std::static_pointer_cast(n)); - } + auto self = res.lock(); + if (not self) return; + + std::list neighbours; + for (auto &neighbour_node : self->GetNeighbours()) { + auto node = neighbour_node.neighbour_node.lock(); + if (not node) continue; + + auto resource = std::static_pointer_cast(node); + neighbours.emplace_back(resource); + } + + push_task_round_robin(self->task_table(), neighbours); +} + +void +Action::PushTaskToNeighbourHasExecutor(const ResourceWPtr &res) { + auto self = res.lock(); + if (not self) return; + + std::list neighbours; + for (auto &neighbour_node : self->GetNeighbours()) { + auto node = neighbour_node.neighbour_node.lock(); + if (not node) continue; + + auto resource = std::static_pointer_cast(node); + if (resource->HasExecutor()) { + neighbours.emplace_back(resource); } } + + push_task_round_robin(self->task_table(), neighbours); } diff --git a/cpp/src/scheduler/resource/CpuResource.cpp b/cpp/src/scheduler/resource/CpuResource.cpp index 01fca35ee46481c0fde222210c9ca0cf7f8bc467..0eb6aeb4f52a999718c75f449f4f57e1bfe4fad7 100644 --- a/cpp/src/scheduler/resource/CpuResource.cpp +++ b/cpp/src/scheduler/resource/CpuResource.cpp @@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const CpuResource &resource) { return out; } -CpuResource::CpuResource(std::string name) - : Resource(std::move(name), ResourceType::CPU) {} +CpuResource::CpuResource(std::string name, bool enable_loader, bool enable_executor) + : Resource(std::move(name), ResourceType::CPU, enable_loader, enable_executor) {} void CpuResource::LoadFile(TaskPtr task) { task->Load(LoadType::DISK2CPU, 0); @@ -29,4 +29,4 @@ void CpuResource::Process(TaskPtr task) { } } -} \ No newline at end of file +} diff --git a/cpp/src/scheduler/resource/CpuResource.h b/cpp/src/scheduler/resource/CpuResource.h index c180ea07d7819fcc9c1748368df9b1f2a71b5a94..19f49c59b464de349701bf0a558152ffedb16154 100644 --- a/cpp/src/scheduler/resource/CpuResource.h +++ b/cpp/src/scheduler/resource/CpuResource.h @@ -17,7 +17,7 @@ namespace engine { class CpuResource : public Resource { public: explicit - CpuResource(std::string name); + CpuResource(std::string name, bool enable_loader, bool enable_executor); inline std::string Dump() const override { diff --git a/cpp/src/scheduler/resource/DiskResource.cpp b/cpp/src/scheduler/resource/DiskResource.cpp index 8612909e44b2b7d5023935e5d4affb5849ab4e86..3a6b0e5d6b51921c2b5a2b79d10c9a34b2e0ba6d 100644 --- a/cpp/src/scheduler/resource/DiskResource.cpp +++ b/cpp/src/scheduler/resource/DiskResource.cpp @@ -15,8 +15,8 @@ std::ostream &operator<<(std::ostream &out, const DiskResource &resource) { return out; } -DiskResource::DiskResource(std::string name) - : Resource(std::move(name), ResourceType::DISK, true, false) { +DiskResource::DiskResource(std::string name, bool enable_loader, bool enable_executor) + : Resource(std::move(name), ResourceType::DISK, enable_loader, enable_executor) { } void DiskResource::LoadFile(TaskPtr task) { diff --git a/cpp/src/scheduler/resource/DiskResource.h b/cpp/src/scheduler/resource/DiskResource.h index 0fb9d625aa78a2afe631c2e6c9ec118da935c221..11263a3298d1128633b3f9b84ac88d47d0e759a9 100644 --- a/cpp/src/scheduler/resource/DiskResource.h +++ b/cpp/src/scheduler/resource/DiskResource.h @@ -16,7 +16,7 @@ namespace engine { class DiskResource : public Resource { public: explicit - DiskResource(std::string name); + DiskResource(std::string name, bool enable_loader, bool enable_executor); inline std::string Dump() const override { diff --git a/cpp/src/scheduler/resource/GpuResource.cpp b/cpp/src/scheduler/resource/GpuResource.cpp index 8606bb78562c411740d7f94c4610799fc3928c39..85760ea6d278f53bc6cede44c593a278508026f8 100644 --- a/cpp/src/scheduler/resource/GpuResource.cpp +++ b/cpp/src/scheduler/resource/GpuResource.cpp @@ -16,8 +16,8 @@ std::ostream &operator<<(std::ostream &out, const GpuResource &resource) { return out; } -GpuResource::GpuResource(std::string name) - : Resource(std::move(name), ResourceType::GPU) {} +GpuResource::GpuResource(std::string name, bool enable_loader, bool enable_executor) + : Resource(std::move(name), ResourceType::GPU, enable_loader, enable_executor) {} void GpuResource::LoadFile(TaskPtr task) { task->Load(LoadType::CPU2GPU, 0); diff --git a/cpp/src/scheduler/resource/GpuResource.h b/cpp/src/scheduler/resource/GpuResource.h index 1cb38df34fbe3f314383a20780906c2178514342..95debd743298e4948d5969cc5e19bf67fc49111e 100644 --- a/cpp/src/scheduler/resource/GpuResource.h +++ b/cpp/src/scheduler/resource/GpuResource.h @@ -16,7 +16,7 @@ namespace engine { class GpuResource : public Resource { public: explicit - GpuResource(std::string name); + GpuResource(std::string name, bool enable_loader, bool enable_executor); inline std::string Dump() const override { diff --git a/cpp/src/scheduler/resource/Resource.h b/cpp/src/scheduler/resource/Resource.h index c32149b46ef8516383cda22aa476c124a5130fb5..ae78c225a019fbe10aad13fbf5f950e4e048f303 100644 --- a/cpp/src/scheduler/resource/Resource.h +++ b/cpp/src/scheduler/resource/Resource.h @@ -45,8 +45,30 @@ enum class RegisterType { class Resource : public Node, public std::enable_shared_from_this { public: /* - * Event function MUST be a short function, never blocking; + * Start loader and executor if enable; */ + void + Start(); + + /* + * Stop loader and executor, join it, blocking util thread exited; + */ + void + Stop(); + + /* + * wake up loader; + */ + void + WakeupLoader(); + + /* + * wake up executor; + */ + void + WakeupExecutor(); + +public: template void Register_T(const RegisterType &type) { register_table_.emplace(type, [] { return std::make_shared(); }); @@ -65,11 +87,17 @@ public: return type_; } - void - Start(); + // TODO: better name? + inline bool + HasLoader() { + return enable_loader_; + } - void - Stop(); + // TODO: better name? + inline bool + HasExecutor() { + return enable_executor_; + } TaskTable & task_table(); @@ -81,24 +109,11 @@ public: friend std::ostream &operator<<(std::ostream &out, const Resource &resource); -public: - /* - * wake up loader; - */ - void - WakeupLoader(); - - /* - * wake up executor; - */ - void - WakeupExecutor(); - protected: Resource(std::string name, ResourceType type, - bool enable_loader = true, - bool enable_executor = true); + bool enable_loader, + bool enable_executor); // TODO: SearchContextPtr to TaskPtr /* diff --git a/cpp/src/scheduler/task/DeleteTask.cpp b/cpp/src/scheduler/task/DeleteTask.cpp index 5f354462004289d3cee884a761a5ae5125b298d1..ee6b63b7708efe9511800d12542fe42cd4de509b 100644 --- a/cpp/src/scheduler/task/DeleteTask.cpp +++ b/cpp/src/scheduler/task/DeleteTask.cpp @@ -20,6 +20,11 @@ XDeleteTask::Execute() { } +TaskPtr +XDeleteTask::Clone() { + return nullptr; +} + } } } diff --git a/cpp/src/scheduler/task/DeleteTask.h b/cpp/src/scheduler/task/DeleteTask.h index c4839fc4cce664fdad7289b72a207c80f7fe71e4..9ca4e8b53ac172986884bf84e450b5edff9803b0 100644 --- a/cpp/src/scheduler/task/DeleteTask.h +++ b/cpp/src/scheduler/task/DeleteTask.h @@ -19,6 +19,9 @@ public: void Execute() override; + + TaskPtr + Clone() override; }; } diff --git a/cpp/src/scheduler/task/SearchTask.cpp b/cpp/src/scheduler/task/SearchTask.cpp index 60aa318b4a7d35123bfd3598ae5e17e670cf2174..98cbdb219b3343657e04806f4e985d994d90b4cb 100644 --- a/cpp/src/scheduler/task/SearchTask.cpp +++ b/cpp/src/scheduler/task/SearchTask.cpp @@ -99,16 +99,27 @@ CollectDurationMetrics(int index_type, double total_time) { } } +XSearchTask::XSearchTask(TableFileSchemaPtr file) : file_(file) { + index_engine_ = EngineFactory::Build(file_->dimension_, + file_->location_, + (EngineType) file_->engine_type_); +} + void XSearchTask::Load(LoadType type, uint8_t device_id) { server::TimeRecorder rc(""); - //step 1: load index - ExecutionEnginePtr index_ptr = EngineFactory::Build(file_->dimension_, - file_->location_, - (EngineType) file_->engine_type_); try { - index_ptr->Load(); + if (type == LoadType::DISK2CPU) { + index_engine_->Load(); + } else if (type == LoadType::CPU2GPU) { + index_engine_->Load(); + index_engine_->CopyToGpu(device_id); + } else if (type == LoadType::GPU2CPU) { + index_engine_->CopyToCpu(); + } else { + // TODO: exception + } } catch (std::exception &ex) { //typical error: out of disk space or permition denied std::string msg = "Failed to load index file: " + std::string(ex.what()); @@ -121,7 +132,7 @@ XSearchTask::Load(LoadType type, uint8_t device_id) { return; } - size_t file_size = index_ptr->PhysicalSize(); + size_t file_size = index_engine_->PhysicalSize(); std::string info = "Load file id:" + std::to_string(file_->id_) + " file type:" + std::to_string(file_->file_type_) + " size:" + std::to_string(file_size) + " bytes from location: " + file_->location_ + " totally cost"; @@ -135,7 +146,6 @@ XSearchTask::Load(LoadType type, uint8_t device_id) { //step 2: return search task for later execution index_id_ = file_->id_; index_type_ = file_->file_type_; - index_engine_ = index_ptr; search_contexts_.swap(search_contexts_); } @@ -157,12 +167,13 @@ XSearchTask::Execute() { for (auto &context : search_contexts_) { //step 1: allocate memory auto inner_k = context->topk(); + auto nprobe = context->nprobe(); output_ids.resize(inner_k * context->nq()); output_distence.resize(inner_k * context->nq()); try { //step 2: search - index_engine_->Search(context->nq(), context->vectors(), inner_k, output_distence.data(), + index_engine_->Search(context->nq(), context->vectors(), inner_k, nprobe, output_distence.data(), output_ids.data()); double span = rc.RecordSection("do search for context:" + context->Identity()); @@ -199,6 +210,16 @@ XSearchTask::Execute() { rc.ElapseFromBegin("totally cost"); } +TaskPtr +XSearchTask::Clone() { + auto ret = std::make_shared(file_); + ret->index_id_ = index_id_; + ret->index_engine_ = index_engine_->Clone(); + ret->search_contexts_ = search_contexts_; + ret->metric_l2 = metric_l2; + return ret; +} + Status XSearchTask::ClusterResult(const std::vector &output_ids, const std::vector &output_distence, uint64_t nq, @@ -343,6 +364,7 @@ Status XSearchTask::TopkResult(SearchContext::ResultSet &result_src, return Status::OK(); } + } } } diff --git a/cpp/src/scheduler/task/SearchTask.h b/cpp/src/scheduler/task/SearchTask.h index abff5a58a8c84c2c9b2f8edbf7b0944a47761abc..fb09b29d322c26c4d833a8df0a8d50de73a709cc 100644 --- a/cpp/src/scheduler/task/SearchTask.h +++ b/cpp/src/scheduler/task/SearchTask.h @@ -14,12 +14,18 @@ namespace engine { class XSearchTask : public Task { public: + explicit + XSearchTask(TableFileSchemaPtr file); + void Load(LoadType type, uint8_t device_id) override; void Execute() override; + TaskPtr + Clone() override; + public: static Status ClusterResult(const std::vector &output_ids, const std::vector &output_distence, diff --git a/cpp/src/scheduler/task/Task.h b/cpp/src/scheduler/task/Task.h index ec8be3df718cd26eb584f541d81616082a1a078a..56716480977fe6b2c9a38094548c44c1792d04e9 100644 --- a/cpp/src/scheduler/task/Task.h +++ b/cpp/src/scheduler/task/Task.h @@ -35,6 +35,9 @@ public: virtual void Execute() = 0; + virtual TaskPtr + Clone() = 0; + public: std::vector search_contexts_; ScheduleTaskPtr task_; diff --git a/cpp/src/scheduler/task/TaskConvert.cpp b/cpp/src/scheduler/task/TaskConvert.cpp index e6fd5016f15f82c6e0dbee0b5d4de33ff5998218..f29fd2960444c47bd9f15718770ffe1b93624869 100644 --- a/cpp/src/scheduler/task/TaskConvert.cpp +++ b/cpp/src/scheduler/task/TaskConvert.cpp @@ -16,8 +16,7 @@ TaskConvert(const ScheduleTaskPtr &schedule_task) { switch (schedule_task->type()) { case ScheduleTaskType::kIndexLoad: { auto load_task = std::static_pointer_cast(schedule_task); - auto task = std::make_shared(); - task->file_ = load_task->file_; + auto task = std::make_shared(load_task->file_); task->search_contexts_ = load_task->search_contexts_; task->task_ = schedule_task; return task; diff --git a/cpp/src/scheduler/task/TestTask.cpp b/cpp/src/scheduler/task/TestTask.cpp index a974482e52a6fc65bd59b12980d6b376325817d4..527e1b0fb18f30b1f5e550d01984a0364d911a2e 100644 --- a/cpp/src/scheduler/task/TestTask.cpp +++ b/cpp/src/scheduler/task/TestTask.cpp @@ -6,6 +6,7 @@ #include "TestTask.h" + namespace zilliz { namespace milvus { namespace engine { @@ -17,7 +18,23 @@ TestTask::Load(LoadType type, uint8_t device_id) { void TestTask::Execute() { + std::lock_guard lock(mutex_); exec_count_++; + done_ = true; +} + +TaskPtr +TestTask::Clone() { + auto ret = std::make_shared(); + ret->load_count_ = load_count_; + ret->exec_count_ = exec_count_; + return ret; +} + +void +TestTask::Wait() { + std::unique_lock lock(mutex_); + cv_.wait(lock, [&] { return done_; }); } } diff --git a/cpp/src/scheduler/task/TestTask.h b/cpp/src/scheduler/task/TestTask.h index 5f49d2e31ebc3399511fdaa463e47c3420f95329..0eb77504c8109f56917e2cead025d80e81d90b7e 100644 --- a/cpp/src/scheduler/task/TestTask.h +++ b/cpp/src/scheduler/task/TestTask.h @@ -23,9 +23,19 @@ public: void Execute() override; + TaskPtr + Clone() override; + + void + Wait(); + public: - uint64_t load_count_; - uint64_t exec_count_; + uint64_t load_count_ = 0; + uint64_t exec_count_ = 0; + + bool done_ = false; + std::mutex mutex_; + std::condition_variable cv_; }; diff --git a/cpp/src/wrapper/knowhere/vec_impl.cpp b/cpp/src/wrapper/knowhere/vec_impl.cpp index f6bdd826187487e59dee84d0fe42cf902d41a819..b0fb4c07990b8d106a79a235a4bed819fc032b51 100644 --- a/cpp/src/wrapper/knowhere/vec_impl.cpp +++ b/cpp/src/wrapper/knowhere/vec_impl.cpp @@ -144,7 +144,9 @@ VecIndexPtr VecIndexImpl::CopyToGpu(const int64_t &device_id, const Config &cfg) // TODO(linxj): update type auto gpu_index = zilliz::knowhere::CopyCpuToGpu(index_, device_id, cfg); - return std::make_shared(gpu_index, type); + auto new_index = std::make_shared(gpu_index, type); + new_index->dim = dim; + return new_index; } // TODO(linxj): rename copytocpu => copygputocpu diff --git a/cpp/unittest/scheduler/cost_test.cpp b/cpp/unittest/scheduler/cost_test.cpp index d4c05257d113b4fc27000c4e8873b0e071e8cc04..c53331d0f9dd4a96485d0901a7bb13238a109c7f 100644 --- a/cpp/unittest/scheduler/cost_test.cpp +++ b/cpp/unittest/scheduler/cost_test.cpp @@ -1,6 +1,7 @@ #include "scheduler/TaskTable.h" #include "scheduler/Cost.h" #include +#include "scheduler/task/TestTask.h" using namespace zilliz::milvus::engine; @@ -10,7 +11,7 @@ protected: void SetUp() override { for (uint64_t i = 0; i < 8; ++i) { - auto task = std::make_shared(); + auto task = std::make_shared(); table_.Put(task); } table_.Get(0)->state = TaskTableItemState::INVALID; diff --git a/cpp/unittest/scheduler/normal_test.cpp b/cpp/unittest/scheduler/normal_test.cpp index 27d16a1b6b8bd7de3719d2a3339aabd761c9a702..e3e791c02c147a049cd51c876d52b0a0b2f3257a 100644 --- a/cpp/unittest/scheduler/normal_test.cpp +++ b/cpp/unittest/scheduler/normal_test.cpp @@ -13,10 +13,10 @@ TEST(normal_test, test1) { // ResourceMgr only compose resources, provide unified event // auto res_mgr = std::make_shared(); auto res_mgr = ResMgrInst::GetInstance(); - auto disk = res_mgr->Add(ResourceFactory::Create("disk", "ssd")); + auto disk = res_mgr->Add(ResourceFactory::Create("disk", "ssd", true, false)); auto cpu = res_mgr->Add(ResourceFactory::Create("cpu")); - auto gpu1 = res_mgr->Add(ResourceFactory::Create("gpu")); - auto gpu2 = res_mgr->Add(ResourceFactory::Create("gpu")); + auto gpu1 = res_mgr->Add(ResourceFactory::Create("gpu", "gpu0", false, false)); + auto gpu2 = res_mgr->Add(ResourceFactory::Create("gpu", "gpu2", false, false)); auto IO = Connection("IO", 500.0); auto PCIE = Connection("IO", 11000.0); @@ -30,7 +30,7 @@ TEST(normal_test, test1) { auto scheduler = SchedInst::GetInstance(); scheduler->Start(); - const uint64_t NUM_TASK = 100; + const uint64_t NUM_TASK = 1000; std::vector> tasks; for (uint64_t i = 0; i < NUM_TASK; ++i) { if (auto observe = disk.lock()) { @@ -45,8 +45,10 @@ TEST(normal_test, test1) { scheduler->Stop(); res_mgr->Stop(); - for (uint64_t i = 0 ; i < NUM_TASK; ++i) { - ASSERT_EQ(tasks[i]->load_count_, 1); - ASSERT_EQ(tasks[i]->exec_count_, 1); + auto pcpu = cpu.lock(); + for (uint64_t i = 0; i < NUM_TASK; ++i) { + auto task = std::static_pointer_cast(pcpu->task_table()[i]->task); + ASSERT_EQ(task->load_count_, 1); + ASSERT_EQ(task->exec_count_, 1); } } diff --git a/cpp/unittest/scheduler/tasktable_test.cpp b/cpp/unittest/scheduler/tasktable_test.cpp index f48db3af2d347e4417de51991a4399cb3e5a2237..2d9108cd68f84c30364b34938f28c027b4e393f3 100644 --- a/cpp/unittest/scheduler/tasktable_test.cpp +++ b/cpp/unittest/scheduler/tasktable_test.cpp @@ -1,4 +1,5 @@ #include "scheduler/TaskTable.h" +#include "scheduler/task/TestTask.h" #include @@ -43,8 +44,8 @@ protected: void SetUp() override { invalid_task_ = nullptr; - task1_ = std::make_shared(); - task2_ = std::make_shared(); + task1_ = std::make_shared(); + task2_ = std::make_shared(); } TaskPtr invalid_task_; @@ -83,7 +84,7 @@ protected: void SetUp() override { for (uint64_t i = 0; i < 8; ++i) { - auto task = std::make_shared(); + auto task = std::make_shared(); table1_.Put(task); }