diff --git a/drivers/ethernet/eth_native_posix.c b/drivers/ethernet/eth_native_posix.c index 86678998a96..b5f3f9a8b2b 100644 --- a/drivers/ethernet/eth_native_posix.c +++ b/drivers/ethernet/eth_native_posix.c @@ -64,9 +64,7 @@ struct eth_context { #endif }; -NET_STACK_DEFINE(RX_ZETH, eth_rx_stack, - CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE, - CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE); +K_THREAD_STACK_DEFINE(eth_rx_stack, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE); static struct k_thread rx_thread_data; /* TODO: support multiple interfaces */ @@ -390,6 +388,7 @@ static void create_rx_handler(struct eth_context *ctx) (k_thread_entry_t)eth_rx, ctx, NULL, NULL, K_PRIO_COOP(14), 0, K_NO_WAIT); + k_thread_name_set(&rx_thread_data, "eth_native_posix_rx"); } static void eth_iface_init(struct net_if *iface) diff --git a/drivers/ieee802154/ieee802154_cc2520.c b/drivers/ieee802154/ieee802154_cc2520.c index ceea873f2b0..2a0bbf142c7 100644 --- a/drivers/ieee802154/ieee802154_cc2520.c +++ b/drivers/ieee802154/ieee802154_cc2520.c @@ -1149,12 +1149,6 @@ NET_DEVICE_INIT(cc2520, CONFIG_IEEE802154_CC2520_DRV_NAME, CONFIG_IEEE802154_CC2520_INIT_PRIO, &cc2520_radio_api, IEEE802154_L2, NET_L2_GET_CTX_TYPE(IEEE802154_L2), 125); - -NET_STACK_INFO_ADDR(RX, cc2520, - CONFIG_IEEE802154_CC2520_RX_STACK_SIZE, - CONFIG_IEEE802154_CC2520_RX_STACK_SIZE, - cc2520_context_data.cc2520_rx_stack, - 0); #endif diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index f719e394383..b1444df8988 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -622,11 +622,6 @@ NET_DEVICE_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME, CONFIG_IEEE802154_NRF5_INIT_PRIO, &nrf5_radio_api, L2, L2_CTX_TYPE, MTU); - -NET_STACK_INFO_ADDR(RX, nrf5_154_radio, - CONFIG_IEEE802154_NRF5_RX_STACK_SIZE, - CONFIG_IEEE802154_NRF5_RX_STACK_SIZE, - nrf5_data.rx_stack, 0); #else DEVICE_AND_API_INIT(nrf5_154_radio, CONFIG_IEEE802154_NRF5_DRV_NAME, nrf5_init, &nrf5_data, &nrf5_radio_cfg, diff --git a/include/net/net_core.h b/include/net/net_core.h index dcc595da861..782499136a0 100644 --- a/include/net/net_core.h +++ b/include/net/net_core.h @@ -97,112 +97,6 @@ int net_recv_data(struct net_if *iface, struct net_pkt *pkt); int net_send_data(struct net_pkt *pkt); /** @cond INTERNAL_HIDDEN */ -/* - * The net_stack_info struct needs to be aligned to 32 byte boundary, - * otherwise the __net_stack_end will point to wrong location and looping - * through net_stack section will go wrong. - * So this alignment is a workaround and should eventually be removed. - */ -struct net_stack_info { - k_thread_stack_t *stack; - const char *pretty_name; - const char *name; - size_t orig_size; - size_t size; - int prio; - int idx; -} __aligned(32); - -#if defined(CONFIG_NET_SHELL) -#define NET_STACK_GET_NAME(pretty, name, sfx) \ - (__net_stack_##pretty##_##name##_##sfx) - -#define NET_STACK_INFO_ADDR(_pretty, _name, _orig, _size, _addr, sfx) \ - static struct net_stack_info \ - (NET_STACK_GET_NAME(_pretty, _name, sfx)) __used \ - __attribute__((__section__(".net_stack.data"))) = { \ - .stack = _addr, \ - .size = _size, \ - .orig_size = _orig, \ - .name = #_name, \ - .pretty_name = #_pretty, \ - .prio = -1, \ - .idx = -1, \ - } - -/* Note that the stack address needs to be fixed at runtime because - * we cannot do it during static initialization. For name we allocate - * some space so that the stack index can be printed too. - */ -#define NET_STACK_INFO_ADDR_ARRAY(_pretty, _name, _orig, _size, _addr, \ - sfx, _nmemb) \ - static struct net_stack_info \ - (NET_STACK_GET_NAME(_pretty, _name, sfx))[_nmemb] __used \ - __attribute__((__section__(".net_stack.data"))) = { \ - [0 ... (_nmemb - 1)] = { \ - .stack = _addr[0], \ - .size = _size, \ - .orig_size = _orig, \ - .name = #_name, \ - .pretty_name = #_pretty, \ - .prio = -1, \ - .idx = -1, \ - } \ - } - -#define NET_STACK_INFO(_pretty_name, _name, _orig, _size) \ - NET_STACK_INFO_ADDR(_pretty_name, _name, _orig, _size, _name, 0) - -#define NET_STACK_INFO_ARRAY(_pretty_name, _name, _orig, _size, _nmemb) \ - NET_STACK_INFO_ADDR_ARRAY(_pretty_name, _name, _orig, _size, _name, \ - 0, _nmemb) - -#define NET_STACK_DEFINE(pretty_name, name, orig, size) \ - K_THREAD_STACK_DEFINE(name, size); \ - NET_STACK_INFO(pretty_name, name, orig, size) - -#define NET_STACK_ARRAY_DEFINE(pretty_name, name, orig, size, nmemb) \ - K_THREAD_STACK_ARRAY_DEFINE(name, nmemb, size); \ - NET_STACK_INFO_ARRAY(pretty_name, name, orig, size, nmemb) - -#else /* CONFIG_NET_SHELL */ - -#define NET_STACK_GET_NAME(pretty, name, sfx) (name) - -#define NET_STACK_INFO(...) -#define NET_STACK_INFO_ADDR(...) - -#define NET_STACK_DEFINE(pretty_name, name, orig, size) \ - K_THREAD_STACK_DEFINE(name, size) - -#define NET_STACK_ARRAY_DEFINE(pretty_name, name, orig, size, nmemb) \ - K_THREAD_STACK_ARRAY_DEFINE(name, nmemb, size) - -#endif /* CONFIG_NET_SHELL */ - -#define NET_STACK_DEFINE_EMBEDDED(name, size) char name[size] - -#if defined(CONFIG_INIT_STACKS) -/* Legacy case: retain containing extern "C" with C++ */ -#include - -static inline void net_analyze_stack_get_values(const char *stack, - size_t size, - unsigned *pcnt, - unsigned *unused) -{ - *unused = stack_unused_space_get(stack, size); - - /* Calculate the real size reserved for the stack */ - *pcnt = ((size - *unused) * 100) / size; -} - -void net_analyze_stack(const char *name, const char *stack, size_t size); - -#else -#define net_analyze_stack(...) -#define net_analyze_stack_get_values(...) -#endif /* Some helper defines for traffic class support */ #if defined(CONFIG_NET_TC_TX_COUNT) && defined(CONFIG_NET_TC_RX_COUNT) diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 6997712da52..bb50b254f75 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -55,20 +55,6 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL); #include "net_stats.h" -#if defined(CONFIG_INIT_STACKS) -void net_analyze_stack(const char *name, const char *stack, size_t size) -{ - unsigned int pcnt, unused; - - net_analyze_stack_get_values(stack, size, &pcnt, &unused); - - NET_INFO("net (%p): %s stack real size %zu " - "unused %u usage %zu/%zu (%u %%)", - k_current_get(), name, - size, unused, size - unused, size, pcnt); -} -#endif /* CONFIG_INIT_STACKS */ - static inline enum net_verdict process_data(struct net_pkt *pkt, bool is_loopback) { diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 7bf62c38716..f4762591463 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -100,9 +100,7 @@ static sys_slist_t mcast_monitor_callbacks; #define CONFIG_NET_PKT_TIMESTAMP_STACK_SIZE 1024 #endif -NET_STACK_DEFINE(TIMESTAMP, tx_ts_stack, - CONFIG_NET_PKT_TIMESTAMP_STACK_SIZE, - CONFIG_NET_PKT_TIMESTAMP_STACK_SIZE); +K_THREAD_STACK_DEFINE(tx_ts_stack, CONFIG_NET_PKT_TIMESTAMP_STACK_SIZE); K_FIFO_DEFINE(tx_ts_queue); static struct k_thread tx_thread_ts; diff --git a/subsys/net/ip/net_mgmt.c b/subsys/net/ip/net_mgmt.c index d2b09188bab..e368f69ee87 100644 --- a/subsys/net/ip/net_mgmt.c +++ b/subsys/net/ip/net_mgmt.c @@ -14,6 +14,7 @@ LOG_MODULE_REGISTER(net_mgmt, CONFIG_NET_MGMT_EVENT_LOG_LEVEL); #include #include #include +#include #include "net_private.h" @@ -35,8 +36,7 @@ struct mgmt_event_wait { static K_SEM_DEFINE(network_event, 0, UINT_MAX); static K_SEM_DEFINE(net_mgmt_lock, 1, 1); -NET_STACK_DEFINE(MGMT, mgmt_stack, CONFIG_NET_MGMT_EVENT_STACK_SIZE, - CONFIG_NET_MGMT_EVENT_STACK_SIZE); +K_THREAD_STACK_DEFINE(mgmt_stack, CONFIG_NET_MGMT_EVENT_STACK_SIZE); static struct k_thread mgmt_thread_data; static struct mgmt_event_entry events[CONFIG_NET_MGMT_EVENT_QUEUE_SIZE]; static u32_t global_event_mask; @@ -216,9 +216,7 @@ static inline void mgmt_run_callbacks(struct mgmt_event_entry *mgmt_event) } #ifdef CONFIG_NET_DEBUG_MGMT_EVENT_STACK - net_analyze_stack("Net MGMT event stack", - Z_THREAD_STACK_BUFFER(mgmt_stack), - K_THREAD_STACK_SIZEOF(mgmt_stack)); + log_stack_usage(&mgmt_thread_data); #endif } diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 762c1bfdb6d..7261e635792 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -91,10 +91,6 @@ struct net_shell_user_data { void *user_data; }; -/* net_stack dedicated section limiters */ -extern struct net_stack_info __net_stack_start[]; -extern struct net_stack_info __net_stack_end[]; - static inline const char *addrtype2str(enum net_addr_type addr_type) { switch (addr_type) { @@ -3307,82 +3303,14 @@ static int cmd_net_route(const struct shell *shell, size_t argc, char *argv[]) return 0; } -#if defined(CONFIG_INIT_STACKS) -extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE); -extern K_THREAD_STACK_DEFINE(sys_work_q_stack, - CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE); -#endif - static int cmd_net_stacks(const struct shell *shell, size_t argc, char *argv[]) { -#if defined(CONFIG_INIT_STACKS) - unsigned int pcnt, unused; -#endif - struct net_stack_info *info; - - ARG_UNUSED(argc); - ARG_UNUSED(argv); - - for (info = __net_stack_start; info != __net_stack_end; info++) { - net_analyze_stack_get_values(Z_THREAD_STACK_BUFFER(info->stack), - info->size, &pcnt, &unused); - -#if defined(CONFIG_INIT_STACKS) - /* If the index is <0, then this stack is not part of stack - * array so do not print the index value in this case. - */ - if (info->idx >= 0) { - PR("%s-%d [%s-%d] stack size %zu/%zu bytes " - "unused %u usage %zu/%zu (%u %%)\n", - info->pretty_name, info->prio, info->name, - info->idx, info->orig_size, - info->size, unused, - info->size - unused, info->size, pcnt); - } else { - PR("%s [%s] stack size %zu/%zu bytes unused %u " - "usage %zu/%zu (%u %%)\n", - info->pretty_name, info->name, info->orig_size, - info->size, unused, - info->size - unused, info->size, pcnt); - } +#if !defined(CONFIG_KERNEL_SHELL) + PR("Enable CONFIG_KERNEL_SHELL and type \"kernel stacks\" to see stack information.\n"); #else - PR("%s [%s] stack size %zu usage not available\n", - info->pretty_name, info->name, info->orig_size); + PR("Type \"kernel stacks\" to see stack information.\n"); #endif - } - -#if defined(CONFIG_INIT_STACKS) - net_analyze_stack_get_values(Z_THREAD_STACK_BUFFER(z_main_stack), - K_THREAD_STACK_SIZEOF(z_main_stack), - &pcnt, &unused); - PR("%s [%s] stack size %d/%d bytes unused %u usage %d/%d (%u %%)\n", - "main", "z_main_stack", CONFIG_MAIN_STACK_SIZE, - CONFIG_MAIN_STACK_SIZE, unused, - CONFIG_MAIN_STACK_SIZE - unused, CONFIG_MAIN_STACK_SIZE, pcnt); - - net_analyze_stack_get_values(Z_THREAD_STACK_BUFFER(_interrupt_stack), - K_THREAD_STACK_SIZEOF(_interrupt_stack), - &pcnt, &unused); - PR("%s [%s] stack size %d/%d bytes unused %u usage %d/%d (%u %%)\n", - "ISR", "_interrupt_stack", CONFIG_ISR_STACK_SIZE, - CONFIG_ISR_STACK_SIZE, unused, - CONFIG_ISR_STACK_SIZE - unused, CONFIG_ISR_STACK_SIZE, pcnt); - - net_analyze_stack_get_values(Z_THREAD_STACK_BUFFER(sys_work_q_stack), - K_THREAD_STACK_SIZEOF(sys_work_q_stack), - &pcnt, &unused); - PR("%s [%s] stack size %d/%d bytes unused %u usage %d/%d (%u %%)\n", - "WORKQ", "system workqueue", - CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE, - CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE, unused, - CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE - unused, - CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE, pcnt); -#else - PR_INFO("Set %s to enable %s support.\n", "CONFIG_INIT_STACKS", - "stack information"); -#endif - return 0; } diff --git a/subsys/net/ip/net_tc.c b/subsys/net/ip/net_tc.c index b136f53ec6b..b661dd83222 100644 --- a/subsys/net/ip/net_tc.c +++ b/subsys/net/ip/net_tc.c @@ -19,16 +19,12 @@ LOG_MODULE_REGISTER(net_tc, CONFIG_NET_TC_LOG_LEVEL); #include "net_tc_mapping.h" /* Stacks for TX work queue */ -NET_STACK_ARRAY_DEFINE(TX, tx_stack, - CONFIG_NET_TX_STACK_SIZE, - CONFIG_NET_TX_STACK_SIZE, - NET_TC_TX_COUNT); +K_THREAD_STACK_ARRAY_DEFINE(tx_stack, NET_TC_TX_COUNT, + CONFIG_NET_TX_STACK_SIZE); /* Stacks for RX work queue */ -NET_STACK_ARRAY_DEFINE(RX, rx_stack, - CONFIG_NET_RX_STACK_SIZE, - CONFIG_NET_RX_STACK_SIZE, - NET_TC_RX_COUNT); +K_THREAD_STACK_ARRAY_DEFINE(rx_stack, NET_TC_RX_COUNT, + CONFIG_NET_RX_STACK_SIZE); static struct net_traffic_class tx_classes[NET_TC_TX_COUNT]; static struct net_traffic_class rx_classes[NET_TC_RX_COUNT]; @@ -169,14 +165,6 @@ static u8_t rx_tc2thread(u8_t tc) return thread_priorities[tc]; } -#if defined(CONFIG_NET_SHELL) -#define TX_STACK(idx) NET_STACK_GET_NAME(TX, tx_stack, 0)[idx].stack -#define RX_STACK(idx) NET_STACK_GET_NAME(RX, rx_stack, 0)[idx].stack -#else -#define TX_STACK(idx) NET_STACK_GET_NAME(TX, tx_stack, 0)[idx] -#define RX_STACK(idx) NET_STACK_GET_NAME(RX, rx_stack, 0)[idx] -#endif - #if defined(CONFIG_NET_STATISTICS) /* Fixup the traffic class statistics so that "net stats" shell command will * print output correctly. @@ -238,18 +226,9 @@ void net_tc_tx_init(void) thread_priority = tx_tc2thread(i); tx_classes[i].tc = thread_priority; -#if defined(CONFIG_NET_SHELL) - /* Fix the thread start address so that "net stacks" - * command will print correct stack information. - */ - NET_STACK_GET_NAME(TX, tx_stack, 0)[i].stack = tx_stack[i]; - NET_STACK_GET_NAME(TX, tx_stack, 0)[i].prio = thread_priority; - NET_STACK_GET_NAME(TX, tx_stack, 0)[i].idx = i; -#endif - - NET_DBG("[%d] Starting TX queue %p stack %p size %zd " + NET_DBG("[%d] Starting TX queue %p stack size %zd " "prio %d (%d)", i, - &tx_classes[i].work_q.queue, TX_STACK(i), + &tx_classes[i].work_q.queue, K_THREAD_STACK_SIZEOF(tx_stack[i]), thread_priority, K_PRIO_COOP(thread_priority)); @@ -277,18 +256,9 @@ void net_tc_rx_init(void) thread_priority = rx_tc2thread(i); rx_classes[i].tc = thread_priority; -#if defined(CONFIG_NET_SHELL) - /* Fix the thread start address so that "net stacks" - * command will print correct stack information. - */ - NET_STACK_GET_NAME(RX, rx_stack, 0)[i].stack = rx_stack[i]; - NET_STACK_GET_NAME(RX, rx_stack, 0)[i].prio = thread_priority; - NET_STACK_GET_NAME(RX, rx_stack, 0)[i].idx = i; -#endif - - NET_DBG("[%d] Starting RX queue %p stack %p size %zd " + NET_DBG("[%d] Starting RX queue %p stack size %zd " "prio %d (%d)", i, - &rx_classes[i].work_q.queue, RX_STACK(i), + &rx_classes[i].work_q.queue, K_THREAD_STACK_SIZEOF(rx_stack[i]), thread_priority, K_PRIO_COOP(thread_priority)); diff --git a/subsys/net/l2/ethernet/gptp/gptp.c b/subsys/net/l2/ethernet/gptp/gptp.c index 06f8c92684d..eaa85b8d222 100644 --- a/subsys/net/l2/ethernet/gptp/gptp.c +++ b/subsys/net/l2/ethernet/gptp/gptp.c @@ -30,7 +30,7 @@ LOG_MODULE_REGISTER(net_gptp, CONFIG_NET_GPTP_LOG_LEVEL); #error Maximum number of ports exceeded. (Max is 32). #endif -NET_STACK_DEFINE(GPTP, gptp_stack, NET_GPTP_STACK_SIZE, NET_GPTP_STACK_SIZE); +K_THREAD_STACK_DEFINE(gptp_stack, NET_GPTP_STACK_SIZE); K_FIFO_DEFINE(gptp_rx_queue); static k_tid_t tid;