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

log: print capacity of the sidewalk workq #676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ config SIDEWALK_THREAD_STACK_SIZE
config SIDEWALK_THREAD_QUEUE_SIZE
int "Message queue size for the Sidewalk thread"
range 4 256
default 16
default 64
help
Set the message queue size for the Sidewalk thread.

Expand Down
13 changes: 13 additions & 0 deletions samples/sid_end_device/include/sidewalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ void sidewalk_event_link_switch(sidewalk_ctx_t *sid, void *ctx);
void sidewalk_event_exit(sidewalk_ctx_t *sid, void *ctx);
void sidewalk_event_reboot(sidewalk_ctx_t *sid, void *ctx);
void sidewalk_event_platform_init(sidewalk_ctx_t *sid, void *ctx);

#define EVENT_TO_NAME(event) \
event == sidewalk_event_process ? "sidewalk_event_process" : \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: use a shorter prefix e.g. sid_ev

event == sidewalk_event_autostart ? "sidewalk_event_autostart" : \
event == sidewalk_event_factory_reset ? "sidewalk_event_factory_reset" : \
event == sidewalk_event_new_status ? "sidewalk_event_new_status" : \
event == sidewalk_event_send_msg ? "sidewalk_event_send_msg" : \
event == sidewalk_event_connect ? "sidewalk_event_connect" : \
event == sidewalk_event_link_switch ? "sidewalk_event_link_switch" : \
event == sidewalk_event_exit ? "sidewalk_event_exit" : \
event == sidewalk_event_reboot ? "sidewalk_event_reboot" : \
event == sidewalk_event_platform_init ? "sidewalk_event_platform_init" : \
"use addr2line to get name of event"
#endif /* SIDEWALK_APP_H */
29 changes: 23 additions & 6 deletions samples/sid_end_device/src/sidewalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <sid_api.h>
#include <sid_error.h>
#include <sidewalk.h>

#include <zephyr/kernel.h>
Expand All @@ -17,6 +19,7 @@ K_MSGQ_DEFINE(sidewalk_thread_msgq, sizeof(sidewalk_ctx_event_t), CONFIG_SIDEWAL
4);

K_SEM_DEFINE(sid_thread_started, 0, 1);

static void sid_thread_entry(void *context, void *unused, void *unused2)
{
ARG_UNUSED(unused);
Expand All @@ -29,16 +32,29 @@ static void sid_thread_entry(void *context, void *unused, void *unused2)

while (1) {
int err = k_msgq_get(&sidewalk_thread_msgq, &event, K_FOREVER);
if (!err) {
switch (err) {
case 0: {
LOG_DBG("event received %p (%s) sidewalk workq usage (%d/%d) ( after get )",
(void *)(event.handler), EVENT_TO_NAME(event.handler),
k_msgq_num_used_get(&sidewalk_thread_msgq),
CONFIG_SIDEWALK_THREAD_QUEUE_SIZE);
if (event.handler) {
event.handler(sid, event.ctx);
}
if (event.ctx_free) {
event.ctx_free(event.ctx);
}
} else {
break;
}
case -EAGAIN:
case -ENOMSG: {
// Do nothing, timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: LOG_DBG("Sidewalk msgq timeout"); ?

break;
}
default: {
LOG_ERR("Sidewalk msgq err %d", err);
}
}
}

LOG_ERR("Sidewalk thread ends. You should never see this message.");
Expand All @@ -64,15 +80,16 @@ int sidewalk_event_send(event_handler_t event, void *ctx, ctx_free free)
k_timeout_t timeout = K_NO_WAIT;
int result = -EFAULT;

#if defined(CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE) && CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE > 0
#if defined(CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE) && \
CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE > 0
if (!k_is_in_isr()) {
timeout = K_MSEC(CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE);
}
#endif /* CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE > 0 */

result = k_msgq_put(&sidewalk_thread_msgq, (void *)&ctx_event, timeout);
LOG_DBG("sidewalk_event_send event = %p, context = %p, k_msgq_put result %d", (void *)event,
ctx, result);
LOG_DBG("sidewalk_event_send event = %p (%s), context = %p, k_msgq_put result %d sidewalk workq usage (%d/%d) (after put)",
(void *)event, EVENT_TO_NAME(event), ctx, result,
k_msgq_num_used_get(&sidewalk_thread_msgq), CONFIG_SIDEWALK_THREAD_QUEUE_SIZE);

return result;
}