Skip to content

Commit 100ae6a

Browse files
committed
mac: fix mac metric aggregator on HFN wrap-around
1 parent b4fe35b commit 100ae6a

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

lib/mac/mac_ctrl/mac_metrics_aggregator.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ constexpr unsigned cell_report_queue_size = 8;
2525

2626
/// Cell metrics report containing scheduler and MAC.
2727
struct full_cell_report {
28+
slot_point_extended start_slot;
2829
scheduler_cell_metrics sched;
2930
std::optional<mac_dl_cell_metric_report> mac;
3031
};
@@ -145,14 +146,15 @@ class mac_metrics_aggregator::cell_metric_handler final : public mac_cell_metric
145146
mac_builder->mac = report;
146147

147148
// Update next report slot.
148-
auto current_report_start_slot_tx = next_report_end_slot_tx - period_slots;
149+
auto start_slot = next_report_end_slot_tx - period_slots;
150+
mac_builder->start_slot = start_slot;
149151
next_report_end_slot_tx += period_slots;
150152

151153
// Commit report to MAC metric aggregator.
152154
mac_builder.reset();
153155

154156
// If the token is acquired, it means that it is this thread's job to dispatch a job to handle pending reports.
155-
unsigned ring_index = current_report_start_slot_tx.count() / period_slots;
157+
unsigned ring_index = start_slot.count() / period_slots;
156158
bool token_acquired = not parent.report_ring[ring_index].end_slot_flag.exchange(true, std::memory_order_acq_rel);
157159
if (not token_acquired) {
158160
// Another cell is already handling the reports.
@@ -284,22 +286,13 @@ bool mac_metrics_aggregator::pop_report(cell_metric_handler& cell)
284286
return false;
285287
}
286288

287-
// Convert report start slot to extended form (with HFN).
288-
slot_point_extended start_slot{next_ev->sched.slot, next_report_start_slot.hyper_sfn()};
289-
if (std::abs(start_slot - next_report_start_slot) >= next_ev->sched.slot.nof_slots_per_hyper_system_frame() / 2) {
290-
if (start_slot < next_report_start_slot) {
291-
start_slot += next_ev->sched.slot.nof_slots_per_hyper_system_frame();
292-
} else {
293-
start_slot -= next_ev->sched.slot.nof_slots_per_hyper_system_frame();
294-
}
295-
}
296-
297289
// Fetch position in the report ring where to save report.
298-
const auto ring_key = start_slot.count() / cell.period_slots;
290+
const auto ring_key = next_ev->start_slot.count() / cell.period_slots;
299291
report_context& report_ctx = report_ring[ring_key];
300292

301-
const bool is_in_window = report_ctx.start_slot.valid() and
302-
start_slot.is_in_interval(report_ctx.start_slot, report_ctx.start_slot + cell.period_slots);
293+
const bool is_in_window =
294+
report_ctx.start_slot.valid() and
295+
next_ev->start_slot.is_in_interval(report_ctx.start_slot, report_ctx.start_slot + cell.period_slots);
303296
if (not is_in_window) {
304297
// Report is not within expected window for this ring slot.
305298

@@ -311,10 +304,7 @@ bool mac_metrics_aggregator::pop_report(cell_metric_handler& cell)
311304
}
312305

313306
// Update start slot in the respective ring report context.
314-
// Note: We are "slotting" the time when reports are produced. E.g. for a period of 10 slots and SCS=15kHz, the
315-
// reports will be for slots 0.0-0.9, 1.0-1.9, 2.0-2.9, ...
316-
unsigned slot_mod = start_slot.count() % cell.period_slots;
317-
report_ctx.start_slot = start_slot - slot_mod;
307+
report_ctx.start_slot = next_ev->start_slot;
318308
}
319309

320310
// Add front to pending report in the report_ring.

0 commit comments

Comments
 (0)