Skip to content

Commit 411f1b8

Browse files
zyczanangl
authored andcommitted
samples: ipc: rework ipc sample
Change in ipc sample which expands throughput mesurment and fixes bug with one way sending. Jira: NCSDK-14841 Signed-off-by: Jan Zyczkowski <[email protected]>
1 parent 95be516 commit 411f1b8

File tree

8 files changed

+97
-61
lines changed

8 files changed

+97
-61
lines changed

samples/ipc/ipc_service/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ if (CONF_FILE)
1515
set(remote_CONF_FILE ${CONF_FILE})
1616
set(DTC_OVERLAY_FILE "${CONF_FILE_BUILD_TYPE}.overlay")
1717
set(remote_DTC_OVERLAY_FILE "${CONF_FILE_BUILD_TYPE}.overlay")
18+
endif()
1819

19-
# Use config overlay with the same name in remote.
20-
if(OVERLAY_CONFIG)
21-
set(remote_OVERLAY_CONFIG ${OVERLAY_CONFIG})
22-
endif()
20+
# Use config overlay with the same name in remote.
21+
if(OVERLAY_CONFIG)
22+
set(remote_OVERLAY_CONFIG ${OVERLAY_CONFIG})
2323
endif()
2424

2525
set(ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_LIST_DIR})

samples/ipc/ipc_service/Kconfig.app

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ config APP_IPC_SERVICE_SEND_INTERVAL
1313
IPC service. Since kernel timeout has 1 ms resolution, the value is
1414
rounded down. If value of this option is lower than 1000 us, busy
1515
wait is used instead of sleep.
16+
17+
config APP_IPC_SERVICE_MESSAGE_LEN
18+
int "Length of single IPC message in bytes"
19+
default 100

samples/ipc/ipc_service/README.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,25 @@ After programming the sample to your development kit, test it by performing the
104104

105105
.. code-block:: console
106106
107-
*** Booting Zephyr OS build v2.7.99-ncs1-2188-g1cd6e614e35d ***
108-
650794
109-
649064
110-
648818
111-
647836
112-
647445
107+
*** Booting Zephyr OS build v3.0.99-ncs1 ***
108+
IPC-service nrf5340dk_nrf5340_cpuapp demo started
109+
Δpkt: 9391 (100 B/pkt) | throughput: 7512800 bit/s
110+
Δpkt: 9389 (100 B/pkt) | throughput: 7511200 bit/s
111+
Δpkt: 9388 (100 B/pkt) | throughput: 7510400 bit/s
112+
Δpkt: 9390 (100 B/pkt) | throughput: 7512000 bit/s
113+
Δpkt: 9396 (100 B/pkt) | throughput: 7516800 bit/s
113114
114115
* For the network core, the output is similar to the following one:
115116

116117
.. code-block:: console
117118
118-
*** Booting Zephyr OS build v2.7.99-ncs1-2188-g1cd6e614e35d ***
119-
519213
120-
522461
121-
522857
122-
523972
123-
523648
119+
*** Booting Zephyr OS build v3.0.99-ncs1 ***
120+
IPC-service nrf5340dk_nrf5340_cpunet demo started
121+
Δpkt: 6665 (100 B/pkt) | throughput: 5332000 bit/s
122+
Δpkt: 6664 (100 B/pkt) | throughput: 5331200 bit/s
123+
Δpkt: 6658 (100 B/pkt) | throughput: 5326400 bit/s
124+
Δpkt: 6665 (100 B/pkt) | throughput: 5332000 bit/s
125+
Δpkt: 6671 (100 B/pkt) | throughput: 5336800 bit/s
124126
125127
Dependencies
126128
************

samples/ipc/ipc_service/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ CONFIG_IPC_SERVICE=y
22

33
CONFIG_PRINTK=y
44
CONFIG_LOG=y
5+
CONFIG_IPC_SERVICE_LOG_LEVEL_INF=y
6+
CONFIG_IPC_SERVICE_BACKEND_RPMSG=y
7+
CONFIG_MBOX=y
58

