Skip to content

Commit a0a0c01

Browse files
carlo-galcodebot
authored andcommitted
sched: fix unittests and related pucch_allocator code
Signed-off-by: Carlo Galiotto <[email protected]>
1 parent 54f61c9 commit a0a0c01

File tree

11 files changed

+848
-544
lines changed

11 files changed

+848
-544
lines changed

include/srsran/scheduler/scheduler_slot_handler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ struct prach_occasion_info {
482482

483483
/// Info about PUCCH used resource.
484484
struct pucch_info {
485+
/// This information only is used by the scheduler.
486+
struct context {
487+
unsigned id = MAX_PUCCH_PDUS_PER_SLOT;
488+
bool is_common = false;
489+
};
490+
485491
rnti_t crnti;
486492
const bwp_configuration* bwp_cfg;
487493
pucch_format format;
@@ -496,6 +502,8 @@ struct pucch_info {
496502
};
497503
/// In case the PUCCH will contain CSI bits, this struct contains information how those bits are to be decoded.
498504
std::optional<csi_report_configuration> csi_rep_cfg;
505+
506+
context pdu_context;
499507
};
500508

501509
struct ul_sched_result {

lib/scheduler/pucch_scheduling/pucch_allocator.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ struct pucch_uci_bits {
2424
/// Number of SR info bits that should have been reported in the removed PUCCH grant.
2525
sr_nof_bits sr_bits{sr_nof_bits::no_sr};
2626
/// Number of CSI Part 1 info bits that should have been reported in the removed PUCCH grant.
27-
unsigned csi_part1_bits{0};
27+
unsigned csi_part1_nof_bits{0};
2828
// TODO: add extra bits for CSI Part 2.
29+
30+
[[nodiscard]] unsigned get_total_bits() const
31+
{
32+
return harq_ack_nof_bits + sr_nof_bits_to_uint(sr_bits) + csi_part1_nof_bits;
33+
}
2934
};
3035

3136
/// PUCCH scheduling interface.

lib/scheduler/pucch_scheduling/pucch_allocator_impl.cpp

Lines changed: 471 additions & 221 deletions
Large diffs are not rendered by default.

lib/scheduler/pucch_scheduling/pucch_allocator_impl.h

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,6 @@ class pucch_allocator_impl final : public pucch_allocator
8787
unsigned r_pucch;
8888
};
8989

90-
struct uci_bits {
91-
unsigned harq_ack_bits = 0U;
92-
sr_nof_bits sr_bits = sr_nof_bits::no_sr;
93-
unsigned csi_part1_bits = 0U;
94-
95-
[[nodiscard]] unsigned get_total_bits() const
96-
{
97-
return harq_ack_bits + sr_nof_bits_to_uint(sr_bits) + csi_part1_bits;
98-
}
99-
};
100-
10190
// At the moment, we only supports PUCCH resource set index 0 and 1.
10291
enum class pucch_res_set_idx : uint8_t { set_0 = 0, set_1 };
10392

@@ -106,21 +95,31 @@ class pucch_allocator_impl final : public pucch_allocator
10695
uint8_t pucch_res_ind = 0;
10796
};
10897

98+
/// Defines the type of resource.
99+
/// HARQ indicates the HAR-ACK resource (it can carry HARQ-ACK and/or SR and/or CSI bits).
100+
/// SR indicates the resource dedicated for SR (it can carry SR and HARQ-ACK bits).
101+
/// CSI indicates the resource dedicated for CSI (it can carry CSI and SR bits).
109102
enum class pucch_grant_type { harq_ack, sr, csi };
110103

