Skip to content

Commit

Permalink
Reduce default buffer sizes (#582)
Browse files Browse the repository at this point in the history
* feat: change config values to be mcu friendly

* feat: remove buffers from config file

* doc: add troubleshooting section to README

* fix: uncomment buffer sizes

* feat: define buffer values in zenoh-pico.h

* fix: switch config values to config.h because of cross include

* doc: update readme

* fix: modulation test compile error

* feat: unify config exposure to cmake

* fix: wconversion errors

* build: update ci workflows

* fix: remove old tokens from freertos cmake

* feat: expose socket timeout option in cmake

* fix: add config.h in zenoh-pico.h

* build update workflows
  • Loading branch information
jean-roland authored Aug 12, 2024
1 parent 37fd830 commit 48887a9
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino_esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
mkdir -p $ARDUINO_BASE
cd $ARDUINO_BASE
platformio init -b esp32thing_plus -O "build_flags=-DZ_FEATURE_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC" -O "lib_ldf_mode=deep+"
platformio init -b esp32thing_plus -O "board_build.cmake_extra_args=-DZ_FEATURE_LINK_BLUETOOTH=1" -O "build_flags=-DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC" -O "lib_ldf_mode=deep+"
cd $ARDUINO_BASE/lib
ln -s $ZENOH_PICO_BASE
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/emscripten.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:
- name: Compile debug
run: |
mkdir build
emcmake cmake -E env CFLAGS="-DZ_FEATURE_LINK_WS=1 -DZ_FEATURE_LINK_TCP=0 -DZ_FEATURE_LINK_UDP_MULTICAST=0 -DZ_FEATURE_LINK_UDP_UNICAST=0 -DZ_FEATURE_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild
emcmake cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -DZ_FEATURE_LINK_WS=1 -DZ_FEATURE_LINK_TCP=0 -DZ_FEATURE_LINK_UDP_MULTICAST=0 -DZ_FEATURE_LINK_UDP_UNICAST=0 -DZ_FEATURE_SCOUTING_UDP=0 -H. -Bbuild
make -C build
7 changes: 1 addition & 6 deletions .github/workflows/freertos_plus_tcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ jobs:
- name: Build examples
run: |
cd examples/freertos_plus_tcp
cmake -Bbuild -G"Ninja Multi-Config"
cmake -Bbuild -G"Ninja Multi-Config" -DZ_FEATURE_LINK_UDP_MULTICAST=0 -DZ_CONFIG_SOCKET_TIMEOUT=1000
cmake --build ./build --config Debug
cmake --build ./build --config Release
env:
Z_FEATURE_PUBLICATION: 1
Z_FEATURE_SUBSCRIPTION: 1
Z_FEATURE_QUERYABLE: 1
Z_FEATURE_QUERY: 1
2 changes: 1 addition & 1 deletion .github/workflows/mbed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
mkdir -p $MBED_BASE
cd $MBED_BASE
pio init -b nucleo_f767zi --project-option="framework=mbed" --project-option="build_flags=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC"
pio init -b nucleo_f767zi --project-option="framework=mbed" --project-option="board_build.cmake_extra_args=-DZ_FEATURE_LINK_SERIAL=1" -O "build_flags=-DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC"
cd $MBED_BASE/lib
ln -s $ZENOH_PICO_BASE
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zephyr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
mkdir -p $ZEPHYR_BASE
cd $ZEPHYR_BASE
pio init -b nucleo_f767zi --project-option="framework=zephyr" --project-option="build_flags=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3"
pio init -b nucleo_f767zi --project-option="framework=zephyr" --project-option="board_build.cmake_extra_args=-DZ_FEATURE_LINK_SERIAL=1 -DZENOH_DEBUG=3"
cd $ZEPHYR_BASE/lib
ln -s $ZENOH_PICO_BASE
Expand Down
41 changes: 31 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static l
option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF)
option(WITH_FREERTOS_PLUS_TCP "Build for FreeRTOS RTOS and FreeRTOS-Plus-TCP network stack" OFF)
set(ZENOH_DEBUG 0 CACHE STRING "Use this to set the ZENOH_DEBUG variable")
set(FRAG_MAX_SIZE 0 CACHE STRING "Use this to override the maximum size for fragmented messages")
set(BATCH_UNICAST_SIZE 0 CACHE STRING "Use this to override the maximum unicast batch size")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
Expand Down Expand Up @@ -181,13 +179,33 @@ add_definition(ZENOH_DEBUG=${ZENOH_DEBUG})