69
# required to allocate virtqueues
710
CONFIG_HEAP_MEM_POOL_SIZE=4096

samples/ipc/ipc_service/prj_icmsg.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ CONFIG_PRINTK=y
44
CONFIG_LOG=y
55

66
CONFIG_APP_IPC_SERVICE_SEND_INTERVAL=60
7+
8+
CONFIG_HEAP_MEM_POOL_SIZE=4096
9+
10+
CONFIG_IPC_SERVICE_LOG_LEVEL_INF=y
11+
CONFIG_IPC_SERVICE_BACKEND_ICMSG=y
12+
CONFIG_MBOX=y

samples/ipc/ipc_service/remote/prj.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ CONFIG_PRINTK=y
44
CONFIG_LOG=y
55

66
# required to allocate virtqueues
7-
CONFIG_HEAP_MEM_POOL_SIZE=4096
7+
CONFIG_HEAP_MEM_POOL_SIZE=2048
88

99
CONFIG_OPENAMP=y
1010
CONFIG_OPENAMP_MASTER=n
11+
12+
CONFIG_IPC_SERVICE_LOG_LEVEL_INF=y
13+
CONFIG_IPC_SERVICE_BACKEND_RPMSG=y
14+
CONFIG_MBOX=y

samples/ipc/ipc_service/remote/prj_icmsg.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ CONFIG_PRINTK=y
44
CONFIG_LOG=y
55

66
CONFIG_APP_IPC_SERVICE_SEND_INTERVAL=25
7+
8+
CONFIG_HEAP_MEM_POOL_SIZE=2048
9+
10+
CONFIG_IPC_SERVICE_LOG_LEVEL_INF=y
11+
CONFIG_IPC_SERVICE_BACKEND_ICMSG=y
12+
CONFIG_MBOX=y

samples/ipc/ipc_service/src/main.c

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@
66

77
#include <zephyr/kernel.h>
88
#include <zephyr/device.h>
9+
#include <string.h>
10+
11+
#include <zephyr/logging/log.h>
912

1013
#include <zephyr/ipc/ipc_service.h>
1114

12-
#include <zephyr/logging/log.h>
13-
LOG_MODULE_REGISTER(host, LOG_LEVEL_INF);
15+
#define STACKSIZE (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)
1416

15-
#define BASE_MESSAGE_LEN 40
16-
#define MESSAGE_LEN 100
17+
K_THREAD_STACK_DEFINE(ipc0_stack, STACKSIZE);
1718

