24#include <seastar/core/map_reduce.hh>
25#include <seastar/util/modules.hh>
38struct scheduling_group_specific_thread_local_data {
39 struct per_scheduling_group {
40 bool queue_is_initialized =
false;
46 std::vector<void*> specific_vals;
48 std::array<per_scheduling_group, max_scheduling_groups()> per_scheduling_group_data;
49 std::vector<scheduling_group_key_config> scheduling_group_key_configs;
52#ifdef SEASTAR_BUILD_SHARED_LIBS
53scheduling_group_specific_thread_local_data** get_scheduling_group_specific_thread_local_data_ptr() noexcept;
56scheduling_group_specific_thread_local_data** get_scheduling_group_specific_thread_local_data_ptr() noexcept {
57 static thread_local scheduling_group_specific_thread_local_data* data;
62scheduling_group_specific_thread_local_data& get_scheduling_group_specific_thread_local_data() noexcept {
63 return **get_scheduling_group_specific_thread_local_data_ptr();
66[[noreturn]]
void no_such_scheduling_group(scheduling_group sg);
77T* scheduling_group_get_specific_ptr(scheduling_group sg, scheduling_group_key key)
noexcept {
78 auto& data = internal::get_scheduling_group_specific_thread_local_data();
80 assert(std::type_index(
typeid(T)) == data.scheduling_group_key_configs[key.id()].type_index);
82 auto sg_id = internal::scheduling_group_index(sg);
83 if (__builtin_expect(sg_id < data.per_scheduling_group_data.size() &&
84 data.per_scheduling_group_data[sg_id].queue_is_initialized,
true)) {
85 return reinterpret_cast<T*
>(data.per_scheduling_group_data[sg_id].specific_vals[key.id()]);
92SEASTAR_MODULE_EXPORT_BEGIN
105 T* p = internal::scheduling_group_get_specific_ptr<T>(sg, std::move(key));
107 internal::no_such_scheduling_group(sg);
124 auto& data = internal::get_scheduling_group_specific_thread_local_data();
125 assert(std::type_index(
typeid(T)) == data.scheduling_group_key_configs[key.id()].type_index);
127 return *
reinterpret_cast<T*
>(data.per_scheduling_group_data[sg_id].specific_vals[key.id()]);
145template<
typename SpecificValType,
typename Mapper,
typename Reducer,
typename Initial>
146requires requires(SpecificValType specific_val, Mapper mapper, Reducer reducer, Initial initial) {
147 {reducer(initial, mapper(specific_val))} -> std::convertible_to<Initial>;
149future<typename function_traits<Reducer>::return_type>
152 using per_scheduling_group = internal::scheduling_group_specific_thread_local_data::per_scheduling_group;
153 auto& data = internal::get_scheduling_group_specific_thread_local_data();
154 auto wrapped_mapper = [key, mapper] (per_scheduling_group& psg) {
155 auto id = internal::scheduling_group_key_id(key);
156 return make_ready_future<typename function_traits<Mapper>::return_type>
157 (mapper(*
reinterpret_cast<SpecificValType*
>(psg.specific_vals[
id])));
161 data.per_scheduling_group_data
162 | std::views::filter(std::mem_fn(&per_scheduling_group::queue_is_initialized)),
163 wrapped_mapper, std::move(initial_val), reducer);
179template<
typename SpecificValType,
typename Reducer,
typename Initial>
180requires requires(SpecificValType specific_val, Reducer reducer, Initial initial) {
181 {reducer(initial, specific_val)} -> std::convertible_to<Initial>;
183future<typename function_traits<Reducer>::return_type>
185 using per_scheduling_group = internal::scheduling_group_specific_thread_local_data::per_scheduling_group;
186 auto& data = internal::get_scheduling_group_specific_thread_local_data();
188 auto mapper = [key] (per_scheduling_group& psg) {
189 auto id = internal::scheduling_group_key_id(key);
190 return make_ready_future<SpecificValType>(*
reinterpret_cast<SpecificValType*
>(psg.specific_vals[
id]));
194 data.per_scheduling_group_data
195 | std::views::filter(std::mem_fn(&per_scheduling_group::queue_is_initialized)),
196 mapper, std::move(initial_val), reducer);
199SEASTAR_MODULE_EXPORT_END
Definition: scheduling.hh:183
Identifies function calls that are accounted as a group.
Definition: scheduling.hh:285
auto map_reduce(Iterator begin, Iterator end, Mapper &&mapper, Reducer &&r) -> typename reducer_traits< Reducer >::future_type
Definition: map_reduce.hh:107
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
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
scheduling_group current_scheduling_group() noexcept
Returns the current scheduling group.
Definition: scheduling.hh:397
T & scheduling_group_get_specific(scheduling_group sg, scheduling_group_key key)
Definition: scheduling_specific.hh:104
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