From df9cd171f62293621ad6867fb57bb2fe3ded18f8 Mon Sep 17 00:00:00 2001 From: Laurent THOMAS Date: Tue, 16 Apr 2024 12:52:22 +0200 Subject: [PATCH 01/10] remove a useless copy and specific buffer for all UE UL payload --- openair1/PHY/INIT/nr_init_ue.c | 13 ++++--------- openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h | 4 +--- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 18 ++++++++---------- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 5 +---- openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 2 +- openair1/SIMULATION/NR_PHY/ulschsim.c | 2 +- openair1/SIMULATION/NR_PHY/ulsim.c | 6 +++--- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index 48152db15b..83b2bd75ac 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -534,8 +534,7 @@ void free_nr_ue_ul_harq(NR_UL_UE_HARQ_t harq_list[NR_MAX_ULSCH_HARQ_PROCESSES], } for (int i = 0; i < number_of_processes; i++) { - free_and_zero(harq_list[i].a); - free_and_zero(harq_list[i].b); + free_and_zero(harq_list[i].payload_AB); for (int r = 0; r < a_segments; r++) { free_and_zero(harq_list[i].c[r]); free_and_zero(harq_list[i].d[r]); @@ -598,13 +597,9 @@ void nr_init_ul_harq_processes(NR_UL_UE_HARQ_t harq_list[NR_MAX_ULSCH_HARQ_PROCE memset(harq_list + i, 0, sizeof(NR_UL_UE_HARQ_t)); - harq_list[i].a = malloc16(ulsch_bytes); - DevAssert(harq_list[i].a); - bzero(harq_list[i].a, ulsch_bytes); - - harq_list[i].b = malloc16(ulsch_bytes); - DevAssert(harq_list[i].b); - bzero(harq_list[i].b, ulsch_bytes); + harq_list[i].payload_AB = malloc16(ulsch_bytes); + DevAssert(harq_list[i].payload_AB); + bzero(harq_list[i].payload_AB, ulsch_bytes); harq_list[i].c = malloc16(a_segments*sizeof(uint8_t *)); harq_list[i].d = malloc16(a_segments*sizeof(uint16_t *)); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h index b2c277cc7a..8fea51ad75 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h @@ -55,9 +55,7 @@ typedef struct { /// Index of current HARQ round for this ULSCH uint8_t round; /// pointer to pdu from MAC interface (TS 36.212 V15.4.0, Sec 5.1 p. 8) - unsigned char *a; - /// Pointer to the payload + CRC - uint8_t *b; + unsigned char *payload_AB; /// Pointers to transport block segments uint8_t **c; /// LDPC-code outputs diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index fa9d692751..ea2d6cec79 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -87,21 +87,19 @@ int nr_ulsch_encoding(PHY_VARS_NR_UE *ue, int B; if (A > NR_MAX_PDSCH_TBS) { // Add 24-bit crc (polynomial A) to payload - crc = crc24a(harq_process->a,A)>>8; - harq_process->a[A>>3] = ((uint8_t*)&crc)[2]; - harq_process->a[1+(A>>3)] = ((uint8_t*)&crc)[1]; - harq_process->a[2 + (A >> 3)] = ((uint8_t *)&crc)[0]; + crc = crc24a(harq_process->payload_AB, A) >> 8; + harq_process->payload_AB[A >> 3] = ((uint8_t *)&crc)[2]; + harq_process->payload_AB[1 + (A >> 3)] = ((uint8_t *)&crc)[1]; + harq_process->payload_AB[2 + (A >> 3)] = ((uint8_t *)&crc)[0]; B = A + 24; AssertFatal((A / 8) + 4 <= max_payload_bytes, "A %d is too big (A/8+4 = %d > %d)\n", A, (A / 8) + 4, max_payload_bytes); - memcpy(harq_process->b,harq_process->a,(A/8)+4); } else { // Add 16-bit crc (polynomial A) to payload - crc = crc16(harq_process->a,A)>>16; - harq_process->a[A>>3] = ((uint8_t*)&crc)[1]; - harq_process->a[1 + (A >> 3)] = ((uint8_t *)&crc)[0]; + crc = crc16(harq_process->payload_AB, A) >> 16; + harq_process->payload_AB[A >> 3] = ((uint8_t *)&crc)[1]; + harq_process->payload_AB[1 + (A >> 3)] = ((uint8_t *)&crc)[0]; B = A + 16; AssertFatal((A / 8) + 3 <= max_payload_bytes, "A %d is too big (A/8+3 = %d > %d)\n", A, (A / 8) + 3, max_payload_bytes); - memcpy(harq_process->b,harq_process->a,(A/8)+3); // using 3 bytes to mimic the case of 24 bit crc } ///////////////////////// b---->| block segmentation |---->c ///////////////////////// @@ -110,7 +108,7 @@ int nr_ulsch_encoding(PHY_VARS_NR_UE *ue, VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_SEGMENTATION, VCD_FUNCTION_IN); start_meas(&ue->ulsch_segmentation_stats); - impp.Kb = nr_segmentation(harq_process->b, + impp.Kb = nr_segmentation(harq_process->payload_AB, harq_process->c, B, &harq_process->C, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index 0e511cd72b..2ac06bfe89 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -191,10 +191,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, mod_order, Nl); - trace_NRpdu(DIRECTION_UPLINK, - harq_process_ul_ue->a, - tb_size, - WS_C_RNTI, rnti, frame, slot, 0, 0); + trace_NRpdu(DIRECTION_UPLINK, harq_process_ul_ue->payload_AB, tb_size, WS_C_RNTI, rnti, frame, slot, 0, 0); if (nr_ulsch_encoding(UE, ulsch_ue, frame_parms, harq_pid, tb_size, G) == -1) return; diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 369c388ad3..8560e3de82 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -468,7 +468,7 @@ static void nr_ue_scheduled_response_ul(PHY_VARS_NR_UE *phy, fapi_nr_ul_config_r ul_config->slot, pdu->pusch_config_pdu.tx_request_body.pdu_length, current_harq_pid); - memcpy(harq_process_ul_ue->a, + memcpy(harq_process_ul_ue->payload_AB, pdu->pusch_config_pdu.tx_request_body.pdu, pdu->pusch_config_pdu.tx_request_body.pdu_length); } diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index 966971ee73..b41896da5e 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -507,7 +507,7 @@ int main(int argc, char **argv) ulsch_ue->pusch_pdu.target_code_rate = code_rate; ulsch_ue->pusch_pdu.qam_mod_order = mod_order; ulsch_ue->pusch_pdu.ldpcBaseGraph = get_BG(TBS, code_rate); - unsigned char *test_input = harq_process_ul_ue->a; + unsigned char *test_input = harq_process_ul_ue->payload_AB; /////////// //////////////////////////////////////////////////////////////////////////////////////////// diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index 091b1ad4ab..90f23c695c 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -1141,7 +1141,7 @@ int main(int argc, char *argv[]) } for (int i = 0; i < (TBS / 8); i++) - UE->ul_harq_processes[harq_pid].a[i] = i & 0xff; + UE->ul_harq_processes[harq_pid].payload_AB[i] = i & 0xff; if (input_fd == NULL) { // set FAPI parameters for UE, put them in the scheduled response and call @@ -1457,8 +1457,8 @@ int main(int argc, char *argv[]) for (i = 0; i < TBS; i++) { uint8_t estimated_output_bit = (ulsch_gNB->harq_process->b[i / 8] & (1 << (i & 7))) >> (i & 7); - uint8_t test_input_bit = (UE->ul_harq_processes[harq_pid].b[i / 8] & (1 << (i & 7))) >> (i & 7); - + uint8_t test_input_bit = (UE->ul_harq_processes[harq_pid].payload_AB[i / 8] & (1 << (i & 7))) >> (i & 7); + if (estimated_output_bit != test_input_bit) { /*if(errors_decoding == 0) printf("\x1B[34m""[frame %d][trial %d]\t1st bit in error in decoding = %d\n" "\x1B[0m", frame, trial, i);*/ From 8e7ecaa73a314fde2321f788b102d331ea105dd5 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Thu, 18 Apr 2024 00:27:46 +0200 Subject: [PATCH 02/10] Compile using -rdynamic with clang -rdynamic is necessary for clang as well to properly link shared executables. Add furthermore an option to ignore unused command line arguments, to suppress warning clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument] This is likely because -rdynamic is only relevant for the linker, but the corresponding option add_link_options() is only available starting cmake 3.13, while we are still at 3.12 (for Ubuntu 18, to my understanding). --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22453e5af6..569aae3975 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,11 +158,16 @@ endif() # add autotools definitions that were maybe used! add_definitions("-DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_FCNTL_H=1 -DHAVE_ARPA_INET_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_SOCKET_H=1 -DHAVE_STRERROR=1 -DHAVE_SOCKET=1 -DHAVE_MEMSET=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1 -DHAVE_LIBSCTP") -set(commonOpts "-pipe -fPIC -Wall -fno-strict-aliasing") +# we need -rdynamic to incorporate all symbols in shared objects, see man page +set(commonOpts "-pipe -fPIC -Wall -fno-strict-aliasing -rdynamic") # GNU C/C++ Compiler might throw many warnings without packed-bitfield-compat, see man page -# also, we need -rdynamic to incorporate all symbols in shared objects, again, see man page if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(commonOpts "${commonOpts} -Wno-packed-bitfield-compat -rdynamic") + set(commonOpts "${commonOpts} -Wno-packed-bitfield-compat") +endif() +# clang: suppress complaints about unused command line argument (-rdynamic only +# used during linking) +if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(commonOpts "${commonOpts} -Wno-unused-command-line-argument") endif() set(CMAKE_C_FLAGS From 24baf08c8717baba9f9eaa1cdb4f82e891631e56 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 17 Apr 2024 17:27:42 +0200 Subject: [PATCH 03/10] Load unaligned data for SIMD processing to avoid segv We access G_N at indexes that are not necessarily 32-byte aligned, leading to segfaults. Use simde_mm256_loadu_si256() to load from memory at an unaligned memory address to avoid the segfault. Discovered using clang; it is unclear why gcc did not encounter the same segfault. --- openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c index 335510953f..f411e0c6be 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c @@ -391,8 +391,8 @@ void build_polar_tables(t_nrPolar_params *polarParams) { // this code packs the one bit per byte of G_N into a packed bits G_N_tab for (int i = 0; i < polarParams->N; i++) { for (int j = 0; j < polarParams->N; j += 64) { - const simde__m256i tmp1 = simde_mm256_cmpgt_epi8(*(simde__m256i *)&polarParams->G_N[i][j], zeros); - const simde__m256i tmp2 = simde_mm256_cmpgt_epi8(*(simde__m256i *)&polarParams->G_N[i][j + 32], zeros); + const simde__m256i tmp1 = simde_mm256_cmpgt_epi8(simde_mm256_loadu_si256((simde__m256i *)&polarParams->G_N[i][j]), zeros); + const simde__m256i tmp2 = simde_mm256_cmpgt_epi8(simde_mm256_loadu_si256((simde__m256i *)&polarParams->G_N[i][j + 32]), zeros); // cast directly to uint64_t from int32_t propagates the sign bit (in gcc) const uint32_t part1 = simde_mm256_movemask_epi8(tmp1); const uint32_t part2 = simde_mm256_movemask_epi8(tmp2); From ed89498c4f76eb7ba4c20325b51cf059d7b4cf62 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Thu, 18 Apr 2024 00:39:46 +0200 Subject: [PATCH 04/10] Use standard C initializer list syntax Fix clang warning warning: use of GNU old-style field designator extension [-Wgnu-designator] --- common/utils/T/DOC/T/howto_new_trace.patch | 2 +- common/utils/T/tracer/enb.c | 2 +- common/utils/T/tracer/event.c | 2 +- common/utils/T/tracer/extract.c | 2 +- common/utils/T/tracer/extract_config.c | 2 +- common/utils/T/tracer/extract_input_subframe.c | 2 +- common/utils/T/tracer/extract_output_subframe.c | 2 +- common/utils/T/tracer/gnb.c | 2 +- common/utils/T/tracer/hacks/dump_nack_signal.c | 2 +- common/utils/T/tracer/hacks/multi-rru-clean.c | 2 +- common/utils/T/tracer/hacks/time_meas.c | 2 +- common/utils/T/tracer/logger/textlog.c | 8 ++++---- common/utils/T/tracer/macpdu2wireshark.c | 2 +- common/utils/T/tracer/multi.c | 4 ++-- common/utils/T/tracer/record.c | 2 +- common/utils/T/tracer/replay.c | 2 +- common/utils/T/tracer/textlog.c | 2 +- common/utils/T/tracer/to_vcd.c | 2 +- common/utils/T/tracer/ue.c | 2 +- common/utils/T/tracer/vcd.c | 2 +- common/utils/T/tracer/view/ticktime.c | 3 +-- common/utils/T/tracer/view/time.c | 3 +-- 22 files changed, 26 insertions(+), 28 deletions(-) diff --git a/common/utils/T/DOC/T/howto_new_trace.patch b/common/utils/T/DOC/T/howto_new_trace.patch index 47bbc66138..86dfe5d23c 100644 --- a/common/utils/T/DOC/T/howto_new_trace.patch +++ b/common/utils/T/DOC/T/howto_new_trace.patch @@ -164,7 +164,7 @@ index 0000000000..00baf34774 + } + + /* a buffer needed to receive events from the nr-softmodem */ -+ OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; ++ OBUF ebuf = { .osize = 0, .omaxsize = 0, .obuf = NULL }; + + /* read events */ + while (1) { diff --git a/common/utils/T/tracer/enb.c b/common/utils/T/tracer/enb.c index 9a4751b67e..5bb1cb87e2 100644 --- a/common/utils/T/tracer/enb.c +++ b/common/utils/T/tracer/enb.c @@ -874,7 +874,7 @@ int main(int n, char **v) if (pthread_mutex_init(&enb_data.lock, NULL)) abort(); setup_event_selector(g, database, is_on, is_on_changed, &enb_data); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; restart: clear_remote_config(); diff --git a/common/utils/T/tracer/event.c b/common/utils/T/tracer/event.c index 41da5c0823..a5d04166d4 100644 --- a/common/utils/T/tracer/event.c +++ b/common/utils/T/tracer/event.c @@ -49,7 +49,7 @@ again: #endif read_error: - return (event){type: -1}; + return (event){.type = -1}; } #ifdef T_SEND_TIME diff --git a/common/utils/T/tracer/extract.c b/common/utils/T/tracer/extract.c index fe3177b74a..445b166f09 100644 --- a/common/utils/T/tracer/extract.c +++ b/common/utils/T/tracer/extract.c @@ -113,7 +113,7 @@ int main(int n, char **v) found = 0; - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; while (1) { event e; diff --git a/common/utils/T/tracer/extract_config.c b/common/utils/T/tracer/extract_config.c index a26c52aeda..b908e60a83 100644 --- a/common/utils/T/tracer/extract_config.c +++ b/common/utils/T/tracer/extract_config.c @@ -36,7 +36,7 @@ int main(int n, char **v) in = fopen(input_filename, "r"); if (in == NULL) { perror(input_filename); abort(); } - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; while (1) { int type; diff --git a/common/utils/T/tracer/extract_input_subframe.c b/common/utils/T/tracer/extract_input_subframe.c index 78bc288df1..c4116953db 100644 --- a/common/utils/T/tracer/extract_input_subframe.c +++ b/common/utils/T/tracer/extract_input_subframe.c @@ -104,7 +104,7 @@ err: fd = open(file, O_RDONLY); if (fd == -1) { perror(file); exit(1); } - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* get wanted frame/subframe */ while (1) { diff --git a/common/utils/T/tracer/extract_output_subframe.c b/common/utils/T/tracer/extract_output_subframe.c index 5c5abb768e..226f6d7a2e 100644 --- a/common/utils/T/tracer/extract_output_subframe.c +++ b/common/utils/T/tracer/extract_output_subframe.c @@ -101,7 +101,7 @@ err: int last_subframe = -1; int subframe_written = 0; - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; while (1) { event e; diff --git a/common/utils/T/tracer/gnb.c b/common/utils/T/tracer/gnb.c index a2953cb00d..22567492f8 100644 --- a/common/utils/T/tracer/gnb.c +++ b/common/utils/T/tracer/gnb.c @@ -265,7 +265,7 @@ int main(int n, char **v) gnb_main_gui(&eg, g, h, database, &gnb_data); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; restart: clear_remote_config(); diff --git a/common/utils/T/tracer/hacks/dump_nack_signal.c b/common/utils/T/tracer/hacks/dump_nack_signal.c index 02825202fb..f50e8a761a 100644 --- a/common/utils/T/tracer/hacks/dump_nack_signal.c +++ b/common/utils/T/tracer/hacks/dump_nack_signal.c @@ -85,7 +85,7 @@ int main(int n, char **v) { socket_send(socket, is_on, number_of_events * sizeof(int)) == -1) abort(); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; char dump[10][T_BUFFER_MAX]; event dump_ev[10]; FILE *z = fopen("/tmp/dd", "w"); diff --git a/common/utils/T/tracer/hacks/multi-rru-clean.c b/common/utils/T/tracer/hacks/multi-rru-clean.c index fd94253fb0..ec7c8f9d1b 100644 --- a/common/utils/T/tracer/hacks/multi-rru-clean.c +++ b/common/utils/T/tracer/hacks/multi-rru-clean.c @@ -145,7 +145,7 @@ int main(int n, char **v) clear_cache(number_of_tags, cache); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; while (1) { int type; diff --git a/common/utils/T/tracer/hacks/time_meas.c b/common/utils/T/tracer/hacks/time_meas.c index 408189cd80..ae38dcd177 100644 --- a/common/utils/T/tracer/hacks/time_meas.c +++ b/common/utils/T/tracer/hacks/time_meas.c @@ -86,7 +86,7 @@ int main(int n, char **v) socket_send(socket, is_on, number_of_events * sizeof(int)) == -1) abort(); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; while (1) { event e; diff --git a/common/utils/T/tracer/logger/textlog.c b/common/utils/T/tracer/logger/textlog.c index 76f920e1e2..8217c2b981 100644 --- a/common/utils/T/tracer/logger/textlog.c +++ b/common/utils/T/tracer/logger/textlog.c @@ -131,7 +131,7 @@ static struct chunk next_chunk(char **s, database_event_format f) cur++; *s = cur; if (find_argument(name, f, &it, &event_arg) == 0) goto error; - return (struct chunk){type:C_ARG_NAME, s:name, it:it, event_arg:event_arg}; + return (struct chunk){.type = C_ARG_NAME, .s = name, .it = it, .event_arg = event_arg}; } /* { } is name of event (anything in between is smashed) */ @@ -143,7 +143,7 @@ static struct chunk next_chunk(char **s, database_event_format f) *cur = 0; cur++; *s = cur; - return (struct chunk){type:C_EVENT_NAME}; + return (struct chunk){.type = C_EVENT_NAME}; } /* anything but [ and { is raw string */ @@ -151,10 +151,10 @@ static struct chunk next_chunk(char **s, database_event_format f) name = cur; while (*cur && *cur != '[' && *cur != '{') cur++; *s = cur; - return (struct chunk){type:C_STRING, s:name}; + return (struct chunk){.type = C_STRING, .s = name}; error: - return (struct chunk){type:C_ERROR}; + return (struct chunk){.type = C_ERROR}; } logger *new_textlog(event_handler *h, void *database, diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index cfa90a24db..d7c4b23b51 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -808,7 +808,7 @@ int main(int n, char **v) d.to.sin_port = htons(port); d.to.sin_addr.s_addr = inet_addr(ip); new_thread(receiver, &d); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* read messages */ while (1) { diff --git a/common/utils/T/tracer/multi.c b/common/utils/T/tracer/multi.c index 73fadc37d3..0b2e48ec7a 100644 --- a/common/utils/T/tracer/multi.c +++ b/common/utils/T/tracer/multi.c @@ -52,7 +52,7 @@ int send_messages_txt(int s, char *T_messages_txt, int T_messages_txt_len) /* TODO: be careful, we use internal T stuff, to rewrite? */ T_LOCAL_size = 0; T_HEADER(T_ID(-1)); - T_PUT_buffer(1, ((T_buffer){addr:(src), length:(send_size)})); + T_PUT_buffer(1, ((T_buffer){.addr = src, .length = send_size})); if (socket_send(s, &T_LOCAL_size, 4) == -1) return -1; if (socket_send(s, buf, T_LOCAL_size) == -1) return -1; src += send_size; @@ -242,7 +242,7 @@ int main(int n, char **v) /* create listener socket */ l = create_listen_socket("0.0.0.0", local_port); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; current_nfd = 0; diff --git a/common/utils/T/tracer/record.c b/common/utils/T/tracer/record.c index e4c059a5ca..9e3c4c41a3 100644 --- a/common/utils/T/tracer/record.c +++ b/common/utils/T/tracer/record.c @@ -123,7 +123,7 @@ int main(int n, char **v) if (signal(SIGINT, force_stop) == SIG_ERR) abort(); if (signal(SIGTSTP, force_stop) == SIG_ERR) abort(); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* read messages */ while (run) { diff --git a/common/utils/T/tracer/replay.c b/common/utils/T/tracer/replay.c index c199a668d5..d9a505520a 100644 --- a/common/utils/T/tracer/replay.c +++ b/common/utils/T/tracer/replay.c @@ -136,7 +136,7 @@ int main(int n, char **v) new_thread(get_message_thread, &socket); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; while (1) { int type; diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c index 6ead65d87a..0a4d2e555c 100644 --- a/common/utils/T/tracer/textlog.c +++ b/common/utils/T/tracer/textlog.c @@ -130,7 +130,7 @@ int main(int n, char **v) /* send the first message - activate selected traces */ activate_traces(socket, is_on, number_of_events); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* read messages */ while (1) { diff --git a/common/utils/T/tracer/to_vcd.c b/common/utils/T/tracer/to_vcd.c index be3c839115..6458443394 100644 --- a/common/utils/T/tracer/to_vcd.c +++ b/common/utils/T/tracer/to_vcd.c @@ -366,7 +366,7 @@ int main(int n, char **v) if (signal(SIGINT, force_stop) == SIG_ERR) abort(); if (signal(SIGTSTP, force_stop) == SIG_ERR) abort(); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* read messages */ while (run) { diff --git a/common/utils/T/tracer/ue.c b/common/utils/T/tracer/ue.c index 31584e0215..b28f83b0f2 100644 --- a/common/utils/T/tracer/ue.c +++ b/common/utils/T/tracer/ue.c @@ -758,7 +758,7 @@ int main(int n, char **v) if (pthread_mutex_init(&ue_data.lock, NULL)) abort(); setup_event_selector(g, database, is_on, is_on_changed, &ue_data); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; restart: clear_remote_config(); diff --git a/common/utils/T/tracer/vcd.c b/common/utils/T/tracer/vcd.c index c57798c4c4..e62fc046eb 100644 --- a/common/utils/T/tracer/vcd.c +++ b/common/utils/T/tracer/vcd.c @@ -187,7 +187,7 @@ int main(int n, char **v) /* send the first message - activate selected traces */ is_on_changed(&vcd_data); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* read messages */ while (1) { diff --git a/common/utils/T/tracer/view/ticktime.c b/common/utils/T/tracer/view/ticktime.c index 1e1c7352a0..7fa13e4d7a 100644 --- a/common/utils/T/tracer/view/ticktime.c +++ b/common/utils/T/tracer/view/ticktime.c @@ -129,8 +129,7 @@ static void *ticktime_thread(void *_this) pixel_length = this->pixel_length; if (this->autoscroll) { - tnext = time_add(this->latest_time, - (struct timespec){tv_sec:0,tv_nsec:1}); + tnext = time_add(this->latest_time, (struct timespec){.tv_sec = 0, .tv_nsec = 1}); tstart = time_sub(tnext, nano_to_time(pixel_length * width)); this->start_time = tstart; } else { diff --git a/common/utils/T/tracer/view/time.c b/common/utils/T/tracer/view/time.c index 287e7b1c7b..18fc02e4d7 100644 --- a/common/utils/T/tracer/view/time.c +++ b/common/utils/T/tracer/view/time.c @@ -122,8 +122,7 @@ static void *time_thread(void *_this) pixel_length = this->pixel_length; if (this->autoscroll) { - tnext = time_add(this->latest_time, - (struct timespec){tv_sec:0,tv_nsec:1}); + tnext = time_add(this->latest_time, (struct timespec){.tv_sec = 0, .tv_nsec = 1}); tstart = time_sub(tnext, nano_to_time(pixel_length * width)); this->start_time = tstart; } else { From c114d2f547c386c08b1ea6b9c18f7b5047ca547a Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Thu, 18 Apr 2024 00:23:40 +0200 Subject: [PATCH 05/10] Fix memory sanitizer warning: uninitialized read Memsan complains that uninitialized reads originate because of these warnings. Most of the corresponding variables are actually read into through by libconfig; nevertheless, initializing them should not have a bad side-effect (because the initialized value is overwritten). --- common/config/libconfig/config_libconfig.c | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/common/config/libconfig/config_libconfig.c b/common/config/libconfig/config_libconfig.c index c5cdd1972f..b0c3c2c6cf 100644 --- a/common/config/libconfig/config_libconfig.c +++ b/common/config/libconfig/config_libconfig.c @@ -322,19 +322,16 @@ int config_libconfig_set(configmodule_interface_t *cfg, paramdef_t *cfgoptions, int config_libconfig_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions, int numoptions, char *prefix) { config_setting_t *setting; - char *str; - int i,u; - long long int llu; - double dbl; - int rst; - int status=0; - int notfound; - int defval; - int fatalerror=0; - int numdefvals=0; + char *str = NULL; + int u = 0; + long long int llu = 0; + double dbl = 0.0f; + int status = 0; + int fatalerror = 0; + int numdefvals = 0; char cfgpath[512]; /* 512 should be enough for the sprintf below */ - for(i=0; i Date: Thu, 18 Apr 2024 00:25:22 +0200 Subject: [PATCH 06/10] Memory sanitizer: unitialized read Reset all the circular buffer to zero; this ensures that we cannot read uninitialized data. Since this is RFsimulator, performance is not a problem here either (and zeroing out happens only once). --- radio/rfsimulator/simulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/rfsimulator/simulator.c b/radio/rfsimulator/simulator.c index 62d08da212..d190851699 100644 --- a/radio/rfsimulator/simulator.c +++ b/radio/rfsimulator/simulator.c @@ -179,7 +179,7 @@ typedef struct { static int allocCirBuf(rfsimulator_state_t *bridge, int sock) { buffer_t *ptr=&bridge->buf[sock]; - ptr->circularBuf = malloc(sampleToByte(CirSize, 1)); + ptr->circularBuf = calloc(1, sampleToByte(CirSize, 1)); if (ptr->circularBuf == NULL) { LOG_E(HW, "malloc(%lu) failed\n", sampleToByte(CirSize, 1)); return -1; From 507e08cd3995704922d4e7c6815bff77387beabe Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Thu, 18 Apr 2024 00:27:10 +0200 Subject: [PATCH 07/10] Memsan uninitialized read: Initialize array to zero --- openair1/PHY/INIT/nr_init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 725e3a9919..c688b20e21 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -184,8 +184,9 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB) AssertFatal(pdsch_dmrs[slot][symb]!=NULL, "NR init: pdsch_dmrs for slot %d symbol %d - malloc failed\n", slot, symb); for (int q=0; q Date: Thu, 18 Apr 2024 00:28:06 +0200 Subject: [PATCH 08/10] Memory sanitizer patch not required anymore Also, the check for clang is done in CMakeLists.txt; sleep is useless --- cmake_targets/build_oai | 2 -- cmake_targets/tools/memsan.patch | 53 -------------------------------- 2 files changed, 55 deletions(-) delete mode 100644 cmake_targets/tools/memsan.patch diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index bb61d356f4..c59017b5ac 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -418,8 +418,6 @@ function main() { CMAKE_CMD="$CMAKE_CMD -DSANITIZE_UNDEFINED=True" shift;; --sanitize-memory | -fsanitize=memory) - echo_warning "Note: memory sanitizer\n* requires clang (tested: v17)\n* is incompatible with address/undefined behavior sanitizer\n* requires cmake_targets/tools/memsan.patch" - sleep 2 CMAKE_CMD="$CMAKE_CMD -DSANITIZE_MEMORY=ON -DSANITIZE_ADDRESS=OFF -DSANITIZE_UNDEFINED=OFF" shift;; --trace-asn1c-enc-dec) diff --git a/cmake_targets/tools/memsan.patch b/cmake_targets/tools/memsan.patch deleted file mode 100644 index a8b8e9f992..0000000000 --- a/cmake_targets/tools/memsan.patch +++ /dev/null @@ -1,53 +0,0 @@ -commit bf7f0c4f0f1bfce586667b50050640b67a7a747a -Author: Robert Schmidt -Date: Wed Jun 7 18:24:50 2023 +0200 - - Fix dlopen() linker errors in dfts, ldpc, ldpc_parityCheck, and params_libconfig - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index c29105d503..3b9e7d1246 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -508,7 +508,7 @@ add_library(CONFIG_LIB - ) - target_link_libraries(CONFIG_LIB PRIVATE dl UTIL) - add_library(params_libconfig MODULE ${CONFIG_ROOTDIR}/libconfig/config_libconfig.c) --target_link_libraries(params_libconfig config) -+target_link_libraries(params_libconfig config CONFIG_LIB minimal_lib) - # shared library loader - set (SHLIB_LOADER_SOURCES - ${OPENAIR_DIR}/common/utils/load_module_shlib.c -@@ -1018,16 +1018,19 @@ if (ENABLE_LDPC_CUDA) - endif() - endif() - --add_library(ldpc MODULE ${PHY_LDPC_OPTIM8SEGMULTI_SRC} ) -+add_library(ldpc MODULE ${PHY_LDPC_OPTIM8SEGMULTI_SRC} ${OPENAIR1_DIR}/PHY/CODING/crc_byte.c) - target_link_libraries(ldpc PRIVATE ldpc_gen_HEADERS) -+target_link_libraries(ldpc PRIVATE UTIL) - - add_library(ldpc_parityCheck MODULE ${PHY_LDPC_OPTIM8SEGMULTI_SRC} ) - target_compile_definitions(ldpc_parityCheck PUBLIC NR_LDPC_ENABLE_PARITY_CHECK) - target_link_libraries(ldpc_parityCheck PRIVATE ldpc_gen_HEADERS) -+target_link_libraries(ldpc_parityCheck PRIVATE UTIL minimal_lib) - - add_library(coding MODULE ${PHY_TURBOSRC} ) - - add_library(dfts MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_dfts.c ) -+target_link_libraries(dfts PRIVATE minimal_lib) - - - set(PHY_SRC_COMMON -diff --git a/common/utils/minimal_stub.c b/common/utils/minimal_stub.c -index be9c1b399d..7ad0df4d56 100644 ---- a/common/utils/minimal_stub.c -+++ b/common/utils/minimal_stub.c -@@ -1,6 +1,8 @@ -+#include - #ifndef T_TRACER - int T_stdout; - #endif -+int oai_exit = 0; - - void exit_function(const char *file, const char *function, const int line, const char *s, const int assert) - { From e3547dfb386f03c0260ca37e069632b7fad21539 Mon Sep 17 00:00:00 2001 From: Jaroslava Fiedlerova Date: Tue, 16 Apr 2024 08:38:15 +0200 Subject: [PATCH 09/10] CI: Modification of log collection in UndeployObject() After the recent update of matix, collected logs contain color codes and we did not find the way to switch them completely off. Replacement of "docker compose logs" by "docker logs" resolves this issue. This commit includes changes related to "docker logs" usage. --- ci-scripts/cls_containerize.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ci-scripts/cls_containerize.py b/ci-scripts/cls_containerize.py index c5e99500b1..7b2813325f 100644 --- a/ci-scripts/cls_containerize.py +++ b/ci-scripts/cls_containerize.py @@ -1021,18 +1021,18 @@ class Containerize(): for s in allServices: # outputs the hash if the container is running ret = mySSH.run(f'docker compose -f {yamlDir}/ci-docker-compose.yml ps --all --quiet -- {s}') - running = ret.stdout.splitlines() - logging.debug(f'running services: {running}') + c = ret.stdout + logging.debug(f'running service {s} with container id {c}') if ret.stdout != "" and ret.returncode == 0: # something is running for that service - services.append(s) - logging.info(f'stopping services {services}') + services.append((s, c)) + logging.info(f'stopping services {[s for s, _ in services]}') mySSH.run(f'docker compose -f {yamlDir}/ci-docker-compose.yml stop -t3') copyin_res = True - for svcName in services: + for service_name, container_id in services: # head -n -1 suppresses the final "X exited with status code Y" - filename = f'{svcName}-{HTML.testCase_id}.log' - mySSH.run(f'docker compose -f {yamlDir}/ci-docker-compose.yml logs --no-log-prefix -- {svcName} &> {lSourcePath}/cmake_targets/log/{filename}') + filename = f'{service_name}-{HTML.testCase_id}.log' + mySSH.run(f'docker logs {container_id} &> {lSourcePath}/cmake_targets/log/{filename}') copyin_res = mySSH.copyin(f'{lSourcePath}/cmake_targets/log/{filename}', f'{filename}') and copyin_res mySSH.run(f'docker compose -f {yamlDir}/ci-docker-compose.yml down -v') @@ -1043,7 +1043,7 @@ class Containerize(): HTML.CreateHtmlTestRow('N/A', 'KO', CONST.ENB_PROCESS_NOLOGFILE_TO_ANALYZE) self.exitStatus = 1 # use function for UE log analysis, when oai-nr-ue container is used - elif 'oai-nr-ue' in services or 'lte_ue0' in services: + elif any(service_name == 'oai-nr-ue' or service_name == 'lte_ue0' for service_name, _ in services): self.exitStatus == 0 logging.debug(f'Analyzing UE logfile {filename}') logStatus = cls_oaicitest.OaiCiTest().AnalyzeLogFile_UE(f'{filename}', HTML, RAN) @@ -1053,12 +1053,12 @@ class Containerize(): else: HTML.CreateHtmlTestRow('UE log Analysis', 'OK', CONST.ALL_PROCESSES_OK) else: - for svcName in services: - if svcName == 'nv-cubb': + for service_name, _ in services: + if service_name == 'nv-cubb': msg = 'Undeploy PNF/Nvidia CUBB' HTML.CreateHtmlTestRow(msg, 'OK', CONST.ALL_PROCESSES_OK) else: - filename = f'{svcName}-{HTML.testCase_id}.log' + filename = f'{service_name}-{HTML.testCase_id}.log' logging.debug(f'\u001B[1m Analyzing logfile {filename}\u001B[0m') logStatus = RAN.AnalyzeLogFile_eNB(filename, HTML, self.ran_checkers) if (logStatus < 0): From 7a9b3485b19b135b9bd0c50313290fc6fd5c2eb9 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Fri, 19 Apr 2024 10:58:09 +0200 Subject: [PATCH 10/10] Remove hardcoding of 5G-S-TMSI on nrUE --- openair2/RRC/NR/MESSAGES/asn1_msg.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 82798b4b75..07c48c88d7 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -893,19 +893,7 @@ uint8_t do_RRCSetupComplete(uint8_t *buffer, NR_RRCSetupComplete_IEs_t *ies = RrcSetupComplete->criticalExtensions.choice.rrcSetupComplete; ies->selectedPLMN_Identity = sel_plmn_id; ies->registeredAMF = NULL; - - ies->ng_5G_S_TMSI_Value = CALLOC(1, sizeof(struct NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value)); - ies->ng_5G_S_TMSI_Value->present = NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value_PR_ng_5G_S_TMSI; - NR_NG_5G_S_TMSI_t *stmsi = &ies->ng_5G_S_TMSI_Value->choice.ng_5G_S_TMSI; - stmsi->size = 6; - stmsi->buf = calloc(stmsi->size, sizeof(*stmsi->buf)); - AssertFatal(stmsi->buf != NULL, "out of memory\n"); - stmsi->buf[0] = 0x12; - stmsi->buf[1] = 0x34; - stmsi->buf[2] = 0x56; - stmsi->buf[3] = 0x78; - stmsi->buf[4] = 0x9A; - stmsi->buf[5] = 0xBC; + ies->ng_5G_S_TMSI_Value = NULL; memset(&ies->dedicatedNAS_Message,0,sizeof(OCTET_STRING_t)); OCTET_STRING_fromBuf(&ies->dedicatedNAS_Message, dedicatedInfoNAS, dedicatedInfoNASLength);