18-
struct data_packet {
19-
uint8_t message;
20-
uint8_t data[MESSAGE_LEN];
19+
LOG_MODULE_REGISTER(host, LOG_LEVEL_INF);
20+
21+
struct payload {
22+
unsigned long cnt;
23+
unsigned long size;
24+
uint8_t data[];
2125
};
2226

27+
struct payload *p_payload;
2328

2429
static K_SEM_DEFINE(bound_sem, 0, 1);
2530

@@ -32,38 +37,15 @@ static void ep_recv(const void *data, size_t len, void *priv)
3237
{
3338
uint8_t received_val = *((uint8_t *)data);
3439
static uint8_t expected_val;
35-
static uint16_t expected_len = BASE_MESSAGE_LEN;
3640

37-
static unsigned long long cnt;
38-
static unsigned int stats_every;
39-
static uint32_t start;
40-
41-
if (start == 0) {
42-
start = k_uptime_get_32();
43-
}
4441

45-
if ((received_val != expected_val) || (len != expected_len)) {
46-
printk("Unexpected message\n");
42+
if ((received_val != expected_val) || (len != CONFIG_APP_IPC_SERVICE_MESSAGE_LEN)) {
43+
printk("Unexpected message received_val: %d , expected_val: %d\n",
44+
received_val,
45+
expected_val);
4746
}
4847

4948
expected_val++;
50-
expected_len++;
51-
52-
cnt += len;
53-
54-
if (stats_every++ > 5000) {
55-
/* Print throuhput [Bytes/s]. Use printk not to overload CPU with logger.
56-
* Sample never reaches lower priority thread because of high throughput
57-
* (100% cpu load) so logging would not be able to handle messages in
58-
* deferred mode (immediate mode would be heavier than printk).
59-
*/
60-
printk("%llu\n", (1000*cnt)/(k_uptime_get_32() - start));
61-
stats_every = 0;
62-
}
63-
64-
if (expected_len > sizeof(struct data_packet)) {
65-
expected_len = BASE_MESSAGE_LEN;
66-
}
6749
}
6850

6951
static struct ipc_ept_cfg ep_cfg = {
@@ -77,10 +59,22 @@ static struct ipc_ept_cfg ep_cfg = {
7759
int main(void)
7860
{
7961
const struct device *ipc0_instance;
80-
struct data_packet msg = {.message = 0};
8162
struct ipc_ept ep;
8263
int ret;
8364

65+
p_payload = (struct payload *) k_malloc(CONFIG_APP_IPC_SERVICE_MESSAGE_LEN);
66+
if (!p_payload) {
67+
printk("k_malloc() failure\n");
68+
return -ENOMEM;
69+
}
70+
71+
memset(p_payload->data, 0xA5, CONFIG_APP_IPC_SERVICE_MESSAGE_LEN - sizeof(struct payload));
72+
73+
p_payload->size = CONFIG_APP_IPC_SERVICE_MESSAGE_LEN;
74+
p_payload->cnt = 0;
75+
76+
printk("IPC-service %s demo started\n", CONFIG_BOARD);
77+
8478
ipc0_instance = DEVICE_DT_GET(DT_NODELABEL(ipc0));
8579

8680
ret = ipc_service_open_instance(ipc0_instance);
@@ -97,24 +91,18 @@ int main(void)
9791

9892
k_sem_take(&bound_sem, K_FOREVER);
9993

100-
uint16_t mlen = BASE_MESSAGE_LEN;
101-
10294
while (true) {
103-
ret = ipc_service_send(&ep, &msg, mlen);
95+
ret = ipc_service_send(&ep, p_payload, CONFIG_APP_IPC_SERVICE_MESSAGE_LEN);
10496
if (ret == -ENOMEM) {
10597
/* No space in the buffer. Retry. */
10698
continue;
10799
} else if (ret < 0) {
108-
LOG_ERR("send_message(%d) failed with ret %d", msg.message, ret);
100+
printk("send_message(%ld) failed with ret %d\n", p_payload->cnt, ret);
109101
break;
110102
}
111103

112-
msg.message++;
104+
p_payload->cnt++;
113105

114-
mlen++;
115-
if (mlen > sizeof(struct data_packet)) {
116-
mlen = BASE_MESSAGE_LEN;
117-
}
118106

119107
/* Quasi minimal busy wait time which allows to continuosly send
120108
* data without -ENOMEM error code. The purpose is to test max
@@ -129,3 +117,26 @@ int main(void)
129117

130118
return 0;
131119
}
120+
121+
static void check_task(void *arg1, void *arg2, void *arg3)
122+
{
123+
ARG_UNUSED(arg1);
124+
ARG_UNUSED(arg2);
125+
ARG_UNUSED(arg3);
126+
127+
unsigned long last_cnt = p_payload->cnt;
128+
unsigned long delta;
129+
130+
while (1) {
131+
k_sleep(K_MSEC(1000));
132+
133+
delta = p_payload->cnt - last_cnt;
134+
135+
printk("Δpkt: %ld (%ld B/pkt) | throughput: %ld bit/s\n",
136+
delta, p_payload->size, delta * CONFIG_APP_IPC_SERVICE_MESSAGE_LEN * 8);
137+
138+
last_cnt = p_payload->cnt;
139+
}
140+
}
141+
K_THREAD_DEFINE(thread_check_id, STACKSIZE, check_task, NULL, NULL, NULL,
142+
K_PRIO_COOP(1), 0, 100);

0 commit comments

Comments
 (0)