104+
/// \brief Defines a PUCCH grant (and its relevant information) currently allocated to a given UE.
105+
/// It is used internally to keep track of the UEs' allocations of the PUCCH grants with dedicated resources.
111106
class pucch_grant
112107
{
113108
public:
114109
pucch_grant_type type;
115110
// Only relevant for HARQ-ACK resources.
116111
harq_res_id harq_id;
117-
pucch_format format;
118-
uci_bits bits;
112+
pucch_uci_bits bits;
119113
const pucch_resource* pucch_res_cfg = nullptr;
120114

115+
[[nodiscard]] pucch_format get_format() const
116+
{
117+
return pucch_res_cfg != nullptr ? pucch_res_cfg->format : pucch_format::NOF_FORMATS;
118+
}
121119
[[nodiscard]] ofdm_symbol_range get_symbols() const;
122120
};
123121

122+
/// \brief List of possible PUCCH grants that allocated to a UE, at a given slot.
124123
class pucch_grant_list
125124
{
126125
public:
@@ -129,30 +128,31 @@ class pucch_allocator_impl final : public pucch_allocator
129128
std::optional<pucch_grant> csi_resource;
130129
unsigned nof_grants = 0;
131130

132-
[[nodiscard]] uci_bits get_uci_bits() const;
131+
[[nodiscard]] pucch_uci_bits get_uci_bits() const;
132+
[[nodiscard]] bool is_emtpy() const;
133133
};
134134

135135
/// Keeps track of the PUCCH grants (common + dedicated) for a given UE.
136136
struct ue_grants {
137137
rnti_t rnti;
138-
bool has_common_pucch;
139-
138+
// Information about the common PUCCH grant.
139+
bool has_common_pucch = false;
140+
// List of PUCCH grants with dedicated resources.
140141
pucch_grant_list pucch_grants;
141142
};
142143

143144
using slot_pucch_grants = static_vector<ue_grants, MAX_PUCCH_PDUS_PER_SLOT>;
144145

145-
class res_manager_garbage_collector
146-
{
147-
public:
148-
res_manager_garbage_collector(pucch_resource_manager& res_manager_) : res_manager(res_manager_){};
149-
146+
/// \brief Collects the information of what PUCCH cell resources have been allocated to a UE at given slot.
147+
/// This info is only used during the allocation, and the PUCCH allocator is called for a new UE or new allocation.
148+
struct res_manager_garbage_collector {
150149
bool harq_set_0 = false;
151150
bool harq_set_1 = false;
152151
bool csi = false;
153152
bool sr = false;
154153
pucch_resource_manager& res_manager;
155154

155+
res_manager_garbage_collector(pucch_resource_manager& res_manager_) : res_manager(res_manager_){};
156156
void reset();
157157
void release_resource(slot_point slot_tx, rnti_t crnti, const ue_cell_configuration& ue_cell_cfg);
158158
};
@@ -168,7 +168,7 @@ class pucch_allocator_impl final : public pucch_allocator
168168
pucch_common_params pucch_params);
169169

170170
std::optional<pucch_common_params> find_common_and_ded_harq_res_available(cell_slot_resource_allocator& pucch_alloc,
171-
ue_grants* existing_grants,
171+
ue_grants& existing_grants,
172172
rnti_t rnti,
173173
const ue_cell_configuration& ue_cell_cfg,
174174
const dci_context_information& dci_info);
@@ -184,34 +184,14 @@ class pucch_allocator_impl final : public pucch_allocator
184184
const ue_cell_configuration& ue_cell_cfg,
185185
unsigned csi_part1_bits);
186186

187-
// Fills the PUCCH HARQ grant for common resources.
188-
void fill_pucch_harq_common_grant(pucch_info& pucch_info, rnti_t rnti, const pucch_res_alloc_cfg& pucch_res);
189-
190-
// Fills the PUCCH Format 1 grant.
191-
void fill_pucch_ded_format1_grant(pucch_info& pucch_grant,
192-
rnti_t crnti,
193-
const pucch_resource& pucch_ded_res_cfg,
194-
unsigned harq_ack_bits,
195-
sr_nof_bits sr_bits);
196-
197-
// Fills the PUCCH Format 2 grant.
198-
void fill_pucch_format2_grant(pucch_info& pucch_grant,
199-
rnti_t crnti,
200-
const pucch_resource& pucch_ded_res_cfg,
201-
const ue_cell_configuration& ue_cell_cfg,
202-
unsigned nof_prbs,
203-
unsigned harq_ack_bits,
204-
sr_nof_bits sr_bits,
205-
unsigned csi_part1_bits);
206-
207187
std::optional<unsigned> multiplex_and_allocate_pucch(cell_slot_resource_allocator& pucch_slot_alloc,
208-
uci_bits new_bits,
188+
pucch_uci_bits new_bits,
209189
ue_grants& current_grants,
210190
const ue_cell_configuration& ue_cell_cfg,
211191
bool preserve_res_indicator = false);
212192

