From: Mohit Agrawal Date: Mon, 28 Jul 2025 13:03:38 +0000 (+0530) Subject: crimson/osd: Refactor crimson scheduler wrapper X-Git-Tag: testing/wip-pdonnell-testing-20260127.160833-debug~9^2~9^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d932f98c3abb3b17efa5f34d84129baf36f5316f;p=ceph-ci.git crimson/osd: Refactor crimson scheduler wrapper Signed-off-by: Mohit Agrawal --- diff --git a/src/crimson/osd/scheduler/scheduler.cc b/src/crimson/osd/scheduler/scheduler.cc index f8d1598c588..256b76819ac 100644 --- a/src/crimson/osd/scheduler/scheduler.cc +++ b/src/crimson/osd/scheduler/scheduler.cc @@ -20,27 +20,10 @@ #include "crimson/osd/scheduler/scheduler.h" #include "crimson/osd/scheduler/mclock_scheduler.h" #include "common/WeightedPriorityQueue.h" +#include "common/mclock_common.h" namespace crimson::osd::scheduler { -std::ostream &operator<<(std::ostream &lhs, const scheduler_class_t &c) -{ - switch (c) { - case scheduler_class_t::background_best_effort: - return lhs << "background_best_effort"; - case scheduler_class_t::background_recovery: - return lhs << "background_recovery"; - case scheduler_class_t::client: - return lhs << "client"; - case scheduler_class_t::repop: - return lhs << "repop"; - case scheduler_class_t::immediate: - return lhs << "immediate"; - default: - return lhs; - } -} - /** * Implements Scheduler in terms of OpQueue * @@ -51,37 +34,37 @@ std::ostream &operator<<(std::ostream &lhs, const scheduler_class_t &c) */ template class ClassedOpQueueScheduler final : public Scheduler { - const scheduler_class_t cutoff; + const SchedulerClass cutoff; T queue; using priority_t = uint64_t; std::array< priority_t, - static_cast(scheduler_class_t::immediate) + static_cast(SchedulerClass::immediate) > priority_map = { // Placeholder, gets replaced with configured values 0, 0, 0 }; - static scheduler_class_t get_io_prio_cut(ConfigProxy &conf) { + static SchedulerClass get_io_prio_cut(ConfigProxy &conf) { if (conf.get_val("osd_op_queue_cut_off") == "debug_random") { srand(time(NULL)); return (rand() % 2 < 1) ? - scheduler_class_t::repop : scheduler_class_t::immediate; + SchedulerClass::repop : SchedulerClass::immediate; } else if (conf.get_val("osd_op_queue_cut_off") == "high") { - return scheduler_class_t::immediate; + return SchedulerClass::immediate; } else { - return scheduler_class_t::repop; + return SchedulerClass::repop; } } - bool use_strict(scheduler_class_t kl) const { + bool use_strict(SchedulerClass kl) const { return static_cast(kl) >= static_cast(cutoff); } - priority_t get_priority(scheduler_class_t kl) const { + priority_t get_priority(SchedulerClass kl) const { ceph_assert(static_cast(kl) < - static_cast(scheduler_class_t::immediate)); + static_cast(SchedulerClass::immediate)); return priority_map[static_cast(kl)]; } @@ -92,16 +75,16 @@ public: queue(std::forward(args)...) { priority_map[ - static_cast(scheduler_class_t::background_best_effort) + static_cast(SchedulerClass::background_best_effort) ] = conf.get_val("osd_scrub_priority"); priority_map[ - static_cast(scheduler_class_t::background_recovery) + static_cast(SchedulerClass::background_recovery) ] = conf.get_val("osd_recovery_op_priority"); priority_map[ - static_cast(scheduler_class_t::client) + static_cast(SchedulerClass::client) ] = conf.get_val("osd_client_op_priority"); priority_map[ - static_cast(scheduler_class_t::repop) + static_cast(SchedulerClass::repop) ] = conf.get_val("osd_client_op_priority"); } @@ -129,7 +112,7 @@ public: return queue.empty(); } - item_t dequeue() final { + WorkItem dequeue() final { return queue.dequeue(); } @@ -146,7 +129,8 @@ public: ~ClassedOpQueueScheduler() final {}; }; -SchedulerRef make_scheduler(ConfigProxy &conf) +SchedulerRef make_scheduler(CephContext *cct, ConfigProxy &conf, int whoami, uint32_t nshards, int sid, + bool is_rotational, bool perf_cnt) { const std::string _type = conf.get_val("osd_op_queue"); const std::string *type = &_type; @@ -167,7 +151,7 @@ SchedulerRef make_scheduler(ConfigProxy &conf) conf->osd_op_pq_min_cost ); } else if (*type == "mclock_scheduler") { - return std::make_unique(conf); + return std::make_unique(cct, whoami, nshards, sid, is_rotational, perf_cnt); } else { ceph_assert("Invalid choice of wq" == 0); return std::unique_ptr(); diff --git a/src/crimson/osd/scheduler/scheduler.h b/src/crimson/osd/scheduler/scheduler.h index 100ba493744..23207a5c855 100644 --- a/src/crimson/osd/scheduler/scheduler.h +++ b/src/crimson/osd/scheduler/scheduler.h @@ -19,33 +19,27 @@ #include #include "crimson/common/config_proxy.h" +#include "common/mclock_common.h" namespace crimson::osd::scheduler { -enum class scheduler_class_t : uint8_t { - background_best_effort = 0, - background_recovery, - client, - repop, - immediate, -}; - -std::ostream &operator<<(std::ostream &, const scheduler_class_t &); - using client_t = uint64_t; -using cost_t = uint64_t; struct params_t { - cost_t cost = 1; + int cost = 1; + unsigned priority = 0; client_t owner; - scheduler_class_t klass; + SchedulerClass klass; }; struct item_t { params_t params; seastar::promise<> wake; + int get_cost() const { return params.cost; } + unsigned get_priority() const { return params.priority; } }; +using WorkItem = std::variant; /** * Base interface for classes responsible for choosing * op processing order in the OSD. @@ -63,7 +57,7 @@ public: virtual bool empty() const = 0; // Return next op to be processed - virtual item_t dequeue() = 0; + virtual WorkItem dequeue() = 0; // Dump formatted representation for the queue virtual void dump(ceph::Formatter &f) const = 0; @@ -78,6 +72,7 @@ public: std::ostream &operator<<(std::ostream &lhs, const Scheduler &); using SchedulerRef = std::unique_ptr; -SchedulerRef make_scheduler(ConfigProxy &); +SchedulerRef make_scheduler(CephContext *cct, ConfigProxy &, int whoami, uint32_t num_shards, + int shard_id, bool is_rotational, bool perf_cnt); }