# Zenoh pico feature configuration options
set(Z_FEATURE_MULTI_THREAD 1 CACHE STRING "Toggle multithread feature")
set(FRAG_MAX_SIZE 4096 CACHE STRING "Use this to override the maximum size for fragmented messages")
set(BATCH_UNICAST_SIZE 2048 CACHE STRING "Use this to override the maximum unicast batch size")
set(BATCH_MULTICAST_SIZE 2048 CACHE STRING "Use this to override the maximum multicast batch size")
set(Z_CONFIG_SOCKET_TIMEOUT 100 CACHE STRING "Default socket timeout in milliseconds")

set(Z_FEATURE_PUBLICATION 1 CACHE STRING "Toggle publication feature")
set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature")
set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature")
set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature")
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport feature")
set(Z_FEATURE_INTEREST 1 CACHE STRING "Toggle interests")
set(Z_FEATURE_FRAGMENTATION 1 CACHE STRING "Toggle fragmentation")
set(Z_FEATURE_ENCODING_VALUES 1 CACHE STRING "Toggle encoding values")
set(Z_FEATURE_MULTI_THREAD 1 CACHE STRING "Toggle multithread")
set(Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0 CACHE STRING "Toggle dynamic memory allocation")

set(Z_FEATURE_LINK_TCP 1 CACHE STRING "Toggle TCP links")
set(Z_FEATURE_LINK_BLUETOOTH 0 CACHE STRING "Toggle Bluetooth links")
set(Z_FEATURE_LINK_WS 0 CACHE STRING "Toggle WebSocket links")
set(Z_FEATURE_LINK_SERIAL 0 CACHE STRING "Toggle Serial links")
set(Z_FEATURE_SCOUTING_UDP 1 CACHE STRING "Toggle UDP scouting")
set(Z_FEATURE_LINK_UDP_MULTICAST 1 CACHE STRING "Toggle UDP multicast links")
set(Z_FEATURE_LINK_UDP_UNICAST 1 CACHE STRING "Toggle UDP unicast links")
set(Z_FEATURE_MULTICAST_TRANSPORT 1 CACHE STRING "Toggle multicast transport")
set(Z_FEATURE_UNICAST_TRANSPORT 1 CACHE STRING "Toggle unicast transport")
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport")
set(Z_FEATURE_INTEREST 1 CACHE STRING "Toggle interest feature")

add_compile_definitions("Z_BUILD_DEBUG=$<CONFIG:Debug>")
message(STATUS "Building with feature confing:\n\
* MULTI-THREAD: ${Z_FEATURE_MULTI_THREAD}\n\
Expand All @@ -204,16 +222,19 @@ configure_file(
@ONLY
)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico/config.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico/config.h
@ONLY
)

# Print summary of CMAKE configurations
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode")
message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}")
message(STATUS "Zenoh Level Log: ${ZENOH_DEBUG}")
if(FRAG_MAX_SIZE)
message(STATUS "Fragmented message max size: ${FRAG_MAX_SIZE}")
endif()
if(BATCH_UNICAST_SIZE)
message(STATUS "Unicast batch max size: ${BATCH_UNICAST_SIZE}")
endif()
message(STATUS "Fragmented message max size: ${FRAG_MAX_SIZE}")
message(STATUS "Unicast batch max size: ${BATCH_UNICAST_SIZE}")
message(STATUS "Multicast batch max size: ${BATCH_MULTICAST_SIZE}")
message(STATUS "Build for Zephyr RTOS: ${WITH_ZEPHYR}")
message(STATUS "Build for FreeRTOS-Plus-TCP: ${WITH_FREERTOS_PLUS_TCP}")
message(STATUS "Configuring for ${CMAKE_SYSTEM_NAME}")
Expand Down
8 changes: 7 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Z_FEATURE_QUERYABLE?=1
Z_FEATURE_INTEREST?=1
Z_FEATURE_RAWETH_TRANSPORT?=0

# Buffer sizes
FRAG_MAX_SIZE?=300000
BATCH_UNICAST_SIZE?=65535
BATCH_MULTICAST_SIZE?=8096

# zenoh-pico/ directory
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

Expand All @@ -75,7 +80,8 @@ CROSSIMG_PREFIX=zenoh-pico_
CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST)\
-DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) -DZ_FEATURE_INTEREST=$(Z_FEATURE_INTEREST) \
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DFRAG_MAX_SIZE=$(FRAG_MAX_SIZE) -DBATCH_UNICAST_SIZE=$(BATCH_UNICAST_SIZE) -DBATCH_MULTICAST_SIZE=$(BATCH_MULTICAST_SIZE)\
-DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.

