net: use k_thread_create()

Common code in include/misc/stack.h is now used for analysis.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-05-09 12:09:34 -07:00 committed by Anas Nashif
commit 7a0782d8ee
5 changed files with 26 additions and 59 deletions

View file

@ -132,50 +132,16 @@ struct net_stack_info {
/** @cond ignore */
#if defined(CONFIG_INIT_STACKS)
#include <offsets.h>
#include <misc/stack.h>
static inline void net_analyze_stack_get_values(unsigned char *stack,
size_t size,
unsigned *stack_offset,
unsigned *pcnt,
unsigned *unused)
{
unsigned i;
*unused = 0;
/* The TCS is always placed on a 4-byte aligned boundary - if
* the stack beginning doesn't match that there will be some
* unused bytes in the beginning.
*/
*stack_offset = K_THREAD_SIZEOF + ((4 - ((unsigned)stack % 4)) % 4);
/* TODO
* Currently all supported platforms have stack growth down and there is no
* Kconfig option to configure it so this always build "else" branch.
* When support for platform with stack direction up (or configurable direction)
* is added this check should be confirmed that correct Kconfig option is used.
*/
#if defined(CONFIG_STACK_GROWS_UP)
for (i = size - 1; i >= *stack_offset; i--) {
if ((unsigned char)stack[i] == 0xaa) {
(*unused)++;
} else {
break;
}
}
#else
for (i = *stack_offset; i < size; i++) {
if ((unsigned char)stack[i] == 0xaa) {
(*unused)++;
} else {
break;
}
}
#endif
*unused = stack_unused_space_get(stack, size);
/* Calculate the real size reserved for the stack */
size -= *stack_offset;
*pcnt = ((size - *unused) * 100) / size;
}
@ -183,15 +149,14 @@ static inline void net_analyze_stack(const char *name,
unsigned char *stack,
size_t size)
{
unsigned stack_offset, pcnt, unused;
unsigned int pcnt, unused;
net_analyze_stack_get_values(stack, size, &stack_offset,
&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 + stack_offset, unused, size - unused, size, pcnt);
size, unused, size - unused, size, pcnt);
}
#else
#define net_analyze_stack(...)

View file

@ -59,7 +59,7 @@
NET_STACK_DEFINE(RX, rx_stack, CONFIG_NET_RX_STACK_SIZE,
CONFIG_NET_RX_STACK_SIZE + CONFIG_NET_RX_STACK_RPL);
static struct k_thread rx_thread_data;
static struct k_fifo rx_queue;
static k_tid_t rx_tid;
static K_SEM_DEFINE(startup_sync, 0, UINT_MAX);
@ -186,7 +186,7 @@ static void init_rx_queue(void)
{
k_fifo_init(&rx_queue);
rx_tid = k_thread_spawn(rx_stack, sizeof(rx_stack),
rx_tid = k_thread_create(&rx_thread_data, rx_stack, sizeof(rx_stack),
(k_thread_entry_t)net_rx_thread,
NULL, NULL, NULL, K_PRIO_COOP(8),
K_ESSENTIAL, K_NO_WAIT);

View file

@ -44,6 +44,7 @@ static sys_slist_t link_callbacks;
NET_STACK_DEFINE(TX, tx_stack, CONFIG_NET_TX_STACK_SIZE,
CONFIG_NET_TX_STACK_SIZE);
static struct k_thread tx_thread_data;
#if defined(CONFIG_NET_DEBUG_IF)
#define debug_check_packet(pkt) \
@ -1678,7 +1679,7 @@ void net_if_init(struct k_sem *startup_sync)
return;
}
k_thread_spawn(tx_stack, sizeof(tx_stack),
k_thread_create(&tx_thread_data, tx_stack, sizeof(tx_stack),
(k_thread_entry_t)net_if_tx_thread,
startup_sync, NULL, NULL, K_PRIO_COOP(7),
K_ESSENTIAL, K_NO_WAIT);

View file

@ -31,6 +31,7 @@ static K_SEM_DEFINE(network_event, 0, UINT_MAX);
NET_STACK_DEFINE(MGMT, mgmt_stack, CONFIG_NET_MGMT_EVENT_STACK_SIZE,
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;
static sys_slist_t event_callbacks;
@ -297,7 +298,7 @@ void net_mgmt_event_init(void)
CONFIG_NET_MGMT_EVENT_QUEUE_SIZE *
sizeof(struct mgmt_event_entry));
k_thread_spawn(mgmt_stack, sizeof(mgmt_stack),
k_thread_create(&mgmt_thread_data, mgmt_stack, sizeof(mgmt_stack),
(k_thread_entry_t)mgmt_thread, NULL, NULL, NULL,
K_PRIO_COOP(CONFIG_NET_MGMT_EVENT_THREAD_PRIO), 0, 0);

View file

@ -1302,7 +1302,7 @@ extern char _interrupt_stack[];
int net_shell_cmd_stacks(int argc, char *argv[])
{
#if defined(CONFIG_INIT_STACKS)
unsigned int stack_offset, pcnt, unused;
unsigned int pcnt, unused;
#endif
struct net_stack_info *info;
@ -1311,13 +1311,13 @@ int net_shell_cmd_stacks(int argc, char *argv[])
for (info = __net_stack_start; info != __net_stack_end; info++) {
net_analyze_stack_get_values(info->stack, info->size,
&stack_offset, &pcnt, &unused);
&pcnt, &unused);
#if defined(CONFIG_INIT_STACKS)
printk("%s [%s] stack size %zu/%zu bytes unused %u usage"
" %zu/%zu (%u %%)\n",
info->pretty_name, info->name, info->orig_size,
info->size + stack_offset, unused,
info->size, unused,
info->size - unused, info->size, pcnt);
#else
printk("%s [%s] stack size %zu usage not available\n",
@ -1327,19 +1327,19 @@ int net_shell_cmd_stacks(int argc, char *argv[])
#if defined(CONFIG_INIT_STACKS)
net_analyze_stack_get_values(_main_stack, CONFIG_MAIN_STACK_SIZE,
&stack_offset, &pcnt, &unused);
&pcnt, &unused);
printk("%s [%s] stack size %d/%d bytes unused %u usage"
" %d/%d (%u %%)\n",
"main", "_main_stack", CONFIG_MAIN_STACK_SIZE,
CONFIG_MAIN_STACK_SIZE + stack_offset, unused,
CONFIG_MAIN_STACK_SIZE, unused,
CONFIG_MAIN_STACK_SIZE - unused, CONFIG_MAIN_STACK_SIZE, pcnt);
net_analyze_stack_get_values(_interrupt_stack, CONFIG_ISR_STACK_SIZE,
&stack_offset, &pcnt, &unused);
&pcnt, &unused);
printk("%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 + stack_offset, unused,
CONFIG_ISR_STACK_SIZE, unused,
CONFIG_ISR_STACK_SIZE - unused, CONFIG_ISR_STACK_SIZE, pcnt);
#endif