Skip to content

samples: net: sockets: http_server: Dont block system workq #93537

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

Merged
Merged
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: 12 additions & 2 deletions samples/net/sockets/http_server/src/ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ static int netstats_collect(char *buf, size_t maxlen)
return ret;
}

#define WS_NETSTATS_STACK_SIZE 2048
K_THREAD_STACK_DEFINE(ws_netstats_stack, WS_NETSTATS_STACK_SIZE);
struct k_work_q ws_netstats_queue;

static void netstats_handler(struct k_work *work)
{
int ret;
Expand All @@ -271,7 +275,8 @@ static void netstats_handler(struct k_work *work)
goto unregister;
}

ret = k_work_reschedule(&ctx->work, K_MSEC(CONFIG_NET_SAMPLE_WEBSOCKET_STATS_INTERVAL));
ret = k_work_reschedule_for_queue(&ws_netstats_queue, &ctx->work,
K_MSEC(CONFIG_NET_SAMPLE_WEBSOCKET_STATS_INTERVAL));
if (ret < 0) {
LOG_ERR("Failed to schedule netstats work, err %d", ret);
goto unregister;
Expand All @@ -286,6 +291,11 @@ static void netstats_handler(struct k_work *work)

int ws_netstats_init(void)
{
struct k_work_queue_config cfg = {.name = "ws_netstats_q"};

k_work_queue_init(&ws_netstats_queue);
k_work_queue_start(&ws_netstats_queue, ws_netstats_stack, WS_NETSTATS_STACK_SIZE, 0, &cfg);

for (int i = 0; i < CONFIG_NET_SAMPLE_NUM_WEBSOCKET_HANDLERS; i++) {
netstats_ctx[i].sock = -1;
k_work_init_delayable(&netstats_ctx[i].work, netstats_handler);
Expand Down Expand Up @@ -344,7 +354,7 @@ int ws_netstats_setup(int ws_socket, struct http_request_ctx *request_ctx, void

netstats_ctx[slot].sock = ws_socket;

ret = k_work_reschedule(&netstats_ctx[slot].work, K_NO_WAIT);
ret = k_work_reschedule_for_queue(&ws_netstats_queue, &netstats_ctx[slot].work, K_NO_WAIT);
if (ret < 0) {
LOG_ERR("Failed to schedule netstats work, err %d", ret);
return ret;
Expand Down