Skip to content

Commit

Permalink
samples: zbus: benchmark: add msg subscriber to benchmark
Browse files Browse the repository at this point in the history
The benchmark sample did not contemplate message subscribers. It adds
the msg subscribers and improves the organization of the project.

Signed-off-by: Rodrigo Peixoto <[email protected]>
  • Loading branch information
rodrigopex committed Oct 28, 2023
1 parent 51fee43 commit f0f482e
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 191 deletions.
16 changes: 15 additions & 1 deletion samples/subsys/zbus/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@ 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()

message(" > Benchmark files: ${app_sources}")

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 "Consuming mode async"

config BM_SUBSCRIBERS
bool "Consuming in asynchronous mode with message subscribers"

config BM_MSG_SUBSCRIBERS
bool "Consuming in asynchronous mode with 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"
27 changes: 15 additions & 12 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 LISTENER(S) 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 Down
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

0 comments on commit f0f482e

Please sign in to comment.