-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmac_sched_uci_pdu_stats.cpp
More file actions
executable file
·206 lines (156 loc) · 7.99 KB
/
mac_sched_uci_pdu_stats.cpp
File metadata and controls
executable file
·206 lines (156 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//ontainers/Docker/srsRAN_Project Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include <linux/bpf.h>
#include "jbpf_srsran_contexts.h"
#include "srsran/scheduler/scheduler_feedback_handler.h"
#include "mac_helpers.h"
#include "mac_sched_uci_stats.pb.h"
#include "../utils/misc_utils.h"
#include "../utils/hashmap_utils.h"
#include "jbpf_defs.h"
#include "jbpf_helper.h"
#include "jbpf_helper_utils.h"
#include "../utils/stats_utils.h"
struct jbpf_load_map_def SEC("maps") uci_not_empty = {
.type = JBPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(uint32_t),
.max_entries = 1,
};
// We store stats in this (single entry) map across runs
struct jbpf_load_map_def SEC("maps") stats_map_uci = {
.type = JBPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(uci_stats),
.max_entries = 1,
};
DEFINE_PROTOHASH_32(uci_hash, MAX_NUM_UE);
//#define DEBUG_PRINT
extern "C" SEC("jbpf_ran_mac_sched")
uint64_t jbpf_main(void* state)
{
int zero_index=0;
struct jbpf_mac_sched_ctx *ctx = (jbpf_mac_sched_ctx *)state;
const srsran::uci_indication::uci_pdu& uci_pdu = *reinterpret_cast<const srsran::uci_indication::uci_pdu*>(ctx->data);
// Ensure the object is within valid bounds
if (reinterpret_cast<const uint8_t*>(&uci_pdu) + sizeof(srsran::uci_indication::uci_pdu) > reinterpret_cast<const uint8_t*>(ctx->data_end)) {
return JBPF_CODELET_FAILURE; // Out-of-bounds access
}
uint32_t *not_empty_stats = (uint32_t*)jbpf_map_lookup_elem(&uci_not_empty, &zero_index);
if (!not_empty_stats) {
return JBPF_CODELET_FAILURE;
}
uci_stats *out = (uci_stats *)jbpf_map_lookup_elem(&stats_map_uci, &zero_index);
if (!out)
return JBPF_CODELET_FAILURE;
int new_val = 0;
// Increase loss count
uint32_t ind = JBPF_PROTOHASH_LOOKUP_ELEM_32(out, stats, uci_hash, uci_pdu.ue_index, new_val);
if (new_val) {
out->stats[ind % MAX_NUM_UE].du_ue_index = uci_pdu.ue_index;
out->stats[ind % MAX_NUM_UE].sr_detected = 0;
out->stats[ind % MAX_NUM_UE].time_advance_offset.count = 0;
out->stats[ind % MAX_NUM_UE].time_advance_offset.total = 0;
out->stats[ind % MAX_NUM_UE].time_advance_offset.min = UINT32_MAX;
out->stats[ind % MAX_NUM_UE].time_advance_offset.max = 0;
out->stats[ind % MAX_NUM_UE].has_time_advance_offset = false;
out->stats[ind % MAX_NUM_UE].csi.ri.count = 0;
out->stats[ind % MAX_NUM_UE].csi.ri.total = 0;
out->stats[ind % MAX_NUM_UE].csi.ri.min = UINT32_MAX;
out->stats[ind % MAX_NUM_UE].csi.ri.max = 0;
out->stats[ind % MAX_NUM_UE].csi.has_ri = false;
out->stats[ind % MAX_NUM_UE].csi.cqi.count = 0;
out->stats[ind % MAX_NUM_UE].csi.cqi.total = 0;
out->stats[ind % MAX_NUM_UE].csi.cqi.min = UINT32_MAX;
out->stats[ind % MAX_NUM_UE].csi.cqi.max = 0;
out->stats[ind % MAX_NUM_UE].csi.has_cqi = false;
out->stats[ind % MAX_NUM_UE].has_csi = false;
}
if (const auto* pucch_f0f1 = std::get_if<srsran::uci_indication::uci_pdu::uci_pucch_f0_or_f1_pdu>(&uci_pdu.pdu)) {
// process uci_pucch_f0_or_f1_pdu
// sr_detected
if (pucch_f0f1->sr_detected) {
out->stats[ind % MAX_NUM_UE].sr_detected++;
}
// harqs
// The harqs are nort read here as they could gove misleading results.
// For correct HARQ ACK, yuse the mac_sched_dl_harq_stst.cpp codelet.
// timing advance
const bool is_uci_valid = not pucch_f0f1->harqs.empty() or pucch_f0f1->sr_detected;
if (is_uci_valid and pucch_f0f1->time_advance_offset.has_value() and pucch_f0f1->ul_sinr_dB.has_value()) {
// Cant handle SINR as it is floating point
// // timing advance offset
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].time_advance_offset, static_cast<uint64_t>(pucch_f0f1->time_advance_offset->to_Tc()));
out->stats[ind % MAX_NUM_UE].has_time_advance_offset = true;
}
} else if (const auto* pusch_pdu = std::get_if<srsran::uci_indication::uci_pdu::uci_pusch_pdu>(&uci_pdu.pdu)) {
// harqs
// The harqs are nort read here as they could gove misleading results.
// For correct HARQ ACK, yuse the mac_sched_dl_harq_stst.cpp codelet.
// csi
if (pusch_pdu->csi.has_value()) {
// ri
if (pusch_pdu->csi->ri.has_value()) {
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].csi.ri, static_cast<uint32_t>(static_cast<uint8_t>(pusch_pdu->csi->ri.value())));
out->stats[ind % MAX_NUM_UE].csi.has_ri = true;
}
// first_tb_wideband_cqi
if (pusch_pdu->csi->first_tb_wideband_cqi.has_value()) {
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].csi.cqi, static_cast<uint32_t>(static_cast<uint8_t>(pusch_pdu->csi->first_tb_wideband_cqi.value())));
out->stats[ind % MAX_NUM_UE].csi.has_cqi = true;
}
// second_tb_wideband_cqi
if (pusch_pdu->csi->second_tb_wideband_cqi.has_value()) {
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].csi.cqi, static_cast<uint32_t>(static_cast<uint8_t>(pusch_pdu->csi->second_tb_wideband_cqi.value())));
out->stats[ind % MAX_NUM_UE].csi.has_cqi = true;
}
out->stats[ind % MAX_NUM_UE].has_csi = true;
}
} else if (const auto* pucch_f2f3f4 = std::get_if<srsran::uci_indication::uci_pdu::uci_pucch_f2_or_f3_or_f4_pdu>(&uci_pdu.pdu)) {
// sr bits
const size_t sr_bit_position_with_1_sr_bit = 0;
if (not pucch_f2f3f4->sr_info.empty() and pucch_f2f3f4->sr_info.test(sr_bit_position_with_1_sr_bit)) {
// Handle SR indication.
out->stats[ind % MAX_NUM_UE].sr_detected++;
}
// harqs
// The harqs are nort read here as they could gove misleading results.
// For correct HARQ ACK, yuse the mac_sched_dl_harq_stst.cpp codelet.
// csi
if (pucch_f2f3f4->csi.has_value()) {
// ri
if (pucch_f2f3f4->csi->ri.has_value()) {
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].csi.ri, static_cast<uint32_t>(static_cast<uint8_t>(pucch_f2f3f4->csi->ri.value())));
out->stats[ind % MAX_NUM_UE].csi.has_ri = true;
}
// first_tb_wideband_cqi
if (pucch_f2f3f4->csi->first_tb_wideband_cqi.has_value()) {
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].csi.cqi, static_cast<uint32_t>(static_cast<uint8_t>(pucch_f2f3f4->csi->first_tb_wideband_cqi.value())));
out->stats[ind % MAX_NUM_UE].csi.has_cqi = true;
}
// second_tb_wideband_cqi
if (pucch_f2f3f4->csi->second_tb_wideband_cqi.has_value()) {
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].csi.cqi, static_cast<uint32_t>(static_cast<uint8_t>(pucch_f2f3f4->csi->second_tb_wideband_cqi.value())));
out->stats[ind % MAX_NUM_UE].csi.has_cqi = true;
}
out->stats[ind % MAX_NUM_UE].has_csi = true;
}
// timing advance
const bool is_uci_valid =
//not pucch_f2f3f4->harqs.empty() or
(not pucch_f2f3f4->sr_info.empty() and pucch_f2f3f4->sr_info.test(sr_bit_position_with_1_sr_bit)) or
pucch_f2f3f4->csi.has_value();
// Process Timing Advance Offset.
if (is_uci_valid and pucch_f2f3f4->time_advance_offset.has_value() and
pucch_f2f3f4->ul_sinr_dB.has_value()) {
// Handle UL SINR and Timing Advance Offset
STATS_UPDATE(out->stats[ind % MAX_NUM_UE].time_advance_offset, static_cast<uint64_t>(pucch_f2f3f4->time_advance_offset->to_Tc()));
out->stats[ind % MAX_NUM_UE].has_time_advance_offset = true;
}
} else {
// jbpf_printf_debug("Unknown UCI PDU type\n");
return JBPF_CODELET_FAILURE;
}
*not_empty_stats = 1;
return JBPF_CODELET_SUCCESS;
}