From 3e5e4eb06c0ea6337464cbda0648a75bf76cca17 Mon Sep 17 00:00:00 2001 From: Lars Amsel Date: Fri, 3 Dec 2021 13:02:09 +0100 Subject: rfnoc: Add atomic item size property for RFNoC blocks An RFNoC block (like the radio) might require a minimal number of items in each clock cycle, e.g. the radio has to process SPC (samples per cycle). Because data in RFNoC is transmitted and processed in packets, we have to make sure the items inside these packets are a multiple of the items processed in each cycle. This commit adds an atomic item size properties which is set by the radio and adapted by the streamers. The streamers adapt the SPP property of the radio block controller depending on the MTU value. This might lead to an SPP value which does not align with the SPC value of the radio block, hence we add a property resolver for the atomic item size. --- host/lib/rfnoc/radio_control_impl.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'host/lib/rfnoc/radio_control_impl.cpp') diff --git a/host/lib/rfnoc/radio_control_impl.cpp b/host/lib/rfnoc/radio_control_impl.cpp index a5c69e229..a08470d8a 100644 --- a/host/lib/rfnoc/radio_control_impl.cpp +++ b/host/lib/rfnoc/radio_control_impl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,8 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) }); // Register spp properties and resolvers _spp_prop.reserve(get_num_output_ports()); + _atomic_item_size_in.reserve(get_num_input_ports()); + _atomic_item_size_out.reserve(get_num_output_ports()); _samp_rate_in.reserve(get_num_input_ports()); _samp_rate_out.reserve(get_num_output_ports()); _type_in.reserve(get_num_input_ports()); @@ -116,6 +119,14 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) get_max_spp(get_max_payload_size({res_source_info::OUTPUT_EDGE, chan})); _spp_prop.push_back( property_t(PROP_KEY_SPP, default_spp, {res_source_info::USER, chan})); + _atomic_item_size_in.push_back( + property_t(PROP_KEY_ATOMIC_ITEM_SIZE, + get_atomic_item_size(), + {res_source_info::INPUT_EDGE, chan})); + _atomic_item_size_out.push_back( + property_t(PROP_KEY_ATOMIC_ITEM_SIZE, + get_atomic_item_size(), + {res_source_info::OUTPUT_EDGE, chan})); _samp_rate_in.push_back(property_t( PROP_KEY_SAMP_RATE, get_tick_rate(), {res_source_info::INPUT_EDGE, chan})); _samp_rate_out.push_back(property_t( @@ -132,6 +143,8 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) _radio_reg_iface.poke32( regmap::REG_RX_MAX_WORDS_PER_PKT, words_per_pkt, chan); }); + register_property(&_atomic_item_size_in.back()); + register_property(&_atomic_item_size_out.back()); register_property(&_samp_rate_in.back()); register_property(&_samp_rate_out.back()); register_property(&_type_in.back()); @@ -163,6 +176,30 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) "spp must be greater than zero! Coercing to " << spp.get()); } }); + add_property_resolver({&_atomic_item_size_in.back(), + get_mtu_prop_ref({res_source_info::INPUT_EDGE, chan})}, + {&_atomic_item_size_in.back()}, + [this, chan, + &ais_in = _atomic_item_size_in.back()]() { + ais_in = uhd::math::lcm(ais_in, get_atomic_item_size()); + ais_in = std::min(ais_in, get_mtu({res_source_info::INPUT_EDGE, chan})); + if (ais_in.get() % get_atomic_item_size() > 0) { + ais_in = ais_in - (ais_in.get() % get_atomic_item_size()); + } + RFNOC_LOG_TRACE("Resolve atomic item size in to " << ais_in); + }); + add_property_resolver({&_atomic_item_size_out.back(), + get_mtu_prop_ref({res_source_info::OUTPUT_EDGE, chan})}, + {&_atomic_item_size_out.back()}, + [this, chan, + &ais_out = _atomic_item_size_out.back()]() { + ais_out = uhd::math::lcm(ais_out, get_atomic_item_size()); + ais_out = std::min(ais_out, get_mtu({res_source_info::OUTPUT_EDGE, chan})); + if (ais_out.get() % get_atomic_item_size() > 0) { + ais_out = ais_out - (ais_out.get() % get_atomic_item_size()); + } + RFNOC_LOG_TRACE("Resolve atomic item size out to " << ais_out); + }); // Note: The following resolver calls coerce_rate(), which is virtual. // At run time, it will use the implementation by the child class. add_property_resolver({&_samp_rate_in.back(), &_samp_rate_out.back()}, -- cgit v1.2.3