Skip to content
Closed
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
1 change: 1 addition & 0 deletions kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ config MAIN_THREAD_PRIORITY
int
prompt "Priority of initialization/main thread"
default 0
default -1 if COOP_ENABLED
default -2 if !PREEMPT_ENABLED
help
Priority at which the initialization thread runs, including the start
Expand Down
6 changes: 6 additions & 0 deletions subsys/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ config NETWORKING
select NET_BUF
select POLL
select ENTROPY_GENERATOR
select COOP_ENABLED
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this actually does anything useful.

You can test this by trying to come up with a situation where this select prevents an invalid configuration from occuring.

default n
help
This option enabled generic link layer and IP networking support.

if NETWORKING

# The networking subsystem requires the system workqueue to execute at
# a cooperative priority.
config SYSTEM_WORKQUEUE_PRIORITY
range -256 -1

source "subsys/net/Kconfig.hostname"

source "subsys/net/ip/Kconfig"
Expand Down
7 changes: 7 additions & 0 deletions subsys/net/ip/net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,11 @@ static int net_init(struct device *unused)
return status;
}

/* The networking subsystem requires the main thread to execute at a
* cooperative priority to function correctly. If this build assert triggers
* verify your configuration to ensure that cooperative threads are enabled
* and that the main thread priority is negative (cooperative).
*/
BUILD_ASSERT(CONFIG_MAIN_THREAD_PRIORITY < 0);

Copy link
Contributor

Choose a reason for hiding this comment

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

Invalid configurations should be detected during configuration instead
of during compilation whenever possible.

I believe that adding the below at an appropriate net Kconfig location would achieve this.

# The networking subsystem requires the main thread to execute at
# a cooperative priority.
config MAIN_THREAD_PRIORITY
	range -256 -1

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see that this is going to do much anyway. The fact that the main thread is or is not preemptible says nothing about users of the network APIs which may or may not be running in the main thread. Not, for example, that ztest always spawns a new thread for every test, so none of the existing tests would be caught by this check if they happened to be hitting the network out of a preemptible thread.

I'd suggest a runtime __ASSERT(k_thread_prioroity_get(k_current_get() < 0) at the relevant API entry points.

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 believe that adding the below at an appropriate net Kconfig location would achieve this.
config MAIN_THREAD_PRIORITY
range -256 -1

This will give error if the default MAIN_THREAD_PRIORITY is 0. In which case user needs to add the proper value into prj.conf file. This PR tries to avoid this.

SYS_INIT(net_init, POST_KERNEL, CONFIG_NET_INIT_PRIO);