24#include <seastar/core/map_reduce.hh>
25#include <seastar/util/modules.hh>
39struct scheduling_group_specific_thread_local_data {
40 struct per_scheduling_group {
41 bool queue_is_initialized =
false;
47 std::vector<void*> specific_vals;
49 std::array<per_scheduling_group, max_scheduling_groups()> per_scheduling_group_data;
50 std::map<unsigned long, scheduling_group_key_config> scheduling_group_key_configs;
53#ifdef SEASTAR_BUILD_SHARED_LIBS
54scheduling_group_specific_thread_local_data** get_scheduling_group_specific_thread_local_data_ptr() noexcept;
57scheduling_group_specific_thread_local_data** get_scheduling_group_specific_thread_local_data_ptr() noexcept {
58 static thread_local scheduling_group_specific_thread_local_data* data;
63scheduling_group_specific_thread_local_data& get_scheduling_group_specific_thread_local_data() noexcept {
64 return **get_scheduling_group_specific_thread_local_data_ptr();
67[[noreturn]]
void no_such_scheduling_group(scheduling_group sg);
78T* scheduling_group_get_specific_ptr(scheduling_group sg, scheduling_group_key key)
noexcept {
79 auto& data = internal::get_scheduling_group_specific_thread_local_data();
81 assert(std::type_index(
typeid(T)) == data.scheduling_group_key_configs[key.id()].type_index);
83 auto sg_id = internal::scheduling_group_index(sg);
84 if (__builtin_expect(sg_id < data.per_scheduling_group_data.size() &&
85 data.per_scheduling_group_data[sg_id].queue_is_initialized,
true)) {
86 return reinterpret_cast<T*
>(data.per_scheduling_group_data[sg_id].specific_vals[key.id()]);
93SEASTAR_MODULE_EXPORT_BEGIN
106 T* p = internal::scheduling_group_get_specific_ptr<T>(sg, std::move(key));
108 internal::no_such_scheduling_group(sg);
125 auto& data = internal::get_scheduling_group_specific_thread_local_data();
126 assert(std::type_index(
typeid(T)) == data.scheduling_group_key_configs[key.id()].type_index);
128 return *
reinterpret_cast<T*
>(data.per_scheduling_group_data[sg_id].specific_vals[key.id()]);
146template<
typename SpecificValType,
typename Mapper,
typename Reducer,
typename Initial>
147requires requires(SpecificValType specific_val, Mapper mapper, Reducer reducer, Initial initial) {
148 {reducer(initial, mapper(specific_val))} -> std::convertible_to<Initial>;
150future<typename function_traits<Reducer>::return_type>
153 using per_scheduling_group = internal::scheduling_group_specific_thread_local_data::per_scheduling_group;
154 auto& data = internal::get_scheduling_group_specific_thread_local_data();
155 auto wrapped_mapper = [key, mapper] (per_scheduling_group& psg) {
156 auto id = internal::scheduling_group_key_id(key);
157 return make_ready_future<typename function_traits<Mapper>::return_type>
158 (mapper(*
reinterpret_cast<SpecificValType*
>(psg.specific_vals[
id])));
162 data.per_scheduling_group_data
163 | std::views::filter(std::mem_fn(&per_scheduling_group::queue_is_initialized)),
164 wrapped_mapper, std::move(initial_val), reducer);
180template<
typename SpecificValType,
typename Reducer,
typename Initial>
181requires requires(SpecificValType specific_val, Reducer reducer, Initial initial) {
182 {reducer(initial, specific_val)} -> std::convertible_to<Initial>;
184future<typename function_traits<Reducer>::return_type>
186 using per_scheduling_group = internal::scheduling_group_specific_thread_local_data::per_scheduling_group;
187 auto& data = internal::get_scheduling_group_specific_thread_local_data();
189 auto mapper = [key] (per_scheduling_group& psg) {
190 auto id = internal::scheduling_group_key_id(key);
191 return make_ready_future<SpecificValType>(*
reinterpret_cast<SpecificValType*
>(psg.specific_vals[
id]));
195 data.per_scheduling_group_data
196 | std::views::filter(std::mem_fn(&per_scheduling_group::queue_is_initialized)),
197 mapper, std::move(initial_val), reducer);
200SEASTAR_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:151
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:105
future< typename function_traits< Reducer >::return_type > reduce_scheduling_group_specific(Reducer reducer, Initial initial_val, scheduling_group_key key)
Definition: scheduling_specific.hh:185