Commit bdc6df8c authored by Bartosz Podrygajlo's avatar Bartosz Podrygajlo

NR UE & gNB imscope.

A new phy scope based on ImGui and ImPlot. This scope uses a different concurrency model than previous
scopes.

The PHY thread writing the data first checks if the data is ready to be written. If its not, nothing is copied.
The GUI thread reads data if available and marks it ready to write. This makes sure that the PHY threads are not
busy copying data that would never be displayed.

Some of the scopes also have a freeze functionality that further limit the amount of data that needs to be copied
from PHY threads. If a scope is "frozen" it still allows the user to explore the data using plots zoom/pan functions
but doesn't cause PHY threads to perform extra writes on the displayed data.

A compile option was added to enable/disable the scope. Use cmake -DENABLE_IMSCOPE=ON to enable the scope.

Update CXX standard to 17; it is required by some libraries (e.g., dear imgui). The oldest gcc version in
use by a distribution supported is Ubuntu 20, which has gcc 9.4 with c++17 support.
parent 69a84825
......@@ -23,6 +23,7 @@
cmake_minimum_required (VERSION 3.16)
project (OpenAirInterface LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
#########################################################
# Base directories, compatible with legacy OAI building #
......@@ -30,6 +31,10 @@ project (OpenAirInterface LANGUAGES C CXX)
set (OPENAIR_DIR ${CMAKE_SOURCE_DIR})
include("cmake_targets/macros.cmake")
if(NOT DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_SOURCE_CACHE ~/.cache/cpm/)
endif()
include("cmake_targets/CPM.cmake")
##############################
### CCache: reduce compilation time
......@@ -288,6 +293,8 @@ set_property(CACHE KPM_VERSION PROPERTY STRINGS "KPM_V2_03" "KPM_V3_00")
message(STATUS "Selected KPM Version: ${KPM_VERSION}")
add_boolean_option(ENABLE_IMSCOPE OFF "Enable phy scope based on imgui" ON)
##################################################
# ASN.1 grammar C code generation & dependencies #
##################################################
......@@ -2340,30 +2347,24 @@ if(ENABLE_TESTS)
find_package(GTest)
if (NOT GTest_FOUND)
message(STATUS "GTest package not found, will download googletest automatically. To prevent that install google test on your system (libgtest-dev)")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # 1.12.1
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.12.1
VERSION 1.12.1
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt" "BUILD_GMOCK OFF"
)
set(BUILD_GMOCK OFF)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()
find_package(benchmark)
if (NOT benchmark_FOUND)
message(STATUS "benchmark package not found, will download benchmark automatically. To prevent that install google benchmark on your system (libbenchmark-dev)")
include(FetchContent)
set(BENCHMARK_ENABLE_TESTING OFF)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.9.0
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
VERSION 1.9.0
OPTIONS "BENCHMARK_ENABLE_TESTING OFF"
)
FetchContent_MakeAvailable(benchmark)
endif()
endif()
......
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.40.1)
set(CPM_HASH_SUM "117cbf2711572f113bab262933eb5187b08cfc06dce0714a1ee94f2183ddc3ec")
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)
include(${CPM_DOWNLOAD_LOCATION})
......@@ -254,6 +254,9 @@ int get_smallest_supported_bandwidth_index(int scs, frequency_range_t frequency_
#define CEILIDIV(a,b) ((a+b-1)/b)
#define ROUNDIDIV(a,b) (((a<<1)+b)/(b<<1))
// Align up to a multiple of 16
#define ALIGN_UP_16(a) ((a + 15) & ~15)
#ifdef __cplusplus
#ifdef min
#undef min
......
......@@ -42,6 +42,8 @@ Running the [build_oai](../cmake_targets/build_oai) script also generates some
The build system for OAI uses [cmake](https://cmake.org/) which is a tool to generate makefiles. The `build_oai` script is a wrapper using `cmake` and `make`/`ninja` to ease the oai build and use. It logs the `cmake` and `ninja`/`make` commands it executes. The file describing how to build the executables from source files is the [CMakeLists.txt](../CMakeLists.txt), it is used as input by cmake to generate the makefiles.
cmake is further extended by using [CPM](https://github.com/cpm-cmake/CPM.cmake). CPM is a cmake script that handles external code dependencies. It is setup to cache downloaded code in `~/.cache/cpm`. While most external dependencies should be handled by system package managers, CPM has the advantage of using any code that is available in a public git repository.
The oai softmodem supports many use cases, and new ones are regularly added. Most of them are accessible using the configuration file or the command line options and continuous effort is done to avoid introducing build options as it makes tests and usage more complicated than run-time options. The following functionalities, originally requiring a specific build are now accessible by configuration or command line options:
- s1, noS1
......
......@@ -106,7 +106,7 @@ The other SDRs (AW2S, LimeSDR, ...) have no READMEs.
## Special-purpose libraries
- OAI has a scope based on Xforms, described in [this README](../openair1/PHY/TOOLS/readme.md)
- OAI has two scopes: one based on Xforms and one based on imgui, described in [this README](../openair1/PHY/TOOLS/readme.md)
- OAI comes with an integrated [telnet server](../common/utils/telnetsrv/DOC/telnethelp.md) to monitor and control
- OAI comes with an integrated [web server](../common/utils/websrv/DOC/websrv.md)
......
......@@ -734,14 +734,18 @@ int main( int argc, char **argv ) {
printf("ALL RUs ready - init gNBs\n");
for (int idx=0;idx<RC.nb_nr_L1_inst;idx++) RC.gNB[idx]->if_inst->sl_ahead = sl_ahead;
if(IS_SOFTMODEM_DOSCOPE) {
if (IS_SOFTMODEM_DOSCOPE) {
sleep(1);
scopeParms_t p;
p.argc=&argc;
p.argv=argv;
p.gNB=RC.gNB[0];
p.ru=RC.ru[0];
load_softscope("nr",&p);
p.argc = &argc;
p.argv = argv;
p.gNB = RC.gNB[0];
p.ru = RC.ru[0];
#ifndef ENABLE_IMSCOPE
load_softscope("nr", &p);
#else
load_softscope("im", &p);
#endif
}
if (NFAPI_MODE != NFAPI_MODE_PNF && NFAPI_MODE != NFAPI_MODE_VNF && NFAPI_MODE != NFAPI_MODE_AERIAL) {
......
......@@ -521,8 +521,12 @@ int main(int argc, char **argv)
init_openair0();
lock_memory_to_ram();
if(IS_SOFTMODEM_DOSCOPE) {
load_softscope("nr",PHY_vars_UE_g[0][0]);
if (IS_SOFTMODEM_DOSCOPE) {
#ifndef ENABLE_IMSCOPE
load_softscope("nr", PHY_vars_UE_g[0][0]);
#else
load_softscope("im", PHY_vars_UE_g[0][0]);
#endif
}
for (int inst = 0; inst < NB_UE_INST; inst++) {
......
......@@ -199,7 +199,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB)
int n_buf = Prx*max_ul_mimo_layers;
int nb_re_pusch = N_RB_UL * NR_NB_SC_PER_RB;
int nb_re_pusch2 = (nb_re_pusch + 15) & ~15;
int nb_re_pusch2 = ALIGN_UP_16(nb_re_pusch);
gNB->pusch_vars = (NR_gNB_PUSCH *)malloc16_clear(gNB->max_nb_pusch * sizeof(NR_gNB_PUSCH));
for (int ULSCH_id = 0; ULSCH_id < gNB->max_nb_pusch; ULSCH_id++) {
......
......@@ -1263,7 +1263,7 @@ static void inner_rx(PHY_VARS_gNB *gNB,
int nb_layer = rel15_ul->nrOfLayers;
int nb_rx_ant = frame_parms->nb_antennas_rx;
int dmrs_symbol_flag = (rel15_ul->ul_dmrs_symb_pos >> symbol) & 0x01;
int buffer_length = (rel15_ul->rb_size * NR_NB_SC_PER_RB + 15) & ~15;
int buffer_length = ALIGN_UP_16(rel15_ul->rb_size * NR_NB_SC_PER_RB);
c16_t rxFext[nb_rx_ant][buffer_length] __attribute__((aligned(32)));
c16_t chFext[nb_layer][nb_rx_ant][buffer_length] __attribute__((aligned(32)));
......@@ -1631,7 +1631,7 @@ int nr_rx_pusch_tp(PHY_VARS_gNB *gNB,
// extract the data in the OFDM frame, to the start of the array
int soffset = (slot % RU_RX_SLOT_DEPTH) * frame_parms->symbols_per_slot * frame_parms->ofdm_symbol_size;
nb_re_pusch = (nb_re_pusch + 15) & ~15;
nb_re_pusch = ALIGN_UP_16(nb_re_pusch);
int dmrs_symbol;
if (gNB->chest_time == 0)
dmrs_symbol = get_valid_dmrs_idx_for_channel_est(rel15_ul->ul_dmrs_symb_pos, meas_symbol);
......@@ -1699,8 +1699,8 @@ int nr_rx_pusch_tp(PHY_VARS_gNB *gNB,
start_meas(&gNB->rx_pusch_symbol_processing_stats);
int numSymbols = gNB->num_pusch_symbols_per_thread;
int total_res = 0;
for(uint8_t symbol = rel15_ul->start_symbol_index; symbol < end_symbol; symbol += numSymbols) {
int total_res = 0;
for (int s = 0; s < numSymbols; s++) {
pusch_vars->ul_valid_re_per_slot[symbol+s] = get_nb_re_pusch(frame_parms,rel15_ul,symbol+s);
pusch_vars->llr_offset[symbol+s] = ((symbol+s) == rel15_ul->start_symbol_index) ?
......@@ -1744,5 +1744,26 @@ int nr_rx_pusch_tp(PHY_VARS_gNB *gNB,
}
stop_meas(&gNB->rx_pusch_symbol_processing_stats);
// Copy the data to the scope. This cannot be performed in one call to gNBscopeCopy because the data is not contiguous in the
// buffer due to reference symbol extraction and padding. The gNBscopeCopy call is broken up into steps: trylock, copy, unlock.
metadata mt = {.slot = slot, .frame = frame};
if (gNBTryLockScopeData(gNB, gNBPuschRxIq, sizeof(c16_t), 1, total_res, &mt)) {
int buffer_length = ALIGN_UP_16(rel15_ul->rb_size * NR_NB_SC_PER_RB);
size_t offset = 0;
for (uint8_t symbol = rel15_ul->start_symbol_index; symbol < (rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols);
symbol++) {
gNBscopeCopyUnsafe(gNB,
gNBPuschRxIq,
&pusch_vars->rxdataF_comp[0][symbol * buffer_length],
sizeof(c16_t) * pusch_vars->ul_valid_re_per_slot[symbol],
offset,
symbol - rel15_ul->start_symbol_index);
offset += sizeof(c16_t) * pusch_vars->ul_valid_re_per_slot[symbol];
}
gNBunlockScopeData(gNB, gNBPuschRxIq)
}
uint32_t total_llrs = total_res * rel15_ul->qam_mod_order * rel15_ul->nrOfLayers;
gNBscopeCopyWithMetadata(gNB, gNBPuschLlr, pusch_vars->llr, sizeof(c16_t), 1, total_llrs, 0, &mt);
return 0;
}
......@@ -442,8 +442,9 @@ int nr_rx_pbch(PHY_VARS_NR_UE *ue,
// legacy code use int16, but it is complex16
if (ue) {
UEscopeCopy(ue, pbchRxdataF_comp, pbch_unClipped, sizeof(struct complex16), frame_parms->nb_antennas_rx, pbch_e_rx_idx / 2, 0);
UEscopeCopy(ue, pbchLlr, pbch_e_rx, sizeof(int16_t), frame_parms->nb_antennas_rx, pbch_e_rx_idx, 0);
metadata meta = {.slot = proc->nr_slot_rx, .frame = proc->frame_rx};
UEscopeCopyWithMetadata(ue, pbchRxdataF_comp, pbch_unClipped, sizeof(struct complex16), frame_parms->nb_antennas_rx, pbch_e_rx_idx / 2, 0, &meta);
UEscopeCopyWithMetadata(ue, pbchLlr, pbch_e_rx, sizeof(int16_t), frame_parms->nb_antennas_rx, pbch_e_rx_idx, 0, &meta);
}
#ifdef DEBUG_PBCH
for (int cnt = 0; cnt < 864 ; cnt++)
......
......@@ -63,3 +63,7 @@ endif()
if (ENABLE_TESTS)
add_subdirectory(tests)
endif()
if (ENABLE_IMSCOPE)
add_subdirectory(imscope)
endif()
CPMAddPackage("gh:ocornut/imgui#v1.90.9")
add_library(imgui
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
)
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
add_library(imgui_opengl_renderer ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp)
target_include_directories(imgui_opengl_renderer PUBLIC ${imgui_SOURCE_DIR}/backends/)
target_link_libraries(imgui_opengl_renderer PUBLIC imgui)
add_library(imgui_glfw_backend ${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp)
target_include_directories(imgui_glfw_backend PUBLIC ${imgui_SOURCE_DIR}/backends/)
target_link_libraries(imgui_glfw_backend PUBLIC imgui)
find_package(OpenGL REQUIRED)
find_package(glfw3 3.3 REQUIRED)
CPMAddPackage("gh:epezent/implot#v0.16")
add_library(implot
${implot_SOURCE_DIR}/implot.cpp
${implot_SOURCE_DIR}/implot_demo.cpp
${implot_SOURCE_DIR}/implot_items.cpp
)
target_link_libraries(implot PUBLIC imgui)
target_include_directories(implot PUBLIC ${implot_SOURCE_DIR})
add_library(imscope MODULE imscope.cpp ../phy_scope_interface.c)
target_link_libraries(imscope PUBLIC imgui_glfw_backend glfw imgui_opengl_renderer OpenGL::OpenGL implot UTIL)
set_target_properties(imscope PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
This diff is collapsed.
......@@ -58,7 +58,7 @@ int end_forms(void) {
return -1;
}
void copyData(void *scopeData, enum scopeDataType type, void *dataIn, int elementSz, int colSz, int lineSz, int offset)
void copyData(void *scopeData, enum scopeDataType type, void *dataIn, int elementSz, int colSz, int lineSz, int offset, metadata *meta)
{
scopeData_t *tmp = (scopeData_t *)scopeData;
......
......@@ -70,7 +70,10 @@ enum scopeDataType {
psbchDlChEstimateTime,
psbchLlr,
psbchRxdataF_comp,
MAX_SCOPE_TYPES
MAX_SCOPE_TYPES,
gNBPuschRxIq = MAX_SCOPE_TYPES,
gNBPuschLlr,
EXTRA_SCOPE_TYPES
};
enum PlotTypeGnbIf {
......@@ -87,34 +90,70 @@ typedef struct {
int lineSz;
} scopeGraphData_t;
typedef struct {
int slot;
int frame;
} metadata;
typedef struct scopeData_s {
int *argc;
char **argv;
RU_t *ru;
PHY_VARS_gNB *gNB;
scopeGraphData_t *liveData[MAX_SCOPE_TYPES];
void (*copyData)(void *, enum scopeDataType, void *data, int elementSz, int colSz, int lineSz, int offset);
void (*copyData)(void *, enum scopeDataType, void *data, int elementSz, int colSz, int lineSz, int offset, metadata *meta);
pthread_mutex_t copyDataMutex;
scopeGraphData_t *copyDataBufs[MAX_SCOPE_TYPES][COPIES_MEM];
int copyDataBufsIdx[MAX_SCOPE_TYPES];
void (*scopeUpdater)(enum PlotTypeGnbIf plotType, int numElements);
bool (*tryLockScopeData)(enum scopeDataType type, int elementSz, int colSz, int lineSz, metadata *meta);
void (*copyDataUnsafeWithOffset)(enum scopeDataType type, void *dataIn, size_t size, size_t offset, int copy_index);
void (*unlockScopeData)(enum scopeDataType type);
} scopeData_t;
int load_softscope(char *exectype, void *initarg);
int end_forms(void) ;
int copyDataMutexInit(scopeData_t *);
void copyData(void *, enum scopeDataType type, void *dataIn, int elementSz, int colSz, int lineSz, int offset);
void copyData(void *, enum scopeDataType type, void *dataIn, int elementSz, int colSz, int lineSz, int offset, metadata *meta);
#define UEscopeCopyWithMetadata(ue, type, ...) \
if (ue->scopeData) { \
((scopeData_t *)ue->scopeData)->copyData((scopeData_t *)ue->scopeData, type, ##__VA_ARGS__); \
}
#define UEscopeCopy(ue, type, ...) \
if (ue->scopeData) \
((scopeData_t *)ue->scopeData)->copyData((scopeData_t *)ue->scopeData, type, ##__VA_ARGS__);
if (ue->scopeData) { \
metadata mt = {.slot = -1, .frame = -1}; \
((scopeData_t *)ue->scopeData)->copyData((scopeData_t *)ue->scopeData, type, ##__VA_ARGS__, &mt); \
}
#define gNBscopeCopyWithMetadata(gnb, type, ...) \
if (gnb->scopeData) { \
((scopeData_t *)gnb->scopeData)->copyData((scopeData_t *)gNB->scopeData, type, ##__VA_ARGS__); \
}
#define gNBscopeCopy(gnb, type, ...) \
if (gnb->scopeData) \
((scopeData_t *)gnb->scopeData)->copyData((scopeData_t *)gNB->scopeData, type, ##__VA_ARGS__);
if (gnb->scopeData) { \
metadata mt = {.slot = -1, .frame = -1}; \
((scopeData_t *)gnb->scopeData)->copyData((scopeData_t *)gNB->scopeData, type, ##__VA_ARGS__, &mt); \
}
#define GnbScopeUpdate(gnb, type, numElt) \
if (gnb->scopeData) \
((scopeData_t *)gnb->scopeData)->scopeUpdater(type, numElt);
#define gNBTryLockScopeData(gnb, type, ...) \
gnb->scopeData && ((scopeData_t *)gnb->scopeData)->tryLockScopeData \
&& ((scopeData_t *)gnb->scopeData)->tryLockScopeData(type, ##__VA_ARGS__)
#define gNBscopeCopyUnsafe(gnb, type, ...) \
scopeData_t *scope_data = (scopeData_t *)gnb->scopeData; \
if (scope_data && scope_data->copyDataUnsafeWithOffset) { \
scope_data->copyDataUnsafeWithOffset(type, ##__VA_ARGS__); \
}
#define gNBunlockScopeData(gnb, type) \
scopeData_t *scope_data = (scopeData_t *)gnb->scopeData; \
if (scope_data && scope_data->unlockScopeData) { \
scope_data->unlockScopeData(type); \
}
extended_kpi_ue* getKPIUE();
#endif
......@@ -31,3 +31,41 @@ or
```
phy_scope_gNB(0, phy_vars_gnb, phy_vars_ru, UE_id)
```
# ImScope
ImScope is a scope based on imgui & implot. This scope uses a different concurrency model than xforms scope, with thread
safety being priority. The goal is to never show incorrect data on the screen and be able to use the scope with real radios.
If correctness cannot be achieved e.g. due to performance issues when using thread safe implementation user should be warned
clearly on the screen.
![image](./imscope/imscope_screenshot.png)
## Prerequisites
ImScope uses imgui, implot, glfw3 and opengl. imgui and implot should be downloaded automatically when configuring the project
with `-DENABLE_IMSCOPE=ON`, using [CPM](https://github.com/cpm-cmake/CPM.cmake). CPM is used because imgui and implot do not have
an official binary release. glfw3 and opengl should be installed with your system, on ubuntu these are contained in packages
libglfw3-dev and libopengl-dev respectivly.
## Building
Add `-DENABLE_IMSCOPE=ON` to your `cmake` command. Build target `imscope`
## Running
Run with `-d` flag
## Usage notes
- It's experimental and might contain bugs
- It uses tree nodes to hide/show scopes (layout is subject to change). If a scope is not visible or is frozen it costs nearly
nothing in the PHY threads. If its unfrozen every time the data is displayed the PHY thread would have to perform the copy. By
default this can happen up to 24 times per second. User is informed on the estimated impact on PHY threads at the top of the
window. You can use FPS target to limit the impact on PHY threads and maintain scope functionality while minimizing the effect
on realtime operation.
## Reporting bugs and feature requests
Report bugs and feature requests on [gitlab](https://gitlab.eurecom.fr/oai/openairinterface5g/-/issues). There is two demo windows
enabled in the scope that showcase imgui/implot, if you find something of interest it can be implemented in the scope.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment