24 #ifndef SEASTAR_MODULE
29 #include <seastar/core/sstring.hh>
30 #include <seastar/core/function_traits.hh>
31 #include <seastar/util/concepts.hh>
32 #include <seastar/util/modules.hh>
38 SEASTAR_MODULE_EXPORT_BEGIN
39 constexpr
unsigned max_scheduling_groups() {
return SEASTAR_SCHEDULING_GROUPS_COUNT; }
41 template <
typename T =
void>
46 class scheduling_group;
47 class scheduling_group_key;
49 using sched_clock = std::chrono::steady_clock;
50 SEASTAR_MODULE_EXPORT_END
55 unsigned scheduling_group_index(scheduling_group sg) noexcept;
56 scheduling_group scheduling_group_from_index(
unsigned index) noexcept;
58 unsigned long scheduling_group_key_id(scheduling_group_key) noexcept;
61 T* scheduling_group_get_specific_ptr(scheduling_group sg, scheduling_group_key key) noexcept;
65 SEASTAR_MODULE_EXPORT_BEGIN
192 unsigned long id() const noexcept {
195 friend class reactor;
205 SEASTAR_MODULE_EXPORT_END
230 template<
typename ConstructorType,
typename Tuple,
size_t...Idx>
231 void apply_constructor(
void* pre_alocated_mem, Tuple args, std::index_sequence<Idx...>) {
232 new (pre_alocated_mem) ConstructorType(std::get<Idx>(args)...);
235 SEASTAR_MODULE_EXPORT_BEGIN
247 template <
typename T,
typename... ConstructorArgs>
248 scheduling_group_key_config
253 sgkc.
constructor = [args = std::make_tuple(args...)] (
void* p) {
254 internal::apply_constructor<T>(p, args, std::make_index_sequence<
sizeof...(ConstructorArgs)>());
257 static_cast<T*
>(p)->~T();
293 bool active() const noexcept;
294 const sstring& name() const noexcept;
295 const sstring& short_name() const noexcept;
298 bool is_main() const noexcept {
return _id == 0; }
299 bool is_at_exit() const noexcept {
return _id == 1; }
308 return *internal::scheduling_group_get_specific_ptr<T>(*
this, key);
330 #if SEASTAR_API_LEVEL >= 7
345 friend unsigned internal::scheduling_group_index(
scheduling_group sg) noexcept;
346 friend scheduling_group internal::scheduling_group_from_index(
unsigned index) noexcept;
348 template<
typename SpecificValType,
typename Mapper,
typename Reducer,
typename Initial>
349 SEASTAR_CONCEPT( requires requires(SpecificValType specific_val, Mapper mapper, Reducer reducer, Initial initial) {
350 {reducer(initial, mapper(specific_val))} -> std::convertible_to<Initial>;
352 friend future<
typename function_traits<Reducer>::return_type>
355 template<
typename SpecificValType,
typename Reducer,
typename Initial>
356 SEASTAR_CONCEPT( requires requires(SpecificValType specific_val, Reducer reducer, Initial initial) {
357 {reducer(initial, specific_val)} -> std::convertible_to<Initial>;
359 friend future<
typename function_traits<Reducer>::return_type>
366 SEASTAR_MODULE_EXPORT_END
371 scheduling_group_index(scheduling_group sg) noexcept {
377 scheduling_group_from_index(
unsigned index) noexcept {
378 return scheduling_group(index);
381 #ifdef SEASTAR_BUILD_SHARED_LIBS
383 current_scheduling_group_ptr() noexcept;
387 current_scheduling_group_ptr() noexcept {
389 static thread_local scheduling_group sg;
396 SEASTAR_MODULE_EXPORT_BEGIN
401 return *internal::current_scheduling_group_ptr();
406 default_scheduling_group() noexcept {
407 return scheduling_group();
410 SEASTAR_MODULE_EXPORT_END
414 scheduling_group::active() const noexcept {
422 SEASTAR_MODULE_EXPORT
426 return seastar::internal::scheduling_group_index(sg);
A representation of a possibly not-yet-computed value.
Definition: future.hh:1238
Definition: reactor.hh:168
Definition: scheduling.hh:183
friend future< scheduling_group_key > scheduling_group_key_create(scheduling_group_key_config cfg) noexcept
friend T & scheduling_group_get_specific(scheduling_group_key key) noexcept
Definition: scheduling_specific.hh:120
scheduling_group_key(const scheduling_group_key &) noexcept=default
The only user allowed operation on a key is copying.
Identifies function calls that are accounted as a group.
Definition: scheduling.hh:286
float get_shares() const noexcept
friend future< typename function_traits< Reducer >::return_type > map_reduce_scheduling_group_specific(Mapper mapper, Reducer reducer, Initial initial_val, scheduling_group_key key)
Definition: scheduling_specific.hh:150
constexpr scheduling_group() noexcept
Creates a scheduling_group object denoting the default group.
Definition: scheduling.hh:292
friend future< typename function_traits< Reducer >::return_type > reduce_scheduling_group_specific(Reducer reducer, Initial initial_val, scheduling_group_key key)
Definition: scheduling_specific.hh:184
friend future rename_scheduling_group(scheduling_group sg, sstring new_name, sstring new_shortname) noexcept
friend future< scheduling_group > create_scheduling_group(sstring name, sstring shortname, float shares) noexcept
T & get_specific(scheduling_group_key key) noexcept
Definition: scheduling.hh:307
friend future destroy_scheduling_group(scheduling_group sg) noexcept
future update_io_bandwidth(uint64_t bandwidth) const
Updates the current IO bandwidth for a given scheduling group.
void set_shares(float shares) noexcept
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
future< scheduling_group > create_scheduling_group(sstring name, float shares) noexcept
scheduling_group current_scheduling_group() noexcept
Returns the current scheduling group.
Definition: scheduling.hh:400
T & scheduling_group_get_specific(scheduling_group sg, scheduling_group_key key)
Definition: scheduling_specific.hh:104
future< scheduling_group_key > scheduling_group_key_create(scheduling_group_key_config cfg) noexcept
future destroy_scheduling_group(scheduling_group sg) noexcept
future rename_scheduling_group(scheduling_group sg, sstring new_name) noexcept
scheduling_group_key_config make_scheduling_group_key_config(ConstructorArgs... args)
Definition: scheduling.hh:249
Definition: scheduling.hh:143
size_t allocation_size
The allocation size for the value (usually: sizeof(T))
Definition: scheduling.hh:161
std::function< void(void *)> constructor
A function that will be called for each newly allocated value.
Definition: scheduling.hh:167
std::function< void(void *)> rename
A function that will be called for each value after the scheduling group is renamed.
Definition: scheduling.hh:169
std::type_index type_index
Holds the type information for debug mode runtime validation.
Definition: scheduling.hh:165
scheduling_group_key_config()
Definition: scheduling.hh:147
size_t alignment
The required alignment of the value (usually: alignof(T))
Definition: scheduling.hh:163
scheduling_group_key_config(const std::type_info &type_info)
Definition: scheduling.hh:158
std::function< void(void *)> destructor
Definition: scheduling.hh:172