Skip to content

Commit c329528

Browse files
carlo-galcodebot
authored andcommitted
sched: add ul grants size check before empl. in ra_sched
Signed-off-by: Carlo Galiotto <[email protected]>
1 parent 3dcd8bc commit c329528

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

lib/scheduler/common_scheduling/ra_scheduler.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ unsigned srsran::get_msg3_delay(const pusch_time_domain_resource_allocation& pus
3333
"PUSCH subcarrier spacing not supported for MSG3 delay");
3434

3535
// The array represents Table 6.1.2.1.1-5, in TS 38.214.
36-
static const std::array<uint8_t, 4> DELTAS{2, 3, 4, 6};
36+
static constexpr std::array<uint8_t, 4> DELTAS{2, 3, 4, 6};
3737

3838
// The MSG3 slot is defined as MSG3_slot = floor( n * (2^*(mu_PUSCH) ) / (2^*(mu_PDCCH) ) ) + k2 + Delta.
3939
// Given the assumption mu_PUSCH == mu_PDCCH, MSG3_delay simplifies to MSG3_delay = k2 + Delta
@@ -145,10 +145,10 @@ ra_scheduler::ra_scheduler(const scheduler_ra_expert_config& sched_cfg_,
145145
void ra_scheduler::precompute_rar_fields()
146146
{
147147
// RAR payload size in bytes as per TS38.321, 6.1.5 and 6.2.3.
148-
static const unsigned rar_payload_size_bytes = 7, rar_subheader_size_bytes = 1;
148+
static constexpr unsigned rar_payload_size_bytes = 7, rar_subheader_size_bytes = 1;
149149
// As per TS 38.214, Section 5.1.3.2, nof_oh_prb = 0 if PDSCH is scheduled by PDCCH with a CRC scrambled by RA-RNTI.
150-
static const unsigned nof_oh_prb = 0;
151-
static const unsigned nof_layers = 1;
150+
static constexpr unsigned nof_oh_prb = 0;
151+
static constexpr unsigned nof_layers = 1;
152152

153153
const span<const pdsch_time_domain_resource_allocation> pdsch_td_list =
154154
get_ra_rnti_pdsch_time_domain_list(cell_cfg.dl_cfg_common.init_dl_bwp.pdsch_common,
@@ -182,8 +182,8 @@ void ra_scheduler::precompute_msg3_pdus()
182182
// Msg3 UL CCCH message size is up to 64bits (8 octets), and its subheader has 1 octet as per TS38.321.
183183
static constexpr unsigned max_msg3_sdu_payload_size_bytes = 8, msg3_subheader_size_bytes = 1;
184184
// As per TS 38.214, Section 5.1.3.2, nof_oh_prb = 0 if PDSCH is scheduled by PDCCH with a CRC scrambled by RA-RNTI.
185-
static const unsigned nof_oh_prb = 0;
186-
static const unsigned nof_layers = 1;
185+
static constexpr unsigned nof_oh_prb = 0;
186+
static constexpr unsigned nof_layers = 1;
187187

188188
msg3_mcs_config = pusch_mcs_get_config(
189189
pusch_mcs_table::qam64, sched_cfg.msg3_mcs_index, cell_cfg.use_msg3_transform_precoder(), false);
@@ -239,7 +239,7 @@ void ra_scheduler::handle_rach_indication(const rach_indication_message& msg)
239239

240240
void ra_scheduler::handle_rach_indication_impl(const rach_indication_message& msg, slot_point sl_tx)
241241
{
242-
static const unsigned prach_duration = 1; // TODO: Take from config
242+
static constexpr unsigned prach_duration = 1; // TODO: Take from config
243243

244244
for (const auto& prach_occ : msg.occasions) {
245245
// As per Section 5.1.3, TS 38.321, and from Section 5.3.2, TS 38.211, slot_idx uses as the numerology of reference
@@ -460,7 +460,7 @@ void ra_scheduler::update_pending_rars(slot_point pdcch_slot)
460460
}
461461
}
462462

463-
bool ra_scheduler::is_slot_candidate_for_rar(cell_slot_resource_allocator& slot_res_alloc)
463+
bool ra_scheduler::is_slot_candidate_for_rar(const cell_slot_resource_allocator& slot_res_alloc)
464464
{
465465
slot_point pdcch_slot = slot_res_alloc.slot;
466466

@@ -694,14 +694,22 @@ unsigned ra_scheduler::schedule_rar(pending_rar_t& rar, cell_resource_allocator&
694694
crb_bitmap used_ul_crbs = msg3_alloc.ul_res_grid.used_crbs(get_ul_bwp_cfg(), pusch_list[puschidx].symbols);
695695
// Mark the CRBs used by PUCCH as occupied.
696696
used_ul_crbs |= pucch_crbs;
697-
crb_interval msg3_crbs = rb_helper::find_empty_interval_of_length(used_ul_crbs, nof_msg3_rbs);
698-
pusch_res_max_allocs = msg3_crbs.length() / nof_rbs_per_msg3;
699-
if (pusch_res_max_allocs == 0) {
697+
crb_interval msg3_crbs = rb_helper::find_empty_interval_of_length(used_ul_crbs, nof_msg3_rbs);
698+
const unsigned max_allocs_on_free_rbs = msg3_crbs.length() / nof_rbs_per_msg3;
699+
700+
if (max_allocs_on_free_rbs == 0) {
700701
continue;
701702
}
702703

703704
// >> Register Msg3 allocations for this PUSCH resource as successful.
704705
unsigned last_crb = msg3_crbs.start();
706+
// NOTE: this should not happen, but we added as an extra safety step.
707+
if (max_allocs_on_free_rbs + msg3_alloc.result.ul.puschs.size() > msg3_alloc.result.ul.puschs.capacity()) {
708+
logger.warning("Overestimated number of MSG3 grants that can be allocated ({} > {}). This number will be capped",
709+
max_allocs_on_free_rbs,
710+
list_space);
711+
}
712+
pusch_res_max_allocs = std::min(max_allocs_on_free_rbs, pusch_res_max_allocs);
705713
for (unsigned i = 0; i < pusch_res_max_allocs; ++i) {
706714
msg3_alloc_candidate& candidate = msg3_candidates.emplace_back();
707715
candidate.crbs = {last_crb, last_crb + nof_rbs_per_msg3};
@@ -718,9 +726,9 @@ unsigned ra_scheduler::schedule_rar(pending_rar_t& rar, cell_resource_allocator&
718726
rar_crbs.resize(get_nof_pdsch_prbs_required(pdsch_time_res_index, max_nof_allocs).nof_prbs);
719727

720728
// > Find space in PDCCH for RAR.
721-
static const aggregation_level aggr_lvl = aggregation_level::n4;
722-
const search_space_id ss_id = cell_cfg.dl_cfg_common.init_dl_bwp.pdcch_common.ra_search_space_id;
723-
pdcch_dl_information* pdcch = pdcch_sch.alloc_dl_pdcch_common(pdcch_alloc, rar.ra_rnti, ss_id, aggr_lvl);
729+
static constexpr aggregation_level aggr_lvl = aggregation_level::n4;
730+
const search_space_id ss_id = cell_cfg.dl_cfg_common.init_dl_bwp.pdcch_common.ra_search_space_id;
731+
pdcch_dl_information* pdcch = pdcch_sch.alloc_dl_pdcch_common(pdcch_alloc, rar.ra_rnti, ss_id, aggr_lvl);
724732
if (pdcch == nullptr) {
725733
log_postponed_rar(rar, "No PDCCH space for RAR", pdcch_slot);
726734
++rar.failed_attempts.pdcch;
@@ -780,11 +788,17 @@ void ra_scheduler::fill_rar_grant(cell_resource_allocator& res_alloc,
780788
auto& pending_msg3 = pending_msg3s[to_value(rar_request.tc_rntis[i]) % MAX_NOF_MSG3];
781789
srsran_sanity_check(pending_msg3.busy(), "Pending Msg3 entry should have been reserved when RACH was received");
782790

783-
// Allocate Msg3 UL HARQ
791+
// Allocate Msg3 UL HARQ.
784792
std::optional<ul_harq_process_handle> h_ul =
785793
pending_msg3.msg3_harq_ent.alloc_ul_harq(msg3_alloc.slot, sched_cfg.max_nof_msg3_harq_retxs);
786794
srsran_sanity_check(h_ul.has_value(), "Pending Msg3 HARQ must be available when RAR is allocated");
787795

796+
if (rar.grants.full() or msg3_alloc.result.ul.puschs.full()) {
797+
logger.error("RAR grant for tc-rnti={} will be dropped. Cause: no available free RAR or UL grants",
798+
pending_msg3.preamble.tc_rnti);
799+
return;
800+
}
801+
788802
// Add MAC SDU with UL grant (Msg3) in RAR PDU.
789803
rar_ul_grant& msg3_info = rar.grants.emplace_back();
790804
msg3_info.rapid = pending_msg3.preamble.preamble_id;
@@ -819,7 +833,7 @@ void ra_scheduler::fill_rar_grant(cell_resource_allocator& res_alloc,
819833
}
820834
}
821835

822-
void ra_scheduler::schedule_msg3_retx(cell_resource_allocator& res_alloc, pending_msg3_t& msg3_ctx)
836+
void ra_scheduler::schedule_msg3_retx(cell_resource_allocator& res_alloc, pending_msg3_t& msg3_ctx) const
823837
{
824838
cell_slot_resource_allocator& pdcch_alloc = res_alloc[0];
825839
const bwp_configuration& bwp_ul_cmn = cell_cfg.ul_cfg_common.init_ul_bwp.generic_params;

lib/scheduler/common_scheduling/ra_scheduler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ra_scheduler
124124
void update_pending_rars(slot_point pdcch_slot);
125125

126126
/// Determines whether the resource grid for the provided slot has the conditions for RAR scheduling.
127-
bool is_slot_candidate_for_rar(cell_slot_resource_allocator& slot_res_alloc);
127+
bool is_slot_candidate_for_rar(const cell_slot_resource_allocator& slot_res_alloc);
128128

129129
/// Try scheduling pending RARs for the provided slot.
130130
void schedule_pending_rars(cell_resource_allocator& res_alloc, slot_point pdcch_slot);
@@ -148,7 +148,7 @@ class ra_scheduler
148148
span<const msg3_alloc_candidate> msg3_candidates);
149149

150150
/// Schedule retransmission of Msg3.
151-
void schedule_msg3_retx(cell_resource_allocator& res_alloc, pending_msg3_t& msg3_ctx);
151+
void schedule_msg3_retx(cell_resource_allocator& res_alloc, pending_msg3_t& msg3_ctx) const;
152152

153153
sch_prbs_tbs get_nof_pdsch_prbs_required(unsigned time_res_idx, unsigned nof_ul_grants) const;
154154

0 commit comments

Comments
 (0)