Skip to content

Commit

Permalink
net: Adjust the thread priorities
Browse files Browse the repository at this point in the history
If networking pre-emptive thread priorities are enabled,
then use the proper macro to enable them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information
jukkar committed Nov 20, 2020
1 parent 6e54f54 commit f02fd19
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions subsys/net/ip/Kconfig.mgmt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ config NET_MGMT_EVENT_STACK_SIZE

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.
Expand Down
3 changes: 1 addition & 2 deletions subsys/net/ip/net_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ void net_mgmt_event_init(void)
k_thread_create(&mgmt_thread_data, mgmt_stack,
K_KERNEL_STACK_SIZEOF(mgmt_stack),
(k_thread_entry_t)mgmt_thread, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_NET_MGMT_EVENT_THREAD_PRIO), 0,
K_NO_WAIT);
CONFIG_NET_MGMT_EVENT_THREAD_PRIO, 0, K_NO_WAIT);
k_thread_name_set(&mgmt_thread_data, "net_mgmt");

NET_DBG("Net MGMT initialized: queue of %u entries, stack size of %u",
Expand Down
10 changes: 7 additions & 3 deletions subsys/net/l2/canbus/6locan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ static inline int canbus_init_ll_addr(struct net_if *iface)
void net_6locan_init(struct net_if *iface)
{
struct canbus_net_ctx *ctx = net_if_l2_data(iface);
uint8_t thread_priority;
int thread_priority;
int i;

NET_DBG("Init CAN net interface");
Expand All @@ -1732,11 +1732,15 @@ void net_6locan_init(struct net_if *iface)
/* This work queue should have precedence over the tx stream
* TODO thread_priority = tx_tc2thread(NET_TC_TX_COUNT -1) - 1;
*/
thread_priority = 6;
if (IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)) {
thread_priority = K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1);
} else {
thread_priority = K_PRIO_PREEMPT(6);
}

k_work_q_start(&net_canbus_workq, net_canbus_stack,
K_KERNEL_STACK_SIZEOF(net_canbus_stack),
K_PRIO_COOP(thread_priority));
thread_priority);
k_thread_name_set(&net_canbus_workq.thread, "isotp_work");
NET_DBG("Workq started. Thread ID: %p", &net_canbus_workq.thread);
}
Expand Down
8 changes: 7 additions & 1 deletion subsys/net/lib/conn_mgr/conn_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ LOG_MODULE_REGISTER(conn_mgr, CONFIG_NET_CONNECTION_MANAGER_LOG_LEVEL);

#include <conn_mgr.h>

#if IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)
#define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
#else
#define THREAD_PRIORITY K_PRIO_PREEMPT(7)
#endif

uint16_t iface_states[CONN_MGR_IFACE_MAX];

K_SEM_DEFINE(conn_mgr_lock, 1, UINT_MAX);
Expand Down Expand Up @@ -172,7 +178,7 @@ static void conn_mgr_handler(void)

K_THREAD_DEFINE(conn_mgr, CONFIG_NET_CONNECTION_MANAGER_STACK_SIZE,
(k_thread_entry_t)conn_mgr_handler, NULL, NULL, NULL,
K_PRIO_COOP(2), 0, 0);
THREAD_PRIORITY, 0, 0);

void net_conn_mgr_resend_status(void)
{
Expand Down
10 changes: 8 additions & 2 deletions subsys/net/lib/lwm2m/lwm2m_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include "lwm2m_rd_client.h"
#endif

#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

#define ENGINE_UPDATE_INTERVAL_MS 500
#define OBSERVE_COUNTER_START 0U

Expand Down Expand Up @@ -4516,8 +4523,7 @@ static int lwm2m_engine_init(const struct device *dev)
K_KERNEL_STACK_SIZEOF(engine_thread_stack),
(k_thread_entry_t) socket_receive_loop,
NULL, NULL, NULL,
/* Lowest priority cooperative thread */
K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1),
THREAD_PRIORITY,
0, K_NO_WAIT);
k_thread_name_set(&engine_thread_data, "lwm2m-sock-recv");
LOG_DBG("LWM2M engine socket receive thread started");
Expand Down
5 changes: 5 additions & 0 deletions subsys/net/lib/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
#define FRAME_TYPE_ACK 0x02

#define OT_WORKER_STACK_SIZE 512

#if IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)
#define OT_WORKER_PRIORITY K_PRIO_COOP(CONFIG_OPENTHREAD_THREAD_PRIORITY)
#else
#define OT_WORKER_PRIORITY K_PRIO_PREEMPT(CONFIG_OPENTHREAD_THREAD_PRIORITY)
#endif

enum pending_events {
PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */
Expand Down

0 comments on commit f02fd19

Please sign in to comment.