From 0dce11b0dde9eb6e38a825089434b14dd04376d9 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:48:08 +0800 Subject: [PATCH] feat remove unused files --- CMakeLists.txt | 1 - tile/fiber/detail/asm/ucontext_mips32.h | 18 ++---- tile/fiber/detail/asm/ucontext_mips64.h | 18 ++---- tile/fiber/detail/asm/ucontext_riscv64.h | 6 +- tile/fiber/detail/asm/ucontext_x64.h | 18 ++---- tile/fiber/detail/asm/ucontext_x86.h | 6 ++ tile/fiber/detail/fiber_test.cc | 3 + tile/fiber/detail/scheduler.cc | 3 - tile/fiber/detail/scheduler.h | 45 -------------- tile/fiber/fiber.cc | 54 ----------------- tile/fiber/fiber.h | 75 ------------------------ tile/fiber/scheduler.cc | 22 ------- tile/fiber/scheduler.h | 39 ------------ 13 files changed, 27 insertions(+), 281 deletions(-) delete mode 100644 tile/fiber/detail/scheduler.cc delete mode 100644 tile/fiber/detail/scheduler.h delete mode 100644 tile/fiber/fiber.cc delete mode 100644 tile/fiber/fiber.h delete mode 100644 tile/fiber/scheduler.cc delete mode 100644 tile/fiber/scheduler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8889804..688cd54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,6 @@ set(TILE_SRCS # "tile/fiber/detail/os_fiber.cc" "tile/fiber/detail/posix_os_fiber.cc" # "tile/fiber/detail/mutex.cc" "tile/fiber/detail/ucontext.c" - "tile/fiber/scheduler.cc" "tile/io/detail/eintr_safe.cc" "tile/io/native/acceptor.cc" "tile/io/descriptor.cc" diff --git a/tile/fiber/detail/asm/ucontext_mips32.h b/tile/fiber/detail/asm/ucontext_mips32.h index 35769ba..510b7d7 100644 --- a/tile/fiber/detail/asm/ucontext_mips32.h +++ b/tile/fiber/detail/asm/ucontext_mips32.h @@ -1,17 +1,7 @@ -// Copyright 2021 The Marl Authors. -// -// 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 -// -// https://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. +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H +#pragma once #define TILE_REG_f20 0x00 #define TILE_REG_f22 0x08 #define TILE_REG_f24 0x10 @@ -129,3 +119,5 @@ static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS32_H diff --git a/tile/fiber/detail/asm/ucontext_mips64.h b/tile/fiber/detail/asm/ucontext_mips64.h index 93f9c8f..5573ce1 100644 --- a/tile/fiber/detail/asm/ucontext_mips64.h +++ b/tile/fiber/detail/asm/ucontext_mips64.h @@ -1,17 +1,7 @@ -// Copyright 2020 The Marl Authors. -// -// 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 -// -// https://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. +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H +#pragma once #define TILE_REG_a0 0x00 #define TILE_REG_a1 0x08 #define TILE_REG_s0 0x10 @@ -129,3 +119,5 @@ static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_MIPS64_H diff --git a/tile/fiber/detail/asm/ucontext_riscv64.h b/tile/fiber/detail/asm/ucontext_riscv64.h index d513b60..5a058ef 100644 --- a/tile/fiber/detail/asm/ucontext_riscv64.h +++ b/tile/fiber/detail/asm/ucontext_riscv64.h @@ -1,5 +1,5 @@ -#ifndef TILE_FIBER_DETAIL_UCONTEXT_RISCV64_H -#define TILE_FIBER_DETAIL_UCONTEXT_RISCV64_H +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H #pragma once #define TILE_REG_a0 0x00 @@ -138,4 +138,4 @@ static_assert(offsetof(tile_ucontext_t, ra) == TILE_REG_ra, #endif // TILE_BUILD_ASM -#endif // TILE_FIBER_DETAIL_UCONTEXT_RISCV64_H +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_RISCV64_H diff --git a/tile/fiber/detail/asm/ucontext_x64.h b/tile/fiber/detail/asm/ucontext_x64.h index b524f9a..369a246 100644 --- a/tile/fiber/detail/asm/ucontext_x64.h +++ b/tile/fiber/detail/asm/ucontext_x64.h @@ -1,17 +1,7 @@ -// Copyright 2019 The Marl Authors. -// -// 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 -// -// https://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. +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H +#pragma once #define TILE_REG_RBX 0x00 #define TILE_REG_RBP 0x08 #define TILE_REG_R12 0x10 @@ -81,3 +71,5 @@ static_assert(offsetof(tile_ucontext_t, RIP) == TILE_REG_RIP, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_X64_H diff --git a/tile/fiber/detail/asm/ucontext_x86.h b/tile/fiber/detail/asm/ucontext_x86.h index 4a7c7b7..3d4e9d6 100644 --- a/tile/fiber/detail/asm/ucontext_x86.h +++ b/tile/fiber/detail/asm/ucontext_x86.h @@ -1,3 +1,7 @@ +#ifndef TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H +#define TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H + +#pragma once #define TILE_REG_EBX 0x00 #define TILE_REG_EBP 0x04 #define TILE_REG_ESI 0x08 @@ -44,3 +48,5 @@ static_assert(offsetof(tile_ucontext_t, EIP) == TILE_REG_EIP, #endif // __cplusplus #endif // TILE_BUILD_ASM + +#endif // TILE_FIBER_DETAIL_ASM_UCONTEXT_X86_H diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc index dd4e852..497b3c1 100644 --- a/tile/fiber/detail/fiber_test.cc +++ b/tile/fiber/detail/fiber_test.cc @@ -9,6 +9,7 @@ namespace detail { TEST(Fiber, Base) { constexpr auto kMaxCnt = 5000000; int cnt = 0; + int resume_cnt = 0; // 0 -> master fiber // [1, 9] -> worker fibers @@ -33,9 +34,11 @@ TEST(Fiber, Base) { auto next_fiber = fibers[Random(1, 9)].get(); next_fiber->Resume(); + ++resume_cnt; ASSERT_EQ(old + 1, cnt); ASSERT_EQ(Fiber::Current(), Fiber::MasterFiber()); } + ASSERT_EQ(resume_cnt, kMaxCnt); } } // namespace detail diff --git a/tile/fiber/detail/scheduler.cc b/tile/fiber/detail/scheduler.cc deleted file mode 100644 index fe53245..0000000 --- a/tile/fiber/detail/scheduler.cc +++ /dev/null @@ -1,3 +0,0 @@ -#include "tile/fiber/detail/scheduler.h" - - diff --git a/tile/fiber/detail/scheduler.h b/tile/fiber/detail/scheduler.h deleted file mode 100644 index fb30bac..0000000 --- a/tile/fiber/detail/scheduler.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_SCHEDULER_H -#define TILE_FIBER_DETAIL_SCHEDULER_H - -#pragma once -#include "tile/base/thread/event.h" -#include "tile/base/thread/spinlock.h" -#include "tile/fiber/fiber.h" -#include -#include -#include -#include -#include -#include - -namespace tile { -namespace fiber { -namespace detail { - -class Fiber; - -class Scheduler { -public: - static Scheduler *Current() noexcept; - - void Yield(OSFiber *self) noexcept; - void Halt(OSFiber *self) noexcept; - void SwitchTo(OSFiber *self, OSFiber *to) noexcept; - - void Queue(std::function task); - -private: - OSFiber *StartFiber(std::function task); - Scheduler(); - ~Scheduler(); - -private: - Spinlock fibers_lock_; - std::list> tasks_; - Event new_task_event_; -}; -} // namespace detail -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_DETAIL_SCHEDULER_H diff --git a/tile/fiber/fiber.cc b/tile/fiber/fiber.cc deleted file mode 100644 index 1012a3f..0000000 --- a/tile/fiber/fiber.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "tile/fiber/fiber.h" -#include "tile/base/internal/index_alloc.h" -#include "tile/fiber/detail/os_fiber.h" - -#include "gflags/gflags.h" - -DEFINE_int32(tile_fiber_stack_size, 1024 * 1024, "Fiber stack size"); - -namespace tile { -namespace fiber { -namespace { -Fiber::Id AllocFiberId() noexcept { - return internal::IndexAlloc::For()->Next(); -} -void FreeFiberId(Fiber::Id id) noexcept { - internal::IndexAlloc::For()->Free(id); -} - -} // namespace - -Fiber::Fiber() - : id_(AllocFiberId()), exit_latch_(std::make_shared(1)), - impl_(detail::os_fiber_registry.New("os_fiber")) {} - -Fiber::Fiber(Fiber &&) noexcept = default; - -Fiber &Fiber::operator=(Fiber &&) noexcept = default; - -Fiber::~Fiber() = default; - -Fiber::Id Fiber::GetId() const { return id_; } - -void Fiber::WorkerProc() { - TILE_LOG_INFO("Only display log"); - FreeFiberId(id_); - exit_latch_->CountDown(); -} - -void Fiber::SwitchTo(Fiber *to) { - TILE_CHECK(to); - impl_->SwitchTo(to->impl_.get()); -} - -} // namespace fiber -} // namespace tile - -namespace tile { -constexpr PoolType PoolTraits::kType; -constexpr std::size_t PoolTraits::kLowWaterMark; -constexpr std::size_t PoolTraits::kHighWaterMark; -constexpr std::chrono::nanoseconds PoolTraits::kMaxIdle; -constexpr std::size_t PoolTraits::kMinimumThreadCacheSize; -constexpr std::size_t PoolTraits::kTransferBatchSize; -} // namespace tile diff --git a/tile/fiber/fiber.h b/tile/fiber/fiber.h deleted file mode 100644 index 11ab3c2..0000000 --- a/tile/fiber/fiber.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef TILE_FIBER_FIBER_H -#define TILE_FIBER_FIBER_H - -#pragma once - -#include "tile/base/internal/test_prod.h" -#include "tile/base/object_pool.h" -#include "tile/base/thread/latch.h" - -#include "gflags/gflags_declare.h" - -DECLARE_int32(tile_fiber_stack_size); - -namespace tile { -namespace fiber { -namespace detail { -class OSFiber; -} // namespace detail -} // namespace fiber -} // namespace tile - -namespace tile { -namespace fiber { -class Scheduler; - -class Fiber { -public: - using Id = std::uint64_t; - using Task = std::function; - enum class FiberState { - Ready, // No task - // Running, // Process task - Waiting, // Blocked - Terminated, // Terminated - }; - - Fiber(Fiber &&) noexcept; - Fiber &operator=(Fiber &&) noexcept; - - ~Fiber(); - - Id GetId() const; - void Yield(); - -private: - friend class ::tile::fiber::Scheduler; - TILE_FRIEND_TEST(Fiber, Base); - - Fiber(); - Fiber(Fiber *main_fiber); - - void WorkerProc(); - void SwitchTo(Fiber *to); - -private: - Id id_; - std::shared_ptr exit_latch_; - std::unique_ptr<::tile::fiber::detail::OSFiber> impl_{nullptr}; -}; -} // namespace fiber -} // namespace tile - -namespace tile { -template <> struct PoolTraits<::tile::fiber::Fiber> { - static constexpr auto kType = PoolType::MemoryNodeShared; - static constexpr std::size_t kLowWaterMark = 32768; - static constexpr std::size_t kHighWaterMark = - std::numeric_limits::max(); - static constexpr std::chrono::nanoseconds kMaxIdle = std::chrono::seconds(5); - static constexpr std::size_t kMinimumThreadCacheSize = 8192; - static constexpr std::size_t kTransferBatchSize = 1024; -}; -} // namespace tile - -#endif // TILE_FIBER_FIBER_H diff --git a/tile/fiber/scheduler.cc b/tile/fiber/scheduler.cc deleted file mode 100644 index 97c7f1d..0000000 --- a/tile/fiber/scheduler.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "tile/fiber/scheduler.h" -#include "tile/fiber/fiber.h" - -namespace tile { -namespace fiber { -namespace detail { -static thread_local Scheduler *current_scheduler = nullptr; -} - -Scheduler *Scheduler::Current() noexcept { return detail::current_scheduler; } - -Scheduler::Scheduler(Options options) : options_(std::move(options)) { - detail::current_scheduler = this; - // main_fiber_ = std::make_unique(); - // fibers_.reserve(options_.affinity.size()); - // for (auto i : options_.affinity) { - // fibers_.push_back(std::make_unique()); - // } -} - -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/scheduler.h b/tile/fiber/scheduler.h deleted file mode 100644 index d4b5a1b..0000000 --- a/tile/fiber/scheduler.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TILE_FIBER_DETAIL_SCHEDULER_H -#define TILE_FIBER_DETAIL_SCHEDULER_H - -#pragma once - -#include "tile/base/align.h" -#include "tile/fiber/fiber.h" - -#include - -namespace tile { -namespace fiber { - -class alignas(hardware_destructive_interference_size) Scheduler { -public: - struct Options { - std::vector affinity; - std::size_t fiber_stack_size = 1024 * 1024; - }; - - Scheduler(Options options); - ~Scheduler(); - - static Scheduler *Current() noexcept; - -private: - void WorkerProc(); - -private: - Options options_; - - std::unique_ptr main_fiber_; - std::vector> fibers_; -}; - -} // namespace fiber -} // namespace tile - -#endif // TILE_FIBER_DETAIL_SCHEDULER_H