Skip to content

Commit 404d013

Browse files
committed
sched: only reserve CSI/SR resources after running the multiplexing algorithm
1 parent a34fcb7 commit 404d013

File tree

3 files changed

+81
-12
lines changed

3 files changed

+81
-12
lines changed

lib/scheduler/pucch_scheduling/pucch_allocator_impl.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "srsran/ran/resource_allocation/ofdm_symbol_range.h"
2020
#include "srsran/scheduler/result/sched_result.h"
2121
#include "srsran/srslog/srslog.h"
22+
#include "srsran/support/srsran_assert.h"
2223
#include <algorithm>
2324
#include <array>
2425
#include <variant>
@@ -1285,6 +1286,28 @@ pucch_allocator_impl::multiplex_and_allocate_pucch(cell_slot_resource_allocator&
12851286
return std::nullopt;
12861287
}
12871288

1289+
// Reserve the resources needed for the multiplexed grants.
1290+
if (grants_to_tx.sr_resource.has_value()) {
1291+
const auto* sr_res = guard.reserve_sr_resource();
1292+
if (sr_res == nullptr) {
1293+
logger.error("rnti={}: the multiplexing of PUCCH resources for slot={} could not be completed. Cause: SR "
1294+
"resource not available",
1295+
current_grants.rnti,
1296+
pucch_slot_alloc.slot);
1297+
return std::nullopt;
1298+
}
1299+
}
1300+
if (grants_to_tx.csi_resource.has_value()) {
1301+
const auto* csi_res = guard.reserve_csi_resource();
1302+
if (csi_res == nullptr) {
1303+
logger.error("rnti={}: the multiplexing of PUCCH resources for slot={} could not be completed. Cause: CSI "
1304+
"resource not available",
1305+
current_grants.rnti,
1306+
pucch_slot_alloc.slot);
1307+
return std::nullopt;
1308+
}
1309+
}
1310+
12881311
// If the grants for the common PUCCH resource are provided, this PUCCH is allocated by the fallback scheduler.
12891312
if (common_grants.has_value()) {
12901313
// At most 3 PUCCH resources with 2 grants each.
@@ -1374,12 +1397,9 @@ pucch_allocator_impl::get_pucch_res_pre_multiplexing(pucch_resource_manager::ue_
13741397
// Get the resource from the resource manager; the UCI bits will be added later.
13751398
// NOTE: if the SR resource was already assigned to this UE, the resource manager will only return the PUCCH
13761399
// config that was reserved previously.
1377-
const pucch_resource* sr_resource = guard.reserve_sr_resource();
1378-
if (sr_resource == nullptr) {
1379-
srsran_assertion_failure("rnti={}: PUCCH SR resource previously reserved not available anymore",
1380-
ue_current_grants.rnti);
1381-
return std::nullopt;
1382-
}
1400+
const pucch_resource* sr_resource = guard.peek_sr_resource();
1401+
srsran_assert(
1402+
sr_resource != nullptr, "rnti={}: Peeking a PUCCH SR resource returned nullptr", ue_current_grants.rnti);
13831403
sr_candidate_grant.set_res_config(*sr_resource);
13841404
// Only copy the SR bits, as at this stage we only need to consider the UCI bits assuming the resources still
13851405
// need to be multiplexed.
@@ -1395,12 +1415,9 @@ pucch_allocator_impl::get_pucch_res_pre_multiplexing(pucch_resource_manager::ue_
13951415
// Get the resource from the resource manager; the UCI bits will be added later.
13961416
// NOTE: if the CSI resource was already assigned to this UE, the resource manager will only return the PUCCH
13971417
// config that was reserved previously.
1398-
const pucch_resource* csi_resource = guard.reserve_csi_resource();
1399-
if (csi_resource == nullptr) {
1400-
srsran_assertion_failure("rnti={}: PUCCH CSI resource previously reserved not available anymore",
1401-
ue_current_grants.rnti);
1402-
return std::nullopt;
1403-
}
1418+
const pucch_resource* csi_resource = guard.peek_csi_resource();
1419+
srsran_assert(
1420+
csi_resource != nullptr, "rnti={}: Peeking a PUCCH CSI resource returned nullptr", ue_current_grants.rnti);
14041421
csi_candidate_grant.set_res_config(*csi_resource);
14051422
// Only copy the HARQ-ACK bits, as at this stage we only need to consider the UCI bits assuming the resources
14061423
// still need to be multiplexed.

lib/scheduler/pucch_scheduling/pucch_resource_manager.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,52 @@ const pucch_resource* pucch_resource_manager::ue_reservation_guard::reserve_csi_
231231
return res_cfg;
232232
}
233233

234+
const pucch_resource* pucch_resource_manager::ue_reservation_guard::peek_sr_resource() const
235+
{
236+
srsran_assert(parent != nullptr, "Trying to make a new PUCCH resource reservation after commit has been called");
237+
const auto& pucch_cfg = ue_cfg.init_bwp().ul_ded->pucch_cfg.value();
238+
239+
// We assume each UE only has 1 SR Resource Config configured.
240+
srsran_sanity_check(pucch_cfg.sr_res_list.size() == 1, "UE SR resource list must have size 1.");
241+
const unsigned cell_res_id = pucch_cfg.sr_res_list[0].pucch_res_id.cell_res_id;
242+
243+
// Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
244+
const auto& pucch_res_list = pucch_cfg.pucch_res_list;
245+
const auto* res_cfg =
246+
std::find_if(pucch_res_list.begin(), pucch_res_list.end(), [cell_res_id](const pucch_resource& res) {
247+
return res.res_id.cell_res_id == cell_res_id;
248+
});
249+
srsran_assert(res_cfg != pucch_res_list.end(),
250+
"rnti={}: PUCCH resource with cell_res_id={} not found in PUCCH resource list",
251+
rnti,
252+
cell_res_id);
253+
254+
return res_cfg;
255+
}
256+
257+
const pucch_resource* pucch_resource_manager::ue_reservation_guard::peek_csi_resource() const
258+
{
259+
srsran_assert(parent != nullptr, "Trying to make a new PUCCH resource reservation after commit has been called");
260+
261+
// Get CSI specific PUCCH resource ID from the CSI meas config.
262+
const int cell_res_id_int = get_csi_cell_res_id(ue_cfg);
263+
srsran_assert(cell_res_id_int >= 0, "rnti={}: CSI PUCCH resource index could not be found", rnti);
264+
const auto cell_res_id = static_cast<unsigned>(cell_res_id_int);
265+
266+
// Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
267+
const auto& pucch_res_list = ue_cfg.init_bwp().ul_ded->pucch_cfg.value().pucch_res_list;
268+
const auto* res_cfg =
269+
std::find_if(pucch_res_list.begin(), pucch_res_list.end(), [cell_res_id](const pucch_resource& res) {
270+
return res.res_id.cell_res_id == cell_res_id;
271+
});
272+
srsran_assert(res_cfg != pucch_res_list.end(),
273+
"rnti={}: PUCCH resource with cell_res_id={} not found in PUCCH resource list",
274+
rnti,
275+
cell_res_id);
276+
277+
return res_cfg;
278+
}
279+
234280
bool pucch_resource_manager::ue_reservation_guard::release_harq_set_0_resource()
235281
{
236282
return release_harq_resource(pucch_res_set_idx::set_0);

lib/scheduler/pucch_scheduling/pucch_resource_manager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class pucch_resource_manager
109109
/// \return A pointer to the resource configuration, if available. Otherwise, \c nullptr.
110110
const pucch_resource* reserve_csi_resource();
111111

112+
/// Peek at the configured SR PUCCH resource for the UE without reserving it.
113+
const pucch_resource* peek_sr_resource() const;
114+
115+
/// Peek at the configured CSI PUCCH resource for the UE without reserving it.
116+
const pucch_resource* peek_csi_resource() const;
117+
112118
/// \brief Release PUCCH resource from Resource Set ID 0 from being allocated to a given UE.
113119
/// \param[in] slot_harq slot for which the PUCCH resource was scheduled.
114120
/// \return True if the resource for the UE was found in the allocation records for the given slot.

0 commit comments

Comments
 (0)