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

net: mgmt: Use proper coop thread priority value #32384

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
8 changes: 0 additions & 8 deletions subsys/net/ip/Kconfig.mgmt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ config NET_MGMT_EVENT_STACK_SIZE
Set the internal stack size for NM to run registered callbacks
on events.

config NET_MGMT_EVENT_THREAD_PRIO
int "Inner thread priority (use with care)"
default -1 if NET_TC_THREAD_COOPERATIVE
default 7
help
Set the network management event core's inner thread priority.
Do not change this unless you know what you are doing.

config NET_MGMT_EVENT_QUEUE_SIZE
int "Size of event queue"
default 16 if NET_MGMT_EVENT_MONITOR
Expand Down
9 changes: 8 additions & 1 deletion subsys/net/ip/net_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,17 @@ void net_mgmt_event_init(void)
(void)memset(events, 0, CONFIG_NET_MGMT_EVENT_QUEUE_SIZE *
sizeof(struct mgmt_event_entry));

#if IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)
/* Lowest priority cooperative thread */
#define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
#else
#define THREAD_PRIORITY K_PRIO_PREEMPT(CONFIG_NUM_PREEMPT_PRIORITIES - 1)
#endif

k_thread_create(&mgmt_thread_data, mgmt_stack,
K_KERNEL_STACK_SIZEOF(mgmt_stack),
(k_thread_entry_t)mgmt_thread, NULL, NULL, NULL,
CONFIG_NET_MGMT_EVENT_THREAD_PRIO, 0, K_NO_WAIT);
THREAD_PRIORITY, 0, K_NO_WAIT);
Copy link
Member

@mnkp mnkp Feb 17, 2021

Choose a reason for hiding this comment

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

There is a predefined K_LOWEST_APPLICATION_THREAD_PRIO in include/kernel.h which could be used here. The define is used by e.g. logger subsystem.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this change same way as the other networking threads are done so not using this define. The name of the define talks about application and we have no applications here but a thread which is part of a subsystem. But it is certainly possible to use that define if needed, but I would do that change in a separate PR if we really want to do it.

Copy link
Member

Choose a reason for hiding this comment

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

From the kernel perspective subsystem is an application. There is no thread priority range that is reserved for subsystems. So the name K_LOWEST_APPLICATION_THREAD_PRIO carries in fact the right meaning. Though I agree that seeing such a define in a networking stack might be confusing. From the user perspective subsystem is certainly not an application. Using the define was just a suggestion.

k_thread_name_set(&mgmt_thread_data, "net_mgmt");

NET_DBG("Net MGMT initialized: queue of %u entries, stack size of %u",
Expand Down
1 change: 0 additions & 1 deletion tests/net/all/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ CONFIG_NET_CONFIG_NEED_IPV6=y
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_STACK_SIZE=800
CONFIG_NET_MGMT_EVENT_THREAD_PRIO=66
CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=2
CONFIG_NET_MGMT_EVENT_LOG_LEVEL_DBG=y
CONFIG_NET_DEBUG_MGMT_EVENT_STACK=y
Expand Down
1 change: 0 additions & 1 deletion tests/net/lib/dns_addremove/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ CONFIG_DNS_NUM_CONCUR_QUERIES=1
CONFIG_NET_LOG=y
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_THREAD_PRIO=7
CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=2
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
Expand Down