ifeq ($(FORCE_C99), ON)
CMAKE_OPT += -DCMAKE_C_STANDARD=99
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,26 @@ And on another shell, do:
$ ./z_pub -m peer -l udp/224.0.0.123:7447#iface=lo0
```
A publisher will start publishing over UDP multicast and the **zenoh** router will take care of forwarding data from the Zenoh-Pico publisher to the Zenoh-Pico subscriber.

## Troubleshooting

### Activate debug logs
By default debug logs are deactivated but if you're encountering issues they can help you finding the cause. To activate them you need to pass the build flag value: `-DZENOH_DEBUG=3`

### Error when opening a session on a microcontroller
If you get an error when opening the session even though everything is setup correctly, it might be because the default buffer sizes are too large for the limited memory available on your system.

The first thing to try is to reduce the values of the following configuration options (found in `CMakeLists.txt`):
* BATCH_UNICAST_SIZE: The maximum size of a packet in client mode.
* BATCH_MULTICAST_SIZE: The maximum size of a packet in peer mode.
* FRAG_MAX_SIZE: The maximum size of a message that can be fragmented into multiple packets.

Until you find values that suits both your app requirements and your system memory constraints.

These values can also be passed directly as cmake args. For example, in a `platformio.ini` you might write:
```
board_build.cmake_extra_args=
-DBATCH_UNICAST_SIZE=1024
-DFRAG_MAX_SIZE=2048
```

9 changes: 0 additions & 9 deletions examples/freertos_plus_tcp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ target_link_libraries(zenohpico
freertos_kernel
freertos_plus_tcp
)
target_compile_definitions(zenohpico
PUBLIC
Z_FEATURE_MULTI_THREAD=1
Z_FEATURE_LINK_TCP=1
Z_FEATURE_SCOUTING_UDP=1
Z_FEATURE_LINK_UDP_UNICAST=1
Z_FEATURE_LINK_UDP_MULTICAST=0
Z_CONFIG_SOCKET_TIMEOUT=1000
)

add_library(main OBJECT main.c)
target_link_libraries(main
Expand Down
12 changes: 1 addition & 11 deletions include/zenoh-pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,11 @@
#define ZENOH_PICO_PATCH 0
#define ZENOH_PICO_TWEAK 0

/* #undef Z_FRAG_MAX_SIZE */
/* #undef Z_BATCH_UNICAST_SIZE */

#define Z_FEATURE_MULTI_THREAD 1
#define Z_FEATURE_PUBLICATION 1
#define Z_FEATURE_SUBSCRIPTION 1
#define Z_FEATURE_QUERY 1
#define Z_FEATURE_QUERYABLE 1
#define Z_FEATURE_RAWETH_TRANSPORT 0
#define Z_FEATURE_INTEREST 1

#include "zenoh-pico/api/constants.h"
#include "zenoh-pico/api/handlers.h"
#include "zenoh-pico/api/macros.h"
#include "zenoh-pico/api/primitives.h"
#include "zenoh-pico/api/types.h"
#include "zenoh-pico/config.h"

#endif /* ZENOH_PICO_H */
12 changes: 1 addition & 11 deletions include/zenoh-pico.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,11 @@
#define ZENOH_PICO_PATCH @ZENOH_PICO_PATCH@
#define ZENOH_PICO_TWEAK @ZENOH_PICO_TWEAK@

#cmakedefine Z_FRAG_MAX_SIZE @FRAG_MAX_SIZE@
#cmakedefine Z_BATCH_UNICAST_SIZE @BATCH_UNICAST_SIZE@

#define Z_FEATURE_MULTI_THREAD @Z_FEATURE_MULTI_THREAD@
#define Z_FEATURE_PUBLICATION @Z_FEATURE_PUBLICATION@
#define Z_FEATURE_SUBSCRIPTION @Z_FEATURE_SUBSCRIPTION@
#define Z_FEATURE_QUERY @Z_FEATURE_QUERY@
#define Z_FEATURE_QUERYABLE @Z_FEATURE_QUERYABLE@
#define Z_FEATURE_RAWETH_TRANSPORT @Z_FEATURE_RAWETH_TRANSPORT@
#define Z_FEATURE_INTEREST @Z_FEATURE_INTEREST@

#include "zenoh-pico/api/constants.h"
#include "zenoh-pico/api/handlers.h"
#include "zenoh-pico/api/macros.h"
#include "zenoh-pico/api/primitives.h"
#include "zenoh-pico/api/types.h"
#include "zenoh-pico/config.h"

#endif /* ZENOH_PICO_H */
Loading

0 comments on commit 48887a9

Please sign in to comment.