213193
std::optional<pucch_grant_list> get_pucch_res_pre_multiplexing(slot_point sl_tx,
214-
uci_bits new_bits,
194+
pucch_uci_bits new_bits,
215195
ue_grants ue_current_grants,
216196
const ue_cell_configuration& ue_cell_cfg);
217197

@@ -233,6 +213,26 @@ class pucch_allocator_impl final : public pucch_allocator
233213
pucch_grant_list grants_to_tx,
234214
const ue_cell_configuration& ue_cell_cfg);
235215

216+
// Fills the PUCCH HARQ grant for common resources.
217+
void fill_pucch_harq_common_grant(pucch_info& pucch_info, rnti_t rnti, const pucch_res_alloc_cfg& pucch_res);
218+
219+
// Fills the PUCCH Format 1 grant.
220+
void fill_pucch_ded_format1_grant(pucch_info& pucch_grant,
221+
rnti_t crnti,
222+
const pucch_resource& pucch_ded_res_cfg,
223+
unsigned harq_ack_bits,
224+
sr_nof_bits sr_bits);
225+
226+
// Fills the PUCCH Format 2 grant.
227+
void fill_pucch_format2_grant(pucch_info& pucch_grant,
228+
rnti_t crnti,
229+
const pucch_resource& pucch_ded_res_cfg,
230+
const ue_cell_configuration& ue_cell_cfg,
231+
unsigned nof_prbs,
232+
unsigned harq_ack_bits,
233+
sr_nof_bits sr_bits,
234+
unsigned csi_part1_bits);
235+
236236
/// //////////// Private helpers //////////////
237237

238238
void remove_unsed_pucch_res(slot_point sl_tx,

lib/scheduler/pucch_scheduling/pucch_resource_manager.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,17 @@ pucch_harq_resource_alloc_record pucch_resource_manager::reserve_next_harq_res_a
273273
"Indexing of PUCCH resource set exceeds the size of the cell resource array");
274274
span<resource_tracker> slot_ue_res_array(&slot_res_array[ue_first_res_id], ue_res_id_set_for_harq.size());
275275

276-
// Check first if there is any PUCCH resource is available.
276+
// Check first if there is any PUCCH resource already used by this UE.
277277
auto* available_resource = std::find_if(slot_ue_res_array.begin(),
278278
slot_ue_res_array.end(),
279-
[](const resource_tracker res) { return res.rnti == rnti_t::INVALID_RNTI; });
279+
[crnti](const resource_tracker res) { return res.rnti == crnti; });
280+
281+
// If not, find an available resource.
282+
if (available_resource == slot_ue_res_array.end()) {
283+
available_resource = std::find_if(slot_ue_res_array.begin(),
284+
slot_ue_res_array.end(),
285+
[](const resource_tracker res) { return res.rnti == rnti_t::INVALID_RNTI; });
286+
}
280287

281288
const auto& pucch_res_list = pucch_cfg.pucch_res_list;
282289

lib/scheduler/uci_scheduling/uci_allocator_impl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ std::optional<uci_allocation> uci_allocator_impl::alloc_uci_harq_ue(cell_resourc
184184
{
185185
// [Implementation-defined] We restrict the number of HARQ bits per PUCCH that are expected to carry CSI reporting to
186186
// 2 , until the PUCCH allocator supports more than this.
187+
// TODO: remove this, as with the new refactor we are not constrained by this anymore.
187188
static const uint8_t max_harq_bits_per_uci = 2U;
188189

189190
const slot_point pdsch_slot = res_alloc[k0].slot;
@@ -262,15 +263,15 @@ void uci_allocator_impl::multiplex_uci_on_pusch(ul_sched_info& pu
262263
const pucch_uci_bits pucch_uci = pucch_alloc.remove_ue_uci_from_pucch(slot_alloc, crnti, ue_cell_cfg);
263264

264265
// In case there are no UCI bits from PUCCH, then there is no UCI to be multiplexed on the PUSCH.
265-
if (pucch_uci.harq_ack_nof_bits == 0 and pucch_uci.csi_part1_bits == 0) {
266+
if (pucch_uci.harq_ack_nof_bits == 0 and pucch_uci.csi_part1_nof_bits == 0) {
266267
return;
267268
}
268269

269270
// We assume that at this point, there are no existing UCI grants in the PUSCH; allocate a new one.
270271
uci_info& uci = pusch_grant.uci.emplace();
271272
uci.alpha = ue_cell_cfg.cfg_dedicated().ul_config.value().init_ul_bwp.pusch_cfg.value().uci_cfg.value().scaling;
272273

273-
if (pucch_uci.csi_part1_bits != 0) {
274+
if (pucch_uci.csi_part1_nof_bits != 0) {
274275
// The number of bits is computed based on the CSI report configuration.
275276
add_csi_to_uci_on_pusch(uci.csi.emplace(uci_info::csi_info()), ue_cell_cfg);
276277
}

tests/unittests/scheduler/scheduler_ue_fallback_mode_test.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class scheduler_con_res_msg4_test : public base_scheduler_conres_test,
111111
void enqueue_random_number_of_rach_indications()
112112
{
113113
rach_indication_message rach_ind{to_du_cell_index(0), next_slot_rx(), {{0, 0, {}}}};
114-
unsigned nof_preambles = test_rgen::uniform_int<unsigned>(1, 10);
114+
auto nof_preambles = test_rgen::uniform_int<unsigned>(1, 10);
115115
for (unsigned i = 0; i != nof_preambles; ++i) {
116116
rach_ind.occasions[0].preambles.push_back({i, to_rnti((uint16_t)rnti + 1 + i), phy_time_unit{}});
117117
}
@@ -173,12 +173,12 @@ TEST_P(scheduler_con_res_msg4_test, while_ue_is_in_fallback_then_common_pucch_is
173173

174174
// Wait for ConRes + Msg4 PDCCH, PDSCH and PUCCH to be scheduled.
175175
ASSERT_TRUE(this->run_slot_until([this]() {
176-
for (const auto& pucch : this->last_sched_res_list[to_du_cell_index(0)]->ul.pucchs) {
177-
if (pucch.crnti == rnti and pucch.format == pucch_format::FORMAT_1 and pucch.format_1.harq_ack_nof_bits > 0) {
178-
return true;
179-
}
180-
}
181-
return false;
176+
return std::any_of(this->last_sched_res_list[to_du_cell_index(0)]->ul.pucchs.begin(),
177+
this->last_sched_res_list[to_du_cell_index(0)]->ul.pucchs.end(),
178+
[rnti = this->rnti](const pucch_info& pucch) {
179+
return pucch.crnti == rnti and pucch.format == pucch_format::FORMAT_1 and
180+
pucch.format_1.harq_ack_nof_bits > 0;
181+
});
182182
}));
183183

184184
// Enqueue SRB1 data; with the UE in fallback mode, and after the MSG4 has been delivered, both common and dedicated
@@ -225,25 +225,31 @@ TEST_P(scheduler_con_res_msg4_test, while_ue_is_in_fallback_then_common_pucch_is
225225
return true;
226226
}
227227
}
228+
return false;
228229
}
229230
// Case of 3 PUCCH grants.
230231
else if (this->last_sched_res_list[to_du_cell_index(0)]->ul.pucchs.size() == 3) {
231232
for (const auto& pucch : this->last_sched_res_list[to_du_cell_index(0)]->ul.pucchs) {
232233
if (pucch.crnti == rnti and pucch.format == pucch_format::FORMAT_1) {
233-
if (pucch.format_1.sr_bits == sr_nof_bits::no_sr) {
234-
if (pucch.format_1.harq_ack_nof_bits > 0) {
235-
pucch.resources.second_hop_prbs.empty() ? pucch_res_ptrs.f1_ded_ptr = &pucch
236-
: pucch_res_ptrs.f1_common_ptr = &pucch;
234+
if (pucch.format_1.sr_bits == sr_nof_bits::no_sr and pucch.format_1.harq_ack_nof_bits > 0 and
235+
not pucch.resources.second_hop_prbs.empty()) {
236+
pucch_res_ptrs.f1_common_ptr = &pucch;
237+
} else if (pucch.format_1.sr_bits == sr_nof_bits::one and pucch.format_1.harq_ack_nof_bits > 0) {
238+
// We cannot tell whether it's a f1_ded_sr_ptr or f1_ded_ptr yet only from the bits and format. But this is
239+
// not important for the test. We only need to know that both pointers are set.
240+
if (pucch_res_ptrs.f1_ded_ptr == nullptr and pucch_res_ptrs.f1_ded_sr_ptr == nullptr) {
241+
pucch_res_ptrs.f1_ded_ptr = &pucch;
242+
} else if (pucch_res_ptrs.f1_ded_ptr != nullptr and pucch_res_ptrs.f1_ded_sr_ptr == nullptr) {
243+
pucch_res_ptrs.f1_ded_sr_ptr = &pucch;
237244
}
238-
} else {
239-
pucch_res_ptrs.f1_ded_sr_ptr = &pucch;
240245
}
241246
}
242247
if (pucch_res_ptrs.f1_common_ptr != nullptr and pucch_res_ptrs.f1_ded_ptr != nullptr and
243248
pucch_res_ptrs.f1_ded_sr_ptr != nullptr) {
244249
return true;
245250
}
246251
}
252+
return false;
247253
}
248254

249255
return false;

tests/unittests/scheduler/test_utils/config_generators.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lib/scheduler/config/sched_config_manager.h"
1515
#include "srsran/du/du_cell_config_helpers.h"
1616
#include "srsran/ran/duplex_mode.h"
17+
#include "srsran/ran/pucch/pucch_info.h"
1718
#include "srsran/scheduler/config/csi_helper.h"
1819
#include "srsran/scheduler/config/logical_channel_config_factory.h"
1920
#include "srsran/scheduler/config/sched_cell_config_helpers.h"
@@ -257,6 +258,12 @@ inline uplink_config make_test_ue_uplink_config(const config_helpers::cell_confi
257258
config_helpers::generate_k2_candidates(cyclic_prefix::NORMAL, params.tdd_ul_dl_cfg_common.value());
258259
}
259260

261+
// Compute the max UCI payload per format.
262+
pucch_cfg.format_max_payload[pucch_format_to_uint(pucch_format::FORMAT_1)] = 2U;
263+
const auto& res_f2 = std::get<pucch_format_2_3_cfg>(res_basic_f2.format_params);
264+
pucch_cfg.format_max_payload[pucch_format_to_uint(pucch_format::FORMAT_2)] = get_pucch_format2_max_payload(
265+
res_f2.nof_prbs, res_f2.nof_symbols, to_max_code_rate_float(pucch_cfg.format_2_common_param.value().max_c_rate));
266+
260267
// > SRS config.
261268
ul_config.init_ul_bwp.srs_cfg.emplace(config_helpers::make_default_srs_config(params));
262269

0 commit comments

Comments
 (0)