Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: zbus: benchmark: complete refactoring and add msg subscriber to benchmark #64524

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion samples/subsys/zbus/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(benchmark)

FILE(GLOB app_sources src/*.c)
set(app_sources src/benchmark.c)

if(CONFIG_BM_LISTENERS)
list(APPEND app_sources src/lis.c)

elseif(CONFIG_BM_SUBSCRIBERS)
list(APPEND app_sources src/sub.c)

elseif(CONFIG_BM_MSG_SUBSCRIBERS)
list(APPEND app_sources src/msg_sub.c)

endif()

target_sources(app PRIVATE ${app_sources})
23 changes: 20 additions & 3 deletions samples/subsys/zbus/benchmark/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ config BM_ONE_TO
int "Number of consumers"
default 8

config BM_ASYNC
bool "Consuming in asynchronous mode"
default false
choice BM_OBSERVER_TYPE
bool "Observer type to be used in the benchmark"

config BM_LISTENERS
bool "Synchronous using listeners"

config BM_SUBSCRIBERS
bool "Asynchronous using subscribers"

config BM_MSG_SUBSCRIBERS
bool "Asynchronous using message subscribers"
select ZBUS_MSG_SUBSCRIBER

endchoice

config BM_FAIRPLAY
bool "Force a comparison with same actions"
help
Forces a message copy on the listeners and subscribers to behave equivalent to
message subscribers.

source "Kconfig.zephyr"
158 changes: 67 additions & 91 deletions samples/subsys/zbus/benchmark/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
:name: Benchmarking
:relevant-api: zbus_apis

Measure the time for sending 256KB from a producer to X consumers.
Measure the time for sending 256KB from a producer to N consumers.

This sample implements an application to measure the time for sending 256KB from the producer to the consumers.
This sample implements an application to measure the time for sending 256KB from the producer to the
consumers.

Building and Running
********************
Expand All @@ -13,28 +14,30 @@ Building and Running
:zephyr-app: samples/subsys/zbus/dyn_channel
:host-os: unix
:board: qemu_cortex_m3
:gen-args: -DCONFIG_BM_MESSAGE_SIZE=1 -DCONFIG_BM_ONE_TO=1 -DCONFIG_BM_ASYNC=y
:gen-args: -DCONFIG_BM_MESSAGE_SIZE=512 -DCONFIG_BM_ONE_TO=1 -DCONFIG_BM_LISTENERS=y
:goals: build run

Notice we have the following parameters:

* **CONFIG_BM_MESSAGE_SIZE** the size of the message to be transferred (1, 2, 4, 8, 16, 32, 64, 128, or 256);
* **CONFIG_BM_ONE_TO** number of consumers to send (1, 2, 4, or 8);
* **CONFIG_BM_ASYNC** if the execution must be asynchronous or synchronous. Use y to async and n to sync;
* **CONFIG_BM_MESSAGE_SIZE** the size of the message to be transferred (2 to 4096 bytes);
* **CONFIG_BM_ONE_TO** number of consumers to send (1 up to 8 consumers);
* **CONFIG_BM_LISTENERS** Use y to perform the benchmark listeners;
* **CONFIG_BM_SUBSCRIBERS** Use y to perform the benchmark subscribers;
* **CONFIG_BM_MSG_SUBSCRIBERS** Use y to perform the benchmark message subscribers.

Sample Output
=============
The result would be something like:

.. code-block:: console

*** Booting Zephyr OS build zephyr-v3.3.0 ***
I: Benchmark 1 to 1: Dynamic memory, SYNC transmission and message size 1
I: Bytes sent = 262144, received = 262144
I: Average data rate: 0.6MB/s
I: Duration: 4.72020167s
*** Booting Zephyr OS build zephyr-vX.Y.Z ***
I: Benchmark 1 to 1 using LISTENERS to transmit with message size: 512 bytes
I: Bytes sent = 262144, received = 262144
I: Average data rate: 12.62MB/s
I: Duration: 0.019805908s

@4072020167
@19805


Running the benchmark automatically
Expand All @@ -43,91 +46,64 @@ Running the benchmark automatically
There is a `Robot framework <https://robotframework.org/>`_ script called ``benchmark_256KB.robot`` which runs all the input combinations as the complete benchmark.
The resulting file, ``zbus_dyn_benchmark_256KB.csv`` is generated in the project root folder. It takes a long time to execute. In the CSV file, we have the following columns:

+------------+---------------------+--------------------------+---------------+-------------+-------------+
| Style | Number of consumers | Message size (bytes) | Duration (ns) | RAM (bytes) | ROM (bytes) |
+============+=====================+==========================+===============+=============+=============+
| SYNC/ASYNC | 1,2,4,8 | 1,2,4,8,16,32,64,128,256 | float | int | int |
+------------+---------------------+--------------------------+---------------+-------------+-------------+
+-----------------+---------------------+--------------------------+---------------+-------------+-------------+
| Observer type | Number of consumers | Message size (bytes) | Duration (ns) | RAM (bytes) | ROM (bytes) |
+=================+=====================+==========================+===============+=============+=============+
| LIS/SUB/MSG_SUB | 1,4,8 | 2,8,32,128,512 | float | int | int |
+-----------------+---------------------+--------------------------+---------------+-------------+-------------+

The complete benchmark command using Robot framework is:

.. code-block:: console

robot --variable serial_port:/dev/ttyACM0 --variable board:nrf52833dk_nrf52833 -d /tmp/benchmark_out benchmark_256KB.robot
robot --variable serial_port:/dev/ttyACM0 --variable board:nrf52dk_nrf52832 -d /tmp/benchmark_out benchmark_256KB.robot

An example of execution using the ``nrf52833dk_nrf52833`` board would generate a file like this:
An example of execution using the ``nrf52dk_nrf52832`` board would generate a file like this:

.. code-block::

SYNC,1,1,2312815348.3333335,7286,23752
SYNC,1,2,1172444661.3333333,7287,23760
SYNC,1,4,602284749.6666666,7289,23768
SYNC,1,8,323750814.0,7293,23772
SYNC,1,16,175120035.66666666,7301,23776
SYNC,1,32,103942871.33333333,7317,23776
SYNC,1,64,68318685.0,7349,23776
SYNC,1,128,50567627.333333336,7477,23776
SYNC,1,256,41656494.0,7733,23776
SYNC,2,1,1277842204.3333333,7298,23768
SYNC,2,2,647094726.6666666,7299,23776
SYNC,2,4,329559326.3333333,7301,23784
SYNC,2,8,170979817.66666666,7305,23796
SYNC,2,16,95174153.66666667,7313,23792
SYNC,2,32,55786133.0,7329,23792
SYNC,2,64,36173502.333333336,7361,23792
SYNC,2,128,26326497.666666668,7489,23792
SYNC,2,256,21280924.333333332,7745,23792
SYNC,4,1,745513916.0,7322,23800
SYNC,4,2,374755859.6666667,7323,23808
SYNC,4,4,191497802.66666666,7325,23816
SYNC,4,8,101399739.66666667,7329,23820
SYNC,4,16,54026286.0,7337,23824
SYNC,4,32,31097412.0,7353,23824
SYNC,4,64,19643148.333333332,7385,23824
SYNC,4,128,13936360.333333334,7513,23824
SYNC,4,256,11047363.333333334,7769,23824
SYNC,8,1,477518717.3333333,7370,23864
SYNC,8,2,240773518.66666666,7371,23872
SYNC,8,4,121897379.33333333,7373,23880
SYNC,8,8,64015706.333333336,7377,23884
SYNC,8,16,33681234.0,7385,23888
SYNC,8,32,18880208.333333332,7401,23888
SYNC,8,64,11505127.0,7433,23888
SYNC,8,128,7781982.333333333,7561,23888
SYNC,8,256,5940755.333333333,7817,23888
ASYNC,1,1,9422749837.333334,7962,24108
ASYNC,1,2,4728759765.333333,7963,24116
ASYNC,1,4,2380554199.3333335,7965,24124
ASYNC,1,8,1225118001.6666667,7969,24128
ASYNC,1,16,618764241.6666666,7977,24132
ASYNC,1,32,326253255.3333333,7993,24132
ASYNC,1,64,179473876.66666666,8025,24132
ASYNC,1,128,106170654.33333333,8217,24132
ASYNC,1,256,69386800.33333333,8601,24136
ASYNC,2,1,8347330729.0,8650,24288
ASYNC,2,2,4186747233.3333335,8651,24296
ASYNC,2,4,2092895507.3333333,8653,24304
ASYNC,2,8,1049245198.6666666,8657,24316
ASYNC,2,16,541544596.6666666,8665,24312
ASYNC,2,32,281127929.6666667,8681,24312
ASYNC,2,64,150746663.66666666,8713,24312
ASYNC,2,128,85662842.0,8969,24312
ASYNC,2,256,48909505.0,9481,24320
ASYNC,4,1,7854085286.666667,10026,24652
ASYNC,4,2,3935852050.3333335,10027,24660
ASYNC,4,4,1972869873.0,10029,24668
ASYNC,4,8,979451497.6666666,10033,24672
ASYNC,4,16,499348958.0,10041,24676
ASYNC,4,32,253712972.0,10057,24676
ASYNC,4,64,131022135.33333333,10089,24676
ASYNC,4,128,69610595.66666667,10473,24676
ASYNC,4,256,38706461.666666664,11241,24692
ASYNC,8,1,7590311686.666667,12778,25220
ASYNC,8,2,3800333658.6666665,12779,25228
ASYNC,8,4,1900014241.6666667,12781,25236
ASYNC,8,8,940419515.0,12785,25240
ASYNC,8,16,478739420.6666667,12793,25244
ASYNC,8,32,241465250.66666666,12809,25244
ASYNC,8,64,122701009.0,12841,25244
ASYNC,8,128,63405355.0,13481,25244
ASYNC,8,256,33752441.666666664,14761,25244
LISTENERS,1,2,890787.3333333334,9247,23091
LISTENERS,1,8,237925.0,9253,23091
LISTENERS,1,32,74513.0,9277,23151
LISTENERS,1,128,33813.0,9565,23231
LISTENERS,1,512,35746.0,10717,23623
LISTENERS,4,2,314198.3333333333,9274,23142
LISTENERS,4,8,82244.33333333333,9280,23142
LISTENERS,4,32,24057.333333333332,9304,23202
LISTENERS,4,128,9816.0,9592,23282
LISTENERS,4,512,9277.0,10744,23674
LISTENERS,8,2,211465.66666666666,9310,23202
LISTENERS,8,8,56294.0,9316,23210
LISTENERS,8,32,15635.0,9340,23270
LISTENERS,8,128,5818.0,9628,23350
LISTENERS,8,512,4862.0,10780,23742
SUBSCRIBERS,1,2,7804351.333333333,9927,23463
SUBSCRIBERS,1,8,1978179.3333333333,9933,23463
SUBSCRIBERS,1,32,514139.3333333333,9957,23523
SUBSCRIBERS,1,128,146759.0,10309,23603
SUBSCRIBERS,1,512,55104.0,11845,23995
SUBSCRIBERS,4,2,5551961.0,11994,24134
SUBSCRIBERS,4,8,1395009.0,12000,24134
SUBSCRIBERS,4,32,354583.3333333333,12024,24194
SUBSCRIBERS,4,128,92976.66666666667,12568,24274
SUBSCRIBERS,4,512,28015.0,15256,24666
SUBSCRIBERS,8,2,5449839.0,14750,24858
SUBSCRIBERS,8,8,1321766.6666666667,14756,24866
SUBSCRIBERS,8,32,332804.0,14780,24926
SUBSCRIBERS,8,128,85489.33333333333,15580,25006
SUBSCRIBERS,8,512,23905.0,19804,25398
MSG_SUBSCRIBERS,1,2,8783538.333333334,10371,25615
MSG_SUBSCRIBERS,1,8,2249592.6666666665,10377,25615
MSG_SUBSCRIBERS,1,32,610168.0,10401,25675
MSG_SUBSCRIBERS,1,128,207295.0,10753,25755
MSG_SUBSCRIBERS,1,512,143584.66666666666,12289,26147
MSG_SUBSCRIBERS,4,2,5787699.0,12318,26126
MSG_SUBSCRIBERS,4,8,1473907.0,12324,26126
MSG_SUBSCRIBERS,4,32,396127.6666666667,12348,26186
MSG_SUBSCRIBERS,4,128,126362.66666666667,12892,26266
MSG_SUBSCRIBERS,4,512,59040.666666666664,15580,26658
MSG_SUBSCRIBERS,8,2,5453999.333333333,14914,26610
MSG_SUBSCRIBERS,8,8,1356312.3333333333,14920,26650
MSG_SUBSCRIBERS,8,32,361368.3333333333,14944,26710
MSG_SUBSCRIBERS,8,128,113148.66666666667,15744,26790
MSG_SUBSCRIBERS,8,512,51218.333333333336,19968,27182
49 changes: 32 additions & 17 deletions samples/subsys/zbus/benchmark/benchmark_256KB.robot
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ Suite Teardown Terminate All Processes kill=True


*** Variables ***
${csv_file} zbus_dyn_benchmark_256kb.csv
${board} hifive1_revb
${serial_port} /dev/ttyACM0
${csv_file} zbus_dyn_benchmark_256kb.csv
${board} hifive1_revb
${serial_port} /dev/ttyACM0


*** Tasks ***
Clear Old CSV File
Empty Csv File ${csv_file}

Zbus Benchmark
FOR ${async} IN "n" "y"
FOR ${consumers} IN 1 2 4 8
FOR ${msg_size} IN 1 2 4 8 16 32 64 128 256
Benchmark Report For message_size=${msg_size} one_to=${consumers} asynchronous=${async}
FOR ${obs_type} IN 0 1 2
FOR ${consumers} IN 1 4 8
FOR ${msg_size} IN 2 8 32 128 512
Benchmark Report For
... message_size=${msg_size}
... one_to=${consumers}
... observer_type=${obs_type}
END
END
END
Expand Down Expand Up @@ -54,30 +58,41 @@ Measure Results
[Teardown] Delete All Ports

Benchmark
[Arguments] ${message_size}=256 ${one_to}=1 ${asynchronous}=n
[Arguments] ${message_size}=256 ${one_to}=1 ${observer_type}=LISTENERS
${result} Run Process
... west build -b ${board} -p always -- -DCONFIG_BM_MESSAGE_SIZE\=${message_size} -DCONFIG_BM_ONE_TO\=${one_to} -DCONFIG_BM_ASYNC\=${asynchronous}
... west build -b ${board} -p always -- -DCONFIG_BM_MESSAGE_SIZE\=${message_size} -DCONFIG_BM_ONE_TO\=${one_to} -DCONFIG_BM_${observer_type}\=y
... shell=True
Should Be Equal As Integers ${result.rc} 0
${duration} Measure Results
RETURN ${duration}

Benchmark Report For
[Arguments] ${message_size}=256 ${one_to}=1 ${asynchronous}=n
${duration} Benchmark message_size=${message_size} one_to=${one_to} asynchronous=${asynchronous}
[Arguments] ${message_size}=256 ${one_to}=1 ${observer_type}=0

${obs_type_str} Set Variable LISTENERS
IF ${observer_type} == 1
${obs_type_str} Set Variable SUBSCRIBERS
ELSE IF ${observer_type} == 2
${obs_type_str} Set Variable MSG_SUBSCRIBERS
END

${duration} Benchmark
... message_size=${message_size}
... one_to=${one_to}
... observer_type=${obs_type_str}

${ram_amount} Run Memory Report ram

${rom_amount} Run Memory Report rom
IF ${asynchronous} == "y"
${async_str} Set Variable ASYNC
ELSE
${async_str} Set Variable SYNC
END

@{results} Create List
... ${async_str}
... ${obs_type_str}
... ${one_to}
... ${message_size}
... ${duration}
... ${ram_amount}
... ${rom_amount}

Log To Console \n${results}

Append To Csv File ${csv_file} ${results}
2 changes: 2 additions & 0 deletions samples/subsys/zbus/benchmark/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
CONFIG_LOG=y
CONFIG_BOOT_BANNER=n
CONFIG_LOG_MODE_MINIMAL=y
CONFIG_ASSERT=n
CONFIG_ZBUS=y
CONFIG_ZBUS_LOG_LEVEL_INF=y
CONFIG_HEAP_MEM_POOL_SIZE=1024
30 changes: 26 additions & 4 deletions samples/subsys/zbus/benchmark/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,37 @@ tests:
type: multi_line
ordered: true
regex:
- "I: Benchmark 1 to 8: Dynamic memory, ASYNC transmission and message size 256"
- "I: Benchmark 1 to 8 using LISTENERS to transmit with message size: 256 bytes"
- "I: Bytes sent = 262144, received = 262144"
- "I: Average data rate: (\\d+).(\\d+)MB/s"
- "I: Duration: (\\d+).(\\d+)s"
- "@(.*)"
extra_configs:
- CONFIG_BM_ONE_TO=8
- CONFIG_BM_MESSAGE_SIZE=256
- CONFIG_BM_ASYNC=y
- CONFIG_BM_LISTENERS=y
- arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
- CONFIG_IDLE_STACK_SIZE=1024
integration_platforms:
- qemu_x86
sample.zbus.benchmark_async_msg_sub:
tags: zbus
min_ram: 16
filter: CONFIG_SYS_CLOCK_EXISTS and not (CONFIG_ARCH_POSIX and not CONFIG_BOARD_NATIVE_POSIX)
harness: console
harness_config:
type: multi_line
ordered: true
regex:
- "I: Benchmark 1 to 8 using MSG_SUBSCRIBERS to transmit with message size: 256 bytes"
- "I: Bytes sent = 262144, received = 262144"
- "I: Average data rate: (\\d+).(\\d+)MB/s"
- "I: Duration: (\\d+).(\\d+)s"
- "@(.*)"
extra_configs:
- CONFIG_BM_ONE_TO=8
- CONFIG_BM_MESSAGE_SIZE=256
- CONFIG_BM_MSG_SUBSCRIBERS=y
- arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
- CONFIG_IDLE_STACK_SIZE=1024
integration_platforms:
Expand All @@ -32,15 +54,15 @@ tests:
type: multi_line
ordered: true
regex:
- "I: Benchmark 1 to 8: Dynamic memory, SYNC transmission and message size 256"
- "I: Benchmark 1 to 8 using SUBSCRIBERS to transmit with message size: 256 bytes"
- "I: Bytes sent = 262144, received = 262144"
- "I: Average data rate: (\\d+).(\\d+)MB/s"
- "I: Duration: (\\d+).(\\d+)s"
- "@(.*)"
extra_configs:
- CONFIG_BM_ONE_TO=8
- CONFIG_BM_MESSAGE_SIZE=256
- CONFIG_BM_ASYNC=n
- CONFIG_BM_SUBSCRIBERS=y
- arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
- CONFIG_IDLE_STACK_SIZE=1024
integration_platforms:
Expand Down
Loading
Loading